Skip to content

Commit

Permalink
Use Pimple instead of Core\Registry and add Monolog for logging
Browse files Browse the repository at this point in the history
  • Loading branch information
fguillot committed Nov 15, 2014
1 parent 1487cb2 commit b081288
Show file tree
Hide file tree
Showing 57 changed files with 549 additions and 593 deletions.
20 changes: 10 additions & 10 deletions app/Action/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Action;

use Pimple\Container;
use Core\Listener;
use Core\Registry;
use Core\Tool;

/**
Expand Down Expand Up @@ -44,12 +44,12 @@ abstract class Base implements Listener
protected $event_name = '';

/**
* Registry instance
* Container instance
*
* @access protected
* @var \Core\Registry
* @var Pimple\Container
*/
protected $registry;
protected $container;

/**
* Execute the action
Expand Down Expand Up @@ -101,13 +101,13 @@ abstract public function hasRequiredCondition(array $data);
* Constructor
*
* @access public
* @param \Core\Registry $registry Regsitry instance
* @param integer $project_id Project id
* @param string $event_name Attached event name
* @param Pimple\Container $container Container
* @param integer $project_id Project id
* @param string $event_name Attached event name
*/
public function __construct(Registry $registry, $project_id, $event_name)
public function __construct(Container $container, $project_id, $event_name)
{
$this->registry = $registry;
$this->container = $container;
$this->project_id = $project_id;
$this->event_name = $event_name;
}
Expand All @@ -132,7 +132,7 @@ public function __toString()
*/
public function __get($name)
{
return Tool::loadModel($this->registry, $name);
return Tool::loadModel($this->container, $name);
}

/**
Expand Down
20 changes: 10 additions & 10 deletions app/Auth/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Auth;

use Core\Tool;
use Core\Registry;
use Pimple\Container;

/**
* Base auth class
Expand All @@ -26,34 +26,34 @@ abstract class Base
protected $db;

/**
* Registry instance
* Container instance
*
* @access protected
* @var \Core\Registry
* @var Pimple\Container
*/
protected $registry;
protected $container;

/**
* Constructor
*
* @access public
* @param \Core\Registry $registry Registry instance
* @param Pimple\Container $container
*/
public function __construct(Registry $registry)
public function __construct(Container $container)
{
$this->registry = $registry;
$this->db = $this->registry->shared('db');
$this->container = $container;
$this->db = $this->container['db'];
}

/**
* Load automatically models
*
* @access public
* @param string $name Model name
* @param string $name Model name
* @return mixed
*/
public function __get($name)
{
return Tool::loadModel($this->registry, $name);
return Tool::loadModel($this->container, $name);
}
}
5 changes: 2 additions & 3 deletions app/Auth/RememberMe.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Core\Request;
use Core\Security;
use Core\Tool;

/**
* RememberMe model
Expand Down Expand Up @@ -311,7 +310,7 @@ public function writeCookie($token, $sequence, $expiration)
$expiration,
BASE_URL_DIRECTORY,
null,
Tool::isHTTPS(),
Request::isHTTPS(),
true
);
}
Expand Down Expand Up @@ -344,7 +343,7 @@ public function deleteCookie()
time() - 3600,
BASE_URL_DIRECTORY,
null,
Tool::isHTTPS(),
Request::isHTTPS(),
true
);
}
Expand Down
17 changes: 9 additions & 8 deletions app/Controller/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Controller;

use Pimple\Container;
use Core\Tool;
use Core\Registry;
use Core\Security;
Expand Down Expand Up @@ -75,34 +76,34 @@ abstract class Base
public $session;

/**
* Registry instance
* Container instance
*
* @access private
* @var \Core\Registry
* @var Pimple\Container
*/
private $registry;
private $container;

/**
* Constructor
*
* @access public
* @param \Core\Registry $registry Registry instance
* @param Pimple\Container $container
*/
public function __construct(Registry $registry)
public function __construct(Container $container)
{
$this->registry = $registry;
$this->container = $container;
}

/**
* Load automatically models
*
* @access public
* @param string $name Model name
* @param string $name Model name
* @return mixed
*/
public function __get($name)
{
return Tool::loadModel($this->registry, $name);
return Tool::loadModel($this->container, $name);
}

/**
Expand Down
83 changes: 0 additions & 83 deletions app/Core/Registry.php

This file was deleted.

14 changes: 14 additions & 0 deletions app/Core/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,20 @@ public function isAjax()
return $this->getHeader('X-Requested-With') === 'XMLHttpRequest';
}

/**
* 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
*
Expand Down
2 changes: 1 addition & 1 deletion app/Core/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public function xss()
*/
public function hsts()
{
if (Tool::isHTTPS()) {
if (Request::isHTTPS()) {
header('Strict-Transport-Security: max-age=31536000');
}
}
Expand Down
20 changes: 11 additions & 9 deletions app/Core/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Core;

use Pimple\Container;

/**
* Router class
*
Expand All @@ -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'];
}
Expand Down Expand Up @@ -81,7 +83,7 @@ public function load($filename, $class, $method)
return false;
}

$instance = new $class($this->registry);
$instance = new $class($this->container);
$instance->request = new Request;
$instance->response = new Response;
$instance->session = new Session;
Expand Down
2 changes: 1 addition & 1 deletion app/Core/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function open($base_path = '/', $save_path = '')
self::SESSION_LIFETIME,
$base_path ?: '/',
null,
Tool::isHTTPS(),
Request::isHTTPS(),
true
);

Expand Down
Loading

0 comments on commit b081288

Please sign in to comment.