All Data Structures Namespaces Files Functions Variables
Context.php
Go to the documentation of this file.
<?php
namespace Tools;
class Context
{
private $hookManager;
private static $instance;
private $moduleManager;
private $router;
private $cart;
private $user;
private $controller;
private $ip;
private $server;
public function __construct($server = null)
{
self::$instance = $this;
if ($server == null)
$server = $_SERVER;
$this->ip = $server["REMOTE_ADDR"];
$this->hookManager = new Hooks($this);
$this->server = $server;
$this->router = new Router($this->server, $this);
}
public function serve()
{
// @codeCoverageIgnoreStart
if (!\Entity\ModelBase::init())
{
@require_once(getcwd().'/core/setup/index.php');
die;
}
// @codeCoverageIgnoreEnd
$this->router->init($this->server);
$this->moduleManager = new ModuleManager($this);
$this->hookManager->trigger("routerSetup");
try
{
$this->controller = $this->router->serveUrl();
if (!$this->controller)
throw new \Exception\Error404();
}
catch (\Exception\Error404 $e)
{
$this->controller = new \Controller\Error404($this, array());
}
return $this->controller;
}
public function run()
{
$this->controller->start();
}
public function __get($key)
{
switch ($key)
{
case "router": return $this->router; break;
case "cart": return $this->cart; break;
case "user": return $this->user; break;
case "moduleManager": return $this->moduleManager; break;
case "hookManager": return $this->hookManager; break;
case "ip": return $this->ip; break;
case "controller": return $this->controller; break;
}
throw new \Exception("Cannot access attribute {$key}");
}
public function isTestingEnvironment()
{
return isset($this->server["phpUnit"]) && $this->server["phpUnit"] == true;
}
public static function getContext()
{
return self::$instance;
}
}
Tools\Context\$user
$user
Definition: Context.php:57
Tools\Context\getContext
static getContext()
Definition: Context.php:164
Tools\Context\$cart
$cart
Definition: Context.php:49
Entity
Definition: Address.php:3
Tools\ModuleManager
Definition: ModuleManager.php:9
Tools\Context\serve
serve()
Definition: Context.php:101
Tools\Context\$hookManager
$hookManager
Definition: Context.php:18
Tools\Context\$moduleManager
$moduleManager
Definition: Context.php:31
Exception
Definition: Error404.php:3
Tools\Router
Definition: Router.php:9
Tools\Context\__construct
__construct($server=null)
Definition: Context.php:90
Tools\Context\$router
$router
Definition: Context.php:40
Tools\Context\$instance
static $instance
Definition: Context.php:23
Tools\Context
Definition: Context.php:10
Tools\Context\isTestingEnvironment
isTestingEnvironment()
Definition: Context.php:155
Tools\Context\$server
$server
Definition: Context.php:77
Tools\Context\__get
__get($key)
Definition: Context.php:137
Tools\Context\$controller
$controller
Definition: Context.php:64
Tools\Context\run
run()
Definition: Context.php:129
Tools\Hooks
Definition: Hooks.php:8
Tools
Definition: AController.php:3
Tools\Context\$ip
$ip
Definition: Context.php:71