@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Model class |
|
4 | - */ |
|
3 | + * Model class |
|
4 | + */ |
|
5 | 5 | namespace Phile\Model; |
6 | 6 | use Phile\Core\Event; |
7 | 7 | use Phile\Core\Registry; |
@@ -17,69 +17,69 @@ discard block |
||
17 | 17 | */ |
18 | 18 | class Meta extends AbstractModel { |
19 | 19 | |
20 | - /** |
|
21 | - * the construtor |
|
22 | - * |
|
23 | - * @param string $rawData the raw data to parse |
|
24 | - */ |
|
25 | - public function __construct($rawData = null) { |
|
26 | - if ($rawData !== null) { |
|
27 | - $this->setRawData($rawData); |
|
28 | - } |
|
29 | - } |
|
20 | + /** |
|
21 | + * the construtor |
|
22 | + * |
|
23 | + * @param string $rawData the raw data to parse |
|
24 | + */ |
|
25 | + public function __construct($rawData = null) { |
|
26 | + if ($rawData !== null) { |
|
27 | + $this->setRawData($rawData); |
|
28 | + } |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * set the raw data to parse |
|
33 | - * |
|
34 | - * @param string $rawData the raw data |
|
35 | - */ |
|
36 | - public function setRawData($rawData) { |
|
37 | - /** |
|
38 | - * @triggerEvent before_read_file_meta this event is triggered before the meta data readed and parsed |
|
39 | - * |
|
40 | - * @param string rawData the unparsed data |
|
41 | - * @param \Phile\Model\Meta meta the meta model |
|
42 | - */ |
|
43 | - Event::triggerEvent('before_read_file_meta', array('rawData' => &$rawData, 'meta' => &$this)); |
|
44 | - $this->parseRawData($rawData); |
|
45 | - /** |
|
46 | - * @triggerEvent after_read_file_meta this event is triggered after the meta data readed and parsed |
|
47 | - * |
|
48 | - * @param string rawData the unparsed data |
|
49 | - * @param \Phile\Model\Meta meta the meta model |
|
50 | - */ |
|
51 | - Event::triggerEvent('after_read_file_meta', array('rawData' => &$rawData, 'meta' => &$this)); |
|
52 | - } |
|
31 | + /** |
|
32 | + * set the raw data to parse |
|
33 | + * |
|
34 | + * @param string $rawData the raw data |
|
35 | + */ |
|
36 | + public function setRawData($rawData) { |
|
37 | + /** |
|
38 | + * @triggerEvent before_read_file_meta this event is triggered before the meta data readed and parsed |
|
39 | + * |
|
40 | + * @param string rawData the unparsed data |
|
41 | + * @param \Phile\Model\Meta meta the meta model |
|
42 | + */ |
|
43 | + Event::triggerEvent('before_read_file_meta', array('rawData' => &$rawData, 'meta' => &$this)); |
|
44 | + $this->parseRawData($rawData); |
|
45 | + /** |
|
46 | + * @triggerEvent after_read_file_meta this event is triggered after the meta data readed and parsed |
|
47 | + * |
|
48 | + * @param string rawData the unparsed data |
|
49 | + * @param \Phile\Model\Meta meta the meta model |
|
50 | + */ |
|
51 | + Event::triggerEvent('after_read_file_meta', array('rawData' => &$rawData, 'meta' => &$this)); |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * get formatted date |
|
56 | - * |
|
57 | - * @return bool|null|string |
|
58 | - */ |
|
59 | - public function getFormattedDate() { |
|
60 | - $config = Registry::get('Phile_Settings'); |
|
61 | - if (!isset($this->data['date'])) { |
|
62 | - return null; |
|
63 | - } |
|
64 | - $date = $this->data['date']; |
|
65 | - if (!is_numeric($date)) { |
|
66 | - $date = strtotime($date); |
|
67 | - } |
|
68 | - return date($config['date_format'], $date); |
|
69 | - } |
|
54 | + /** |
|
55 | + * get formatted date |
|
56 | + * |
|
57 | + * @return bool|null|string |
|
58 | + */ |
|
59 | + public function getFormattedDate() { |
|
60 | + $config = Registry::get('Phile_Settings'); |
|
61 | + if (!isset($this->data['date'])) { |
|
62 | + return null; |
|
63 | + } |
|
64 | + $date = $this->data['date']; |
|
65 | + if (!is_numeric($date)) { |
|
66 | + $date = strtotime($date); |
|
67 | + } |
|
68 | + return date($config['date_format'], $date); |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * parse the raw data |
|
73 | - * |
|
74 | - * @param $rawData |
|
75 | - */ |
|
76 | - protected function parseRawData($rawData) { |
|
77 | - /** @var \Phile\ServiceLocator\MetaInterface $metaParser */ |
|
78 | - $metaParser = ServiceLocator::getService('Phile_Parser_Meta'); |
|
79 | - $data = $metaParser->parse($rawData); |
|
71 | + /** |
|
72 | + * parse the raw data |
|
73 | + * |
|
74 | + * @param $rawData |
|
75 | + */ |
|
76 | + protected function parseRawData($rawData) { |
|
77 | + /** @var \Phile\ServiceLocator\MetaInterface $metaParser */ |
|
78 | + $metaParser = ServiceLocator::getService('Phile_Parser_Meta'); |
|
79 | + $data = $metaParser->parse($rawData); |
|
80 | 80 | |
81 | - foreach ($data as $key => $value) { |
|
82 | - $this->set($key, $value); |
|
83 | - } |
|
84 | - } |
|
81 | + foreach ($data as $key => $value) { |
|
82 | + $this->set($key, $value); |
|
83 | + } |
|
84 | + } |
|
85 | 85 | } |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * the abstract base model |
|
4 | - */ |
|
3 | + * the abstract base model |
|
4 | + */ |
|
5 | 5 | namespace Phile\Model; |
6 | 6 | |
7 | 7 | /** |
@@ -13,144 +13,144 @@ discard block |
||
13 | 13 | * @package Phile\Model |
14 | 14 | */ |
15 | 15 | class AbstractModel implements \ArrayAccess { |
16 | - /** @var array the storage */ |
|
17 | - protected $data = array(); |
|
16 | + /** @var array the storage */ |
|
17 | + protected $data = array(); |
|
18 | 18 | |
19 | - /** |
|
20 | - * get value for given key |
|
21 | - * |
|
22 | - * @param $key |
|
23 | - * |
|
24 | - * @return null|mixed |
|
25 | - */ |
|
26 | - public function get($key) { |
|
27 | - return (isset($this->data[$key])) ? $this->data[$key] : null; |
|
28 | - } |
|
19 | + /** |
|
20 | + * get value for given key |
|
21 | + * |
|
22 | + * @param $key |
|
23 | + * |
|
24 | + * @return null|mixed |
|
25 | + */ |
|
26 | + public function get($key) { |
|
27 | + return (isset($this->data[$key])) ? $this->data[$key] : null; |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * get all entries |
|
32 | - * |
|
33 | - * @return array |
|
34 | - */ |
|
35 | - public function getAll() { |
|
36 | - return $this->data; |
|
37 | - } |
|
30 | + /** |
|
31 | + * get all entries |
|
32 | + * |
|
33 | + * @return array |
|
34 | + */ |
|
35 | + public function getAll() { |
|
36 | + return $this->data; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * set value for given key |
|
41 | - * |
|
42 | - * @param string $key the key |
|
43 | - * @param mixed $value the value |
|
44 | - */ |
|
45 | - public function set($key, $value) { |
|
46 | - $this->data[$key] = $value; |
|
47 | - } |
|
39 | + /** |
|
40 | + * set value for given key |
|
41 | + * |
|
42 | + * @param string $key the key |
|
43 | + * @param mixed $value the value |
|
44 | + */ |
|
45 | + public function set($key, $value) { |
|
46 | + $this->data[$key] = $value; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * magic method to get value |
|
51 | - * |
|
52 | - * @param $name |
|
53 | - * |
|
54 | - * @return null|mixed |
|
55 | - */ |
|
56 | - public function __get($name) { |
|
57 | - return $this->get($name); |
|
58 | - } |
|
49 | + /** |
|
50 | + * magic method to get value |
|
51 | + * |
|
52 | + * @param $name |
|
53 | + * |
|
54 | + * @return null|mixed |
|
55 | + */ |
|
56 | + public function __get($name) { |
|
57 | + return $this->get($name); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * magic method to set value |
|
62 | - * |
|
63 | - * @param string $name |
|
64 | - * @param mixed $value |
|
65 | - */ |
|
66 | - public function __set($name, $value) { |
|
67 | - $this->set($name, $value); |
|
68 | - } |
|
60 | + /** |
|
61 | + * magic method to set value |
|
62 | + * |
|
63 | + * @param string $name |
|
64 | + * @param mixed $value |
|
65 | + */ |
|
66 | + public function __set($name, $value) { |
|
67 | + $this->set($name, $value); |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * magic method to access properties by getter / setter |
|
72 | - * |
|
73 | - * @param string $name the name of method |
|
74 | - * @param array $args the arguments of the method |
|
75 | - * |
|
76 | - * @return mixed|null|void |
|
77 | - */ |
|
78 | - public function __call($name, $args) { |
|
79 | - if (strpos($name, 'get') !== false) { |
|
80 | - $name = substr($name, 3); |
|
70 | + /** |
|
71 | + * magic method to access properties by getter / setter |
|
72 | + * |
|
73 | + * @param string $name the name of method |
|
74 | + * @param array $args the arguments of the method |
|
75 | + * |
|
76 | + * @return mixed|null|void |
|
77 | + */ |
|
78 | + public function __call($name, $args) { |
|
79 | + if (strpos($name, 'get') !== false) { |
|
80 | + $name = substr($name, 3); |
|
81 | 81 | |
82 | - return $this->get($name); |
|
83 | - } |
|
84 | - if (strpos($name, 'set') !== false) { |
|
85 | - $name = substr($name, 3); |
|
82 | + return $this->get($name); |
|
83 | + } |
|
84 | + if (strpos($name, 'set') !== false) { |
|
85 | + $name = substr($name, 3); |
|
86 | 86 | |
87 | - return $this->set($name, $args[0]); |
|
88 | - } |
|
87 | + return $this->set($name, $args[0]); |
|
88 | + } |
|
89 | 89 | |
90 | - } |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * (PHP 5 >= 5.0.0) |
|
94 | - * Whether a offset exists |
|
95 | - * |
|
96 | - * @link http://php.net/manual/en/arrayaccess.offsetexists.php |
|
97 | - * |
|
98 | - * @param mixed $offset |
|
99 | - * An offset to check for. |
|
100 | - * |
|
101 | - * @return boolean true on success or false on failure. |
|
102 | - * The return value will be casted to boolean if non-boolean was returned. |
|
103 | - */ |
|
104 | - public function offsetExists($offset) { |
|
105 | - return (isset($this->data[$offset])); |
|
106 | - } |
|
92 | + /** |
|
93 | + * (PHP 5 >= 5.0.0) |
|
94 | + * Whether a offset exists |
|
95 | + * |
|
96 | + * @link http://php.net/manual/en/arrayaccess.offsetexists.php |
|
97 | + * |
|
98 | + * @param mixed $offset |
|
99 | + * An offset to check for. |
|
100 | + * |
|
101 | + * @return boolean true on success or false on failure. |
|
102 | + * The return value will be casted to boolean if non-boolean was returned. |
|
103 | + */ |
|
104 | + public function offsetExists($offset) { |
|
105 | + return (isset($this->data[$offset])); |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * (PHP 5 >= 5.0.0) |
|
110 | - * Offset to retrieve |
|
111 | - * |
|
112 | - * @link http://php.net/manual/en/arrayaccess.offsetget.php |
|
113 | - * |
|
114 | - * @param mixed $offset |
|
115 | - * The offset to retrieve. |
|
116 | - * |
|
117 | - * @return mixed Can return all value types. |
|
118 | - */ |
|
119 | - public function offsetGet($offset) { |
|
120 | - return $this->get($offset); |
|
121 | - } |
|
108 | + /** |
|
109 | + * (PHP 5 >= 5.0.0) |
|
110 | + * Offset to retrieve |
|
111 | + * |
|
112 | + * @link http://php.net/manual/en/arrayaccess.offsetget.php |
|
113 | + * |
|
114 | + * @param mixed $offset |
|
115 | + * The offset to retrieve. |
|
116 | + * |
|
117 | + * @return mixed Can return all value types. |
|
118 | + */ |
|
119 | + public function offsetGet($offset) { |
|
120 | + return $this->get($offset); |
|
121 | + } |
|
122 | 122 | |
123 | - /** |
|
124 | - * (PHP 5 >= 5.0.0) |
|
125 | - * Offset to set |
|
126 | - * |
|
127 | - * @link http://php.net/manual/en/arrayaccess.offsetset.php |
|
128 | - * |
|
129 | - * @param mixed $offset |
|
130 | - * The offset to assign the value to. |
|
131 | - * @param mixed $value |
|
132 | - * The value to set. |
|
133 | - * |
|
134 | - * @return void |
|
135 | - */ |
|
136 | - public function offsetSet($offset, $value) { |
|
137 | - $this->set($offset, $value); |
|
138 | - } |
|
123 | + /** |
|
124 | + * (PHP 5 >= 5.0.0) |
|
125 | + * Offset to set |
|
126 | + * |
|
127 | + * @link http://php.net/manual/en/arrayaccess.offsetset.php |
|
128 | + * |
|
129 | + * @param mixed $offset |
|
130 | + * The offset to assign the value to. |
|
131 | + * @param mixed $value |
|
132 | + * The value to set. |
|
133 | + * |
|
134 | + * @return void |
|
135 | + */ |
|
136 | + public function offsetSet($offset, $value) { |
|
137 | + $this->set($offset, $value); |
|
138 | + } |
|
139 | 139 | |
140 | - /** |
|
141 | - * (PHP 5 >= 5.0.0) |
|
142 | - * Offset to unset |
|
143 | - * |
|
144 | - * @link http://php.net/manual/en/arrayaccess.offsetunset.php |
|
145 | - * |
|
146 | - * @param mixed $offset |
|
147 | - * The offset to unset. |
|
148 | - * |
|
149 | - * @return void |
|
150 | - */ |
|
151 | - public function offsetUnset($offset) { |
|
152 | - if ($this->offsetExists($offset)) { |
|
153 | - unset($this->data[$offset]); |
|
154 | - } |
|
155 | - } |
|
140 | + /** |
|
141 | + * (PHP 5 >= 5.0.0) |
|
142 | + * Offset to unset |
|
143 | + * |
|
144 | + * @link http://php.net/manual/en/arrayaccess.offsetunset.php |
|
145 | + * |
|
146 | + * @param mixed $offset |
|
147 | + * The offset to unset. |
|
148 | + * |
|
149 | + * @return void |
|
150 | + */ |
|
151 | + public function offsetUnset($offset) { |
|
152 | + if ($this->offsetExists($offset)) { |
|
153 | + unset($this->data[$offset]); |
|
154 | + } |
|
155 | + } |
|
156 | 156 | } |
@@ -13,13 +13,13 @@ |
||
13 | 13 | * @package Phile\Gateway |
14 | 14 | */ |
15 | 15 | interface EventObserverInterface { |
16 | - /** |
|
17 | - * event method |
|
18 | - * |
|
19 | - * @param string $eventKey |
|
20 | - * @param mixed $data |
|
21 | - * |
|
22 | - * @return mixed |
|
23 | - */ |
|
24 | - public function on($eventKey, $data = null); |
|
16 | + /** |
|
17 | + * event method |
|
18 | + * |
|
19 | + * @param string $eventKey |
|
20 | + * @param mixed $data |
|
21 | + * |
|
22 | + * @return mixed |
|
23 | + */ |
|
24 | + public function on($eventKey, $data = null); |
|
25 | 25 | } |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * the filter class for content files |
|
4 | - */ |
|
3 | + * the filter class for content files |
|
4 | + */ |
|
5 | 5 | namespace Phile\FilterIterator; |
6 | 6 | |
7 | 7 | /** |
@@ -10,13 +10,13 @@ discard block |
||
10 | 10 | * @package Phile\FilterIterator |
11 | 11 | */ |
12 | 12 | class ContentFileFilterIterator extends \FilterIterator { |
13 | - /** |
|
14 | - * method to decide if file is filterd or not |
|
15 | - * @return bool |
|
16 | - */ |
|
17 | - public function accept() { |
|
18 | - /** @var \SplFileInfo $this */ |
|
19 | - return (preg_match('/^[^\.]{1}.*'.CONTENT_EXT.'/', $this->getFilename()) > 0); |
|
20 | - } |
|
13 | + /** |
|
14 | + * method to decide if file is filterd or not |
|
15 | + * @return bool |
|
16 | + */ |
|
17 | + public function accept() { |
|
18 | + /** @var \SplFileInfo $this */ |
|
19 | + return (preg_match('/^[^\.]{1}.*'.CONTENT_EXT.'/', $this->getFilename()) > 0); |
|
20 | + } |
|
21 | 21 | |
22 | 22 | } |
23 | 23 | \ No newline at end of file |
@@ -16,7 +16,7 @@ |
||
16 | 16 | */ |
17 | 17 | public function accept() { |
18 | 18 | /** @var \SplFileInfo $this */ |
19 | - return (preg_match('/^[^\.]{1}.*'.CONTENT_EXT.'/', $this->getFilename()) > 0); |
|
19 | + return (preg_match('/^[^\.]{1}.*' . CONTENT_EXT . '/', $this->getFilename()) > 0); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | } |
23 | 23 | \ No newline at end of file |
@@ -9,13 +9,13 @@ |
||
9 | 9 | * @package Phile\FilterIterator |
10 | 10 | */ |
11 | 11 | class GeneralFileFilterIterator extends \FilterIterator { |
12 | - /** |
|
13 | - * method to decide if file is filterd or not |
|
14 | - * @return bool |
|
15 | - */ |
|
16 | - public function accept() { |
|
17 | - // accept all kind of files, no filter |
|
18 | - return true; |
|
19 | - } |
|
12 | + /** |
|
13 | + * method to decide if file is filterd or not |
|
14 | + * @return bool |
|
15 | + */ |
|
16 | + public function accept() { |
|
17 | + // accept all kind of files, no filter |
|
18 | + return true; |
|
19 | + } |
|
20 | 20 | |
21 | 21 | } |
22 | 22 | \ No newline at end of file |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Registry class |
|
4 | - */ |
|
3 | + * Registry class |
|
4 | + */ |
|
5 | 5 | namespace Phile\Core; |
6 | 6 | |
7 | 7 | /** |
@@ -13,137 +13,137 @@ discard block |
||
13 | 13 | * @package Phile\Core |
14 | 14 | */ |
15 | 15 | class Registry extends \ArrayObject { |
16 | - /** |
|
17 | - * Registry object provides storage for shared objects. |
|
18 | - * |
|
19 | - * @var Registry |
|
20 | - */ |
|
21 | - private static $_registry = null; |
|
16 | + /** |
|
17 | + * Registry object provides storage for shared objects. |
|
18 | + * |
|
19 | + * @var Registry |
|
20 | + */ |
|
21 | + private static $_registry = null; |
|
22 | 22 | |
23 | - /** |
|
24 | - * Retrieves the default registry instance. |
|
25 | - * |
|
26 | - * @return Registry |
|
27 | - */ |
|
28 | - public static function getInstance() { |
|
29 | - if (self::$_registry === null) { |
|
30 | - self::init(); |
|
31 | - } |
|
23 | + /** |
|
24 | + * Retrieves the default registry instance. |
|
25 | + * |
|
26 | + * @return Registry |
|
27 | + */ |
|
28 | + public static function getInstance() { |
|
29 | + if (self::$_registry === null) { |
|
30 | + self::init(); |
|
31 | + } |
|
32 | 32 | |
33 | - return self::$_registry; |
|
34 | - } |
|
33 | + return self::$_registry; |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * Set the default registry instance to a specified instance. |
|
38 | - * |
|
39 | - * @param Registry $registry An object instance of type Registry, |
|
40 | - * or a subclass. |
|
41 | - * |
|
42 | - * @param Registry $registry |
|
43 | - * |
|
44 | - * @throws \Exception |
|
45 | - */ |
|
46 | - public static function setInstance(Registry $registry) { |
|
47 | - if (self::$_registry !== null) { |
|
48 | - throw new \Exception('Registry is already initialized', 1398536572); |
|
49 | - } |
|
50 | - self::$_registry = $registry; |
|
51 | - } |
|
36 | + /** |
|
37 | + * Set the default registry instance to a specified instance. |
|
38 | + * |
|
39 | + * @param Registry $registry An object instance of type Registry, |
|
40 | + * or a subclass. |
|
41 | + * |
|
42 | + * @param Registry $registry |
|
43 | + * |
|
44 | + * @throws \Exception |
|
45 | + */ |
|
46 | + public static function setInstance(Registry $registry) { |
|
47 | + if (self::$_registry !== null) { |
|
48 | + throw new \Exception('Registry is already initialized', 1398536572); |
|
49 | + } |
|
50 | + self::$_registry = $registry; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Initialize the default registry instance. |
|
55 | - * |
|
56 | - * @return void |
|
57 | - */ |
|
58 | - protected static function init() { |
|
59 | - self::setInstance(new Registry()); |
|
60 | - } |
|
53 | + /** |
|
54 | + * Initialize the default registry instance. |
|
55 | + * |
|
56 | + * @return void |
|
57 | + */ |
|
58 | + protected static function init() { |
|
59 | + self::setInstance(new Registry()); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Unset the default registry instance. |
|
64 | - * Primarily used in tearDown() in unit tests. |
|
65 | - * |
|
66 | - * @returns void |
|
67 | - */ |
|
68 | - public static function _unsetInstance() { |
|
69 | - self::$_registry = null; |
|
70 | - } |
|
62 | + /** |
|
63 | + * Unset the default registry instance. |
|
64 | + * Primarily used in tearDown() in unit tests. |
|
65 | + * |
|
66 | + * @returns void |
|
67 | + */ |
|
68 | + public static function _unsetInstance() { |
|
69 | + self::$_registry = null; |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * getter method, basically same as offsetGet(). |
|
74 | - * |
|
75 | - * This method can be called from an object of type Registry, or it |
|
76 | - * can be called statically. In the latter case, it uses the default |
|
77 | - * static instance stored in the class. |
|
78 | - * |
|
79 | - * @param string $index - get the value associated with $index |
|
80 | - * |
|
81 | - * @return mixed |
|
82 | - * @throws \Exception if no entry is registerd for $index. |
|
83 | - */ |
|
84 | - public static function get($index) { |
|
85 | - $instance = self::getInstance(); |
|
86 | - if (!$instance->offsetExists($index)) { |
|
87 | - throw new \Exception("No entry is registered for key '$index'", 1398536594); |
|
88 | - } |
|
72 | + /** |
|
73 | + * getter method, basically same as offsetGet(). |
|
74 | + * |
|
75 | + * This method can be called from an object of type Registry, or it |
|
76 | + * can be called statically. In the latter case, it uses the default |
|
77 | + * static instance stored in the class. |
|
78 | + * |
|
79 | + * @param string $index - get the value associated with $index |
|
80 | + * |
|
81 | + * @return mixed |
|
82 | + * @throws \Exception if no entry is registerd for $index. |
|
83 | + */ |
|
84 | + public static function get($index) { |
|
85 | + $instance = self::getInstance(); |
|
86 | + if (!$instance->offsetExists($index)) { |
|
87 | + throw new \Exception("No entry is registered for key '$index'", 1398536594); |
|
88 | + } |
|
89 | 89 | |
90 | - return $instance->offsetGet($index); |
|
91 | - } |
|
90 | + return $instance->offsetGet($index); |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * setter method, basically same as offsetSet(). |
|
95 | - * |
|
96 | - * This method can be called from an object of type Registry, or it |
|
97 | - * can be called statically. In the latter case, it uses the default |
|
98 | - * static instance stored in the class. |
|
99 | - * |
|
100 | - * @param string $index The location in the ArrayObject in which to store |
|
101 | - * the value. |
|
102 | - * @param mixed $value The object to store in the ArrayObject. |
|
103 | - * |
|
104 | - * @return void |
|
105 | - */ |
|
106 | - public static function set($index, $value) { |
|
107 | - $instance = self::getInstance(); |
|
108 | - $instance->offsetSet($index, $value); |
|
109 | - } |
|
93 | + /** |
|
94 | + * setter method, basically same as offsetSet(). |
|
95 | + * |
|
96 | + * This method can be called from an object of type Registry, or it |
|
97 | + * can be called statically. In the latter case, it uses the default |
|
98 | + * static instance stored in the class. |
|
99 | + * |
|
100 | + * @param string $index The location in the ArrayObject in which to store |
|
101 | + * the value. |
|
102 | + * @param mixed $value The object to store in the ArrayObject. |
|
103 | + * |
|
104 | + * @return void |
|
105 | + */ |
|
106 | + public static function set($index, $value) { |
|
107 | + $instance = self::getInstance(); |
|
108 | + $instance->offsetSet($index, $value); |
|
109 | + } |
|
110 | 110 | |
111 | - /** |
|
112 | - * Returns TRUE if the $index is a named value in the registry, |
|
113 | - * or FALSE if $index was not found in the registry. |
|
114 | - * |
|
115 | - * @param string $index |
|
116 | - * |
|
117 | - * @return boolean |
|
118 | - */ |
|
119 | - public static function isRegistered($index) { |
|
120 | - if (self::$_registry === null) { |
|
121 | - return false; |
|
122 | - } |
|
111 | + /** |
|
112 | + * Returns TRUE if the $index is a named value in the registry, |
|
113 | + * or FALSE if $index was not found in the registry. |
|
114 | + * |
|
115 | + * @param string $index |
|
116 | + * |
|
117 | + * @return boolean |
|
118 | + */ |
|
119 | + public static function isRegistered($index) { |
|
120 | + if (self::$_registry === null) { |
|
121 | + return false; |
|
122 | + } |
|
123 | 123 | |
124 | - return self::$_registry->offsetExists($index); |
|
125 | - } |
|
124 | + return self::$_registry->offsetExists($index); |
|
125 | + } |
|
126 | 126 | |
127 | - /** |
|
128 | - * the constructor |
|
129 | - * |
|
130 | - * @param array $array data array |
|
131 | - * @param integer $flags ArrayObject flags |
|
132 | - */ |
|
133 | - public function __construct($array = array(), $flags = parent::ARRAY_AS_PROPS) { |
|
134 | - parent::__construct($array, $flags); |
|
135 | - } |
|
127 | + /** |
|
128 | + * the constructor |
|
129 | + * |
|
130 | + * @param array $array data array |
|
131 | + * @param integer $flags ArrayObject flags |
|
132 | + */ |
|
133 | + public function __construct($array = array(), $flags = parent::ARRAY_AS_PROPS) { |
|
134 | + parent::__construct($array, $flags); |
|
135 | + } |
|
136 | 136 | |
137 | - /** |
|
138 | - * method to check if offset exists |
|
139 | - * |
|
140 | - * @param string $index |
|
141 | - * |
|
142 | - * @returns mixed |
|
143 | - * |
|
144 | - * Workaround for http://bugs.php.net/bug.php?id=40442 (ZF-960). |
|
145 | - */ |
|
146 | - public function offsetExists($index) { |
|
147 | - return array_key_exists($index, $this); |
|
148 | - } |
|
137 | + /** |
|
138 | + * method to check if offset exists |
|
139 | + * |
|
140 | + * @param string $index |
|
141 | + * |
|
142 | + * @returns mixed |
|
143 | + * |
|
144 | + * Workaround for http://bugs.php.net/bug.php?id=40442 (ZF-960). |
|
145 | + */ |
|
146 | + public function offsetExists($index) { |
|
147 | + return array_key_exists($index, $this); |
|
148 | + } |
|
149 | 149 | } |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * the Router class |
|
4 | - */ |
|
3 | + * the Router class |
|
4 | + */ |
|
5 | 5 | |
6 | 6 | namespace Phile\Core; |
7 | 7 | |
@@ -15,138 +15,138 @@ discard block |
||
15 | 15 | */ |
16 | 16 | class Router { |
17 | 17 | |
18 | - /** |
|
19 | - * @var array with $_SERVER environment |
|
20 | - */ |
|
21 | - protected $server; |
|
22 | - |
|
23 | - /** |
|
24 | - * @param array $server $_SERVER environment |
|
25 | - */ |
|
26 | - public function __construct(array $server = []) { |
|
27 | - if (empty($server)) { |
|
28 | - $server = $_SERVER; |
|
29 | - } |
|
30 | - $this->server = $server; |
|
31 | - } |
|
32 | - |
|
33 | - /** |
|
34 | - * get request-URL relative to Phile base-URL |
|
35 | - * |
|
36 | - * @return string relative URL e.g. `index`, `sub/`, `sub/page` |
|
37 | - */ |
|
38 | - public function getCurrentUrl() { |
|
39 | - $url = $this->server['REQUEST_URI']; |
|
40 | - |
|
41 | - // remove query string |
|
42 | - $queryPosition = strpos($url, '?'); |
|
43 | - if ($queryPosition) { |
|
44 | - $url = substr($url, 0, $queryPosition); |
|
45 | - } |
|
46 | - |
|
47 | - // resolve root-relative URL-path |
|
48 | - $baseUrl = $this->getBaseUrl(); |
|
49 | - $basePath = $this->getUrlPath($baseUrl); |
|
50 | - if (!empty($basePath) && strpos($url, $basePath) === 0) { |
|
51 | - $url = substr($url, strlen($basePath)); |
|
52 | - } |
|
53 | - $url = ltrim($url, '/'); |
|
54 | - |
|
55 | - $url = urldecode($url); |
|
56 | - |
|
57 | - return $url; |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Get base-URL of the Phile installation |
|
62 | - * |
|
63 | - * @return string `scheme://host/path/phile-root` |
|
64 | - */ |
|
65 | - public function getBaseUrl() { |
|
66 | - if (Registry::isRegistered('Phile_Settings')) { |
|
67 | - $config = Registry::get('Phile_Settings'); |
|
68 | - if (!empty($config['base_url'])) { |
|
69 | - return $config['base_url']; |
|
70 | - } |
|
71 | - } |
|
72 | - |
|
73 | - $url = ''; |
|
74 | - |
|
75 | - if (isset($this->server['PHP_SELF'])) { |
|
76 | - $url = preg_replace('/index\.php(.*)?$/', '', $this->server['PHP_SELF']); |
|
77 | - } |
|
78 | - |
|
79 | - if (isset($this->server['HTTP_HOST'])) { |
|
80 | - $host = $this->server['HTTP_HOST']; |
|
81 | - $protocol = $this->getProtocol(); |
|
82 | - $url = $protocol . '://' . $host . $url; |
|
83 | - } |
|
84 | - |
|
85 | - $url = rtrim($url, '/'); |
|
86 | - return $url; |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * get the URL for a page-Id |
|
91 | - * |
|
92 | - * e.g. `sub/index` --> `http://host/phile-root/sub` |
|
93 | - * |
|
94 | - * @param string $pageId |
|
95 | - * @param bool $base return a full or root-relative URL |
|
96 | - * @return string URL |
|
97 | - */ |
|
98 | - public function urlForPage($pageId, $base = true) { |
|
99 | - $url = $pageId; |
|
100 | - if ($base) { |
|
101 | - $url = $this->url($url); |
|
102 | - } |
|
103 | - return $url; |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * converts Phile-root relative URL to full URL |
|
108 | - * |
|
109 | - * e.g. `foo/bar.ext` --> `http://host/phile-root/foo/bar.ext` |
|
110 | - * |
|
111 | - * @param string $url |
|
112 | - * @return string |
|
113 | - */ |
|
114 | - public function url($url) { |
|
115 | - return $this->getBaseUrl() . '/' . ltrim($url, '/'); |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * get the HTTP-protocol |
|
120 | - * |
|
121 | - * @return string |
|
122 | - */ |
|
123 | - public function getProtocol() { |
|
124 | - if (empty($this->server['HTTP_HOST'])) { |
|
125 | - return null; |
|
126 | - } |
|
127 | - $protocol = 'http'; |
|
128 | - if (isset($this->server['HTTPS']) && strtolower($this->server['HTTPS']) !== 'off') { |
|
129 | - $protocol = 'https'; |
|
130 | - } |
|
131 | - return $protocol; |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * get path of an URL |
|
136 | - * |
|
137 | - * `scheme://host/path/sub` --> `/path/sub` |
|
138 | - * |
|
139 | - * @param string $url |
|
140 | - * @return string |
|
141 | - */ |
|
142 | - protected function getUrlPath($url) { |
|
143 | - $path = ''; |
|
144 | - if (strpos($url, '://') !== false) { |
|
145 | - $parsed = parse_url($url); |
|
146 | - if (isset($parsed['path'])) { |
|
147 | - $path = $parsed['path']; |
|
148 | - } |
|
149 | - } |
|
150 | - return $path; |
|
151 | - } |
|
18 | + /** |
|
19 | + * @var array with $_SERVER environment |
|
20 | + */ |
|
21 | + protected $server; |
|
22 | + |
|
23 | + /** |
|
24 | + * @param array $server $_SERVER environment |
|
25 | + */ |
|
26 | + public function __construct(array $server = []) { |
|
27 | + if (empty($server)) { |
|
28 | + $server = $_SERVER; |
|
29 | + } |
|
30 | + $this->server = $server; |
|
31 | + } |
|
32 | + |
|
33 | + /** |
|
34 | + * get request-URL relative to Phile base-URL |
|
35 | + * |
|
36 | + * @return string relative URL e.g. `index`, `sub/`, `sub/page` |
|
37 | + */ |
|
38 | + public function getCurrentUrl() { |
|
39 | + $url = $this->server['REQUEST_URI']; |
|
40 | + |
|
41 | + // remove query string |
|
42 | + $queryPosition = strpos($url, '?'); |
|
43 | + if ($queryPosition) { |
|
44 | + $url = substr($url, 0, $queryPosition); |
|
45 | + } |
|
46 | + |
|
47 | + // resolve root-relative URL-path |
|
48 | + $baseUrl = $this->getBaseUrl(); |
|
49 | + $basePath = $this->getUrlPath($baseUrl); |
|
50 | + if (!empty($basePath) && strpos($url, $basePath) === 0) { |
|
51 | + $url = substr($url, strlen($basePath)); |
|
52 | + } |
|
53 | + $url = ltrim($url, '/'); |
|
54 | + |
|
55 | + $url = urldecode($url); |
|
56 | + |
|
57 | + return $url; |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Get base-URL of the Phile installation |
|
62 | + * |
|
63 | + * @return string `scheme://host/path/phile-root` |
|
64 | + */ |
|
65 | + public function getBaseUrl() { |
|
66 | + if (Registry::isRegistered('Phile_Settings')) { |
|
67 | + $config = Registry::get('Phile_Settings'); |
|
68 | + if (!empty($config['base_url'])) { |
|
69 | + return $config['base_url']; |
|
70 | + } |
|
71 | + } |
|
72 | + |
|
73 | + $url = ''; |
|
74 | + |
|
75 | + if (isset($this->server['PHP_SELF'])) { |
|
76 | + $url = preg_replace('/index\.php(.*)?$/', '', $this->server['PHP_SELF']); |
|
77 | + } |
|
78 | + |
|
79 | + if (isset($this->server['HTTP_HOST'])) { |
|
80 | + $host = $this->server['HTTP_HOST']; |
|
81 | + $protocol = $this->getProtocol(); |
|
82 | + $url = $protocol . '://' . $host . $url; |
|
83 | + } |
|
84 | + |
|
85 | + $url = rtrim($url, '/'); |
|
86 | + return $url; |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * get the URL for a page-Id |
|
91 | + * |
|
92 | + * e.g. `sub/index` --> `http://host/phile-root/sub` |
|
93 | + * |
|
94 | + * @param string $pageId |
|
95 | + * @param bool $base return a full or root-relative URL |
|
96 | + * @return string URL |
|
97 | + */ |
|
98 | + public function urlForPage($pageId, $base = true) { |
|
99 | + $url = $pageId; |
|
100 | + if ($base) { |
|
101 | + $url = $this->url($url); |
|
102 | + } |
|
103 | + return $url; |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * converts Phile-root relative URL to full URL |
|
108 | + * |
|
109 | + * e.g. `foo/bar.ext` --> `http://host/phile-root/foo/bar.ext` |
|
110 | + * |
|
111 | + * @param string $url |
|
112 | + * @return string |
|
113 | + */ |
|
114 | + public function url($url) { |
|
115 | + return $this->getBaseUrl() . '/' . ltrim($url, '/'); |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * get the HTTP-protocol |
|
120 | + * |
|
121 | + * @return string |
|
122 | + */ |
|
123 | + public function getProtocol() { |
|
124 | + if (empty($this->server['HTTP_HOST'])) { |
|
125 | + return null; |
|
126 | + } |
|
127 | + $protocol = 'http'; |
|
128 | + if (isset($this->server['HTTPS']) && strtolower($this->server['HTTPS']) !== 'off') { |
|
129 | + $protocol = 'https'; |
|
130 | + } |
|
131 | + return $protocol; |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * get path of an URL |
|
136 | + * |
|
137 | + * `scheme://host/path/sub` --> `/path/sub` |
|
138 | + * |
|
139 | + * @param string $url |
|
140 | + * @return string |
|
141 | + */ |
|
142 | + protected function getUrlPath($url) { |
|
143 | + $path = ''; |
|
144 | + if (strpos($url, '://') !== false) { |
|
145 | + $parsed = parse_url($url); |
|
146 | + if (isset($parsed['path'])) { |
|
147 | + $path = $parsed['path']; |
|
148 | + } |
|
149 | + } |
|
150 | + return $path; |
|
151 | + } |
|
152 | 152 | } |
@@ -22,119 +22,119 @@ |
||
22 | 22 | */ |
23 | 23 | class Response { |
24 | 24 | |
25 | - /** |
|
26 | - * @var string HTTP body |
|
27 | - */ |
|
28 | - protected $body = ''; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var string charset |
|
32 | - */ |
|
33 | - protected $charset = 'utf-8'; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var array HTTP-headers |
|
37 | - */ |
|
38 | - protected $headers = []; |
|
39 | - |
|
40 | - /** |
|
41 | - * @var int HTTP status code |
|
42 | - */ |
|
43 | - protected $statusCode = 200; |
|
44 | - |
|
45 | - /** |
|
46 | - * redirect to another URL |
|
47 | - * |
|
48 | - * @param string $url URL |
|
49 | - * @param int $statusCode |
|
50 | - */ |
|
51 | - public function redirect($url, $statusCode = 302) { |
|
52 | - $this->setStatusCode($statusCode) |
|
53 | - ->setHeader('Location', $url, true) |
|
54 | - ->setBody('') |
|
55 | - ->send() |
|
56 | - ->stop(); |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * set the response body |
|
61 | - * |
|
62 | - * @param $body |
|
63 | - * @return $this |
|
64 | - */ |
|
65 | - public function setBody($body) { |
|
66 | - $this->body = $body; |
|
67 | - return $this; |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * set the response character-set |
|
72 | - * |
|
73 | - * @param $charset |
|
74 | - * @return $this |
|
75 | - */ |
|
76 | - public function setCharset($charset) { |
|
77 | - $this->charset = $charset; |
|
78 | - return $this; |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * set a response HTTP-header |
|
83 | - * |
|
84 | - * @param string $key |
|
85 | - * @param string $value |
|
86 | - * @param bool $clear clear out any existing headers |
|
87 | - * @return $this |
|
88 | - */ |
|
89 | - public function setHeader($key, $value, $clear = false) { |
|
90 | - if ($clear) { |
|
91 | - $this->headers = []; |
|
92 | - } |
|
93 | - $this->headers[$key] = "$key: $value"; |
|
94 | - return $this; |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * set the response HTTP status code |
|
99 | - * |
|
100 | - * @param $code |
|
101 | - * @return $this |
|
102 | - */ |
|
103 | - public function setStatusCode($code) { |
|
104 | - $this->statusCode = $code; |
|
105 | - return $this; |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * sends the HTTP response |
|
110 | - * |
|
111 | - * @return $this |
|
112 | - */ |
|
113 | - public function send() { |
|
114 | - if (!isset($this->headers['Content-Type'])) { |
|
115 | - $this->setHeader('Content-Type', 'text/html; charset=' . $this->charset); |
|
116 | - } |
|
117 | - $this->outputHeader(); |
|
118 | - http_response_code($this->statusCode); |
|
119 | - echo $this->body; |
|
120 | - return $this; |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * helper for easy testing |
|
125 | - */ |
|
126 | - public function stop() { |
|
127 | - die(); |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * output all set response headers |
|
132 | - */ |
|
133 | - protected function outputHeader() { |
|
134 | - foreach ($this->headers as $header) { |
|
135 | - header($header); |
|
136 | - } |
|
137 | - } |
|
25 | + /** |
|
26 | + * @var string HTTP body |
|
27 | + */ |
|
28 | + protected $body = ''; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var string charset |
|
32 | + */ |
|
33 | + protected $charset = 'utf-8'; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var array HTTP-headers |
|
37 | + */ |
|
38 | + protected $headers = []; |
|
39 | + |
|
40 | + /** |
|
41 | + * @var int HTTP status code |
|
42 | + */ |
|
43 | + protected $statusCode = 200; |
|
44 | + |
|
45 | + /** |
|
46 | + * redirect to another URL |
|
47 | + * |
|
48 | + * @param string $url URL |
|
49 | + * @param int $statusCode |
|
50 | + */ |
|
51 | + public function redirect($url, $statusCode = 302) { |
|
52 | + $this->setStatusCode($statusCode) |
|
53 | + ->setHeader('Location', $url, true) |
|
54 | + ->setBody('') |
|
55 | + ->send() |
|
56 | + ->stop(); |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * set the response body |
|
61 | + * |
|
62 | + * @param $body |
|
63 | + * @return $this |
|
64 | + */ |
|
65 | + public function setBody($body) { |
|
66 | + $this->body = $body; |
|
67 | + return $this; |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * set the response character-set |
|
72 | + * |
|
73 | + * @param $charset |
|
74 | + * @return $this |
|
75 | + */ |
|
76 | + public function setCharset($charset) { |
|
77 | + $this->charset = $charset; |
|
78 | + return $this; |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * set a response HTTP-header |
|
83 | + * |
|
84 | + * @param string $key |
|
85 | + * @param string $value |
|
86 | + * @param bool $clear clear out any existing headers |
|
87 | + * @return $this |
|
88 | + */ |
|
89 | + public function setHeader($key, $value, $clear = false) { |
|
90 | + if ($clear) { |
|
91 | + $this->headers = []; |
|
92 | + } |
|
93 | + $this->headers[$key] = "$key: $value"; |
|
94 | + return $this; |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * set the response HTTP status code |
|
99 | + * |
|
100 | + * @param $code |
|
101 | + * @return $this |
|
102 | + */ |
|
103 | + public function setStatusCode($code) { |
|
104 | + $this->statusCode = $code; |
|
105 | + return $this; |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * sends the HTTP response |
|
110 | + * |
|
111 | + * @return $this |
|
112 | + */ |
|
113 | + public function send() { |
|
114 | + if (!isset($this->headers['Content-Type'])) { |
|
115 | + $this->setHeader('Content-Type', 'text/html; charset=' . $this->charset); |
|
116 | + } |
|
117 | + $this->outputHeader(); |
|
118 | + http_response_code($this->statusCode); |
|
119 | + echo $this->body; |
|
120 | + return $this; |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * helper for easy testing |
|
125 | + */ |
|
126 | + public function stop() { |
|
127 | + die(); |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * output all set response headers |
|
132 | + */ |
|
133 | + protected function outputHeader() { |
|
134 | + foreach ($this->headers as $header) { |
|
135 | + header($header); |
|
136 | + } |
|
137 | + } |
|
138 | 138 | |
139 | 139 | } |
140 | 140 |
@@ -14,64 +14,64 @@ |
||
14 | 14 | * @package Phile\Core |
15 | 15 | */ |
16 | 16 | class ServiceLocator { |
17 | - /** |
|
18 | - * @var array of services |
|
19 | - */ |
|
20 | - protected static $services; |
|
17 | + /** |
|
18 | + * @var array of services |
|
19 | + */ |
|
20 | + protected static $services; |
|
21 | 21 | |
22 | - /** |
|
23 | - * @var array $serviceMap for mapping speaking names/keys to the interfaces |
|
24 | - */ |
|
25 | - protected static $serviceMap = array( |
|
26 | - 'Phile_Cache' => 'Phile\ServiceLocator\CacheInterface', |
|
27 | - 'Phile_Template' => 'Phile\ServiceLocator\TemplateInterface', |
|
28 | - 'Phile_Parser' => 'Phile\ServiceLocator\ParserInterface', |
|
29 | - 'Phile_Data_Persistence' => 'Phile\ServiceLocator\PersistenceInterface', |
|
30 | - 'Phile_Parser_Meta' => 'Phile\ServiceLocator\MetaInterface', |
|
31 | - 'Phile_ErrorHandler' => 'Phile\ServiceLocator\ErrorHandlerInterface', |
|
32 | - ); |
|
22 | + /** |
|
23 | + * @var array $serviceMap for mapping speaking names/keys to the interfaces |
|
24 | + */ |
|
25 | + protected static $serviceMap = array( |
|
26 | + 'Phile_Cache' => 'Phile\ServiceLocator\CacheInterface', |
|
27 | + 'Phile_Template' => 'Phile\ServiceLocator\TemplateInterface', |
|
28 | + 'Phile_Parser' => 'Phile\ServiceLocator\ParserInterface', |
|
29 | + 'Phile_Data_Persistence' => 'Phile\ServiceLocator\PersistenceInterface', |
|
30 | + 'Phile_Parser_Meta' => 'Phile\ServiceLocator\MetaInterface', |
|
31 | + 'Phile_ErrorHandler' => 'Phile\ServiceLocator\ErrorHandlerInterface', |
|
32 | + ); |
|
33 | 33 | |
34 | - /** |
|
35 | - * method to register a service |
|
36 | - * |
|
37 | - * @param string $serviceKey the key for the service |
|
38 | - * @param mixed $object |
|
39 | - * |
|
40 | - * @throws ServiceLocatorException |
|
41 | - */ |
|
42 | - public static function registerService($serviceKey, $object) { |
|
43 | - $interfaces = class_implements($object); |
|
44 | - $interface = self::$serviceMap[$serviceKey]; |
|
45 | - if ($interfaces === false || !in_array($interface, $interfaces)) { |
|
46 | - throw new ServiceLocatorException("the object must implement the interface: '{$interface}'", 1398536617); |
|
47 | - } |
|
48 | - self::$services[$serviceKey] = $object; |
|
49 | - } |
|
34 | + /** |
|
35 | + * method to register a service |
|
36 | + * |
|
37 | + * @param string $serviceKey the key for the service |
|
38 | + * @param mixed $object |
|
39 | + * |
|
40 | + * @throws ServiceLocatorException |
|
41 | + */ |
|
42 | + public static function registerService($serviceKey, $object) { |
|
43 | + $interfaces = class_implements($object); |
|
44 | + $interface = self::$serviceMap[$serviceKey]; |
|
45 | + if ($interfaces === false || !in_array($interface, $interfaces)) { |
|
46 | + throw new ServiceLocatorException("the object must implement the interface: '{$interface}'", 1398536617); |
|
47 | + } |
|
48 | + self::$services[$serviceKey] = $object; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * checks if a service is registered |
|
53 | - * |
|
54 | - * @param string $serviceKey |
|
55 | - * |
|
56 | - * @return bool |
|
57 | - */ |
|
58 | - public static function hasService($serviceKey) { |
|
59 | - return (isset(self::$services[$serviceKey])); |
|
60 | - } |
|
51 | + /** |
|
52 | + * checks if a service is registered |
|
53 | + * |
|
54 | + * @param string $serviceKey |
|
55 | + * |
|
56 | + * @return bool |
|
57 | + */ |
|
58 | + public static function hasService($serviceKey) { |
|
59 | + return (isset(self::$services[$serviceKey])); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * returns a service |
|
64 | - * |
|
65 | - * @param string $serviceKey the service key |
|
66 | - * |
|
67 | - * @return mixed |
|
68 | - * @throws ServiceLocatorException |
|
69 | - */ |
|
70 | - public static function getService($serviceKey) { |
|
71 | - if (!isset(self::$services[$serviceKey])) { |
|
72 | - throw new ServiceLocatorException("the service '{$serviceKey}' is not registered", 1398536637); |
|
73 | - } |
|
62 | + /** |
|
63 | + * returns a service |
|
64 | + * |
|
65 | + * @param string $serviceKey the service key |
|
66 | + * |
|
67 | + * @return mixed |
|
68 | + * @throws ServiceLocatorException |
|
69 | + */ |
|
70 | + public static function getService($serviceKey) { |
|
71 | + if (!isset(self::$services[$serviceKey])) { |
|
72 | + throw new ServiceLocatorException("the service '{$serviceKey}' is not registered", 1398536637); |
|
73 | + } |
|
74 | 74 | |
75 | - return self::$services[$serviceKey]; |
|
76 | - } |
|
75 | + return self::$services[$serviceKey]; |
|
76 | + } |
|
77 | 77 | } |