예제 #1
0
파일: Smarty.php 프로젝트: heromaeda/hayate
 protected function __construct()
 {
     $config = Hayate_Config::getInstance();
     if ((!$config->get('view', false) || !isset($config->core->view['smarty_dir'])) && !class_exists('Smarty', false)) {
         throw new Hayate_View_Exception(_('smarty_dir configuration parameter missing.'));
     }
     if (!class_exists('Smarty', false)) {
         require_once rtrim($config->core->view['smarty_dir'], '\\/') . '/Smarty.class.php';
     }
     // finally we can instantiate
     $this->smarty = new Smarty();
     // and set the properties values
     $ro = new ReflectionObject($this->smarty);
     foreach ($config->core->view as $prop => $val) {
         if ($ro->hasProperty($prop)) {
             $this->smarty->{$prop} = $val;
         }
     }
     /*
             if (version_compare($this->smarty->_version, '3.0') < 0)
             {
                 $this->is_smarty_2 = true;
             }
     */
 }
예제 #2
0
파일: Crypto.php 프로젝트: hayate/hayate
 private function __construct()
 {
     if (!function_exists('mcrypt_module_open')) {
         throw new Hayate_Exception(sprintf(_('%s: mcrypt extension is missing.'), __CLASS__));
     }
     switch (self::ALGO) {
         case 'aes':
             $algo = MCRYPT_RIJNDAEL_256;
             break;
         case 'tripledes':
             $algo = MCRYPT_TRIPLEDES;
             break;
         case 'blowfish':
             $algo = MCRYPT_BLOWFISH;
             break;
         default:
             throw new Hayate_Exception(sprintf(_('%s is not supported, please use "aes", "tripledes" or "blowfish"'), self::ALGO));
     }
     // initialize mcrypt
     $this->mcrypt = mcrypt_module_open($algo, '', MCRYPT_MODE_CBC, '');
     // calculate IV size
     $this->ivsize = mcrypt_enc_get_iv_size($this->mcrypt);
     // calculate key max key length
     $this->maxKeysize = mcrypt_enc_get_key_size($this->mcrypt);
     $config = Hayate_Config::getInstance();
     if ($config->get('core.secret_key', false)) {
         $this->setKey($config->core->secret_key);
     }
 }
예제 #3
0
파일: URI.php 프로젝트: hayate/hayate
 protected function __construct()
 {
     $this->config = Hayate_Config::getInstance();
     $this->current = $this->scheme() . '://' . $this->hostname() . '/' . $this->path() . $this->query(true);
     $this->segments = preg_split('|/|', $this->path(), -1, PREG_SPLIT_NO_EMPTY);
     // make sure all segments are lower case
     $this->segments = array_map('mb_strtolower', $this->segments);
 }
예제 #4
0
파일: Database.php 프로젝트: hayate/hayate
 public static function getInstance($name = 'default')
 {
     if (isset(self::$db[$name])) {
         return self::$db[$name];
     }
     $config = Hayate_Config::getInstance()->get('database.' . $name, null);
     if (null === $config) {
         throw new Hayate_Database_Exception(sprintf(_('Database config "%s" not found.'), $name));
     }
     self::$db[$name] = new Hayate_Database_Pdo($config);
     return self::$db[$name];
 }
예제 #5
0
파일: Input.php 프로젝트: heromaeda/hayate
 protected function __construct()
 {
     $this->params = array('get' => array(), 'post' => array(), 'cookie' => array(), 'put' => array(), 'rawput' => array());
     if (Hayate_Config::getInstance()->get('xss_clean', true)) {
         foreach ($_GET as $key => $val) {
             $this->params['get'][$key] = htmlentities($val, ENT_QUOTES, 'utf-8');
         }
         foreach ($_POST as $key => $val) {
             $this->params['post'][$key] = htmlentities($val, ENT_QUOTES, 'utf-8');
         }
         foreach ($_COOKIE as $key => $val) {
             $this->params['cookie'][$key] = htmlentities($val, ENT_QUOTES, 'utf-8');
         }
     }
     if (Hayate_Request::getInstance()->isPut()) {
         $this->loadPut();
     }
 }
예제 #6
0
파일: Validator.php 프로젝트: hayate/hayate
 /**
  * @param string $field The field name
  * @param array $params Min and Max values respective at position 0 and 1 of the array
  */
 protected function size($field, array $params)
 {
     if (array_key_exists($field, $this)) {
         $charset = Hayate_Config::getInstance()->get('charset', 'UTF-8');
         $min = $params[0];
         $max = $params[1];
         return mb_strlen($this[$field], $charset) >= $min && mb_strlen($this[$field], $charset) <= $max;
     }
     return true;
 }
