Passed
Push — master ( e61ad7...373a1b )
by Alain
02:28
created
src/View/Engine/EngineInterface.php 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -22,26 +22,26 @@
 block discarded – undo
22 22
 interface EngineInterface
23 23
 {
24 24
 
25
-    /**
26
-     * Check whether the engine can render a given URI.
27
-     *
28
-     * @since 0.1.0
29
-     *
30
-     * @param string $uri URI that wants to be rendered.
31
-     *
32
-     * @return bool Whether the engine can render the given URI.
33
-     */
34
-    public function canRender($uri);
25
+	/**
26
+	 * Check whether the engine can render a given URI.
27
+	 *
28
+	 * @since 0.1.0
29
+	 *
30
+	 * @param string $uri URI that wants to be rendered.
31
+	 *
32
+	 * @return bool Whether the engine can render the given URI.
33
+	 */
34
+	public function canRender($uri);
35 35
 
36
-    /**
37
-     * Render a given URI.
38
-     *
39
-     * @since 0.1.0
40
-     *
41
-     * @param string $uri     URI to render.
42
-     * @param array  $context Context in which to render.
43
-     *
44
-     * @return string Rendered HTML.
45
-     */
46
-    public function render($uri, array $context = []);
36
+	/**
37
+	 * Render a given URI.
38
+	 *
39
+	 * @since 0.1.0
40
+	 *
41
+	 * @param string $uri     URI to render.
42
+	 * @param array  $context Context in which to render.
43
+	 *
44
+	 * @return string Rendered HTML.
45
+	 */
46
+	public function render($uri, array $context = []);
47 47
 }
Please login to merge, or discard this patch.
src/View/Engine/EngineFinder.php 1 patch
Indentation   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -25,87 +25,87 @@
 block discarded – undo
25 25
 class EngineFinder extends AbstractFinder
26 26
 {
27 27
 
28
-    /**
29
-     * Find a result based on a specific criteria.
30
-     *
31
-     * @since 0.1.0
32
-     *
33
-     * @param array $criteria Criteria to search for.
34
-     *
35
-     * @return mixed Result of the search.
36
-     */
37
-    public function find(array $criteria)
38
-    {
39
-        $this->initializeEngines();
28
+	/**
29
+	 * Find a result based on a specific criteria.
30
+	 *
31
+	 * @since 0.1.0
32
+	 *
33
+	 * @param array $criteria Criteria to search for.
34
+	 *
35
+	 * @return mixed Result of the search.
36
+	 */
37
+	public function find(array $criteria)
38
+	{
39
+		$this->initializeEngines();
40 40
 
41
-        foreach ($criteria as $entry) {
42
-            /** @var EngineInterface $engine */
43
-            foreach ($this->findables as $engine) {
44
-                if ($engine->canRender($entry)) {
45
-                    return $engine;
46
-                }
47
-            }
48
-        }
41
+		foreach ($criteria as $entry) {
42
+			/** @var EngineInterface $engine */
43
+			foreach ($this->findables as $engine) {
44
+				if ($engine->canRender($entry)) {
45
+					return $engine;
46
+				}
47
+			}
48
+		}
49 49
 
50
-        return $this->nullObject;
51
-    }
50
+		return $this->nullObject;
51
+	}
52 52
 
53
-    /**
54
-     * Initialize the engines that can be iterated.
55
-     *
56
-     * @since 0.1.0
57
-     *
58
-     */
59
-    protected function initializeEngines()
60
-    {
61
-        foreach ($this->findables as &$engine) {
62
-            $engine = $this->initializeEngine($engine);
63
-        }
53
+	/**
54
+	 * Initialize the engines that can be iterated.
55
+	 *
56
+	 * @since 0.1.0
57
+	 *
58
+	 */
59
+	protected function initializeEngines()
60
+	{
61
+		foreach ($this->findables as &$engine) {
62
+			$engine = $this->initializeEngine($engine);
63
+		}
64 64
 
65
-        $this->nullObject = $this->initializeEngine($this->nullObject);
66
-    }
65
+		$this->nullObject = $this->initializeEngine($this->nullObject);
66
+	}
67 67
 
68
-    /**
69
-     * Initialize a single engine by instantiating class name strings and calling closures.
70
-     *
71
-     * @since 0.1.0
72
-     *
73
-     * @param mixed $engine Engine to instantiate.
74
-     *
75
-     * @return EngineInterface Instantiated engine.
76
-     * @throws FailedToInstantiateEngineException If the engine could not be instantiated.
77
-     */
78
-    protected function initializeEngine($engine)
79
-    {
80
-        if (is_string($engine)) {
81
-            $engine = new $engine();
82
-        }
68
+	/**
69
+	 * Initialize a single engine by instantiating class name strings and calling closures.
70
+	 *
71
+	 * @since 0.1.0
72
+	 *
73
+	 * @param mixed $engine Engine to instantiate.
74
+	 *
75
+	 * @return EngineInterface Instantiated engine.
76
+	 * @throws FailedToInstantiateEngineException If the engine could not be instantiated.
77
+	 */
78
+	protected function initializeEngine($engine)
79
+	{
80
+		if (is_string($engine)) {
81
+			$engine = new $engine();
82
+		}
83 83
 
84
-        if (is_callable($engine)) {
85
-            $engine = $engine();
86
-        }
84
+		if (is_callable($engine)) {
85
+			$engine = $engine();
86
+		}
87 87
 
88
-        if (! $engine instanceof EngineInterface) {
89
-            throw new FailedToInstantiateEngineException(
90
-                sprintf(
91
-                    _('Could not instantiate engine "%s".'),
92
-                    serialize($engine)
93
-                )
94
-            );
95
-        }
88
+		if (! $engine instanceof EngineInterface) {
89
+			throw new FailedToInstantiateEngineException(
90
+				sprintf(
91
+					_('Could not instantiate engine "%s".'),
92
+					serialize($engine)
93
+				)
94
+			);
95
+		}
96 96
 
97
-        return $engine;
98
-    }
97
+		return $engine;
98
+	}
99 99
 
100
-    /**
101
-     * Get the config key for the Findables definitions.
102
-     *
103
-     * @since 0.1.0
104
-     *
105
-     * @return string Config key use to define the Findables.
106
-     */
107
-    protected function getFindablesConfigKey()
108
-    {
109
-        return 'Engines';
110
-    }
100
+	/**
101
+	 * Get the config key for the Findables definitions.
102
+	 *
103
+	 * @since 0.1.0
104
+	 *
105
+	 * @return string Config key use to define the Findables.
106
+	 */
107
+	protected function getFindablesConfigKey()
108
+	{
109
+		return 'Engines';
110
+	}
111 111
 }
