public function load(Reader $reader) { $caches = $reader->read(); foreach ($caches as $cacheName => $cacheValue) { // Check name if (!Validate::isVariableName($cacheName)) { throw new \Exception('Name of cache must be a valid variable name'); } // Check options $params = array(); foreach ($cacheValue as $name => $value) { // no use comment (for xml file) if ($name == 'comment') { continue; } // cast if (is_string($value)) { $value = Tools::castValue($value); } // add value into cache parameters $params[$name] = $value; } // check adaptater if (!isset($params['adaptater'])) { throw new \Exception('Miss adaptater parameter for cache : "' . $cacheName . '"'); } // Add param name $params['name'] = $cacheName; // Add cache CacheManager::addCache($cacheName, CacheManager::factory($params['adaptater'], $params, 'framework\\cache\\adaptaters', 'framework\\cache\\IAdaptater'), true); } }
public function load(Reader $reader) { $constants = $reader->read(); foreach ($constants as $name => $value) { // Check name if (!Validate::isVariableName($name)) { throw new \Exception('Name of constant must be a valid variable name'); } // Check if is already loaded if (array_key_exists($name, self::$_constants)) { // If is already defined => next if (defined($name)) { Logger::getInstance()->debug('Constant : "' . $name . '" already defined'); continue; } Logger::getInstance()->debug('Constant : "' . $name . '" already load, was overloaded'); } if (is_array($value)) { if (empty($value)) { $value = null; } else { throw new \Exception('Constant value cannot be an array'); } } // Cast value if (is_string($value)) { $value = Tools::castValue($value); } // Add self::$_constants[$name] = $value; } }
public function load(Reader $reader) { $security = $reader->read(); foreach ($security as $type => $datas) { $securityData = array(); if (isset($datas['autorun']) && is_string($datas['autorun'])) { $securityData['autorun'] = Tools::castValue($datas['autorun']); } elseif (!isset($datas['autorun'])) { $securityData['autorun'] = false; } //default value foreach ($datas as $name => $value) { if ($name == 'autorun' || $name == 'comment' || $name == 'form') { continue; } if (is_string($value)) { $value = Tools::castValue($value); } $securityData[$name] = $value; } //formulaires (for Form api) if (isset($datas['form'])) { $securityData = array(); foreach ($datas['form'] as $formName => $formDatas) { if (!Validate::isVariableName($formName)) { throw new \Exception('Security form name must be a valid variable'); } $form = new \stdClass(); $form->name = $formName; if (isset($formDatas['protection'])) { $protections = array(); foreach ($formDatas['protection'] as $protectionType => $protectionDatas) { if (is_array($protectionDatas)) { foreach ($protectionDatas as $optionName => $optionValue) { if ($optionName == 'comment') { continue; } if (is_string($optionValue)) { $protectionDatas[$optionName] = Tools::castValue($optionValue); } } } if (is_string($value)) { $value = Tools::castValue($value); } $protections[$protectionType] = $protectionDatas; } } $form->protections = $protections; $securityData[] = $form; } } SecurityManager::addSecurity($type, array('autorun' => $datas['autorun'], 'datas' => $securityData), true); } }
public static function getVar($varName, $default = null) { if (!Validate::isVariableName($varName)) { throw new \Exception('language var name : "' . $varName . '"must be a valid variable'); } if (!property_exists(self::$_languageVars, $varName)) { Logger::getInstance()->debug('Language var ' . $varName . ' is not setted'); return $default; } else { return Tools::castValue((string) self::$_languageVars->{$varName}); } }
public function load(Reader $reader) { $routes = $reader->read(); foreach ($routes as $name => $datas) { // Check name if (!Validate::isVariableName($name)) { throw new \Exception('Route name must be a valid variable'); } // Check controller info if (!isset($datas['controller'])) { throw new \Exception('Miss controller into route "' . $name . '"'); } // create instance of route $route = new RouterRoute($name, $datas['controller']); // Optionnals parameters if (isset($datas['regex'])) { $route->setRegex(Tools::castValue($datas['regex'])); } if (isset($datas['requireSsl'])) { $route->setRequireSsl(Tools::castValue($datas['requireSsl'])); } if (isset($datas['requireAjax'])) { $route->setRequireAjax(Tools::castValue($datas['requireAjax'])); } if (isset($datas['autoSetAjax'])) { $route->setAutoSetAjax(Tools::castValue($datas['autoSetAjax'])); } if (isset($datas['requireHttpMethod'])) { $route->setRequireHttpMethod(Tools::castValue($datas['requireHttpMethod'])); } if (isset($datas['httpResponseStatusCode'])) { $route->setHttpResponseStatusCode(Tools::castValue($datas['httpResponseStatusCode'])); } if (isset($datas['httpProtocol'])) { $route->setHttpProtocol(Tools::castValue($datas['httpProtocol'])); } if (isset($datas['rules'])) { if (is_array($datas['rules'])) { if (isset($datas['rules']['rule']) && is_array($datas['rules']['rule'])) { $datas['rules'] = $datas['rules']['rule']; } } $route->setRules($datas['rules']); } if (isset($datas['methods'])) { if (is_array($datas['methods'])) { $methods = $datas['methods']; foreach ($methods as $method => $val) { //no have parameters, replace wtih empty parameters list if (is_int($method)) { //TODO fix : replace methode into good order unset($methods[$method]); $methods[$val] = array(); } } $route->setMethods($methods); } } // Add into router Router::addRoute($route, true); } }
public function __construct($options = array()) { if (isset($options['dataFile'])) { if (!file_exists($options['dataFile']) || !Validate::isFileMimeType('xml', $options['dataFile'])) { throw new \Exception('Security captcha invalid data file'); } $xml = simplexml_load_file($options['dataFile']); if (is_null($xml) || !$xml) { throw new \Exception('Security captcha invalid data xml file : "' . $options['dataFile'] . '"'); } // Casting options into xml data file $optionsData = $xml->option; $optionsLoaded = array(); foreach ($optionsData as $option) { $optionsLoaded[(string) $option->name] = Tools::castValue((string) $option->value); } // merge $options = array_merge_recursive($options, $optionsLoaded); } if (!isset($options['refreshUrl'])) { throw new \Exception('Miss refresh url name'); } $this->_refreshUrl = $options['refreshUrl']; if (isset($options['charsList'])) { $this->setCharsList($options['charsList']); } if (isset($options['length'])) { $this->setLength($options['length']); } // Image options if (isset($options['image'])) { $this->setImage($options['image'], $options); } // Audio options if (isset($options['audio'])) { $this->setAudio($options['audio'], $options); } }