Ejemplo n.º 1
0
 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;
     }
 }
Ejemplo n.º 2
0
 public function setName($name)
 {
     if (!Validate::isVariableName($name)) {
         throw new \Exception('Name parameter must be a valid variable name');
     }
     $this->_name = $name;
 }
Ejemplo n.º 3
0
 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);
     }
 }
Ejemplo n.º 4
0
 public function setFormName($name)
 {
     if (!Validate::isVariableName($name)) {
         throw new \Exception('Form name must be a valid variable name');
     }
     $this->_formName = $name;
 }
Ejemplo n.º 5
0
 public function init($params)
 {
     if (!is_array($params)) {
         throw new \Exception('Must be an array');
     }
     if (!isset($params['name']) || !is_string($params['name'])) {
         throw new \Exception('Miss name parameter, or is invalid');
     }
     $this->_name = $params['name'];
     if (isset($params['prefix'])) {
         if (!is_string($params['prefix']) || !Validate::isVariableName($params['prefix'])) {
             throw new \Exception('Must be a valid string');
         }
         $this->_prefix = $params['prefix'];
     }
     //garbage collector setting
     $gcType = isset($params['gc']) ? $params['gc'] : false;
     $gcOption = isset($params['gcOption']) ? $params['gcOption'] : null;
     $this->setGc($gcType, $gcOption);
     if (isset($params['groups'])) {
         //update prefixGroups
         $this->_prefixGroups = str_replace(',', '-', $params['groups'] . '-');
         $groups = explode(',', $params['groups']);
         $this->_groups = $groups;
     }
 }
Ejemplo n.º 6
0
 public function setName($name)
 {
     // Check name
     if (!Validate::isVariableName($name)) {
         throw new \Exception('Route name must be a valid variable');
     }
     $this->_name = $name;
 }
Ejemplo n.º 7
0
 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);
     }
 }
Ejemplo n.º 8
0
 public static function setVar($name, $value, $forceReplace = false)
 {
     if (!Validate::isVariableName($name)) {
         throw new \Exception('language var name must be a valid variable');
     }
     if (method_exists(self::$_languageVars, $name) && !$forceReplace) {
         throw new \Exception('language var already defined');
     }
     //put on vars
     self::$_languageVars->{$name} = $value;
 }
Ejemplo n.º 9
0
 public function addVar($varName, $varValue)
 {
     if (!Validate::isVariableName($varName)) {
         throw new \Exception('Var name must be a validate variable name');
     }
     //On verifie que la var n'a pas déja été définie
     for ($i = 0; $i < count($this->mailVars); $i++) {
         if ($varName == $this->mailVars[$i]['varName']) {
             throw new \Exception('Var : "' . $varName . '" is already defined');
         }
     }
     //On assimile les valeurs
     $this->mailVars[] = array('varName' => $varName, 'varValue' => $varValue);
     return $this;
 }
Ejemplo n.º 10
0
 public function __construct($options = array())
 {
     if (isset($options['trapName']) && Validate::isVariableName($options['trapName'])) {
         $this->_trapName = $options['trapName'];
     }
     if (isset($options['badCrawlerFile'])) {
         if (!file_exists($options['badCrawlerFile'])) {
             throw new \Exception('badCrawlerFile does\'t exists');
         }
         if (!Validate::isFileMimeType('xml', $options['badCrawlerFile'])) {
             throw new \Exception('goodCrawlerFile invalid format, must be xml');
         }
         $this->_badCrawlerFile = $options['badCrawlerFile'];
     }
     if (isset($options['goodCrawlerFile'])) {
         if (!file_exists($options['goodCrawlerFile'])) {
             throw new \Exception('goodCrawlerFile does\'t exists');
         }
         if (!Validate::isFileMimeType('xml', $options['goodCrawlerFile'])) {
             throw new \Exception('goodCrawlerFile invalid format, must be xml');
         }
         $this->_goodCrawlerFile = $options['goodCrawlerFile'];
     }
     if (isset($options['logBadCrawler'])) {
         if (!is_bool($options['logBadCrawler'])) {
             throw new \Exception('logBadCrawler parameter must be a boolean');
         }
         $this->_logBadCrawler = $options['logBadCrawler'];
     }
     if (isset($options['logGoodCrawler'])) {
         if (!is_bool($options['logGoodCrawler'])) {
             throw new \Exception('logGoodCrawler parameter must be a boolean');
         }
         $this->_logBadCrawler = $options['logGoodCrawler'];
     }
     if (isset($options['logUnknownCrawler'])) {
         if (!is_bool($options['logUnknownCrawler'])) {
             throw new \Exception('logUnknownCrawler parameter must be a boolean');
         }
         $this->_logUnknownCrawler = $options['logUnknownCrawler'];
     }
 }
Ejemplo n.º 11
0
 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);
     }
 }
Ejemplo n.º 12
0
 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);
     }
 }
Ejemplo n.º 13
0
 public function deleteVar($name)
 {
     if (!Validate::isVariableName($name)) {
         throw new \Exception('Name of variable must be a valid variable name');
     }
     if (!property_exists($this->_vars, $name)) {
         throw new \Exception('Variable : "' . $name . '" don\'t exists');
     }
     unset($this->_vars->{$name});
 }
Ejemplo n.º 14
0
 public function bind($value, $type = Database::PARAM_STR, $key = false, $isParam = false)
 {
     if (!is_bool($isParam)) {
         throw new \Exception('Is param must be a boolean');
     }
     if (!is_string($type) && !is_int($type)) {
         throw new \Exception('Type must be an integer or a string');
     }
     if (!array_key_exists($type, $this->_paramType)) {
         throw new \Exception('Type "' . $type . '" don\'t exist');
     }
     // If key setted, check if it's variable normalization format
     if ($key !== false && !Validate::isVariableName($key)) {
         throw new \Exception('Key for param must bet start with letter and can have caracters : a-zA-Z0-9_-');
     }
     // Search if is not mixed key format
     if ($key !== false && $this->_bindParamType === Database::PARAM_BIND_POSITIONAL) {
         throw new \Exception('You cannot mixed positionnal and named parameter');
     }
     if ($key === false && count($this->_params) > 0 && $this->_bindParamType === Database::PARAM_BIND_NAMED) {
         throw new \Exception('You cannot mixed positionnal and named parameter');
     }
     // Add datas on params array
     if ($key) {
         $this->_params[$key] = array('value' => $value, 'type' => $this->_paramType[$type], 'key' => $key, 'isParam' => $isParam);
     } else {
         $this->_params[] = array('value' => $value, 'type' => $this->_paramType[$type], 'key' => $key, 'isParam' => $isParam);
     }
     return $this;
 }
Ejemplo n.º 15
0
 public function lock($key)
 {
     if (!Validate::isVariableName($key)) {
         throw new \Exception('The key must be a valid key name');
     }
     $this->_lockedKeys[$key] = true;
 }