Please login to merge, or discard this patch.
src/View/Engine/NullEngine.php 1 patch
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -24,32 +24,32 @@
 block discarded – undo
24 24
 class NullEngine implements EngineInterface, NullObject
25 25
 {
26 26
 
27
-    /**
28
-     * Check whether the engine can render a given URI.
29
-     *
30
-     * @since 0.1.0
31
-     *
32
-     * @param string $uri URI that wants to be rendered.
33
-     *
34
-     * @return bool Whether the engine can render the given URI.
35
-     */
36
-    public function canRender($uri)
37
-    {
38
-        return true;
39
-    }
27
+	/**
28
+	 * Check whether the engine can render a given URI.
29
+	 *
30
+	 * @since 0.1.0
31
+	 *
32
+	 * @param string $uri URI that wants to be rendered.
33
+	 *
34
+	 * @return bool Whether the engine can render the given URI.
35
+	 */
36
+	public function canRender($uri)
37
+	{
38
+		return true;
39
+	}
40 40
 
41
-    /**
42
-     * Render a given URI.
43
-     *
44
-     * @since 0.1.0
45
-     *
46
-     * @param string $uri     URI to render.
47
-     * @param array  $context Context in which to render.
48
-     *
49
-     * @return string Rendered HTML.
50
-     */
51
-    public function render($uri, array $context = [])
52
-    {
53
-        return '';
54
-    }
41
+	/**
42
+	 * Render a given URI.
43
+	 *
44
+	 * @since 0.1.0
45
+	 *
46
+	 * @param string $uri     URI to render.
47
+	 * @param array  $context Context in which to render.
48
+	 *
49
+	 * @return string Rendered HTML.
50
+	 */
51
+	public function render($uri, array $context = [])
52
+	{
53
+		return '';
54
+	}
55 55
 }
Please login to merge, or discard this patch.
src/View/Location/FilesystemLocation.php 1 patch
Indentation   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -24,86 +24,86 @@
 block discarded – undo
24 24
 class FilesystemLocation implements LocationInterface
