read(); } catch (\Exception $e) {} if ($config !== null) { foreach ($config as $key=>$val) { try { $this->__set($key,$val); } catch (\Exception $e) {} } } } public function write($file=null) { $path = __DIR__."/../".$file; if ((file_exists($path) ? is_writable($path):is_writable(__DIR__."/../Config/"))) { $vars= get_object_vars($this); $cond = true; foreach($vars as $key=>$var) $cond &= !empty($var); if ($cond) { $file = fopen($path, 'w'); fwrite($file, json_encode($vars)); fclose($file); } } else { throw new \Exception(Translator::getInstance()->trans("Can't write file ").$file.". ". Translator::getInstance()->trans("Please change the rights on the file and/or directory.")); } } /** * @return array */ public static function read($file=null) { $path = __DIR__."/../".$file; $ret = null; if (is_readable($path)) { $json = json_decode(file_get_contents($path), true); if ($json !== null) { $ret = $json; } else { throw new \Exception(Translator::getInstance()->trans("Can't read file ").$file.". ". Translator::getInstance()->trans("The file is corrupted.")); } } elseif (!file_exists($path)) { throw new \Exception(Translator::getInstance()->trans("The file ").$file. Translator::getInstance()->trans(" doesn't exist. You have to create it in order to use this module. Please see module's configuration page.")); } else { throw new \Exception(Translator::getInstance()->trans("Can't read file ").$file.". ". Translator::getInstance()->trans("Please change the rights on the file.")); } return $ret; } /** * @param string $CMCIC_PAGE * @return $this */ public function setCMCICPAGE($CMCIC_PAGE) { $this->CMCIC_PAGE = $CMCIC_PAGE; return $this; } /** * @param string $CMCIC_KEY * @return $this */ public function setCMCICKEY($CMCIC_KEY) { $this->CMCIC_KEY = $CMCIC_KEY; return $this; } /** * @param string $CMCIC_CODESOCIETE * @return $this */ public function setCMCICCODESOCIETE($CMCIC_CODESOCIETE) { $this->CMCIC_CODESOCIETE = $CMCIC_CODESOCIETE; return $this; } /** * @param string $CMCIC_SERVEUR * @return $this */ public function setCMCICSERVER($CMCIC_SERVER) { $this->CMCIC_SERVER = $CMCIC_SERVER; return $this; } /** * @param string $CMCIC_TPE * @return $this */ public function setCMCICTPE($CMCIC_TPE) { $this->CMCIC_TPE = $CMCIC_TPE; return $this; } /** * @param string $CMCIC_VERSION * @return $this */ public function setCMCICVERSION($CMCIC_VERSION) { $this->CMCIC_VERSION = $CMCIC_VERSION; return $this; } }