2014-05-14 23:24:20 +10:00
|
|
|
<?php namespace Cms\Classes;
|
|
|
|
|
|
|
|
use ArrayAccess;
|
|
|
|
use October\Rain\Extension\Extendable;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parent class for PHP classes created for layout and page code sections.
|
|
|
|
*
|
|
|
|
* @package october\cms
|
|
|
|
* @author Alexey Bobkov, Samuel Georges
|
|
|
|
*/
|
|
|
|
class CodeBase extends Extendable implements ArrayAccess
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var \Cms\Classes\Page Specifies the current page
|
|
|
|
*/
|
|
|
|
public $page;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Cms\Classes\Layout Specifies the current layout
|
|
|
|
*/
|
|
|
|
public $layout;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Cms\Classes\controller Specifies the CMS controller
|
|
|
|
*/
|
|
|
|
public $controller;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates the object instance.
|
|
|
|
* @param \Cms\Classes\Page $page Specifies the CMS page.
|
|
|
|
* @param \Cms\Classes\Layout $layout Specifies the CMS layout.
|
|
|
|
* @param \Cms\Classes\Controller $controller Specifies the CMS controller.
|
|
|
|
*/
|
|
|
|
public function __construct($page, $layout, $controller)
|
|
|
|
{
|
|
|
|
$this->page = $page;
|
|
|
|
$this->layout = $layout;
|
|
|
|
$this->controller = $controller;
|
|
|
|
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
2014-07-07 18:39:00 +10:00
|
|
|
/**
|
|
|
|
* This event is triggered when all components are initialized and before AJAX is handled.
|
|
|
|
* The layout's onInit method triggers before the page's onInit method.
|
|
|
|
*/
|
2014-10-11 01:22:03 +02:00
|
|
|
public function onInit()
|
|
|
|
{
|
|
|
|
}
|
2014-07-07 18:39:00 +10:00
|
|
|
|
2014-05-14 23:24:20 +10:00
|
|
|
/**
|
|
|
|
* This event is triggered in the beginning of the execution cycle.
|
|
|
|
* The layout's onStart method triggers before the page's onStart method.
|
|
|
|
*/
|
2014-10-11 01:22:03 +02:00
|
|
|
public function onStart()
|
|
|
|
{
|
|
|
|
}
|
2014-05-14 23:24:20 +10:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This event is triggered in the end of the execution cycle, but before the page is displayed.
|
|
|
|
* The layout's onEnd method triggers after the page's onEnd method.
|
|
|
|
*/
|
2014-10-11 01:22:03 +02:00
|
|
|
public function onEnd()
|
|
|
|
{
|
|
|
|
}
|
2014-05-14 23:24:20 +10:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ArrayAccess implementation
|
|
|
|
*/
|
|
|
|
public function offsetSet($offset, $value)
|
|
|
|
{
|
|
|
|
$this->controller->vars[$offset] = $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ArrayAccess implementation
|
|
|
|
*/
|
|
|
|
public function offsetExists($offset)
|
|
|
|
{
|
|
|
|
return isset($this->controller->vars[$offset]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ArrayAccess implementation
|
|
|
|
*/
|
|
|
|
public function offsetUnset($offset)
|
|
|
|
{
|
|
|
|
unset($this->controller->vars[$offset]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ArrayAccess implementation
|
|
|
|
*/
|
|
|
|
public function offsetGet($offset)
|
|
|
|
{
|
|
|
|
return isset($this->controller->vars[$offset]) ? $this->controller->vars[$offset] : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dynamically handle calls into the controller instance.
|
|
|
|
* @param string $method
|
|
|
|
* @param array $parameters
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function __call($method, $parameters)
|
|
|
|
{
|
2015-05-16 09:29:27 +10:00
|
|
|
if ($this->methodExists($method)) {
|
2014-05-14 23:24:20 +10:00
|
|
|
return call_user_func_array([$this, $method], $parameters);
|
2014-10-11 01:22:03 +02:00
|
|
|
}
|
2014-05-14 23:24:20 +10:00
|
|
|
|
|
|
|
return call_user_func_array([$this->controller, $method], $parameters);
|
|
|
|
}
|
2014-05-24 21:08:33 +10:00
|
|
|
|
|
|
|
/**
|
2015-05-16 09:29:27 +10:00
|
|
|
* This is used as a helper for accessing controller variables/components
|
|
|
|
* easier in the page code, eg. $this->foo instead of $this['foo']
|
2014-05-24 21:08:33 +10:00
|
|
|
* @param string $name
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __get($name)
|
|
|
|
{
|
2015-05-16 09:29:27 +10:00
|
|
|
return $this[$name];
|
2014-05-24 21:08:33 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-05-16 09:29:27 +10:00
|
|
|
* This will set a property on the CMS Page object.
|
2014-06-18 00:14:23 +02:00
|
|
|
* @param string $name
|
2014-06-18 00:19:09 +02:00
|
|
|
* @param mixed $value
|
2014-05-24 21:08:33 +10:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __set($name, $value)
|
|
|
|
{
|
|
|
|
return $this->page->{$name} = $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-05-16 09:29:27 +10:00
|
|
|
* This will check if a property isset on the CMS Page object.
|
2014-06-18 00:14:23 +02:00
|
|
|
* @param string $name
|
2014-05-24 21:08:33 +10:00
|
|
|
* @return void
|
|
|
|
*/
|
2014-06-17 23:36:12 +02:00
|
|
|
public function __isset($name)
|
2014-05-24 21:08:33 +10:00
|
|
|
{
|
|
|
|
return isset($this->page->{$name});
|
|
|
|
}
|
2014-05-14 23:24:20 +10:00
|
|
|
}
|