25 25
 {
26 26
 
27
-    /**
28
-     * Path that this location points to.
29
-     *
30
-     * @since 0.1.0
31
-     *
32
-     * @var string
33
-     */
34
-    protected $path;
27
+	/**
28
+	 * Path that this location points to.
29
+	 *
30
+	 * @since 0.1.0
31
+	 *
32
+	 * @var string
33
+	 */
34
+	protected $path;
35 35
 
36
-    /**
37
-     * Extensions that this location can accept.
38
-     *
39
-     * @since 0.1.0
40
-     *
41
-     * @var array<string>
42
-     */
43
-    protected $extensions;
36
+	/**
37
+	 * Extensions that this location can accept.
38
+	 *
39
+	 * @since 0.1.0
40
+	 *
41
+	 * @var array<string>
42
+	 */
43
+	protected $extensions;
44 44
 
45
-    /**
46
-     * Instantiate a FilesystemLocation object.
47
-     *
48
-     * @since 0.1.0
49
-     *
50
-     * @param string $path       Path that this location points to.
51
-     * @param array  $extensions Array of extensions that this location can accept.
52
-     */
53
-    public function __construct($path, array $extensions = [])
54
-    {
55
-        $this->path       = $path;
56
-        $this->extensions = array_merge($extensions, ['']);
57
-    }
45
+	/**
46
+	 * Instantiate a FilesystemLocation object.
47
+	 *
48
+	 * @since 0.1.0
49
+	 *
50
+	 * @param string $path       Path that this location points to.
51
+	 * @param array  $extensions Array of extensions that this location can accept.
52
+	 */
53
+	public function __construct($path, array $extensions = [])
54
+	{
55
+		$this->path       = $path;
56
+		$this->extensions = array_merge($extensions, ['']);
57
+	}
58 58
 
59
-    /**
60
-     * Get an URI that matches the given criteria.
61
-     *
62
-     * @since 0.1.0
63
-     *
64
-     * @param array $criteria Criteria to match.
65
-     *
66
-     * @return string|false URI that matches the criteria or false if none found.
67
-     */
68
-    public function getURI(array $criteria)
69
-    {
70
-        foreach ($criteria as $entry) {
71
-            if ($uri = $this->transform($entry)) {
72
-                return $uri;
73
-            }
74
-        }
59
+	/**
60
+	 * Get an URI that matches the given criteria.
61
+	 *
62
+	 * @since 0.1.0
63
+	 *
64
+	 * @param array $criteria Criteria to match.
65
+	 *
66
+	 * @return string|false URI that matches the criteria or false if none found.
67
+	 */
68
+	public function getURI(array $criteria)
69
+	{
70
+		foreach ($criteria as $entry) {
71
+			if ($uri = $this->transform($entry)) {
72
+				return $uri;
73
+			}
74
+		}
75 75
 
76
-        return false;
77
-    }
76
+		return false;
77
+	}
78 78
 
79
-    /**
80
-     * Try to transform the entry into possible URIs.
81
-     *
82
-     * @since 0.1.0
83
-     *
84
-     * @param string $entry Entry to transform.
85
-     *
86
-     * @return string|bool URI of the view, or false if none found.
87
-     */
88
-    protected function transform($entry)
89
-    {
90
-        try {
91
-            foreach ($this->extensions as $extension) {
79
+	/**
80
+	 * Try to transform the entry into possible URIs.
81
+	 *
82
+	 * @since 0.1.0
83
+	 *
84
+	 * @param string $entry Entry to transform.
85
+	 *
86
+	 * @return string|bool URI of the view, or false if none found.
87
+	 */
88
+	protected function transform($entry)
89
+	{
90
+		try {
91
+			foreach ($this->extensions as $extension) {
92 92
 
93
-                $uri = $entry . $extension;
94
-                if (is_readable($uri)) {
95
-                    return $uri;
96
-                }
93
+				$uri = $entry . $extension;
94
+				if (is_readable($uri)) {
95
+					return $uri;
96
+				}
97 97
 
98
-                $uri = $this->path . DIRECTORY_SEPARATOR . $uri;
99
-                if (is_readable($uri)) {
100
-                    return $uri;
101
-                }
102
-            }
103
-        } catch (Exception $exception) {
104
-            // Fail silently.
105
-        }
98
+				$uri = $this->path . DIRECTORY_SEPARATOR . $uri;
99
+				if (is_readable($uri)) {
100
+					return $uri;
101
+				}
102
+			}
103
+		} catch (Exception $exception) {
104
+			// Fail silently.
105
+		}
106 106
 
107
-        return false;
108
-    }
107
+		return false;
108
+	}
109 109
 }
Please login to merge, or discard this patch.
src/View/Location/LocationInterface.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -22,14 +22,14 @@
 block discarded – undo
22 22
 interface LocationInterface
23 23
 {
24 24
 
25
-    /**
26
-     * Get an URI that matches the given criteria.
27
-     *
28
-     * @since 0.1.0
29
-     *
30
-     * @param array $criteria Criteria to match.
31
-     *
32
-     * @return string|false URI that matches the criteria or false if none found.
33
-     */
34
-    public function getURI(array $criteria);
25
+	/**
26
+	 * Get an URI that matches the given criteria.
27
+	 *
28
+	 * @since 0.1.0
29
+	 *
30
+	 * @param array $criteria Criteria to match.
31
+	 *
32
+	 * @return string|false URI that matches the criteria or false if none found.
33
+	 */
34
+	public function getURI(array $criteria);
35 35
 }
Please login to merge, or discard this patch.
src/View/ViewBuilder.php 1 patch
Indentation   +205 added lines, -205 removed lines patch added patch discarded remove patch
@@ -32,209 +32,209 @@
 block discarded – undo
32 32
 class ViewBuilder
33 33
 {
34 34
 
35
-    use ConfigTrait;
36
-
37
-    const ENGINE_FINDER_KEY = 'EngineFinder';
38
-    const VIEW_FINDER_KEY   = 'ViewFinder';
39
-
40
-    /**
41
-     * ViewFinder instance.
42
-     *
43
-     * @since 0.1.0
44
-     *
45
-     * @var ViewFinderInterface
46
-     */
47
-    protected $viewFinder;
48
-
49
-    /**
50
-     * EngineFinder instance.
51
-     *
52
-     * @since 0.1.0
53
-     *
54
-     * @var EngineFinderInterface
55
-     */
56
-    protected $engineFinder;
57
-
58
-    /**
59
-     * Locations to scan for views.
60
-     *
61
-     * @since 0.1.0
62
-     *
63
-     * @var LocationInterface[]
64
-     */
65
-    protected $locations;
66
-
67
-    /**
68
-     * Instantiate a ViewBuilder object.
69
-     *
70
-     * @since 0.1.0
71
-     *
72
-     * @param ConfigInterface            $config       Configuration settings.
73
-     * @param ViewFinderInterface|null   $viewFinder   ViewFinder instance.
74
-     * @param EngineFinderInterface|null $engineFinder EngineFinder instance.
75
-     *
76
-     * @throws FailedToProcessConfigException If the config could not be processed.
77
-     */
78
-    public function __construct(
79
-        ConfigInterface $config,
80
-        ViewFinderInterface $viewFinder = null,
81
-        EngineFinderInterface $engineFinder = null
82
-    ) {
83
-        $this->processConfig($config);
84
-        $this->viewFinder   = $viewFinder;
85
-        $this->engineFinder = $engineFinder;
86
-    }
87
-
88
-    /**
89
-     * Create a new view for a given URI.
90
-     *
91
-     * @since 0.1.0
92
-     *
93
-     * @param string      $view View identifier to create a view for.
94
-     * @param string|null $type Type of view to create.
95
-     *
96
-     * @return ViewInterface Instance of the requested view.
97
-     */
98
-    public function create($view, $type = null)
99
-    {
100
-        $uri    = $this->scanLocations([$view]);
101
-        $engine = $this->getEngine($uri);
102
-
103
-        return $this->getView($uri, $engine, $type);
104
-    }
105
-
106
-    /**
107
-     * Get an Engine that can deal with the given URI.
108
-     *
109
-     * @since 0.1.0
110
-     *
111
-     * @param string $uri URI to get an engine for.
112
-     *
113
-     * @return EngineInterface Instance of an engine that can deal with the given URI.
114
-     */
115
-    public function getEngine($uri)
116
-    {
117
-        return $this->getEngineFinder()->find([$uri]);
118
-    }
119
-
120
-    /**
121
-     * Get a view for a given URI, engine and type.
122
-     *
123
-     * @since 0.1.0
124
-     *
125
-     * @param string          $uri    URI to get a view for.
126
-     * @param EngineInterface $engine Engine to use for the view.
127
-     * @param null            $type   Type of view to get.
128
-     *
129
-     * @return ViewInterface View that matches the given requirements.
130
-     */
131
-    public function getView($uri, EngineInterface $engine, $type = null)
132
-    {
133
-        if (null === $type) {
134
-            return $this->getViewFinder()->find([$uri], $engine);
135
-        }
136
-
137
-        return $this->resolveType($type, $uri, $engine);
138
-    }
139
-
140
-    /**
141
-     * Get the ViewFinder instance.
142
-     *
143
-     * @since 0.1.0
144
-     *
145
-     * @return ViewFinderInterface Instance of a ViewFinder.
146
-     */
147
-    public function getViewFinder()
148
-    {
149
-        if (null === $this->viewFinder) {
150
-            $viewFinderClass  = $this->config->getKey(ViewBuilder::VIEW_FINDER_KEY, 'ClassName');
151
-            $this->viewFinder = new $viewFinderClass($this->config->getSubConfig(ViewBuilder::VIEW_FINDER_KEY));
152
-        }
153
-
154
-        return $this->viewFinder;
155
-    }
156
-
157
-    /**
158
-     * Get the EngineFinder instance.
159
-     *
160
-     * @since 0.1.0
161
-     *
162
-     * @return EngineFinderInterface Instance of a EngineFinder.
163
-     */
164
-    public function getEngineFinder()
165
-    {
166
-        if (null === $this->engineFinder) {
167
-            $engineFinderClass  = $this->config->getKey(ViewBuilder::ENGINE_FINDER_KEY, 'ClassName');
168
-            $this->engineFinder = new $engineFinderClass($this->config->getSubConfig(ViewBuilder::ENGINE_FINDER_KEY));
169
-        }
170
-
171
-        return $this->engineFinder;
172
-    }
173
-
174
-    /**
175
-     * Add a location to scan with the ViewFinder.
176
-     *
177
-     * @since 0.1.0
178
-     *
179
-     * @param LocationInterface $location Location to scan with the ViewFinder.
180
-     */
181
-    public function addLocation(LocationInterface $location)
182
-    {
183
-        $this->locations[] = $location;
184
-    }
185
-
186
-    /**
187
-     * Scan Locations for an URI that matches the specified criteria.
188
-     *
189
-     * @since 0.1.0
190
-     *
191
-     * @param array $criteria Criteria to match.
192
-     *
193
-     * @return string|bool URI of the requested view, or false if not found.
194
-     */
195
-    public function scanLocations(array $criteria)
196
-    {
197
-        /** @var LocationInterface $location */
198
-        foreach ($this->locations as $location) {
199
-            if ($uri = $location->getURI($criteria)) {
200
-                return $uri;
201
-            }
202
-        }
203
-
204
-        return false;
205
-    }
206
-
207
-    /**
208
-     * Resolve the view type.
209
-     *
210
-     * @since 0.1.0
211
-     *
212
-     * @param mixed           $type   Type of view that was requested.
213
-     * @param string          $uri    URI to get a view for.
214
-     * @param EngineInterface $engine Engine to use for the view.
215
-     *
216
-     * @return ViewInterface Resolved View object.
217
-     * @throws FailedToInstantiateViewException If the view type could not be resolved.
218
-     */
219
-    protected function resolveType($type, $uri, EngineInterface $engine = null)
220
-    {
221
-        if (is_string($type) && $this->config->hasKey(ViewBuilder::VIEW_FINDER_KEY)) {
222
-            $type = new $type($uri, $engine);
223
-        }
224
-
225
-        if (is_callable($type)) {
226
-            $type = $type($uri, $engine);
227
-        }
228
-
229
-        if (! $type instanceof ViewInterface) {
230
-            throw new FailedToInstantiateViewException(
231
-                sprintf(
232
-                    _('Could not instantiate view "%s".'),
233
-                    serialize($type)
234
-                )
235
-            );
236
-        }
237
-
238
-        return $type;
239
-    }
35
+	use ConfigTrait;
36
+
37
+	const ENGINE_FINDER_KEY = 'EngineFinder';
38
+	const VIEW_FINDER_KEY   = 'ViewFinder';
39
+
40
+	/**
41
+	 * ViewFinder instance.
42
+	 *
43
+	 * @since 0.1.0
44
+	 *
45
+	 * @var ViewFinderInterface
46
+	 */
47
+	protected $viewFinder;
48
+
49
+	/**
50
+	 * EngineFinder instance.
51
+	 *
52
+	 * @since 0.1.0
53
+	 *
54
+	 * @var EngineFinderInterface
55
+	 */
56
+	protected $engineFinder;
57
+
58
+	/**
59
+	 * Locations to scan for views.
60
+	 *
61
+	 * @since 0.1.0
62
+	 *
63
+	 * @var LocationInterface[]
64
+	 */
65
+	protected $locations;
66
+
67
+	/**
68
+	 * Instantiate a ViewBuilder object.
69
+	 *
70
+	 * @since 0.1.0
71
+	 *
72
+	 * @param ConfigInterface            $config       Configuration settings.
73
+	 * @param ViewFinderInterface|null   $viewFinder   ViewFinder instance.
74
+	 * @param EngineFinderInterface|null $engineFinder EngineFinder instance.
75
+	 *
76
+	 * @throws FailedToProcessConfigException If the config could not be processed.
77
+	 */
78
+	public function __construct(
79
+		ConfigInterface $config,
80
+		ViewFinderInterface $viewFinder = null,
81
+		EngineFinderInterface $engineFinder = null
82
+	) {
83
+		$this->processConfig($config);
84
+		$this->viewFinder   = $viewFinder;
85
+		$this->engineFinder = $engineFinder;
86
+	}
87
+
88
+	/**
89
+	 * Create a new view for a given URI.
90
+	 *
91
+	 * @since 0.1.0
92
+	 *
93
+	 * @param string      $view View identifier to create a view for.
94
+	 * @param string|null $type Type of view to create.
95
+	 *
96
+	 * @return ViewInterface Instance of the requested view.
97
+	 */
98
+	public function create($view, $type = null)
99
+	{
100
+		$uri    = $this->scanLocations([$view]);
101
+		$engine = $this->getEngine($uri);
102
+
103
+		return $this->getView($uri, $engine, $type);
104
+	}
105
+
106
+	/**
107
+	 * Get an Engine that can deal with the given URI.
108
+	 *
109
+	 * @since 0.1.0
110
+	 *
111
+	 * @param string $uri URI to get an engine for.
112
+	 *
113
+	 * @return EngineInterface Instance of an engine that can deal with the given URI.
114
+	 */
115
+	public function getEngine($uri)
116
+	{
117
+		return $this->getEngineFinder()->find([$uri]);
118
+	}
119
+
120
+	/**
121
+	 * Get a view for a given URI, engine and type.
122
+	 *
123
+	 * @since 0.1.0
124
+	 *
125
+	 * @param string          $uri    URI to get a view for.
126
+	 * @param EngineInterface $engine Engine to use for the view.
127
+	 * @param null            $type   Type of view to get.
128
+	 *
129
+	 * @return ViewInterface View that matches the given requirements.
130
+	 */
131
+	public function getView($uri, EngineInterface $engine, $type = null)
132
+	{
133
+		if (null === $type) {
134
+			return $this->getViewFinder()->find([$uri], $engine);
135
+		}
136
+
137
+		return $this->resolveType($type, $uri, $engine);
138
+	}
139
+
140
+	/**
141
+	 * Get the ViewFinder instance.
142
+	 *
143
+	 * @since 0.1.0
144
+	 *
145
+	 * @return ViewFinderInterface Instance of a ViewFinder.
146
+	 */
147
+	public function getViewFinder()
148
+	{
149
+		if (null === $this->viewFinder) {
150
+			$viewFinderClass  = $this->config->getKey(ViewBuilder::VIEW_FINDER_KEY, 'ClassName');
151
+			$this->viewFinder = new $viewFinderClass($this->config->getSubConfig(ViewBuilder::VIEW_FINDER_KEY));
152
+		}
153
+
154
+		return $this->viewFinder;
155
+	}
156
+
157
+	/**
158
+	 * Get the EngineFinder instance.
159
+	 *
160
+	 * @since 0.1.0
161
+	 *
162
+	 * @return EngineFinderInterface Instance of a EngineFinder.
163
+	 */
164
+	public function getEngineFinder()
165
+	{
166
+		if (null === $this->engineFinder) {
167
+			$engineFinderClass  = $this->config->getKey(ViewBuilder::ENGINE_FINDER_KEY, 'ClassName');
168
+			$this->engineFinder = new $engineFinderClass($this->config->getSubConfig(ViewBuilder::ENGINE_FINDER_KEY));
169
+		}
170
+
171
+		return $this->engineFinder;
172
+	}
173
+
174
+	/**
175
+	 * Add a location to scan with the ViewFinder.
176
+	 *
177
+	 * @since 0.1.0
178
+	 *
179
+	 * @param LocationInterface $location Location to scan with the ViewFinder.
180
+	 */
181
+	public function addLocation(LocationInterface $location)
182
+	{
183
+		$this->locations[] = $location;
184
+	}
185
+
186
+	/**
187
+	 * Scan Locations for an URI that matches the specified criteria.
188
+	 *
189
+	 * @since 0.1.0
190
+	 *
191
+	 * @param array $criteria Criteria to match.
192
+	 *
193
+	 * @return string|bool URI of the requested view, or false if not found.
194
+	 */
195
+	public function scanLocations(array $criteria)
196
+	{
197
+		/** @var LocationInterface $location */
198
+		foreach ($this->locations as $location) {
199
+			if ($uri = $location->getURI($criteria)) {
200
+				return $uri;
201
+			}
202
+		}
203
+
204
+		return false;
205
+	}
206
+
207
+	/**
208
+	 * Resolve the view type.
209
+	 *
210
+	 * @since 0.1.0
211
+	 *
212
+	 * @param mixed           $type   Type of view that was requested.
213
+	 * @param string          $uri    URI to get a view for.
214
+	 * @param EngineInterface $engine Engine to use for the view.
215
+	 *
216
+	 * @return ViewInterface Resolved View object.
217
+	 * @throws FailedToInstantiateViewException If the view type could not be resolved.
218
+	 */
219
+	protected function resolveType($type, $uri, EngineInterface $engine = null)
220
+	{
221
+		if (is_string($type) && $this->config->hasKey(ViewBuilder::VIEW_FINDER_KEY)) {
222
+			$type = new $type($uri, $engine);
223
+		}
224
+
225
+		if (is_callable($type)) {
226
+			$type = $type($uri, $engine);
227
+		}
228
+
229
+		if (! $type instanceof ViewInterface) {
230
+			throw new FailedToInstantiateViewException(
231
+				sprintf(
232
+					_('Could not instantiate view "%s".'),
233
+					serialize($type)
234
+				)
235
+			);
236
+		}
237
+
238
+		return $type;
239
+	}
240 240
 }
