1 <?php
2
3 /*
4 * This file is part of the Icybee package.
5 *
6 * (c) Olivier Laviale <olivier.laviale@gmail.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Icybee\Modules\Views;
13
14 use ICanBoogie\PropertyNotReadable;
15
16 /**
17 * Provides data for a view.
18 */
19 abstract class Provider
20 {
21 const RETURNS_ONE = 1;
22 const RETURNS_MANY = 2;
23 const RETURNS_OTHER = 3;
24
25 protected $view;
26 protected $context;
27 protected $module;
28 protected $conditions;
29 protected $returns;
30
31 public function __construct(View $view, \BlueTihi\Context $context, \ICanBoogie\Module $module, array $conditions, $returns)
32 {
33 $this->view = $view;
34 $this->context = $context;
35 $this->module = $module;
36 $this->conditions = $conditions;
37 $this->returns = $returns;
38 }
39
40 public function __get($property)
41 {
42 static $readers = array('returns');
43
44 if (in_array($property, $readers))
45 {
46 return $this->$property;
47 }
48
49 throw new PropertyNotReadable($property);
50 }
51
52 abstract public function __invoke();
53
54 /**
55 * Alters the conditions.
56 *
57 * @param array $conditions
58 */
59 protected function alter_conditions(array $conditions)
60 {
61 return $conditions;
62 }
63
64 /**
65 * Alters rendering context.
66 *
67 * @param array $context
68 */
69 protected function alter_context(\BlueTihi\Context $context, \ICanBoogie\ActiveRecord\Query $query, array $conditions)
70 {
71 return $context;
72 }
73 }