예제 #7
0
파일: View.php 프로젝트: heromaeda/hayate
 protected static function factory()
 {
     $config = Hayate_Config::getInstance()->get('view', array('name' => 'native'));
     if (isset($config['name'])) {
         switch ($config['name']) {
             case 'smarty':
                 return Hayate_View_Smarty::getInstance();
             case 'native':
                 return Hayate_View_Native::getInstance();
             default:
                 throw new Hayate_View_Exception(_('Supported views are "smarty" and "native".'));
         }
     }
     throw new Hayate_View_Exception(_('View name is missing.'));
 }
예제 #8
0
 public static function modules()
 {
     $config = Hayate_Config::getInstance();
     $modules = $config->get('modules', array());
     $modules[] = $config->get('default_module', 'default');
     return $modules;
 }
예제 #9
0
 public function exceptionDispatch(Exception $ex)
 {
     try {
         if (Hayate_Event::run('hayate.exception', array($this, $ex))) {
             return;
         }
         // try to dispatch to the current module error.php controller
         $module = $this->module();
         $filepath = $this->modulesPath . $module . '/controllers/error.php';
         // if the error controller does not exists in the current module
         // look in the default module
         if (!is_file($filepath)) {
             $module = Hayate_Config::getInstance()->get('default_module', 'default');
             $filepath = $this->modulesPath . $module . '/controllers/error.php';
         }
         if (is_file($filepath)) {
             require_once $filepath;
             $classname = ucfirst($module) . '_ErrorController';
             $rfc = new ReflectionClass($classname);
             if ($rfc->isSubclassOf('Hayate_Controller') && $rfc->isInstantiable()) {
                 $controller = $rfc->newInstance();
                 $action = $rfc->hasMethod('index') ? $rfc->getMethod('index') : $rfc->getMethod('__call');
                 if ($action->isPublic()) {
                     $action->invokeArgs($controller, array($ex));
                 }
             }
         } else {
             $display_errors = Hayate_Config::getInstance()->get('display_errors', false);
             if ($display_errors && $this->errorReporter) {
                 Hayate_Event::remove('hayate.send_headers');
                 Hayate_Event::remove('hayate.render');
                 $this->errorReporter->setException($ex);
                 echo $this->errorReporter->report();
             }
         }
     } catch (Exception $ex) {
     }
 }
예제 #10
0
파일: Cookie.php 프로젝트: heromaeda/hayate
 /**
  * @param string $name The name of the cookie
  * @param mixed $default If $name is not set this value is returned
  * @param bool $xss_clean If boolean it will overwrite the configuration settings (prevent xss attacts)
  * @return mixed The value of the cookie
  */
 public function get($name, $default = null, $xss_clean = null)
 {
     if (!$this->exists($name)) {
         return $default;
     }
     $ans = $_COOKIE[$name];
     if ($this->encrypt) {
         $crypto = Hayate_Crypto::getInstance();
         $ans = $crypto->decrypt($ans);
     }
     $xss = Hayate_Config::getInstance()->get('xss_clean', false);
     if (is_bool($xss_clean)) {
         $xss = $xss_clean;
     }
     return $xss ? htmlentities($ans, ENT_QUOTES, 'utf-8') : $ans;
 }
예제 #11
0
파일: Cookie.php 프로젝트: hayate/hayate
 /**
  * @param string $name The name of the cookie
  * @param mixed $default If $name is not set this value is returned
  * @param bool $xss_clean If boolean it will overwrite the configuration settings (prevent xss attacts)
  * @return mixed The value of the cookie
  */
 public function get($name, $default = null, $xss_clean = null)
 {
     if (!array_key_exists($name, $_COOKIE)) {
         return $default;
     }
     $ans = $_COOKIE[$name];
     if ($this->encrypt) {
         $crypto = Hayate_Crypto::getInstance();
         $ans = $crypto->decrypt($ans);
     }
     $xss = Hayate_Config::getInstance()->get('xss_clean', false);
     if (is_bool($xss_clean)) {
         $xss = $xss_clean;
     }
     $ans = unserialize($ans);
     return is_string($ans) && $xss ? htmlspecialchars($ans, ENT_QUOTES, Hayate_Config::getInstance()->get('charset', 'UTF-8')) : $ans;
 }