ecom
E-commerce cms
 All Data Structures Namespaces Files Functions Variables
Public Member Functions | Static Public Member Functions | Private Attributes | Static Private Attributes
Context Class Reference

Public Member Functions

 __construct ($server=null)
 
 serve ()
 
 run ()
 
 __get ($key)
 
 isTestingEnvironment ()
 

Static Public Member Functions

static getContext ()
 

Private Attributes

 $hookManager
 
 $moduleManager
 
 $router
 
 $cart
 
 $user
 
 $controller
 
 $ip
 
 $server
 

Static Private Attributes

static $instance
 

Detailed Description

Cms context Contains all website informations Will be passed to themes files and to modules

Definition at line 10 of file Context.php.

Constructor & Destructor Documentation

__construct (   $server = null)

Create context from $_SERVER environment and initialize all data

Parameters
array$serveroptional, contains $_SERVER configuration -> REMOTE_ADDR client's ip -> SCRIPT_NAME -> DOCUMENT_ROOT -> REQUEST_SCHEME 'http:https' -> REQUEST_URI -> HTTP_HOST

Definition at line 90 of file Context.php.

91  {
92  self::$instance = $this;
93  if ($server == null)
94  $server = $_SERVER;
95  $this->ip = $server["REMOTE_ADDR"];
96  $this->hookManager = new Hooks($this);
97  $this->server = $server;
98  $this->router = new Router($this->server, $this);
99  }

Member Function Documentation

__get (   $key)

Getter function

Definition at line 137 of file Context.php.

138  {
139  switch ($key)
140  {
141  case "router": return $this->router; break;
142  case "cart": return $this->cart; break;
143  case "user": return $this->user; break;
144  case "moduleManager": return $this->moduleManager; break;
145  case "hookManager": return $this->hookManager; break;
146  case "ip": return $this->ip; break;
147  case "controller": return $this->controller; break;
148  }
149  throw new \Exception("Cannot access attribute {$key}");
150  }
static getContext ( )
static
Returns
context Get the last Context instance

Definition at line 164 of file Context.php.

165  {
166  return self::$instance;
167  }
isTestingEnvironment ( )

Check if executed from phpUnit

Definition at line 155 of file Context.php.

156  {
157  return isset($this->server["phpUnit"]) && $this->server["phpUnit"] == true;
158  }
run ( )

Execute controller

Definition at line 129 of file Context.php.

130  {
131  $this->controller->start();
132  }
serve ( )

Definition at line 101 of file Context.php.

102  {
103  // @codeCoverageIgnoreStart
104  if (!\Entity\ModelBase::init())
105  {
106  @require_once(getcwd().'/core/setup/index.php');
107  die;
108  }
109  // @codeCoverageIgnoreEnd
110  $this->router->init($this->server);
111  $this->moduleManager = new ModuleManager($this);
112  $this->hookManager->trigger("routerSetup");
113  try
114  {
115  $this->controller = $this->router->serveUrl();
116  if (!$this->controller)
117  throw new \Exception\Error404();
118  }
119  catch (\Exception\Error404 $e)
120  {
121  $this->controller = new \Controller\Error404($this, array());
122  }
123  return $this->controller;
124  }

Field Documentation

Tools Cart $cart
private

TODO

/core/tools/Cart.php Not defined yet Can be accessed read-only via $instance->cart

Definition at line 49 of file Context.php.

Tools AController $controller
private

/core/tools/AController.php Controller being called by user's request

Definition at line 64 of file Context.php.

Tools Hooks $hookManager
private

/core/tools/Hooks.php allow triggering hooks and registers module's endpoints Can be accessed read-only via $instance->hookManager

Definition at line 18 of file Context.php.

$instance
staticprivate

Definition at line 23 of file Context.php.

string $ip
private

Contains the remote client's IP, or empty Can be accessed via ->ip

Definition at line 71 of file Context.php.

Tools ModuleManager $moduleManager
private

/core/tools/ModuleManager.php load all active modules and contains informations about them Can be accessed read-only via $instance->moduleManager

Definition at line 31 of file Context.php.

Tools Router $router
private

/core/tools/Router.php Contains information about directories and paths Allow user to generate links Can be accessed read-only via $instance->router

Definition at line 40 of file Context.php.

array $server
private

contains $_SERVER or Unit test environment

Definition at line 77 of file Context.php.

Tools User $user
private

TODO

/core/tools/User.php Can be accessed read-only via $instance->user

Definition at line 57 of file Context.php.


The documentation for this class was generated from the following file: