@@ -1,10 +1,10 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Created by PhpStorm. |
|
4 | - * User: franae |
|
5 | - * Date: 30/10/13 |
|
6 | - * Time: 14:47 |
|
7 | - */ |
|
3 | + * Created by PhpStorm. |
|
4 | + * User: franae |
|
5 | + * Date: 30/10/13 |
|
6 | + * Time: 14:47 |
|
7 | + */ |
|
8 | 8 | |
9 | 9 | namespace Phile\Exception; |
10 | 10 |
@@ -1,7 +1,7 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * The Event class |
|
4 | - */ |
|
3 | + * The Event class |
|
4 | + */ |
|
5 | 5 | namespace Phile; |
6 | 6 | |
7 | 7 | /** |
@@ -1,7 +1,7 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * config file |
|
4 | - */ |
|
3 | + * config file |
|
4 | + */ |
|
5 | 5 | return [ |
6 | 6 | 'setting-example' => 'I love Phile!' |
7 | 7 | ]; |
@@ -1,7 +1,7 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * The SerciveLocator class |
|
4 | - */ |
|
3 | + * The SerciveLocator class |
|
4 | + */ |
|
5 | 5 | namespace Phile\Core; |
6 | 6 | |
7 | 7 | use Phile\Exception\ServiceLocatorException; |
@@ -11,25 +11,25 @@ |
||
11 | 11 | ob_start(); |
12 | 12 | |
13 | 13 | try { |
14 | - \Phile\Bootstrap::getInstance()->initializeBasics(); |
|
15 | - $router = new \Phile\Core\Router(); |
|
16 | - $response = new \Phile\Core\Response(); |
|
17 | - $phileCore = new \Phile\Core($router, $response); |
|
18 | - $phileCore->render(); |
|
14 | + \Phile\Bootstrap::getInstance()->initializeBasics(); |
|
15 | + $router = new \Phile\Core\Router(); |
|
16 | + $response = new \Phile\Core\Response(); |
|
17 | + $phileCore = new \Phile\Core($router, $response); |
|
18 | + $phileCore->render(); |
|
19 | 19 | } catch (\Phile\Exception\AbstractException $e) { |
20 | - if (\Phile\Core\ServiceLocator::hasService('Phile_ErrorHandler')) { |
|
21 | - ob_end_clean(); |
|
20 | + if (\Phile\Core\ServiceLocator::hasService('Phile_ErrorHandler')) { |
|
21 | + ob_end_clean(); |
|
22 | 22 | |
23 | - /** @var \Phile\ServiceLocator\ErrorHandlerInterface $errorHandler */ |
|
24 | - $errorHandler = \Phile\Core\ServiceLocator::getService('Phile_ErrorHandler'); |
|
25 | - $errorHandler->handleException($e); |
|
26 | - } |
|
23 | + /** @var \Phile\ServiceLocator\ErrorHandlerInterface $errorHandler */ |
|
24 | + $errorHandler = \Phile\Core\ServiceLocator::getService('Phile_ErrorHandler'); |
|
25 | + $errorHandler->handleException($e); |
|
26 | + } |
|
27 | 27 | } catch (\Exception $e) { |
28 | - if (\Phile\Core\ServiceLocator::hasService('Phile_ErrorHandler')) { |
|
29 | - ob_end_clean(); |
|
28 | + if (\Phile\Core\ServiceLocator::hasService('Phile_ErrorHandler')) { |
|
29 | + ob_end_clean(); |
|
30 | 30 | |
31 | - /** @var \Phile\ServiceLocator\ErrorHandlerInterface $errorHandler */ |
|
32 | - $errorHandler = \Phile\Core\ServiceLocator::getService('Phile_ErrorHandler'); |
|
33 | - $errorHandler->handleException($e); |
|
34 | - } |
|
31 | + /** @var \Phile\ServiceLocator\ErrorHandlerInterface $errorHandler */ |
|
32 | + $errorHandler = \Phile\Core\ServiceLocator::getService('Phile_ErrorHandler'); |
|
33 | + $errorHandler->handleException($e); |
|
34 | + } |
|
35 | 35 | } |
@@ -9,24 +9,24 @@ |
||
9 | 9 | |
10 | 10 | class Plugin extends AbstractPlugin { |
11 | 11 | |
12 | - protected $events = [ |
|
13 | - 'phile\testPlugin.testEvent' => 'onTestEvent', |
|
14 | - 'phile\testPlugin.testEvent-missingMethod' => 'missingMethod' |
|
15 | - ]; |
|
16 | - |
|
17 | - protected $settings = ['A' => 'X', 'B' => 'X', 'C' => 'C']; |
|
18 | - |
|
19 | - /** |
|
20 | - * accessor for easy testing |
|
21 | - * |
|
22 | - * @param string $path |
|
23 | - * @return null|string |
|
24 | - */ |
|
25 | - public function getPluginPath($path = '') { |
|
26 | - return parent::getPluginPath($path); |
|
27 | - } |
|
28 | - |
|
29 | - protected function onTestEvent() { |
|
30 | - } |
|
12 | + protected $events = [ |
|
13 | + 'phile\testPlugin.testEvent' => 'onTestEvent', |
|
14 | + 'phile\testPlugin.testEvent-missingMethod' => 'missingMethod' |
|
15 | + ]; |
|
16 | + |
|
17 | + protected $settings = ['A' => 'X', 'B' => 'X', 'C' => 'C']; |
|
18 | + |
|
19 | + /** |
|
20 | + * accessor for easy testing |
|
21 | + * |
|
22 | + * @param string $path |
|
23 | + * @return null|string |
|
24 | + */ |
|
25 | + public function getPluginPath($path = '') { |
|
26 | + return parent::getPluginPath($path); |
|
27 | + } |
|
28 | + |
|
29 | + protected function onTestEvent() { |
|
30 | + } |
|
31 | 31 | |
32 | 32 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | return [ |
4 | - 'A' => 'X', |
|
5 | - 'B' => 'B' |
|
4 | + 'A' => 'X', |
|
5 | + 'B' => 'B' |
|
6 | 6 | ]; |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Template engine class |
|
4 | - */ |
|
3 | + * Template engine class |
|
4 | + */ |
|
5 | 5 | namespace Phile\Plugin\Phile\TemplateTwig\Template; |
6 | 6 | |
7 | 7 | use Phile\Core\Event; |
@@ -19,157 +19,157 @@ discard block |
||
19 | 19 | * @package Phile\Plugin\Phile\TemplateTwig\Template |
20 | 20 | */ |
21 | 21 | class Twig implements TemplateInterface { |
22 | - /** |
|
23 | - * @var array the complete phile config |
|
24 | - */ |
|
25 | - protected $settings; |
|
26 | - |
|
27 | - /** |
|
28 | - * @var array the config for twig |
|
29 | - */ |
|
30 | - protected $config; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var Page the page model |
|
34 | - */ |
|
35 | - protected $page; |
|
36 | - |
|
37 | - /** |
|
38 | - * the constructor |
|
39 | - * |
|
40 | - * @param array $config the configuration |
|
41 | - */ |
|
42 | - public function __construct($config = []) { |
|
43 | - $this->config = $config; |
|
44 | - $this->settings = Registry::get('Phile_Settings'); |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * method to set the current page |
|
49 | - * |
|
50 | - * @param Page $page the page model |
|
51 | - * |
|
52 | - * @return mixed|void |
|
53 | - */ |
|
54 | - public function setCurrentPage(Page $page) { |
|
55 | - $this->page = $page; |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * method to render the page/template |
|
60 | - * |
|
61 | - * @return mixed|string |
|
62 | - */ |
|
63 | - public function render() { |
|
64 | - $engine = $this->getEngine(); |
|
65 | - $vars = $this->getTemplateVars(); |
|
66 | - |
|
67 | - Event::triggerEvent( |
|
68 | - 'template_engine_registered', |
|
69 | - ['engine' => &$engine, 'data' => &$vars] |
|
70 | - ); |
|
71 | - |
|
72 | - return $this->_render($engine, $vars); |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * wrapper to call the render engine |
|
77 | - * |
|
78 | - * @param $engine |
|
79 | - * @param $vars |
|
80 | - * @return mixed |
|
81 | - */ |
|
82 | - protected function _render($engine, $vars) { |
|
83 | - try { |
|
84 | - $template = $this->getTemplateFileName(); |
|
85 | - } catch (\RuntimeException $e) { |
|
86 | - return $e->getMessage(); |
|
87 | - } |
|
88 | - return $engine->render($template, $vars); |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * get template engine |
|
93 | - * |
|
94 | - * @return \Twig_Environment |
|
95 | - */ |
|
96 | - protected function getEngine() { |
|
97 | - $loader = new \Twig_Loader_Filesystem($this->getTemplatePath()); |
|
98 | - $twig = new \Twig_Environment($loader, $this->config); |
|
99 | - |
|
100 | - // load the twig debug extension if required |
|
101 | - if (!empty($this->config['debug'])) { |
|
102 | - $twig->addExtension(new \Twig_Extension_Debug()); |
|
103 | - } |
|
104 | - return $twig; |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * get template file name |
|
109 | - * |
|
110 | - * @return string |
|
111 | - * @throws \RuntimeException |
|
112 | - */ |
|
113 | - protected function getTemplateFileName() { |
|
114 | - $template = $this->page->getMeta()->get('template'); |
|
115 | - if (empty($template)) { |
|
116 | - $template = 'index'; |
|
117 | - } |
|
118 | - if (!empty($this->config['template-extension'])) { |
|
119 | - $template .= '.' . $this->config['template-extension']; |
|
120 | - } |
|
121 | - $templatePath = $this->getTemplatePath($template); |
|
122 | - if (!file_exists($templatePath)) { |
|
123 | - throw new \RuntimeException( |
|
124 | - "Template file '{$templatePath}' not found.", |
|
125 | - 1427990135 |
|
126 | - ); |
|
127 | - } |
|
128 | - return $template; |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * get file path to (sub-path) in theme-path |
|
133 | - * |
|
134 | - * @param string $sub |
|
135 | - * @return string |
|
136 | - */ |
|
137 | - protected function getTemplatePath($sub = '') { |
|
138 | - $themePath = THEMES_DIR . $this->settings['theme']; |
|
139 | - if (!empty($sub)) { |
|
140 | - $themePath .= '/' . ltrim($sub, DIRECTORY_SEPARATOR); |
|
141 | - } |
|
142 | - return $themePath; |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * get template vars |
|
147 | - * |
|
148 | - * @return array|mixed |
|
149 | - * @throws \Exception |
|
150 | - */ |
|
151 | - protected function getTemplateVars() { |
|
152 | - $repository = new Repository($this->settings); |
|
153 | - $defaults = [ |
|
154 | - 'content' => $this->page->getContent(), |
|
155 | - 'meta' => $this->page->getMeta(), |
|
156 | - 'current_page' => $this->page, |
|
157 | - 'base_dir' => rtrim(ROOT_DIR, '/'), |
|
158 | - 'base_url' => $this->settings['base_url'], |
|
159 | - 'config' => $this->settings, |
|
160 | - 'content_dir' => CONTENT_DIR, |
|
161 | - 'content_url' => $this->settings['base_url'] . '/' . basename(CONTENT_DIR), |
|
162 | - 'pages' => $repository->findAll(), |
|
163 | - 'site_title' => $this->settings['site_title'], |
|
164 | - 'theme_dir' => THEMES_DIR . $this->settings['theme'], |
|
165 | - 'theme_url' => $this->settings['base_url'] . '/' . basename(THEMES_DIR) . '/' . $this->settings['theme'], |
|
166 | - ]; |
|
167 | - |
|
168 | - /** @var array $templateVars */ |
|
169 | - $templateVars = Registry::get('templateVars'); |
|
170 | - $templateVars += $defaults; |
|
171 | - |
|
172 | - return $templateVars; |
|
173 | - } |
|
22 | + /** |
|
23 | + * @var array the complete phile config |
|
24 | + */ |
|
25 | + protected $settings; |
|
26 | + |
|
27 | + /** |
|
28 | + * @var array the config for twig |
|
29 | + */ |
|
30 | + protected $config; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var Page the page model |
|
34 | + */ |
|
35 | + protected $page; |
|
36 | + |
|
37 | + /** |
|
38 | + * the constructor |
|
39 | + * |
|
40 | + * @param array $config the configuration |
|
41 | + */ |
|
42 | + public function __construct($config = []) { |
|
43 | + $this->config = $config; |
|
44 | + $this->settings = Registry::get('Phile_Settings'); |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * method to set the current page |
|
49 | + * |
|
50 | + * @param Page $page the page model |
|
51 | + * |
|
52 | + * @return mixed|void |
|
53 | + */ |
|
54 | + public function setCurrentPage(Page $page) { |
|
55 | + $this->page = $page; |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * method to render the page/template |
|
60 | + * |
|
61 | + * @return mixed|string |
|
62 | + */ |
|
63 | + public function render() { |
|
64 | + $engine = $this->getEngine(); |
|
65 | + $vars = $this->getTemplateVars(); |
|
66 | + |
|
67 | + Event::triggerEvent( |
|
68 | + 'template_engine_registered', |
|
69 | + ['engine' => &$engine, 'data' => &$vars] |
|
70 | + ); |
|
71 | + |
|
72 | + return $this->_render($engine, $vars); |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * wrapper to call the render engine |
|
77 | + * |
|
78 | + * @param $engine |
|
79 | + * @param $vars |
|
80 | + * @return mixed |
|
81 | + */ |
|
82 | + protected function _render($engine, $vars) { |
|
83 | + try { |
|
84 | + $template = $this->getTemplateFileName(); |
|
85 | + } catch (\RuntimeException $e) { |
|
86 | + return $e->getMessage(); |
|
87 | + } |
|
88 | + return $engine->render($template, $vars); |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * get template engine |
|
93 | + * |
|
94 | + * @return \Twig_Environment |
|
95 | + */ |
|
96 | + protected function getEngine() { |
|
97 | + $loader = new \Twig_Loader_Filesystem($this->getTemplatePath()); |
|
98 | + $twig = new \Twig_Environment($loader, $this->config); |
|
99 | + |
|
100 | + // load the twig debug extension if required |
|
101 | + if (!empty($this->config['debug'])) { |
|
102 | + $twig->addExtension(new \Twig_Extension_Debug()); |
|
103 | + } |
|
104 | + return $twig; |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * get template file name |
|
109 | + * |
|
110 | + * @return string |
|
111 | + * @throws \RuntimeException |
|
112 | + */ |
|
113 | + protected function getTemplateFileName() { |
|
114 | + $template = $this->page->getMeta()->get('template'); |
|
115 | + if (empty($template)) { |
|
116 | + $template = 'index'; |
|
117 | + } |
|
118 | + if (!empty($this->config['template-extension'])) { |
|
119 | + $template .= '.' . $this->config['template-extension']; |
|
120 | + } |
|
121 | + $templatePath = $this->getTemplatePath($template); |
|
122 | + if (!file_exists($templatePath)) { |
|
123 | + throw new \RuntimeException( |
|
124 | + "Template file '{$templatePath}' not found.", |
|
125 | + 1427990135 |
|
126 | + ); |
|
127 | + } |
|
128 | + return $template; |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * get file path to (sub-path) in theme-path |
|
133 | + * |
|
134 | + * @param string $sub |
|
135 | + * @return string |
|
136 | + */ |
|
137 | + protected function getTemplatePath($sub = '') { |
|
138 | + $themePath = THEMES_DIR . $this->settings['theme']; |
|
139 | + if (!empty($sub)) { |
|
140 | + $themePath .= '/' . ltrim($sub, DIRECTORY_SEPARATOR); |
|
141 | + } |
|
142 | + return $themePath; |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * get template vars |
|
147 | + * |
|
148 | + * @return array|mixed |
|
149 | + * @throws \Exception |
|
150 | + */ |
|
151 | + protected function getTemplateVars() { |
|
152 | + $repository = new Repository($this->settings); |
|
153 | + $defaults = [ |
|
154 | + 'content' => $this->page->getContent(), |
|
155 | + 'meta' => $this->page->getMeta(), |
|
156 | + 'current_page' => $this->page, |
|
157 | + 'base_dir' => rtrim(ROOT_DIR, '/'), |
|
158 | + 'base_url' => $this->settings['base_url'], |
|
159 | + 'config' => $this->settings, |
|
160 | + 'content_dir' => CONTENT_DIR, |
|
161 | + 'content_url' => $this->settings['base_url'] . '/' . basename(CONTENT_DIR), |
|
162 | + 'pages' => $repository->findAll(), |
|
163 | + 'site_title' => $this->settings['site_title'], |
|
164 | + 'theme_dir' => THEMES_DIR . $this->settings['theme'], |
|
165 | + 'theme_url' => $this->settings['base_url'] . '/' . basename(THEMES_DIR) . '/' . $this->settings['theme'], |
|
166 | + ]; |
|
167 | + |
|
168 | + /** @var array $templateVars */ |
|
169 | + $templateVars = Registry::get('templateVars'); |
|
170 | + $templateVars += $defaults; |
|
171 | + |
|
172 | + return $templateVars; |
|
173 | + } |
|
174 | 174 | |
175 | 175 | } |
@@ -19,17 +19,17 @@ |
||
19 | 19 | */ |
20 | 20 | class Plugin extends AbstractPlugin { |
21 | 21 | |
22 | - protected $events = ['plugins_loaded' => 'onPluginsLoaded']; |
|
22 | + protected $events = ['plugins_loaded' => 'onPluginsLoaded']; |
|
23 | 23 | |
24 | - /** |
|
25 | - * onPluginsLoaded method |
|
26 | - * |
|
27 | - * @param null $data |
|
28 | - * |
|
29 | - * @return mixed|void |
|
30 | - */ |
|
31 | - public function onPluginsLoaded($data = null) { |
|
32 | - ServiceLocator::registerService('Phile_Template', |
|
33 | - new Twig($this->settings)); |
|
34 | - } |
|
24 | + /** |
|
25 | + * onPluginsLoaded method |
|
26 | + * |
|
27 | + * @param null $data |
|
28 | + * |
|
29 | + * @return mixed|void |
|
30 | + */ |
|
31 | + public function onPluginsLoaded($data = null) { |
|
32 | + ServiceLocator::registerService('Phile_Template', |
|
33 | + new Twig($this->settings)); |
|
34 | + } |
|
35 | 35 | } |