1 <?php
2
3 namespace Icybee\Rendering;
4
5 use ICanBoogie\OffsetNotWritable;
6
7 use BlueTihi\render;
8
9 use ICanBoogie\Exception;
10
11 class PropertyRenderers implements \IteratorIterator, \ArrayAccess
12 {
13 14 15 16 17
18 protected static $instance;
19
20 21 22 23 24
25 static public function get()
26 {
27 if (!self::$instance)
28 {
29 self::$instance = new static();
30 }
31
32 return self::$instance;
33 }
34
35 36 37 38 39 40 41 42 43 44
45 static public function synthesize_config(array $fragments)
46 {
47 $collection = array();
48
49 foreach ($fragments as $pathname => $fragment)
50 {
51 if (empty($fragment['properties']))
52 {
53 continue;
54 }
55
56 foreach ($fragment['properties'] as $key => $callback)
57 {
58 if (!strpos($key, '::'))
59 {
60 throw new \InvalidArgumentException(format
61 (
62 'Property definition must be <code>{class}/{property}</code> given: :key in %path', array
63 (
64 'key' => $key,
65 'path' => $pathname
66 )
67 ));
68 }
69
70 list($class, $property) = explode('::', $key);
71
72 $collection[$property][$class][] = $callback;
73 }
74 }
75
76 return $collection;
77 }
78
79 protected $collection = array();
80
81 82 83
84 protected function __construct()
85 {
86 global $core;
87
88 $this->collection = $core->configs['rendering.properties'];
89
90
91 }
92
93 94 95
96 public function getIterator()
97 {
98 return new \ArrayIterator($this->collection);
99 }
100
101 102 103
104 public function offsetExists($offset)
105 {
106 return isset($this->collection[$offset]);
107 }
108
109 110 111
112 public function offsetGet($offset)
113 {
114 list($class, $property) = explode('::', $offset);
115 }
116
117 118 119
120 public function offsetSet($offset, $value)
121 {
122 throw new OffsetNotWritable(array($offset, $this));
123 }
124
125 126 127
128 public function offsetUnset($offset)
129 {
130 throw new OffsetNotWritable(array($offset, $this));
131 }
132 }
133
134 class Rendering
135 {
136 static public function render($source, array $options=array())
137 {
138
139 }
140 }
141
142 return array
143 (
144 'properties' => array
145 (
146 'Icybee\Modules\Nodes\Node::title' => 'callback'
147 ),
148
149 'records' => array
150 (
151 'Icybee\Modules\Nodes\Node' => 'callback'
152 ),
153
154 'template' => array
155 (
156 'php' => array
157 (
158 'class' => 'Engine'
159 )
160 )
161 );
162