1 | <?php |
||
14 | class ExternalModule extends Module implements iExternalModule |
||
15 | { |
||
16 | /** @var Module Pointer to parent module */ |
||
17 | public $parent = null; |
||
18 | |||
19 | /** Коллекция связанных модулей с текущим */ |
||
20 | protected $requirements = array(); |
||
21 | |||
22 | /** |
||
23 | * ExternalModule constructor. |
||
24 | * |
||
25 | * @param string $path |
||
26 | * @param ResourcesInterface $resources |
||
27 | * @param SystemInterface $system |
||
28 | */ |
||
29 | public function __construct($path, ResourcesInterface $resources, SystemInterface $system) |
||
44 | |||
45 | /** @see \samson\core\iExternalModule::copy() */ |
||
46 | public function ©() |
||
47 | { |
||
48 | // Get current class name |
||
49 | $classname = get_class($this); |
||
50 | |||
51 | // Create copy instance |
||
52 | $clone = new $classname($this->path, $this->resourceMap, $this->system); |
||
53 | $clone->views = &$this->views; |
||
54 | $clone->parent = &$this->parent; |
||
55 | $clone->path = $this->path; |
||
56 | |||
57 | return $clone; |
||
58 | } |
||
59 | |||
60 | /** Обработчик сериализации объекта */ |
||
61 | public function __sleep() |
||
66 | |||
67 | /** |
||
68 | * Set current view for rendering. |
||
69 | * |
||
70 | * @param string $viewPath Path for view searching |
||
71 | * @return self Chaining |
||
72 | */ |
||
73 | public function view($viewPath) |
||
95 | |||
96 | /** |
||
97 | * Overloading default module rendering behaviour |
||
98 | * as it is used in templates and views using m()->render() |
||
99 | * without specifying concrete module or passing a variable. |
||
100 | * |
||
101 | * @param string $controller Controller action name |
||
102 | */ |
||
103 | public function render($controller = null) |
||
117 | |||
118 | /** |
||
119 | * Module preparation handler. |
||
120 | * This function is triggered after module instance is being created. |
||
121 | * |
||
122 | * @return bool Preparation result |
||
123 | */ |
||
124 | public function prepare() |
||
128 | |||
129 | /** |
||
130 | * Module initialization. |
||
131 | * This function is triggered when system has started. So here |
||
132 | * we have all modules already prepared and loaded. |
||
133 | * |
||
134 | * @param array $params Collection of module initialization parameters |
||
135 | * @return bool Initialization result |
||
136 | */ |
||
137 | public function init(array $params = array()) |
||
143 | } |
||
144 |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.