예제 #1
0
 public function endForm($csrfProtection = true)
 {
     $s = '';
     if ($csrfProtection) {
         $s .= '<input type="hidden" name="' . Factory::getRequest()->getCsrfToken() . '" value=1>';
     }
     $s .= '</form>';
     echo $s;
 }
예제 #2
0
 /**
  * initConfig
  * @param $config
  */
 public function __construct($config = array())
 {
     // Load config
     if (empty($config)) {
         ConfigHandler::get('session');
         // Read config from session key in config file
     }
     $this->_config = array_merge($this->_config, $config);
     if (isset($this->_config['storage']) && $this->_config['storage']) {
         $handlerClass = $this->_config['storage'];
         unset($this->_config['handler']);
         $storage = new $handlerClass($this->_config);
         session_set_save_handler(array(&$storage, 'open'), array(&$storage, 'close'), array(&$storage, 'read'), array(&$storage, 'write'), array(&$storage, 'destroy'), array(&$storage, 'gc'));
         self::$_storage = $storage;
     }
     if (isset($this->_config['name'])) {
         session_name($this->_config['name']);
     }
     ini_set('session.gc_maxlifetime', $this->_config['lifetime']);
     //define the lifetime of the cookie
     if (isset($this->_config['cookie_ttl']) || isset($this->_config['cookie_domain']) || isset($this->_config['cookie_path'])) {
         // cross subdomain validity is default behavior
         $ttl = isset($this->_config['cookie_ttl']) ? (int) $this->_config['cookie_ttl'] : 0;
         $domain = isset($this->_config['cookie_domain']) ? $this->_config['cookie_domain'] : '.' . Factory::getRouter()->getDomain();
         $path = isset($this->_config['cookie_path']) ? '/' . trim($this->_config['cookie_path'], '/') . '/' : '/';
         session_set_cookie_params($ttl, $path, $domain);
     } else {
         $cookie = session_get_cookie_params();
         session_set_cookie_params($cookie['lifetime'], $cookie['path'], $cookie['domain']);
     }
     if (Base::getApp()) {
         if (Factory::getRequest()->isSecure()) {
             ini_set('session.cookie_secure', true);
         }
     }
     ini_set('session.use_only_cookies', 1);
     if (isset($handlerClass)) {
         $this->dispatch('onAfterInitSessionConfig', new Event($this, array('handler' => $handlerClass)));
     } else {
         $this->dispatch('onAfterInitSessionConfig', new Event($this, array('handler' => 'default')));
     }
 }
 /**
  *
  */
 protected function _init()
 {
     define('TASK_DIR', APP_PATH . '/');
     ini_set('display_errors', ConfigHandler::get('debug') ? 'on' : 'off');
     //Error reporting
     if (Base::getEnv() == Base::ENV_DEV) {
         error_reporting(E_ALL);
     } else {
         if (Base::getEnv() == Base::ENV_TEST) {
             error_reporting(E_ALL ^ E_NOTICE);
         }
     }
     //set timezone
     if (ConfigHandler::has('timezone')) {
         date_default_timezone_set(ConfigHandler::get('timezone'));
     } else {
         date_default_timezone_set(@date_default_timezone_get());
     }
     if (true === $this->isCli()) {
         $argv = $_SERVER['argv'];
         $seek = 1;
         if (null == $this->_task) {
             $this->_task = $argv[$seek];
             ++$seek;
         }
         if (null == $this->_act && isset($argv[$seek])) {
             $this->_act = $argv[$seek];
             ++$seek;
         } else {
             $this->_act = 'default';
         }
         if (isset($argv[$seek])) {
             $this->_originalParams = array_slice($argv, $seek);
             $this->_params = $this->_process($this->_originalParams);
         }
     } else {
         //run on browser (only for test)
         if (null !== ($task = Factory::getRequest()->get('task'))) {
             $this->_task = $task;
         }
         if (null !== ($act = Factory::getRequest()->get('act'))) {
             $this->_act = $act;
         }
     }
 }
예제 #4
0
 /**
  * @return \Flywheel\Http\Request
  */
 public function request()
 {
     return Factory::getRequest();
 }
예제 #5
0
 protected function _setOptions()
 {
     if (isset($this->_config['session_name'])) {
         session_name($this->_config['session_name']);
     }
     if (isset($this->_config['session_id'])) {
         session_id($this->_config['session_id']);
     }
     //using cookie secure
     if (Base::getApp()) {
         if (Factory::getRequest()->isSecure()) {
             ini_set('session.cookie_secure', true);
         }
     }
     ini_set('session.gc_maxlifetime', $this->_config['lifetime']);
     ini_set('session.cookie_lifetime', $this->_config['lifetime']);
 }
 /**
  * Parses a URL based on this rule.
  * @param WebRouter $router the URL manager
  * @param string $pathInfo path info part of the URL
  * @param string $rawPathInfo path info that contains the potential URL suffix
  * @return mixed the route that consists of the controller ID and action ID or false on error
  */
 public function parseUrl($router, $pathInfo, $rawPathInfo)
 {
     $request = Factory::getRequest();
     if (isset($this->filter['method']) && is_array($this->filter['method']) && !in_array($request->getMethod(), $this->filter['method'], true)) {
         return false;
     }
     if (isset($this->options['urlSuffix']) && null !== $this->options['urlSuffix']) {
         $pathInfo = $router->removeUrlSuffix($rawPathInfo, $this->options['urlSuffix']);
     }
     $pathInfo .= '/';
     if (preg_match($this->pattern, $pathInfo, $matches)) {
         foreach ($this->initParameters as $name => $value) {
             if (!isset($_GET[$name])) {
                 $_REQUEST[$name] = $_GET[$name] = $value;
             }
         }
         $tr = array();
         foreach ($matches as $key => $value) {
             if (isset($this->references[$key])) {
                 $tr[$this->references[$key]] = $value;
             } else {
                 if (isset($this->params[$key])) {
                     $router->params[$key] = $_GET[$key] = $value;
                 }
             }
         }
         if ($pathInfo !== $matches[0]) {
             $router->parsePathInfo(ltrim(substr($pathInfo, strlen($matches[0])), '/'));
         }
         if ($this->routePattern !== null) {
             return strtr($this->route, $tr);
         } else {
             return $this->route;
         }
     } else {
         return false;
     }
 }