1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49:
<?php
/**
* Class Controller acts as a stepping stone (or "intermediate agent") between the user-defined code (<b>/src/controllers/</b>)
* and the system-defined code (<b>ParentController</b>) that helps to better structure the code. See @example
* @example
* <code>
* // To avoid:
* FooController->showProducts();
* // and
* BarController->showProducts();
* // to be defined twice (one in each controller) or once (in ParentController, bad code practices)
* Controller->showProducts();
* // can be defined and thus accessed from both <b>Foo</b> and <b>Bar</b> Controllers.
* </code>
*/
class Controller extends \Core\ParentController
{
/**
* @var Controller The class instance.
* @internal
*/
protected static $instance;
/**
* @var Model The instance of Model.
*/
protected $model;
/**
* Returns a Controller instance, creating it if it did not exist.
* @return Controller
*/
public static function singleton()
{
if (!self::$instance) {
$v = __CLASS__;
self::$instance = new $v;
}
return self::$instance;
}
public function __construct() {
parent::__construct();
$this->model = Model::singleton();
}
}