예제 #1
0
파일: Session.php 프로젝트: hayate/hayate
 protected function __construct()
 {
     $this->config = Hayate_Config::load('session');
     $driver = isset($this->config->session->driver) ? $this->config->session->driver : 'native';
     switch ($driver) {
         case 'database':
             // can we get a db connection ?
             if (null === Hayate_Database::getInstance()) {
                 throw new Hayate_Exception(sprintf(_('%s cannot use "database" driver as it is unable' . ' to retrieve a valid database connection.'), __CLASS__));
             }
             $ses = Hayate_Session_Database::getInstance();
             session_set_save_handler(array($ses, 'open'), array($ses, 'close'), array($ses, 'read'), array($ses, 'write'), array($ses, 'destroy'), array($ses, 'gc'));
             break;
         case 'native':
             break;
         default:
             throw new Hayate_Exception(sprintf(_('Session driver: "%s" not supported.'), $driver));
     }
     // @see http://php.net/manual/en/function.session-write-close.php
     Hayate_Event::add('hayate.shutdown', 'session_write_close');
     ini_set('session.use_only_cookies', true);
     ini_set('session.use_trans_sid', 0);
     session_name($this->config->get('session.name', 'HayateSession'));
     // session will not work with a domain without top level
     $domain = $this->config->get('session.domain', $_SERVER['SERVER_NAME']);
     if (preg_match('/^\\.?.+\\.[a-z]{2,4}$/i', $domain) != 1) {
         $domain = '';
     }
     session_set_cookie_params((int) $this->config->get('session.lifetime', 0), $this->config->get('session.path', '/'), $domain, $this->config->get('session.secure', false), $this->config->get('session.httponly', false));
     session_start();
     Hayate_Log::info(sprintf(_('%s initialized.'), __CLASS__));
 }
예제 #2
0
파일: Router.php 프로젝트: hayate/hayate
 protected function __construct()
 {
     $config = Hayate_Config::load('routes', false);
     if ($config && isset($config->routes)) {
         $this->routes = $config->routes->getArrayCopy();
     }
     if (count($this->routes)) {
         $keys = array_keys($this->routes);
         $values = array_values($this->routes);
         array_walk($keys, array($this, 'trimSlash'));
         array_walk($values, array($this, 'trimSlash'));
         $this->routes = array_combine($keys, $values);
     }
     $base_path = array();
     if (isset($config->core->base_path)) {
         $base_path = preg_split('|/|', $config->core->base_path, -1, PREG_SPLIT_NO_EMPTY);
     }
     $segments = Hayate_URI::getInstance()->segments();
     for ($i = 0; $i < count($base_path); $i++) {
         if (isset($segments[$i]) && $segments[$i] == $base_path[$i]) {
             unset($segments[$i]);
         }
     }
     $this->path = $this->routed_path = implode('/', $segments);
 }
예제 #3
0
파일: Cookie.php 프로젝트: heromaeda/hayate
 protected function __construct()
 {
     Hayate_Crypto::getInstance();
     $this->config = Hayate_Config::load('cookie');
     $this->encrypt = isset($this->config->cookie->encrypt) ? (bool) $this->config->cookie->encrypt : false;
     $this->expire = isset($this->config->cookie->expire) ? $this->config->cookie->expire : 0;
     $this->path = isset($this->config->cookie->path) ? $this->config->cookie->path : '/';
     $this->domain = isset($this->config->cookie->domain) ? $this->config->cookie->domain : Hayate_URI::getInstance()->hostname();
     $this->secure = isset($this->config->cookie->secure) ? (bool) $this->config->cookie->secure : false;
     $this->httponly = isset($this->config->cookie->httponly) ? (bool) $this->config->cookie->httponly : false;
 }
예제 #4
0
파일: Database.php 프로젝트: hayate/hayate
 protected function __construct()
 {
     $this->config = Hayate_Config::load('session');
     $connName = $this->config->get('session.connection', 'default');
     $this->db = Hayate_Database::getInstance($connName);
     $this->crypto = null;
     // if we want the session encrypted, and the cookie does not
     // encrypt then we encrypt here otherwise we let the cookie class encrypt
     if ($this->config->get('session.encrypt', false)) {
         $this->crypto = Hayate_Crypto::getInstance();
     }
 }
예제 #5
0
파일: Log.php 프로젝트: hayate/hayate
 protected static function write($type, $msg, $print_r)
 {
     if (!$print_r && !is_string($msg)) {
         return self::write($type, $msg, true);
     }
     $config = Hayate_Config::load();
     $error_level = $config->get('error_level', self::HAYATE_LOG_OFF);
     if ($type <= $error_level) {
         $logdir = $config->get('log_directory', APPPATH . 'logs/', true);
         if (is_dir($logdir) && is_writable($logdir)) {
             $filename = $logdir . 'log-' . date('d-m-Y') . '.log';
             $logfile = new SplFileObject($filename, 'a');
             self::header($type, $logfile);
             if (true === $print_r) {
                 $msg = print_r($msg, true);
             }
             $logfile->fwrite($msg);
             self::footer($logfile);
         }
     }
 }
예제 #6
0
 private function __construct()
 {
     self::$hayatePath = dirname(dirname(__FILE__));
     $include_path = get_include_path() . PATH_SEPARATOR;
     $include_path .= self::$hayatePath . PATH_SEPARATOR;
     set_include_path($include_path);
     if (version_compare(PHP_VERSION, self::REQUIRED_PHP_VERSION) < 0) {
         require_once 'Hayate/Exception.php';
         throw new Hayate_Exception(sprintf(_('Hayate requires PHP >= %s, but %s is installed.'), self::REQUIRED_PHP_VERSION, PHP_VERSION));
     }
     // register error handler
     set_error_handler('Hayate_Bootstrap::error_handler');
     // register shutdown function, capture fatal errors
     register_shutdown_function('Hayate_Bootstrap::shutdown_function');
     // Hayate knows how to autoload its own classes
     if (false === spl_autoload_functions()) {
         if (function_exists('__autoload')) {
             spl_autoload_register('__autoload');
         }
     }
     spl_autoload_register('Hayate_Bootstrap::autoload');
     // register exception handler
     set_exception_handler(array(Hayate_Dispatcher::getInstance(), 'exceptionDispatch'));
     // load main config
     $config = Hayate_Config::load();
     // to autoload models class
     self::$modelsPath = $config->get('models_dir', array());
     if (false !== $config->get('display_errors', false)) {
         ini_set('display_errors', 'On');
     }
     if (false !== $config->get('error_reporting', false)) {
         error_reporting($config->core->error_reporting);
     }
     if ($config->get('timezone', false)) {
         date_default_timezone_set($config->core->timezone);
     }
     if ($config->get('charset', false)) {
         mb_internal_encoding($config->core->charset);
     }
     if ($config->get('locale', false)) {
         setLocale(LC_ALL, $config->core->locale);
     }
     if ($config->get('enable_hooks', false)) {
         // if present load application hooks
         $hook = APPPATH . 'hook.php';
         if (is_file($hook)) {
             require_once $hook;
         }
         foreach (self::modules() as $module) {
             $hookpath = MODPATH . $module . '/hook.php';
             if (is_file($hookpath)) {
                 require_once $hookpath;
             }
         }
     }
     // if present load this application bootstrap file
     $bs = APPPATH . 'bootstrap.php';
     if (is_file($bs)) {
         require_once $bs;
     }
 }