1 | <?php |
||
8 | abstract class AbstractComponent |
||
9 | { |
||
10 | /** |
||
11 | * An associative array holding the model to be used by this controller |
||
12 | * @var array |
||
13 | */ |
||
14 | protected $model; |
||
15 | |||
16 | /** |
||
17 | * Constructor |
||
18 | * |
||
19 | * @param array $model |
||
20 | */ |
||
21 | public function __construct( array $model = array() ) |
||
36 | |||
37 | /** |
||
38 | * Get model parameter value by name. |
||
39 | * |
||
40 | * @param string $name The parameter's name. |
||
41 | * |
||
42 | * @return mixed the parameter's value. |
||
43 | */ |
||
44 | public function __get( $name ) |
||
51 | |||
52 | /** |
||
53 | * Set model parameter by name. |
||
54 | * |
||
55 | * @param string $name The parameter's name. |
||
56 | * @param mixed $value The value to set. |
||
57 | * |
||
58 | * @return mixed the settings' parameter value. |
||
59 | */ |
||
60 | public function __set( $name, $value ) |
||
64 | |||
65 | /** |
||
66 | * Render the template with the local properties. |
||
67 | * |
||
68 | * @return string The rendered template. |
||
69 | * @throws TemplateNotFoundException Thrown if the template file can |
||
70 | * not found. |
||
71 | */ |
||
72 | public function render( $echo = false ){ |
||
93 | |||
94 | /** |
||
95 | * The default model to use when none is provided to the constructor. |
||
96 | * This method should be overriden by child class to define the default |
||
97 | * model. |
||
98 | * |
||
99 | * @return array |
||
100 | */ |
||
101 | public function default_model() |
||
105 | |||
106 | /** |
||
107 | * Get the current component model data. |
||
108 | * |
||
109 | * @return array |
||
110 | */ |
||
111 | public function get_model() |
||
115 | |||
116 | /** |
||
117 | * The list of required model parameters. |
||
118 | * This method should be overriden by child class to specify required model |
||
119 | * parameters. |
||
120 | * |
||
121 | * @return array |
||
122 | */ |
||
123 | public function required_parameters() |
||
127 | |||
128 | /** |
||
129 | * A hook that is called once the component has been created. |
||
130 | */ |
||
131 | protected function on_created() {} |
||
132 | |||
133 | /** |
||
134 | * Get the full path to the template file. |
||
135 | * |
||
136 | * @return string The full path. |
||
137 | */ |
||
138 | abstract function get_script_path(); |
||
139 | } |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.