public function setFormName($name) { if (!Validate::isVariableName($name)) { throw new \Exception('Form name must be a valid variable name'); } $this->_formName = $name; }
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; } }
public function shorten($longUrl, $returnFullReponse = false) { if (!Validate::isUrl($longUrl)) { throw new \Exception('longUrl parameter must be a valid url'); } if (!is_bool($returnFullReponse)) { throw new \Exception('returnFullReponse parameter must be an boolean'); } $curl = new Curl($this->getApiUrl()); if ($this->getApiKey()) { $curl->addArgument('key', $this->getApiKey(), 'GET'); } $curl->addArgument('longUrl', $longUrl, 'POST'); $curl->setCurlOpt(CURLOPT_HTTPHEADER, array('Content-type: application/json')); $curl->execute(true, false, false, true); $reponse = json_decode($curl->getResponse()); if ($returnFullReponse) { return $reponse; } else { if (isset($reponse->error)) { Logger::getInstance()->debug('Goo.gl shorten url error, code : "' . $reponse->error->code . '" and message : "' . $reponse->error->message . '"'); return false; } else { Logger::getInstance()->debug('Goo.gl shorten url : "' . $longUrl . '" result is : "' . $reponse->id . '"'); return $reponse->id; } } }
public function shorten($longUrl, $returnFullReponse = false) { if (!Validate::isUrl($longUrl)) { throw new \Exception('Url parameter must be a valid url'); } if (!is_bool($returnFullReponse)) { throw new \Exception('returnFullReponse parameter must be an boolean'); } $curl = new Curl($this->getApiUrl() . 'shorten'); $curl->addArgument('version', $this->getApiVersion(), 'GET'); $curl->addArgument('longUrl', $longUrl, 'GET'); $curl->addArgument('login', $this->getApiLogin(), 'GET'); $curl->addArgument('apiKey', $this->getApiKey(), 'GET'); $curl->execute(true); $reponse = json_decode($curl->getResponse()); if ($returnFullReponse) { return $reponse; } else { if ($reponse->errorCode != 0) { throw new \Exception('Bit.Ly shorten url error, code : "' . $reponse->errorCode . '" and message : "' . $reponse->errorMessage . '"'); } if ($reponse->statusCode == 'OK') { Logger::getInstance()->debug('Bit.Ly shorten url : "' . $longUrl . '" result is : "' . $reponse->results->{$longUrl}->shortUrl . '"'); return $reponse->results->{$longUrl}->shortUrl; } return false; } }
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) { $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 setName($name) { if (!Validate::isVariableName($name)) { throw new \Exception('Name parameter must be a valid variable name'); } $this->_name = $name; }
public function setCharset($charset) { if (!Validate::isCharset($charset)) { throw new \Exception('Charset in\'t a valid charset type'); } $this->_charset = $charset; }
public static function getServerResponse($url = null, $format = false, $onlyResponseCode = false, $checkIfSent = false) { if (!is_bool($checkIfSent)) { throw new \Exception('CheckIfSent parameter must be an boolean'); } if (!is_bool($onlyResponseCode)) { throw new \Exception('onlyResponseCode parameter must be an boolean'); } if ($onlyResponseCode) { return self::getHeaderResponseStatusCode(); } if (is_null($url)) { $request = Http::getRootRequest(); $url = Http::isHttps() ? 'https://' . $request : 'http://' . $request; } if (!Validate::isUrl($url)) { throw new \Exception('Url must be a valid url'); } if (!is_bool($format)) { throw new \Exception('Format parameter must be an boolean'); } $response = $checkIfSent ? headers_sent() ? get_headers($url, $format) : null : get_headers($url, $format); if (!$response && !$checkIfSent) { throw new \Exception('Error while get headers response status'); } return $response; }
public function setName($name) { // Check name if (!Validate::isVariableName($name)) { throw new \Exception('Route name must be a valid variable'); } $this->_name = $name; }
protected function _check($ip, $userAgent) { if (Http::getQuery($this->_trapName) && !Validate::isGoogleBot()) { $isBadCrawler = false; $isGoodCrawler = false; if ($this->_badCrawlerFile) { $badCrawlerXml = simplexml_load_file($this->_badCrawlerFile); if (is_null($badCrawlerXml) || !$badCrawlerXml) { throw new \Exception('Invalid xml file : "' . $this->_badCrawlerFile . '"'); } } if ($this->_goodCrawlerFile) { $goodCrawlerXml = simplexml_load_file($this->_goodCrawlerFile); if (is_null($goodCrawlerXml) || !$goodCrawlerXml) { throw new \Exception('Invalid xml file : "' . $this->_goodCrawlerFile . '"'); } } if ($badCrawlerXml) { $badCrawlerList = $badCrawlerXml->crawler; foreach ($badCrawlerList as $crawler) { if (isset($crawler->ip) && (string) $crawler->ip == $ip) { $isBadCrawler = true; } if (isset($crawler->userAgent) && strripos((string) $crawler->userAgent, $userAgent) !== false) { $isBadCrawler = true; } if ($isBadCrawler) { $this->_catch($ip, $userAgent, self::CRAWLER_BAD); Session::getInstance()->add(md5($ip . 'badcrawler'), true, true, true); Router::getInstance()->show403(true); break; } } unset($crawler); } if ($goodCrawlerXml) { $goodCrawlerList = $goodCrawlerXml->crawler; foreach ($goodCrawlerList as $crawler) { if (isset($crawler->ip) && (string) $crawler->ip == $ip) { $isGoodCrawler = true; } if (isset($crawler->userAgent) && strripos((string) $crawler->userAgent, $userAgent) !== false) { $isGoodCrawler = true; } if ($isGoodCrawler) { $this->_catch($ip, $userAgent, self::CRAWLER_BAD); break; } } unset($crawler); } // unknown if (!$isBadCrawler && !$isGoodCrawler) { $this->_catch($ip, $userAgent, self::CRAWLER_BAD); } } }
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 __construct($filename) { if (!file_exists($filename)) { throw new \Exception('File : "' . $filename . '" not exists'); } if (!is_readable($filename)) { throw new \Exception('File : "' . $filename . '" is not readable'); } if (!Validate::isFileMimeType('xml', $filename)) { throw new \Exception('File : "' . $filename . '" is not a xml file'); } $this->_filename = $filename; }
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; }
public function view($slug) { $new = $this->_read('new', $slug); if (is_null($new)) { $this->router->show404(true); } $this->tpl->setVar('new', $new, false, true); $this->tpl->setVar('title', ucfirst($new->langTitle->{$this->tpl->lang}), false, true); if (!Validate::isEmpty($new->langDescr->{$this->tpl->lang})) { $this->tpl->setVar('desc', ucfirst($new->langDescr->{$this->tpl->lang}), false, true); } if (!Validate::isEmpty($new->langKeywords->{$this->tpl->lang})) { $this->tpl->setVar('keywords', $new->langKeywords->{$this->tpl->lang}, false, true); } $this->tpl->setFile('controllers' . DS . 'News' . DS . 'new.tpl.php'); }
public function __construct($mailConfig) { SwiftMailer::getInstance(); //Set mail config if (!is_array($mailConfig)) { throw new \Exception('mailConfig parameter must be an array'); } // sender params if (!isset($mailConfig['fromEmail'])) { throw new \Exception('fromEmail parameter don\'t exists'); } if (!Validate::isEmail($mailConfig['fromEmail'])) { throw new \Exception('fromEmail parameter must be a valid email'); } $this->_mailConfig['fromEmail'] = $mailConfig['fromEmail']; if (!isset($mailConfig['fromName'])) { throw new \Exception('fromName parameter don\'t exists'); } if (!is_string($mailConfig['fromName'])) { throw new \Exception('fromName parameter must be a string'); } $this->_mailConfig['fromName'] = $mailConfig['fromName']; // receiver params if (!isset($mailConfig['toEmail'])) { throw new \Exception('toEmai parameter don\'t exists'); } if (!Validate::isEmail($mailConfig['toEmail'])) { throw new \Exception('toEmail parameter must be a valid email'); } $this->_mailConfig['toEmail'] = $mailConfig['toEmail']; if (!isset($mailConfig['toName'])) { throw new \Exception('toName parameter don\'t exists'); } if (!is_string($mailConfig['fromName'])) { throw new \Exception('fromName parameter must be a string'); } $this->_mailConfig['toName'] = $mailConfig['toName']; //Optional subject of mail params if (isset($mailConfig['mailSubject'])) { if (!is_string($mailConfig['mailSubject'])) { throw new \Exception('mailSubject parameter must be a string'); } $this->_mailConfig['mailSubject'] = $mailConfig['mailSubject']; } }
public function setLanguage($language, $setAsDefault = false) { if (!Validate::isLanguage($language)) { throw new \Exception('Invalid lang format'); } Logger::getInstance()->debug('Try load language : "' . $language . '"', 'language'); //check datas files $file = self::getDatasPath() . $language . '.xml'; if (!file_exists($file)) { if (!$setAsDefault) { Logger::getInstance()->debug('Invalid lang : "' . $language . '", have not xml datas file', 'language'); return; } throw new \Exception('Invalid lang : "' . $language . '", have not xml datas file'); } $xml = simplexml_load_file($file); if (is_null($xml) || !$xml) { throw new \Exception('Invalid lang : "' . $language . '" invalid xml file'); } Logger::getInstance()->debug('Load datas file : "' . $file . '"', 'language'); //delete comment unset($xml->comment); // set language self::$_languageVars = $xml; $this->_language = $language; if ($setAsDefault) { $this->_defaultLanguage = $this->_language; self::$_defaultLanguageVars = self::$_languageVars; Logger::getInstance()->debug('Language : "' . $this->_language . '" defined as default', 'language'); } //Check if alls vars defined if ($this->_defaultLanguage != $this->_language) { foreach (self::$_defaultLanguageVars as $name => $value) { if (!property_exists(self::$_languageVars, $name)) { Logger::getInstance()->debug('Miss language var : "' . $name . '" on new language : "' . $language . '"', 'language'); // restore var, by default language self::$_languageVars->{$name} = self::$_defaultLanguageVars->{$name}; } } } Logger::getInstance()->debug('Current language is : "' . $this->_language . '"', 'language'); }
public function setUrl($url) { if (!$this->_getCurlInitialized()) { throw new \Exception('Curl must be initialized'); } if (!is_string($url)) { throw new \Exception('Url parameter must be a string'); } if (!Validate::isUrl($url)) { throw new \Exception('Url parameter must be a valid url'); } if (Validate::isUrl($url, true)) { if (!$this->getAllowSsl()) { throw new \Exception('SSL url cannot be used'); } $this->setCurlOpt(CURLOPT_SSL_VERIFYPEER, false); $this->setCurlOpt(CURLOPT_SSL_VERIFYHOST, 2); } $this->_url = $url; }
public function view($slug) { $page = $this->_read('page', $slug); //check if exists if (is_null($page)) { $this->router->show404(true); } //define vars and template $this->tpl->setVar('page', $page, false, true); $this->tpl->setVar('title', ucfirst($page->langTitle->{$this->tpl->lang}), false, true); if (!Validate::isEmpty($page->langDescr->{$this->tpl->lang})) { $this->tpl->setVar('desc', ucfirst($page->langDescr->{$this->tpl->lang}), false, true); } if (!Validate::isEmpty($page->langKeywords->{$this->tpl->lang})) { $this->tpl->setVar('keywords', $page->langKeywords->{$this->tpl->lang}, false, true); } $this->tpl->setFile('controllers' . DS . 'Pages' . DS . 'page.tpl.php'); //run custom function for required pages (news, home, contact) $this->_defaultPage($slug); }
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; }
public function setAudioNoiseFile($noiseFile) { if (!file_exists($noiseFile) || !is_readable($noiseFile) || !Validate::isFileMimeType('wav', $noiseFile)) { throw new \Exception('Invalid audio noise file, must be an readable wav file'); } $this->_audioNoiseFile = $noiseFile; }
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 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}); }
public function minify($returnContent = true, $forceCacheUpdate = false) { // autoloading files foreach (Tools::cleanScandir($this->getPath()) as $file) { if (Validate::isFileExtension($this->_type, $file)) { $this->addFile($this->getPath() . $file); } } $this->_key = md5($this->_name . Router::getHost(true, Http::isHttps()) . $this->getPath()); if ($this->_cacheExpired() || $forceCacheUpdate) { $this->_generateCache(); } if ($returnContent) { return $this->getContent(); } }
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 lock($key) { if (!Validate::isVariableName($key)) { throw new \Exception('The key must be a valid key name'); } $this->_lockedKeys[$key] = true; }