Please login to merge, or discard this patch.
src/View.php 1 patch
Indentation   +91 added lines, -91 removed lines patch added patch discarded remove patch
@@ -28,104 +28,104 @@
 block discarded – undo
28 28
 class View
29 29
 {
30 30
 
31
-    /**
32
-     * ViewBuilder Instance.
33
-     *
34
-     * @since 0.1.0
35
-     *
36
-     * @var ViewBuilder
37
-     */
38
-    protected static $viewBuilder;
31
+	/**
32
+	 * ViewBuilder Instance.
33
+	 *
34
+	 * @since 0.1.0
35
+	 *
36
+	 * @var ViewBuilder
37
+	 */
38
+	protected static $viewBuilder;
39 39
 
40
-    /**
41
-     * Add a location to the ViewBuilder.
42
-     *
43
-     * @since 0.1.0
44
-     *
45
-     * @param LocationInterface $location Location to add.
46
-     */
47
-    public static function addLocation(LocationInterface $location)
48
-    {
49
-        $viewBuilder = static::getViewBuilder();
50
-        $viewBuilder->addLocation($location);
51
-    }
40
+	/**
41
+	 * Add a location to the ViewBuilder.
42
+	 *
43
+	 * @since 0.1.0
44
+	 *
45
+	 * @param LocationInterface $location Location to add.
46
+	 */
47
+	public static function addLocation(LocationInterface $location)
48
+	{
49
+		$viewBuilder = static::getViewBuilder();
50
+		$viewBuilder->addLocation($location);
51
+	}
52 52
 
53
-    /**
54
-     * Get the ViewBuilder instance.
55
-     *
56
-     * @since 0.1.0
57
-     *
58
-     * @return ViewBuilder
59
-     */
60
-    public static function getViewBuilder()
61
-    {
62
-        if (null === static::$viewBuilder) {
63
-            static::$viewBuilder = static::instantiateViewBuilder();
64
-        }
53
+	/**
54
+	 * Get the ViewBuilder instance.
55
+	 *
56
+	 * @since 0.1.0
57
+	 *
58
+	 * @return ViewBuilder
59
+	 */
60
+	public static function getViewBuilder()
61
+	{
62
+		if (null === static::$viewBuilder) {
63
+			static::$viewBuilder = static::instantiateViewBuilder();
64
+		}
65 65
 
66
-        return static::$viewBuilder;
67
-    }
66
+		return static::$viewBuilder;
67
+	}
68 68
 
69
-    /**
70
-     * Instantiate the ViewBuilder.
71
-     *
72
-     * @since 0.1.0
73
-     *
74
-     * @param ConfigInterface|null $config Optional. Configuration to pass into the ViewBuilder.
75
-     *
76
-     * @return ViewBuilder Instance of the ViewBuilder.
77
-     */
78
-    public static function instantiateViewBuilder(ConfigInterface $config = null)
79
-    {
80
-        return static::$viewBuilder = new ViewBuilder($config ?: static::getDefaultConfig());
81
-    }
69
+	/**
70
+	 * Instantiate the ViewBuilder.
71
+	 *
72
+	 * @since 0.1.0
73
+	 *
74
+	 * @param ConfigInterface|null $config Optional. Configuration to pass into the ViewBuilder.
75
+	 *
76
+	 * @return ViewBuilder Instance of the ViewBuilder.
77
+	 */
78
+	public static function instantiateViewBuilder(ConfigInterface $config = null)
79
+	{
80
+		return static::$viewBuilder = new ViewBuilder($config ?: static::getDefaultConfig());
81
+	}
82 82
 
83
-    /**
84
-     * Get the default configuration to inject into the ViewBuilder.
85
-     *
86
-     * @since 0.1.0
87
-     *
88
-     * @return ConfigInterface Default configuration.
89
-     */
90
-    public static function getDefaultConfig()
91
-    {
92
-        return ConfigFactory::create(__DIR__ . '/../config/defaults.php')
93
-                            ->getSubConfig('BrightNucleus\View');
94
-    }
83
+	/**
84
+	 * Get the default configuration to inject into the ViewBuilder.
85
+	 *
86
+	 * @since 0.1.0
87
+	 *
88
+	 * @return ConfigInterface Default configuration.
89
+	 */
90
+	public static function getDefaultConfig()
91
+	{
92
+		return ConfigFactory::create(__DIR__ . '/../config/defaults.php')
93
+							->getSubConfig('BrightNucleus\View');
94
+	}
95 95
 
96
-    /**
97
-     * Create a new view for a given URI.
98
-     *
99
-     * @since 0.1.0
100
-     *
101
-     * @param string      $view View identifier to create a view for.
102
-     * @param string|null $type Type of view to create.
103
-     *
104
-     * @return ViewInterface Instance of the requested view.
105
-     */
106
-    public static function create($view, $type = null)
107
-    {
108
-        $viewBuilder = static::getViewBuilder();
96
+	/**
97
+	 * Create a new view for a given URI.
98
+	 *
99
+	 * @since 0.1.0
100
+	 *
101
+	 * @param string      $view View identifier to create a view for.
102
+	 * @param string|null $type Type of view to create.
103
+	 *
104
+	 * @return ViewInterface Instance of the requested view.
105
+	 */
106
+	public static function create($view, $type = null)
107
+	{
108
+		$viewBuilder = static::getViewBuilder();
109 109
 
110
-        return $viewBuilder->create($view, $type);
111
-    }
110
+		return $viewBuilder->create($view, $type);
111
+	}
112 112
 
113
-    /**
114
-     * Render a view for a given URI.
115
-     *
116
-     * @since 0.1.0
117
-     *
118
-     * @param string      $view    View identifier to create a view for.
119
-     * @param array       $context Optional. The context in which to render the view.
120
-     * @param string|null $type    Type of view to create.
121
-     *
122
-     * @return ViewInterface Instance of the requested view.
123
-     */
124
-    public static function render($view, array $context = [], $type = null)
125
-    {
126
-        $viewBuilder = static::getViewBuilder();
127
-        $viewObject  = $viewBuilder->create($view, $type);
113
+	/**
114
+	 * Render a view for a given URI.
115
+	 *
116
+	 * @since 0.1.0
117
+	 *
118
+	 * @param string      $view    View identifier to create a view for.
119
+	 * @param array       $context Optional. The context in which to render the view.
120
+	 * @param string|null $type    Type of view to create.
121
+	 *
122
+	 * @return ViewInterface Instance of the requested view.
123
+	 */
124
+	public static function render($view, array $context = [], $type = null)
125
+	{
126
+		$viewBuilder = static::getViewBuilder();
127
+		$viewObject  = $viewBuilder->create($view, $type);
128 128
 
129
-        return $viewObject->render($context);
130
-    }
129
+		return $viewObject->render($context);
130
+	}
131 131
 }
Please login to merge, or discard this patch.