Completed
Pull Request — master (#286)
by Frank
07:37
created
plugins/phile/parserMarkdown/Classes/Parser/Markdown.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * The Mardown parser class
4
- */
3
+     * The Mardown parser class
4
+     */
5 5
 namespace Phile\Plugin\Phile\ParserMarkdown\Parser;
6 6
 
7 7
 use Michelf\MarkdownExtra;
@@ -16,33 +16,33 @@  discard block
 block discarded – undo
16 16
  * @package Phile\Plugin\Phile\ParserMarkdown\Parser
17 17
  */
18 18
 class Markdown implements ParserInterface {
19
-	/** @var mixed the configuration */
20
-	private $config;
19
+    /** @var mixed the configuration */
20
+    private $config;
21 21
 
22
-	/**
23
-	 * the constructor
24
-	 *
25
-	 * @param null $config
26
-	 */
27
-	public function __construct($config = null) {
28
-		if (!is_null($config)) {
29
-			$this->config = $config;
30
-		}
31
-	}
22
+    /**
23
+     * the constructor
24
+     *
25
+     * @param null $config
26
+     */
27
+    public function __construct($config = null) {
28
+        if (!is_null($config)) {
29
+            $this->config = $config;
30
+        }
31
+    }
32 32
 
33
-	/**
34
-	 * overload parse with the MarkdownExtra parser
35
-	 *
36
-	 * @param $data
37
-	 *
38
-	 * @return string
39
-	 */
40
-	public function parse($data) {
41
-		$parser = new MarkdownExtra;
42
-		foreach ($this->config as $key => $value) {
43
-			$parser->{$key} = $value;
44
-		}
33
+    /**
34
+     * overload parse with the MarkdownExtra parser
35
+     *
36
+     * @param $data
37
+     *
38
+     * @return string
39
+     */
40
+    public function parse($data) {
41
+        $parser = new MarkdownExtra;
42
+        foreach ($this->config as $key => $value) {
43
+            $parser->{$key} = $value;
44
+        }
45 45
 
46
-		return $parser->transform($data);
47
-	}
46
+        return $parser->transform($data);
47
+    }
48 48
 }
Please login to merge, or discard this patch.
plugins/phile/parserMarkdown/config.php 1 patch
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -1,25 +1,25 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * the configuration file
4
- *
5
- * @see https://michelf.ca/projects/php-markdown/configuration/
6
- */
3
+     * the configuration file
4
+     *
5
+     * @see https://michelf.ca/projects/php-markdown/configuration/
6
+     */
7 7
 
8 8
 return array(
9
-	'empty_element_suffix' => ' />',
10
-	'tab_width'            => 4,
11
-	'no_markup'            => false,
12
-	'no_entities'          => false,
13
-	'predef_urls'          => array(
14
-		'base_url' => \Phile\Core\Utility::getBaseUrl() // base_url is a good reference to have
15
-	),
16
-	'predef_titles'        => array(),
17
-	'fn_id_prefix'         => "",
18
-	'fn_link_title'        => "",
19
-	'fn_backlink_title'    => "",
20
-	'fn_link_class'        => "footnote-ref",
21
-	'fn_backlink_class'    => "footnote-backref",
22
-	'code_class_prefix'    => "",
23
-	'code_attr_on_pre'     => false,
24
-	'predef_abbr'          => array()
9
+    'empty_element_suffix' => ' />',
10
+    'tab_width'            => 4,
11
+    'no_markup'            => false,
12
+    'no_entities'          => false,
13
+    'predef_urls'          => array(
14
+        'base_url' => \Phile\Core\Utility::getBaseUrl() // base_url is a good reference to have
15
+    ),
16
+    'predef_titles'        => array(),
17
+    'fn_id_prefix'         => "",
18
+    'fn_link_title'        => "",
19
+    'fn_backlink_title'    => "",
20
+    'fn_link_class'        => "footnote-ref",
21
+    'fn_backlink_class'    => "footnote-backref",
22
+    'code_class_prefix'    => "",
23
+    'code_attr_on_pre'     => false,
24
+    'predef_abbr'          => array()
25 25
 );
Please login to merge, or discard this patch.
plugins/mycompany/demoPlugin/Classes/Plugin.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@
 block discarded – undo
47 47
 		// you can access this plugins' config in $this->settings
48 48
 		$settings = $this->settings;
49 49
 
50
-		$content =  $data['content'];
50
+		$content = $data['content'];
51 51
 		$content = $this->printPhpAsMarkdown($settings) . $content;
52 52
 
53 53
 		$page = $data['page'];
Please login to merge, or discard this patch.
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -28,37 +28,37 @@
 block discarded – undo
28 28
  */
29 29
 class Plugin extends \Phile\Plugin\AbstractPlugin {
30 30
 
31
-	/**
32
-	 * subscribe to Phile events with methods of this class
33
-	 *
34
-	 * In this example we subscribe to "before_parse_content" and
35
-	 * "outputPluginSettings" will be called.
36
-	 */
37
-	protected $events = ['before_parse_content' => 'outputPluginSettings'];
31
+    /**
32
+     * subscribe to Phile events with methods of this class
33
+     *
34
+     * In this example we subscribe to "before_parse_content" and
35
+     * "outputPluginSettings" will be called.
36
+     */
37
+    protected $events = ['before_parse_content' => 'outputPluginSettings'];
38 38
 
39
-	/**
40
-	 * the method we assigned to the 'before_parse_content' event
41
-	 *
42
-	 * in this example we output this plugins' settings on the top of every page
43
-	 *
44
-	 * @param null|array $data depends on the particular event (see Phile's event docs)
45
-	 */
46
-	public function outputPluginSettings($data = null) {
47
-		// you can access this plugins' config in $this->settings
48
-		$settings = $this->settings;
39
+    /**
40
+     * the method we assigned to the 'before_parse_content' event
41
+     *
42
+     * in this example we output this plugins' settings on the top of every page
43
+     *
44
+     * @param null|array $data depends on the particular event (see Phile's event docs)
45
+     */
46
+    public function outputPluginSettings($data = null) {
47
+        // you can access this plugins' config in $this->settings
48
+        $settings = $this->settings;
49 49
 
50
-		$content =  $data['content'];
51
-		$content = $this->printPhpAsMarkdown($settings) . $content;
50
+        $content =  $data['content'];
51
+        $content = $this->printPhpAsMarkdown($settings) . $content;
52 52
 
53
-		$page = $data['page'];
54
-		$page->setContent($content);
55
-	}
53
+        $page = $data['page'];
54
+        $page->setContent($content);
55
+    }
56 56
 
57
-	/**
58
-	 * plugin helper method for printing PHP as markdown code
59
-	 */
60
-	protected function printPhpAsMarkdown($input) {
61
-		return "\n```php\n" . trim(print_r($input, true), "\n") . "\n```\n";
62
-	}
57
+    /**
58
+     * plugin helper method for printing PHP as markdown code
59
+     */
60
+    protected function printPhpAsMarkdown($input) {
61
+        return "\n```php\n" . trim(print_r($input, true), "\n") . "\n```\n";
62
+    }
63 63
 
64 64
 }
Please login to merge, or discard this patch.
plugins/mycompany/demoPlugin/config.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -3,5 +3,5 @@
 block discarded – undo
3 3
  * config file
4 4
  */
5 5
 return [
6
-	'setting-example' => 'I love Phile!'
6
+    'setting-example' => 'I love Phile!'
7 7
 ];
Please login to merge, or discard this patch.
default_config.php 1 patch
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -57,49 +57,49 @@
 block discarded – undo
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;
Please login to merge, or discard this patch.
lib/Phile/Plugin/PluginRepository.php 1 patch
Indentation   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -14,109 +14,109 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
lib/Phile/Core.php 1 patch
Indentation   +160 added lines, -160 removed lines patch added patch discarded remove patch
@@ -18,165 +18,165 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
lib/Phile/ServiceLocator/PersistenceInterface.php 1 patch
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
lib/Phile/ServiceLocator/CacheInterface.php 1 patch
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.