コード例 #1
0
ファイル: RegexRoute.php プロジェクト: johnnyos/johnnyos
 /**
  * Check if request matches this route.
  *
  * @param Request $request Request to check against.
  * @return bool
  */
 public function match(Request $request) : bool
 {
     // use absolute path
     if ($this->flags & self::UseAbsolutePath) {
         $path = $request->getPath();
         // use relative path
     } else {
         $path = $request->getRelativePath();
     }
     return (bool) preg_match(sprintf('/%s/', str_replace('/', '\\/', $this->path)), rawurldecode($path));
 }
コード例 #2
0
ファイル: GenericRoute.php プロジェクト: johnnyos/johnnyos
 /**
  * Check if request matches this route.
  *
  * @param Request $request Request to check against.
  * @return bool
  */
 public function match(Request $request) : bool
 {
     // use absolute path
     if ($this->flags & self::UseAbsolutePath) {
         $path = $request->getPath();
         // use relative path
     } else {
         $path = $request->getRelativePath();
     }
     return $this->path === rawurldecode($path);
 }
コード例 #3
0
 /**
  * Creates a Controller instance.
  *
  * @param Request $request Request data.
  * @param Response $response Response data.
  */
 public function __construct(Request $request, Response $response)
 {
     // split up request path
     $path = explode('/', trim($request->getRelativePath(), '/'));
     // first item is action
     $action = array_shift($path);
     // set action if not empty
     if (empty($action) === false) {
         $this->setAction($action);
     }
     $this->setParameters((array) $path)->execute($request, $response);
 }
コード例 #4
0
ファイル: DatabaseSession.php プロジェクト: johnnyos/johnnyos
 /**
  * Will be called on each newly-created object.
  *
  * @link https://php.net/manual/function.session-set-save-handler
  * @link https://php.net/manual/session.configuration
  * @param Database $db Database instance.
  * @param Request $request Request instance.
  * @return self
  */
 public function __construct(Database $db, Request $request)
 {
     // save database instance
     $this->db = $db;
     /**
      * Specifies the name of the session which is used as cookie name. It
      * should only contain alphanumeric characters. Defaults to PHPSESSID.
      */
     ini_set('session.name', static::NAME);
     /**
      * Specifies the number of seconds after which data will be seen as
      * 'garbage' and potentially cleaned up. Garbage collection may occur
      * during session start (depending on session.gc_probability and
      * session.gc_divisor).
      */
     ini_set('session.gc_maxlifetime', $this->getMaxLifetime());
     /**
      * In conjunction with session.gc_divisor is used to manage probability
      * that the gc (garbage collection) routine is started. Defaults to 1.
      * See session.gc_divisor for details.
      */
     ini_set('session.gc_probability', 1);
     /**
      * Coupled with session.gc_probability defines the probability that the
      * gc (garbage collection) process is started on every session
      * initialization. The probability is calculated by using gc_probability
      * /gc_divisor, e.g. 1/100 means there is a 1% chance that the GC
      * process starts on each request. session.gc_divisor defaults to 100.
      */
     ini_set('session.gc_divisor', 100);
     /**
      * Specifies whether the session module starts a session automatically
      * on request startup. Is not relevant to JohnnyOS as it tells PHP to
      * start a session before PHP starts to execute user-land code. Setting
      * during runtime has no effect.
      */
     // ini_set('session.auto_start', 1);
     /**
      * Marks the cookie as accessible only through the HTTP protocol. This
      * means that the cookie won't be accessible by scripting languages,
      * such as JavaScript. This setting can effectively help to reduce
      * identity theft through XSS attacks (although it is not supported by
      * all browsers).
      */
     ini_set('session.cookie_httponly', true);
     /**
      * Specifies the lifetime of the cookie in seconds which is sent to the
      * browser. The value 0 means "until the browser is closed." Defaults
      * to 0.
      */
     ini_set('session.cookie_lifetime', $this->getMaxLifetime());
     /**
      * Specifies whether cookies should only be sent over secure
      * connections. Defaults to off.
      */
     ini_set('session.cookie_secure', $request->getScheme() === 'https');
     /**
      * Specifies whether the module will only use cookies to store the
      * session id on the client side. Enabling this setting prevents
      * attacks involved passing session ids in URLs. This setting was added
      * in PHP 4.3.0. Defaults to 1 (enabled) since PHP 5.3.0.
      */
     ini_set('session.use_only_cookies', true);
     // register this instance as handler
     session_set_save_handler($this, true);
 }