diff options
Diffstat (limited to 'app/Core')
-rw-r--r-- | app/Core/Registry.php | 83 | ||||
-rw-r--r-- | app/Core/Request.php | 14 | ||||
-rw-r--r-- | app/Core/Response.php | 2 | ||||
-rw-r--r-- | app/Core/Router.php | 20 | ||||
-rw-r--r-- | app/Core/Session.php | 2 | ||||
-rw-r--r-- | app/Core/Tool.php | 28 |
6 files changed, 35 insertions, 114 deletions
diff --git a/app/Core/Registry.php b/app/Core/Registry.php deleted file mode 100644 index d8b9063e..00000000 --- a/app/Core/Registry.php +++ /dev/null @@ -1,83 +0,0 @@ -<?php - -namespace Core; - -use RuntimeException; - -/** - * The registry class is a dependency injection container - * - * @property mixed db - * @property mixed event - * @package core - * @author Frederic Guillot - */ -class Registry -{ - /** - * Contains all dependencies - * - * @access private - * @var array - */ - private $container = array(); - - /** - * Contains all instances - * - * @access private - * @var array - */ - private $instances = array(); - - /** - * Set a dependency - * - * @access public - * @param string $name Unique identifier for the service/parameter - * @param mixed $value The value of the parameter or a closure to define an object - */ - public function __set($name, $value) - { - $this->container[$name] = $value; - } - - /** - * Get a dependency - * - * @access public - * @param string $name Unique identifier for the service/parameter - * @return mixed The value of the parameter or an object - * @throws RuntimeException If the identifier is not found - */ - public function __get($name) - { - if (isset($this->container[$name])) { - - if (is_callable($this->container[$name])) { - return $this->container[$name](); - } - else { - return $this->container[$name]; - } - } - - throw new \RuntimeException('Identifier not found in the registry: '.$name); - } - - /** - * Return a shared instance of a dependency - * - * @access public - * @param string $name Unique identifier for the service/parameter - * @return mixed Same object instance of the dependency - */ - public function shared($name) - { - if (! isset($this->instances[$name])) { - $this->instances[$name] = $this->$name; - } - - return $this->instances[$name]; - } -} diff --git a/app/Core/Request.php b/app/Core/Request.php index 1b643208..c7ca3184 100644 --- a/app/Core/Request.php +++ b/app/Core/Request.php @@ -125,6 +125,20 @@ class Request } /** + * Check if the page is requested through HTTPS + * + * Note: IIS return the value 'off' and other web servers an empty value when it's not HTTPS + * + * @static + * @access public + * @return boolean + */ + public static function isHTTPS() + { + return isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== '' && $_SERVER['HTTPS'] !== 'off'; + } + + /** * Return a HTTP header value * * @access public diff --git a/app/Core/Response.php b/app/Core/Response.php index 347cdde7..6534d64f 100644 --- a/app/Core/Response.php +++ b/app/Core/Response.php @@ -246,7 +246,7 @@ class Response */ public function hsts() { - if (Tool::isHTTPS()) { + if (Request::isHTTPS()) { header('Strict-Transport-Security: max-age=31536000'); } } diff --git a/app/Core/Router.php b/app/Core/Router.php index c9af6e2c..1750753c 100644 --- a/app/Core/Router.php +++ b/app/Core/Router.php @@ -2,6 +2,8 @@ namespace Core; +use Pimple\Container; + /** * Router class * @@ -27,24 +29,24 @@ class Router private $action = ''; /** - * Registry instance + * Container instance * * @access private - * @var \Core\Registry + * @var Pimple\Container */ - private $registry; + private $container; /** * Constructor * * @access public - * @param Registry $registry Registry instance - * @param string $controller Controller name - * @param string $action Action name + * @param Pimple\Container $container Container instance + * @param string $controller Controller name + * @param string $action Action name */ - public function __construct(Registry $registry, $controller = '', $action = '') + public function __construct(Container $container, $controller = '', $action = '') { - $this->registry = $registry; + $this->container = $container; $this->controller = empty($_GET['controller']) ? $controller : $_GET['controller']; $this->action = empty($_GET['action']) ? $action : $_GET['action']; } @@ -81,7 +83,7 @@ class Router return false; } - $instance = new $class($this->registry); + $instance = new $class($this->container); $instance->request = new Request; $instance->response = new Response; $instance->session = new Session; diff --git a/app/Core/Session.php b/app/Core/Session.php index 6028f0b9..e50c36b3 100644 --- a/app/Core/Session.php +++ b/app/Core/Session.php @@ -49,7 +49,7 @@ class Session self::SESSION_LIFETIME, $base_path ?: '/', null, - Tool::isHTTPS(), + Request::isHTTPS(), true ); diff --git a/app/Core/Tool.php b/app/Core/Tool.php index e54a0d3b..c010d932 100644 --- a/app/Core/Tool.php +++ b/app/Core/Tool.php @@ -2,6 +2,8 @@ namespace Core; +use Pimple\Container; + /** * Tool class * @@ -37,31 +39,17 @@ class Tool * * @static * @access public - * @param Core\Registry $registry DPI container - * @param string $name Model name + * @param Pimple\Container $container Container instance + * @param string $name Model name * @return mixed */ - public static function loadModel(Registry $registry, $name) + public static function loadModel(Container $container, $name) { - if (! isset($registry->$name)) { + if (! isset($container[$name])) { $class = '\Model\\'.ucfirst($name); - $registry->$name = new $class($registry); + $container[$name] = new $class($container); } - return $registry->shared($name); - } - - /** - * Check if the page is requested through HTTPS - * - * Note: IIS return the value 'off' and other web servers an empty value when it's not HTTPS - * - * @static - * @access public - * @return boolean - */ - public static function isHTTPS() - { - return isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== '' && $_SERVER['HTTPS'] !== 'off'; + return $container[$name]; } } |