@@ -3,5 +3,5 @@ |
||
| 3 | 3 | * config file |
| 4 | 4 | */ |
| 5 | 5 | return [ |
| 6 | - 'setting-example' => 'I love Phile!' |
|
| 6 | + 'setting-example' => 'I love Phile!' |
|
| 7 | 7 | ]; |
@@ -57,49 +57,49 @@ |
||
| 57 | 57 | * include core plugins |
| 58 | 58 | */ |
| 59 | 59 | $config['plugins'] = [ |
| 60 | - /** |
|
| 61 | - * error handler |
|
| 62 | - */ |
|
| 63 | - 'phile\\errorHandler' => [ |
|
| 64 | - 'active' => true, |
|
| 65 | - 'handler' => \Phile\Plugin\Phile\ErrorHandler\Plugin::HANDLER_DEVELOPMENT |
|
| 66 | - ], |
|
| 67 | - /** |
|
| 68 | - * setup check |
|
| 69 | - */ |
|
| 70 | - 'phile\\setupCheck' => ['active' => true], |
|
| 71 | - /** |
|
| 72 | - * parser |
|
| 73 | - */ |
|
| 74 | - 'phile\\parserMarkdown' => ['active' => true], |
|
| 75 | - /** |
|
| 76 | - * meta-tag parser |
|
| 77 | - */ |
|
| 78 | - 'phile\\parserMeta' => [ |
|
| 79 | - 'active' => true, |
|
| 80 | - /** |
|
| 81 | - * Set meta-data format. |
|
| 82 | - * |
|
| 83 | - * - 'Phile' (default) Phile legacy format |
|
| 84 | - * - 'YAML' YAML |
|
| 85 | - * |
|
| 86 | - * Phile is going to switch to YAML for parsing meta tags. But if you |
|
| 87 | - * want to use YAML today you can change the format here. |
|
| 88 | - */ |
|
| 89 | - 'format' => 'Phile' |
|
| 90 | - ], |
|
| 91 | - /** |
|
| 92 | - * template engine |
|
| 93 | - */ |
|
| 94 | - 'phile\\templateTwig' => ['active' => true], |
|
| 95 | - /** |
|
| 96 | - * cache engine |
|
| 97 | - */ |
|
| 98 | - 'phile\\phpFastCache' => ['active' => true], |
|
| 99 | - /** |
|
| 100 | - * persistent data storage |
|
| 101 | - */ |
|
| 102 | - 'phile\\simpleFileDataPersistence' => ['active' => true], |
|
| 60 | + /** |
|
| 61 | + * error handler |
|
| 62 | + */ |
|
| 63 | + 'phile\\errorHandler' => [ |
|
| 64 | + 'active' => true, |
|
| 65 | + 'handler' => \Phile\Plugin\Phile\ErrorHandler\Plugin::HANDLER_DEVELOPMENT |
|
| 66 | + ], |
|
| 67 | + /** |
|
| 68 | + * setup check |
|
| 69 | + */ |
|
| 70 | + 'phile\\setupCheck' => ['active' => true], |
|
| 71 | + /** |
|
| 72 | + * parser |
|
| 73 | + */ |
|
| 74 | + 'phile\\parserMarkdown' => ['active' => true], |
|
| 75 | + /** |
|
| 76 | + * meta-tag parser |
|
| 77 | + */ |
|
| 78 | + 'phile\\parserMeta' => [ |
|
| 79 | + 'active' => true, |
|
| 80 | + /** |
|
| 81 | + * Set meta-data format. |
|
| 82 | + * |
|
| 83 | + * - 'Phile' (default) Phile legacy format |
|
| 84 | + * - 'YAML' YAML |
|
| 85 | + * |
|
| 86 | + * Phile is going to switch to YAML for parsing meta tags. But if you |
|
| 87 | + * want to use YAML today you can change the format here. |
|
| 88 | + */ |
|
| 89 | + 'format' => 'Phile' |
|
| 90 | + ], |
|
| 91 | + /** |
|
| 92 | + * template engine |
|
| 93 | + */ |
|
| 94 | + 'phile\\templateTwig' => ['active' => true], |
|
| 95 | + /** |
|
| 96 | + * cache engine |
|
| 97 | + */ |
|
| 98 | + 'phile\\phpFastCache' => ['active' => true], |
|
| 99 | + /** |
|
| 100 | + * persistent data storage |
|
| 101 | + */ |
|
| 102 | + 'phile\\simpleFileDataPersistence' => ['active' => true], |
|
| 103 | 103 | ]; |
| 104 | 104 | |
| 105 | 105 | return $config; |
@@ -14,109 +14,109 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class PluginRepository { |
| 16 | 16 | |
| 17 | - /** @var array of AbstractPlugin */ |
|
| 18 | - protected $plugins = []; |
|
| 19 | - |
|
| 20 | - /** @var array errors during load; keys: 'message' and 'code' */ |
|
| 21 | - protected $loadErrors = []; |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * get load errors |
|
| 25 | - * |
|
| 26 | - * @return array |
|
| 27 | - */ |
|
| 28 | - public function getLoadErrors() { |
|
| 29 | - return $this->loadErrors; |
|
| 30 | - } |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * loads all activated plugins from $settings |
|
| 34 | - * |
|
| 35 | - * @param array $settings plugin-settings |
|
| 36 | - * @return array of AbstractPlugin |
|
| 37 | - * @throws PluginException |
|
| 38 | - */ |
|
| 39 | - public function loadAll($settings) { |
|
| 40 | - $this->reset(); |
|
| 41 | - foreach ($settings as $pluginKey => $config) { |
|
| 42 | - if (!isset($config['active']) || !$config['active']) { |
|
| 43 | - continue; |
|
| 44 | - } |
|
| 45 | - try { |
|
| 46 | - $this->plugins[$pluginKey] = $this->load($pluginKey); |
|
| 47 | - } catch (PluginException $e) { |
|
| 48 | - $this->loadErrors[] = [ |
|
| 49 | - 'message' => $e->getMessage(), |
|
| 50 | - 'code' => $e->getCode() |
|
| 51 | - ]; |
|
| 52 | - } |
|
| 53 | - } |
|
| 54 | - return $this->plugins; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * load and return single plugin |
|
| 59 | - * |
|
| 60 | - * @param $pluginKey |
|
| 61 | - * @return AbstractPlugin |
|
| 62 | - * @throws PluginException |
|
| 63 | - */ |
|
| 64 | - protected function load($pluginKey) { |
|
| 65 | - list($vendor, $pluginName) = explode('\\', $pluginKey); |
|
| 66 | - // uppercase first letter convention |
|
| 67 | - $pluginClassName = '\\Phile\\Plugin\\' . ucfirst($vendor) . '\\' . ucfirst($pluginName) . '\\Plugin'; |
|
| 68 | - |
|
| 69 | - if (!class_exists($pluginClassName)) { |
|
| 70 | - throw new PluginException( |
|
| 71 | - "the plugin '{$pluginKey}' could not be loaded!", |
|
| 72 | - 1398536479 |
|
| 73 | - ); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - /** @var \Phile\Plugin\AbstractPlugin $plugin */ |
|
| 77 | - $plugin = new $pluginClassName; |
|
| 78 | - if (($plugin instanceof AbstractPlugin) === false) { |
|
| 79 | - throw new PluginException( |
|
| 80 | - "the plugin '{$pluginKey}' is not an instance of \\Phile\\Plugin\\AbstractPlugin", |
|
| 81 | - 1398536526 |
|
| 82 | - ); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - $plugin->initializePlugin($pluginKey); |
|
| 86 | - return $plugin; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * clear out repository |
|
| 91 | - */ |
|
| 92 | - protected function reset() { |
|
| 93 | - $this->loadErrors = []; |
|
| 94 | - $this->plugins = []; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * auto-loader plugin namespace |
|
| 99 | - * |
|
| 100 | - * @param $className |
|
| 101 | - */ |
|
| 102 | - public static function autoload($className) { |
|
| 103 | - if (strpos($className, "Phile\\Plugin\\") !== 0) { |
|
| 104 | - return; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - $className = substr($className, 13); |
|
| 108 | - $classNameParts = explode('\\', $className); |
|
| 109 | - $pluginVendor = lcfirst(array_shift($classNameParts)); |
|
| 110 | - $pluginName = lcfirst(array_shift($classNameParts)); |
|
| 111 | - $classPath = array_merge( |
|
| 112 | - [$pluginVendor, $pluginName, 'Classes'], |
|
| 113 | - $classNameParts |
|
| 114 | - ); |
|
| 115 | - |
|
| 116 | - $fileName = PLUGINS_DIR . implode(DIRECTORY_SEPARATOR, $classPath) . '.php'; |
|
| 117 | - if (file_exists($fileName)) { |
|
| 118 | - require_once $fileName; |
|
| 119 | - } |
|
| 120 | - } |
|
| 17 | + /** @var array of AbstractPlugin */ |
|
| 18 | + protected $plugins = []; |
|
| 19 | + |
|
| 20 | + /** @var array errors during load; keys: 'message' and 'code' */ |
|
| 21 | + protected $loadErrors = []; |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * get load errors |
|
| 25 | + * |
|
| 26 | + * @return array |
|
| 27 | + */ |
|
| 28 | + public function getLoadErrors() { |
|
| 29 | + return $this->loadErrors; |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * loads all activated plugins from $settings |
|
| 34 | + * |
|
| 35 | + * @param array $settings plugin-settings |
|
| 36 | + * @return array of AbstractPlugin |
|
| 37 | + * @throws PluginException |
|
| 38 | + */ |
|
| 39 | + public function loadAll($settings) { |
|
| 40 | + $this->reset(); |
|
| 41 | + foreach ($settings as $pluginKey => $config) { |
|
| 42 | + if (!isset($config['active']) || !$config['active']) { |
|
| 43 | + continue; |
|
| 44 | + } |
|
| 45 | + try { |
|
| 46 | + $this->plugins[$pluginKey] = $this->load($pluginKey); |
|
| 47 | + } catch (PluginException $e) { |
|
| 48 | + $this->loadErrors[] = [ |
|
| 49 | + 'message' => $e->getMessage(), |
|
| 50 | + 'code' => $e->getCode() |
|
| 51 | + ]; |
|
| 52 | + } |
|
| 53 | + } |
|
| 54 | + return $this->plugins; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * load and return single plugin |
|
| 59 | + * |
|
| 60 | + * @param $pluginKey |
|
| 61 | + * @return AbstractPlugin |
|
| 62 | + * @throws PluginException |
|
| 63 | + */ |
|
| 64 | + protected function load($pluginKey) { |
|
| 65 | + list($vendor, $pluginName) = explode('\\', $pluginKey); |
|
| 66 | + // uppercase first letter convention |
|
| 67 | + $pluginClassName = '\\Phile\\Plugin\\' . ucfirst($vendor) . '\\' . ucfirst($pluginName) . '\\Plugin'; |
|
| 68 | + |
|
| 69 | + if (!class_exists($pluginClassName)) { |
|
| 70 | + throw new PluginException( |
|
| 71 | + "the plugin '{$pluginKey}' could not be loaded!", |
|
| 72 | + 1398536479 |
|
| 73 | + ); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + /** @var \Phile\Plugin\AbstractPlugin $plugin */ |
|
| 77 | + $plugin = new $pluginClassName; |
|
| 78 | + if (($plugin instanceof AbstractPlugin) === false) { |
|
| 79 | + throw new PluginException( |
|
| 80 | + "the plugin '{$pluginKey}' is not an instance of \\Phile\\Plugin\\AbstractPlugin", |
|
| 81 | + 1398536526 |
|
| 82 | + ); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + $plugin->initializePlugin($pluginKey); |
|
| 86 | + return $plugin; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * clear out repository |
|
| 91 | + */ |
|
| 92 | + protected function reset() { |
|
| 93 | + $this->loadErrors = []; |
|
| 94 | + $this->plugins = []; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * auto-loader plugin namespace |
|
| 99 | + * |
|
| 100 | + * @param $className |
|
| 101 | + */ |
|
| 102 | + public static function autoload($className) { |
|
| 103 | + if (strpos($className, "Phile\\Plugin\\") !== 0) { |
|
| 104 | + return; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + $className = substr($className, 13); |
|
| 108 | + $classNameParts = explode('\\', $className); |
|
| 109 | + $pluginVendor = lcfirst(array_shift($classNameParts)); |
|
| 110 | + $pluginName = lcfirst(array_shift($classNameParts)); |
|
| 111 | + $classPath = array_merge( |
|
| 112 | + [$pluginVendor, $pluginName, 'Classes'], |
|
| 113 | + $classNameParts |
|
| 114 | + ); |
|
| 115 | + |
|
| 116 | + $fileName = PLUGINS_DIR . implode(DIRECTORY_SEPARATOR, $classPath) . '.php'; |
|
| 117 | + if (file_exists($fileName)) { |
|
| 118 | + require_once $fileName; |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | 122 | } |
@@ -18,165 +18,165 @@ |
||
| 18 | 18 | * @package Phile |
| 19 | 19 | */ |
| 20 | 20 | class Core { |
| 21 | - /** |
|
| 22 | - * @var array the settings array |
|
| 23 | - */ |
|
| 24 | - protected $settings; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * @var array the loaded plugins |
|
| 28 | - */ |
|
| 29 | - protected $plugins; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @var \Phile\Repository\Page the page repository |
|
| 33 | - */ |
|
| 34 | - protected $pageRepository; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @var null|\Phile\Model\Page the page model |
|
| 38 | - */ |
|
| 39 | - protected $page; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @var string the output (rendered page) |
|
| 43 | - */ |
|
| 44 | - protected $output; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @var \Phile\Core\Response the response the core send |
|
| 48 | - */ |
|
| 49 | - protected $response; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @var Router |
|
| 53 | - */ |
|
| 54 | - protected $router; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * The constructor carries out all the processing in Phile. |
|
| 58 | - * Does URL routing, Markdown processing and Twig processing. |
|
| 59 | - * |
|
| 60 | - * @param Router $router |
|
| 61 | - * @param Response $response |
|
| 62 | - * @throws \Exception |
|
| 63 | - */ |
|
| 64 | - public function __construct(Router $router, Response $response) { |
|
| 65 | - $this->initializeErrorHandling(); |
|
| 66 | - $this->initialize($router, $response); |
|
| 67 | - $this->checkSetup(); |
|
| 68 | - $this->initializeCurrentPage(); |
|
| 69 | - $this->initializeTemplate(); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * return the page |
|
| 74 | - * |
|
| 75 | - * @return string |
|
| 76 | - */ |
|
| 77 | - public function render() { |
|
| 78 | - $this->response->send(); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - protected function initialize(Router $router, Response $response) { |
|
| 82 | - $this->settings = Registry::get('Phile_Settings'); |
|
| 83 | - $this->pageRepository = new Repository(); |
|
| 84 | - $this->router = $router; |
|
| 85 | - $this->response = $response; |
|
| 86 | - $this->response->setCharset($this->settings['charset']); |
|
| 87 | - |
|
| 88 | - Event::triggerEvent('after_init_core', ['response' => $this->response]); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * initialize the current page |
|
| 93 | - */ |
|
| 94 | - protected function initializeCurrentPage() { |
|
| 95 | - $pageId = $this->router->getCurrentUrl(); |
|
| 96 | - |
|
| 97 | - Event::triggerEvent('request_uri', ['uri' => $pageId]); |
|
| 98 | - |
|
| 99 | - $page = $this->pageRepository->findByPath($pageId); |
|
| 100 | - $found = $page instanceof Page; |
|
| 101 | - |
|
| 102 | - if ($found && $pageId !== $page->getPageId()) { |
|
| 103 | - $url = $this->router->urlForPage($page->getPageId()); |
|
| 104 | - $this->response->redirect($url, 301); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - if (!$found) { |
|
| 108 | - $this->response->setStatusCode(404); |
|
| 109 | - $page = $this->pageRepository->findByPath('404'); |
|
| 110 | - Event::triggerEvent('after_404'); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - Event::triggerEvent('after_resolve_page', ['pageId' => $pageId, 'page' => &$page]); |
|
| 114 | - |
|
| 115 | - $this->page = $page; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * initialize error handling |
|
| 120 | - */ |
|
| 121 | - protected function initializeErrorHandling() { |
|
| 122 | - if (ServiceLocator::hasService('Phile_ErrorHandler')) { |
|
| 123 | - $errorHandler = ServiceLocator::getService('Phile_ErrorHandler'); |
|
| 124 | - set_error_handler([$errorHandler, 'handleError']); |
|
| 125 | - register_shutdown_function([$errorHandler, 'handleShutdown']); |
|
| 126 | - ini_set('display_errors', $this->settings['display_errors']); |
|
| 127 | - } |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * check the setup |
|
| 132 | - */ |
|
| 133 | - protected function checkSetup() { |
|
| 134 | - /** |
|
| 135 | - * @triggerEvent before_setup_check this event is triggered before the setup check |
|
| 136 | - */ |
|
| 137 | - Event::triggerEvent('before_setup_check'); |
|
| 138 | - |
|
| 139 | - if (!Registry::isRegistered('templateVars')) { |
|
| 140 | - Registry::set('templateVars', []); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - Event::triggerEvent('setup_check'); |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * @triggerEvent after_setup_check this event is triggered after the setup check |
|
| 147 | - */ |
|
| 148 | - Event::triggerEvent('after_setup_check'); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * initialize template engine |
|
| 153 | - */ |
|
| 154 | - protected function initializeTemplate() { |
|
| 155 | - /** |
|
| 156 | - * @triggerEvent before_init_template this event is triggered before the template engine is init |
|
| 157 | - */ |
|
| 158 | - Event::triggerEvent('before_init_template'); |
|
| 159 | - |
|
| 160 | - $templateEngine = ServiceLocator::getService('Phile_Template'); |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * @triggerEvent before_render_template this event is triggered before the template is rendered |
|
| 164 | - * |
|
| 165 | - * @param \Phile\ServiceLocator\TemplateInterface the template engine |
|
| 166 | - */ |
|
| 167 | - Event::triggerEvent('before_render_template', array('templateEngine' => &$templateEngine)); |
|
| 168 | - |
|
| 169 | - $templateEngine->setCurrentPage($this->page); |
|
| 170 | - $output = $templateEngine->render(); |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * @triggerEvent after_render_template this event is triggered after the template is rendered |
|
| 174 | - * |
|
| 175 | - * @param \Phile\ServiceLocator\TemplateInterface the template engine |
|
| 176 | - * @param string the generated ouput |
|
| 177 | - */ |
|
| 178 | - Event::triggerEvent('after_render_template', array('templateEngine' => &$templateEngine, 'output' => &$output)); |
|
| 179 | - $this->response->setBody($output); |
|
| 180 | - } |
|
| 21 | + /** |
|
| 22 | + * @var array the settings array |
|
| 23 | + */ |
|
| 24 | + protected $settings; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * @var array the loaded plugins |
|
| 28 | + */ |
|
| 29 | + protected $plugins; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @var \Phile\Repository\Page the page repository |
|
| 33 | + */ |
|
| 34 | + protected $pageRepository; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @var null|\Phile\Model\Page the page model |
|
| 38 | + */ |
|
| 39 | + protected $page; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @var string the output (rendered page) |
|
| 43 | + */ |
|
| 44 | + protected $output; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @var \Phile\Core\Response the response the core send |
|
| 48 | + */ |
|
| 49 | + protected $response; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @var Router |
|
| 53 | + */ |
|
| 54 | + protected $router; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * The constructor carries out all the processing in Phile. |
|
| 58 | + * Does URL routing, Markdown processing and Twig processing. |
|
| 59 | + * |
|
| 60 | + * @param Router $router |
|
| 61 | + * @param Response $response |
|
| 62 | + * @throws \Exception |
|
| 63 | + */ |
|
| 64 | + public function __construct(Router $router, Response $response) { |
|
| 65 | + $this->initializeErrorHandling(); |
|
| 66 | + $this->initialize($router, $response); |
|
| 67 | + $this->checkSetup(); |
|
| 68 | + $this->initializeCurrentPage(); |
|
| 69 | + $this->initializeTemplate(); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * return the page |
|
| 74 | + * |
|
| 75 | + * @return string |
|
| 76 | + */ |
|
| 77 | + public function render() { |
|
| 78 | + $this->response->send(); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + protected function initialize(Router $router, Response $response) { |
|
| 82 | + $this->settings = Registry::get('Phile_Settings'); |
|
| 83 | + $this->pageRepository = new Repository(); |
|
| 84 | + $this->router = $router; |
|
| 85 | + $this->response = $response; |
|
| 86 | + $this->response->setCharset($this->settings['charset']); |
|
| 87 | + |
|
| 88 | + Event::triggerEvent('after_init_core', ['response' => $this->response]); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * initialize the current page |
|
| 93 | + */ |
|
| 94 | + protected function initializeCurrentPage() { |
|
| 95 | + $pageId = $this->router->getCurrentUrl(); |
|
| 96 | + |
|
| 97 | + Event::triggerEvent('request_uri', ['uri' => $pageId]); |
|
| 98 | + |
|
| 99 | + $page = $this->pageRepository->findByPath($pageId); |
|
| 100 | + $found = $page instanceof Page; |
|
| 101 | + |
|
| 102 | + if ($found && $pageId !== $page->getPageId()) { |
|
| 103 | + $url = $this->router->urlForPage($page->getPageId()); |
|
| 104 | + $this->response->redirect($url, 301); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + if (!$found) { |
|
| 108 | + $this->response->setStatusCode(404); |
|
| 109 | + $page = $this->pageRepository->findByPath('404'); |
|
| 110 | + Event::triggerEvent('after_404'); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + Event::triggerEvent('after_resolve_page', ['pageId' => $pageId, 'page' => &$page]); |
|
| 114 | + |
|
| 115 | + $this->page = $page; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * initialize error handling |
|
| 120 | + */ |
|
| 121 | + protected function initializeErrorHandling() { |
|
| 122 | + if (ServiceLocator::hasService('Phile_ErrorHandler')) { |
|
| 123 | + $errorHandler = ServiceLocator::getService('Phile_ErrorHandler'); |
|
| 124 | + set_error_handler([$errorHandler, 'handleError']); |
|
| 125 | + register_shutdown_function([$errorHandler, 'handleShutdown']); |
|
| 126 | + ini_set('display_errors', $this->settings['display_errors']); |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * check the setup |
|
| 132 | + */ |
|
| 133 | + protected function checkSetup() { |
|
| 134 | + /** |
|
| 135 | + * @triggerEvent before_setup_check this event is triggered before the setup check |
|
| 136 | + */ |
|
| 137 | + Event::triggerEvent('before_setup_check'); |
|
| 138 | + |
|
| 139 | + if (!Registry::isRegistered('templateVars')) { |
|
| 140 | + Registry::set('templateVars', []); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + Event::triggerEvent('setup_check'); |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * @triggerEvent after_setup_check this event is triggered after the setup check |
|
| 147 | + */ |
|
| 148 | + Event::triggerEvent('after_setup_check'); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * initialize template engine |
|
| 153 | + */ |
|
| 154 | + protected function initializeTemplate() { |
|
| 155 | + /** |
|
| 156 | + * @triggerEvent before_init_template this event is triggered before the template engine is init |
|
| 157 | + */ |
|
| 158 | + Event::triggerEvent('before_init_template'); |
|
| 159 | + |
|
| 160 | + $templateEngine = ServiceLocator::getService('Phile_Template'); |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * @triggerEvent before_render_template this event is triggered before the template is rendered |
|
| 164 | + * |
|
| 165 | + * @param \Phile\ServiceLocator\TemplateInterface the template engine |
|
| 166 | + */ |
|
| 167 | + Event::triggerEvent('before_render_template', array('templateEngine' => &$templateEngine)); |
|
| 168 | + |
|
| 169 | + $templateEngine->setCurrentPage($this->page); |
|
| 170 | + $output = $templateEngine->render(); |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * @triggerEvent after_render_template this event is triggered after the template is rendered |
|
| 174 | + * |
|
| 175 | + * @param \Phile\ServiceLocator\TemplateInterface the template engine |
|
| 176 | + * @param string the generated ouput |
|
| 177 | + */ |
|
| 178 | + Event::triggerEvent('after_render_template', array('templateEngine' => &$templateEngine, 'output' => &$output)); |
|
| 179 | + $this->response->setBody($output); |
|
| 180 | + } |
|
| 181 | 181 | |
| 182 | 182 | } |
@@ -12,12 +12,12 @@ |
||
| 12 | 12 | * @package Phile\ServiceLocator |
| 13 | 13 | */ |
| 14 | 14 | interface ParserInterface { |
| 15 | - /** |
|
| 16 | - * parse data |
|
| 17 | - * |
|
| 18 | - * @param $data |
|
| 19 | - * |
|
| 20 | - * @return mixed |
|
| 21 | - */ |
|
| 22 | - public function parse($data); |
|
| 15 | + /** |
|
| 16 | + * parse data |
|
| 17 | + * |
|
| 18 | + * @param $data |
|
| 19 | + * |
|
| 20 | + * @return mixed |
|
| 21 | + */ |
|
| 22 | + public function parse($data); |
|
| 23 | 23 | } |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * The Persistence ServiceLocator interface |
|
| 4 | - */ |
|
| 3 | + * The Persistence ServiceLocator interface |
|
| 4 | + */ |
|
| 5 | 5 | namespace Phile\ServiceLocator; |
| 6 | 6 | |
| 7 | 7 | /** |
@@ -12,40 +12,40 @@ discard block |
||
| 12 | 12 | * @package Phile\ServiceLocator |
| 13 | 13 | */ |
| 14 | 14 | interface PersistenceInterface { |
| 15 | - /** |
|
| 16 | - * check if an entry exists for given key |
|
| 17 | - * |
|
| 18 | - * @param $key |
|
| 19 | - * |
|
| 20 | - * @return mixed |
|
| 21 | - */ |
|
| 22 | - public function has($key); |
|
| 15 | + /** |
|
| 16 | + * check if an entry exists for given key |
|
| 17 | + * |
|
| 18 | + * @param $key |
|
| 19 | + * |
|
| 20 | + * @return mixed |
|
| 21 | + */ |
|
| 22 | + public function has($key); |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * get the entry by given key |
|
| 26 | - * |
|
| 27 | - * @param $key |
|
| 28 | - * |
|
| 29 | - * @return mixed |
|
| 30 | - */ |
|
| 31 | - public function get($key); |
|
| 24 | + /** |
|
| 25 | + * get the entry by given key |
|
| 26 | + * |
|
| 27 | + * @param $key |
|
| 28 | + * |
|
| 29 | + * @return mixed |
|
| 30 | + */ |
|
| 31 | + public function get($key); |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * set the value for given key |
|
| 35 | - * |
|
| 36 | - * @param $key |
|
| 37 | - * @param $value |
|
| 38 | - * |
|
| 39 | - * @return mixed |
|
| 40 | - */ |
|
| 41 | - public function set($key, $value); |
|
| 33 | + /** |
|
| 34 | + * set the value for given key |
|
| 35 | + * |
|
| 36 | + * @param $key |
|
| 37 | + * @param $value |
|
| 38 | + * |
|
| 39 | + * @return mixed |
|
| 40 | + */ |
|
| 41 | + public function set($key, $value); |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * delete the entry by given key |
|
| 45 | - * |
|
| 46 | - * @param $key |
|
| 47 | - * |
|
| 48 | - * @return mixed |
|
| 49 | - */ |
|
| 50 | - public function delete($key); |
|
| 43 | + /** |
|
| 44 | + * delete the entry by given key |
|
| 45 | + * |
|
| 46 | + * @param $key |
|
| 47 | + * |
|
| 48 | + * @return mixed |
|
| 49 | + */ |
|
| 50 | + public function delete($key); |
|
| 51 | 51 | } |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * The TemplateInterface |
|
| 4 | - */ |
|
| 3 | + * The TemplateInterface |
|
| 4 | + */ |
|
| 5 | 5 | namespace Phile\ServiceLocator; |
| 6 | 6 | |
| 7 | 7 | /** |
@@ -12,19 +12,19 @@ discard block |
||
| 12 | 12 | * @package Phile\ServiceLocator |
| 13 | 13 | */ |
| 14 | 14 | interface TemplateInterface { |
| 15 | - /** |
|
| 16 | - * render the template |
|
| 17 | - * |
|
| 18 | - * @return mixed |
|
| 19 | - */ |
|
| 20 | - public function render(); |
|
| 15 | + /** |
|
| 16 | + * render the template |
|
| 17 | + * |
|
| 18 | + * @return mixed |
|
| 19 | + */ |
|
| 20 | + public function render(); |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * set current page |
|
| 24 | - * |
|
| 25 | - * @param \Phile\Model\Page $page |
|
| 26 | - * |
|
| 27 | - * @return mixed |
|
| 28 | - */ |
|
| 29 | - public function setCurrentPage(\Phile\Model\Page $page); |
|
| 22 | + /** |
|
| 23 | + * set current page |
|
| 24 | + * |
|
| 25 | + * @param \Phile\Model\Page $page |
|
| 26 | + * |
|
| 27 | + * @return mixed |
|
| 28 | + */ |
|
| 29 | + public function setCurrentPage(\Phile\Model\Page $page); |
|
| 30 | 30 | } |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Interface for a service locator |
|
| 4 | - */ |
|
| 3 | + * Interface for a service locator |
|
| 4 | + */ |
|
| 5 | 5 | namespace Phile\ServiceLocator; |
| 6 | 6 | |
| 7 | 7 | /** |
@@ -12,48 +12,48 @@ discard block |
||
| 12 | 12 | * @package Phile\ServiceLocator |
| 13 | 13 | */ |
| 14 | 14 | interface CacheInterface { |
| 15 | - /** |
|
| 16 | - * check if an entry with this key exists |
|
| 17 | - * |
|
| 18 | - * @param $key |
|
| 19 | - * |
|
| 20 | - * @return mixed |
|
| 21 | - */ |
|
| 22 | - public function has($key); |
|
| 15 | + /** |
|
| 16 | + * check if an entry with this key exists |
|
| 17 | + * |
|
| 18 | + * @param $key |
|
| 19 | + * |
|
| 20 | + * @return mixed |
|
| 21 | + */ |
|
| 22 | + public function has($key); |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * get the entry by given key |
|
| 26 | - * |
|
| 27 | - * @param $key |
|
| 28 | - * |
|
| 29 | - * @return mixed |
|
| 30 | - */ |
|
| 31 | - public function get($key); |
|
| 24 | + /** |
|
| 25 | + * get the entry by given key |
|
| 26 | + * |
|
| 27 | + * @param $key |
|
| 28 | + * |
|
| 29 | + * @return mixed |
|
| 30 | + */ |
|
| 31 | + public function get($key); |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * set the entry to the given key |
|
| 35 | - * |
|
| 36 | - * @param $key |
|
| 37 | - * @param $value |
|
| 38 | - * @param int $time |
|
| 39 | - * @param array $options |
|
| 40 | - * |
|
| 41 | - * @return mixed |
|
| 42 | - */ |
|
| 43 | - public function set($key, $value, $time = 300, array $options = array()); |
|
| 33 | + /** |
|
| 34 | + * set the entry to the given key |
|
| 35 | + * |
|
| 36 | + * @param $key |
|
| 37 | + * @param $value |
|
| 38 | + * @param int $time |
|
| 39 | + * @param array $options |
|
| 40 | + * |
|
| 41 | + * @return mixed |
|
| 42 | + */ |
|
| 43 | + public function set($key, $value, $time = 300, array $options = array()); |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * delete the entry by given key |
|
| 47 | - * |
|
| 48 | - * @param $key |
|
| 49 | - * @param array $options |
|
| 50 | - * |
|
| 51 | - * @return mixed |
|
| 52 | - */ |
|
| 53 | - public function delete($key, array $options = array()); |
|
| 45 | + /** |
|
| 46 | + * delete the entry by given key |
|
| 47 | + * |
|
| 48 | + * @param $key |
|
| 49 | + * @param array $options |
|
| 50 | + * |
|
| 51 | + * @return mixed |
|
| 52 | + */ |
|
| 53 | + public function delete($key, array $options = array()); |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * clean complete cache and delete all cached entries |
|
| 57 | - */ |
|
| 58 | - public function clean(); |
|
| 55 | + /** |
|
| 56 | + * clean complete cache and delete all cached entries |
|
| 57 | + */ |
|
| 58 | + public function clean(); |
|
| 59 | 59 | } |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * ServiceLocator MetaParser interface |
|
| 4 | - */ |
|
| 3 | + * ServiceLocator MetaParser interface |
|
| 4 | + */ |
|
| 5 | 5 | namespace Phile\ServiceLocator; |
| 6 | 6 | |
| 7 | 7 | /** |
@@ -12,12 +12,12 @@ discard block |
||
| 12 | 12 | * @package Phile\ServiceLocator |
| 13 | 13 | */ |
| 14 | 14 | interface MetaInterface { |
| 15 | - /** |
|
| 16 | - * parse the content |
|
| 17 | - * |
|
| 18 | - * @param $rawData |
|
| 19 | - * |
|
| 20 | - * @return array with key/value store |
|
| 21 | - */ |
|
| 22 | - public function parse($rawData); |
|
| 15 | + /** |
|
| 16 | + * parse the content |
|
| 17 | + * |
|
| 18 | + * @param $rawData |
|
| 19 | + * |
|
| 20 | + * @return array with key/value store |
|
| 21 | + */ |
|
| 22 | + public function parse($rawData); |
|
| 23 | 23 | } |