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 function load(Reader $reader) { $databases = $reader->read(); foreach ($databases as $name => $datas) { // Check name if (!Validate::isVariableName($name)) { throw new \Exception('Name of database must be a valid variable name'); } // Check essential parameters if (!isset($datas['adaptater'])) { throw new \Exception('Miss adaptater config param for database : "' . $name . '"'); } if (!isset($datas['type'])) { throw new \Exception('Miss type config param for database : "' . $name . '"'); } if (!isset($datas['server'])) { throw new \Exception('Miss server config param for database : "' . $name . '"'); } // Create database instance $database = new DatabaseManager($name, $datas['type'], DatabaseManager::factory($datas['adaptater'], $name, 'framework\\database\\adaptaters', 'framework\\database\\IAdaptater')); // Fetch servers foreach ($datas['server'] as $server) { // extract server informations extract($server); // extract dsn if (isset($dsn)) { extract(Tools::parseDsn($dsn)); } // check required infos if (!isset($type)) { throw new \Exception('Miss server type'); } if (!isset($dbuser)) { throw new \Exception('Miss server dbuser type'); } if (!isset($dbpassword)) { throw new \Exception('Miss server dbpassword type'); } if (!isset($driver)) { throw new \Exception('Miss driver type'); } if (!isset($host)) { throw new \Exception('Miss server host type'); } if (!isset($port)) { throw new \Exception('Miss server port type'); } if (!isset($dbname)) { throw new \Exception('Miss server dbname type'); } if (!isset($charset)) { throw new \Exception('Miss server charset type'); } // Check driver is supported by database adaptater if (!$database->isValidDriver($driver)) { throw new \Exception('Invalid driver : "' . $driver . '", not supported database adaptater : "' . $datas['adaptater'] . '"'); } // Create server instance $serverInstance = new Server($type, $dbuser, $dbpassword, $driver, $host, $port, $dbname, $charset); if (isset($dsn)) { $serverInstance->setDsn($dsn, false); } // Add into servers list $database->addServer($serverInstance); //flush vars unset($type, $dbuser, $dbpassword, $driver, $host, $port, $dbname, $charset, $dsn, $serverInstance); } // Add database DatabaseManager::addDatabase($name, $database, true); } }
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); } }