Test Failed
Push — master ( 147d4d...670e11 )
by Alain
03:28
created
src/View/View/NullView.php 1 patch
Indentation   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -26,74 +26,74 @@
 block discarded – undo
26 26
 class NullView implements View, NullFindable
27 27
 {
28 28
 
29
-    /**
30
-     * Check whether the Findable can handle an individual criterion.
31
-     *
32
-     * @since 0.1.0
33
-     *
34
-     * @param mixed $criterion Criterion to check.
35
-     *
36
-     * @return bool Whether the Findable can handle the criterion.
37
-     */
38
-    public function canHandle($criterion): bool
39
-    {
40
-        return true;
41
-    }
29
+	/**
30
+	 * Check whether the Findable can handle an individual criterion.
31
+	 *
32
+	 * @since 0.1.0
33
+	 *
34
+	 * @param mixed $criterion Criterion to check.
35
+	 *
36
+	 * @return bool Whether the Findable can handle the criterion.
37
+	 */
38
+	public function canHandle($criterion): bool
39
+	{
40
+		return true;
41
+	}
42 42
 
43
-    /**
44
-     * Render the view.
45
-     *
46
-     * @since 0.1.0
47
-     *
48
-     * @param array $context Optional. The context in which to render the view.
49
-     * @param bool  $echo    Optional. Whether to echo the output immediately. Defaults to false.
50
-     *
51
-     * @return string Rendered HTML.
52
-     */
53
-    public function render(array $context = [], bool $echo = false): string
54
-    {
55
-        return '';
56
-    }
43
+	/**
44
+	 * Render the view.
45
+	 *
46
+	 * @since 0.1.0
47
+	 *
48
+	 * @param array $context Optional. The context in which to render the view.
49
+	 * @param bool  $echo    Optional. Whether to echo the output immediately. Defaults to false.
50
+	 *
51
+	 * @return string Rendered HTML.
52
+	 */
53
+	public function render(array $context = [], bool $echo = false): string
54
+	{
55
+		return '';
56
+	}
57 57
 
58
-    /**
59
-     * Render a partial view (or section) for a given URI.
60
-     *
61
-     * @since 0.2.0
62
-     *
63
-     * @param string      $view    View identifier to create a view for.
64
-     * @param array       $context Optional. The context in which to render the view.
65
-     * @param string|null $type    Type of view to create.
66
-     *
67
-     * @return string Rendered HTML content.
68
-     */
69
-    public function section(string $view, array $context = [], $type = null): string
70
-    {
71
-        return '';
72
-    }
58
+	/**
59
+	 * Render a partial view (or section) for a given URI.
60
+	 *
61
+	 * @since 0.2.0
62
+	 *
63
+	 * @param string      $view    View identifier to create a view for.
64
+	 * @param array       $context Optional. The context in which to render the view.
65
+	 * @param string|null $type    Type of view to create.
66
+	 *
67
+	 * @return string Rendered HTML content.
68
+	 */
69
+	public function section(string $view, array $context = [], $type = null): string
70
+	{
71
+		return '';
72
+	}
73 73
 
74
-    /**
75
-     * Get the entire array of contextual data.
76
-     *
77
-     * @since 0.4.0
78
-     *
79
-     * @return array Array of contextual data.
80
-     */
81
-    public function getContext(): array
82
-    {
83
-        return [];
84
-    }
74
+	/**
75
+	 * Get the entire array of contextual data.
76
+	 *
77
+	 * @since 0.4.0
78
+	 *
79
+	 * @return array Array of contextual data.
80
+	 */
81
+	public function getContext(): array
82
+	{
83
+		return [];
84
+	}
85 85
 
86
-    /**
87
-     * Associate a view builder with this view.
88
-     *
89
-     * @since 0.2.0
90
-     *
91
-     * @param ViewBuilder $builder
92
-     *
93
-     * @return View
94
-     */
95
-    public function setBuilder(ViewBuilder $builder): View
96
-    {
97
-        return $this;
98
-    }
86
+	/**
87
+	 * Associate a view builder with this view.
88
+	 *
89
+	 * @since 0.2.0
90
+	 *
91
+	 * @param ViewBuilder $builder
92
+	 *
93
+	 * @return View
94
+	 */
95
+	public function setBuilder(ViewBuilder $builder): View
96
+	{
97
+		return $this;
98
+	}
99 99
 }
Please login to merge, or discard this patch.
src/View/Engine/Engine.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -24,15 +24,15 @@
 block discarded – undo
24 24
 interface Engine extends Findable
25 25
 {
26 26
 
27
-    /**
28
-     * Get the rendering callback for a given URI.
29
-     *
30
-     * @since 0.1.0
31
-     *
32
-     * @param string $uri     URI to render.
33
-     * @param array  $context Context in which to render.
34
-     *
35
-     * @return callable Render callback.
36
-     */
37
-    public function getRenderCallback(string $uri, array $context = []): callable;
27
+	/**
28
+	 * Get the rendering callback for a given URI.
29
+	 *
30
+	 * @since 0.1.0
31
+	 *
32
+	 * @param string $uri     URI to render.
33
+	 * @param array  $context Context in which to render.
34
+	 *
35
+	 * @return callable Render callback.
36
+	 */
37
+	public function getRenderCallback(string $uri, array $context = []): callable;
38 38
 }
Please login to merge, or discard this patch.
config/defaults.php 1 patch
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -15,35 +15,35 @@
 block discarded – undo
15 15
  * Engine finder default configuration.
16 16
  */
17 17
 $engineFinder = [
18
-    // Class to use for instantiating the EngineFinder implementation.
19
-    Engine\EngineFinder::CLASS_NAME_KEY => Engine\BaseEngineFinder::class,
20
-    // Engine implementations to register with the EngineFinder.
21
-    Engine\EngineFinder::ENGINES_KEY    => [
22
-        'PHPEngine' => Engine\PHPEngine::class,
23
-    ],
24
-    // Null object implementation to use with the EngineFinder.
25
-    Engine\EngineFinder::NULL_OBJECT    => Engine\NullEngine::class,
18
+	// Class to use for instantiating the EngineFinder implementation.
19
+	Engine\EngineFinder::CLASS_NAME_KEY => Engine\BaseEngineFinder::class,
20
+	// Engine implementations to register with the EngineFinder.
21
+	Engine\EngineFinder::ENGINES_KEY    => [
22
+		'PHPEngine' => Engine\PHPEngine::class,
23
+	],
24
+	// Null object implementation to use with the EngineFinder.
25
+	Engine\EngineFinder::NULL_OBJECT    => Engine\NullEngine::class,
26 26
 ];
27 27
 
28 28
 /*
29 29
  * View finder default configuration.
30 30
  */
31 31
 $viewFinder = [
32
-    // Class to use for instantiating the ViewFinder implementation.
33
-    View\ViewFinder::CLASS_NAME_KEY => View\BaseViewFinder::class,
34
-    // View implementations to register with the ViewFinder.
35
-    View\ViewFinder::VIEWS_KEY      => [
36
-        'BaseView' => View\BaseView::class,
37
-    ],
38
-    // Null object implementation to use with the ViewFinder.
39
-    View\ViewFinder::NULL_OBJECT    => View\NullView::class,
32
+	// Class to use for instantiating the ViewFinder implementation.
33
+	View\ViewFinder::CLASS_NAME_KEY => View\BaseViewFinder::class,
34
+	// View implementations to register with the ViewFinder.
35
+	View\ViewFinder::VIEWS_KEY      => [
36
+		'BaseView' => View\BaseView::class,
37
+	],
38
+	// Null object implementation to use with the ViewFinder.
39
+	View\ViewFinder::NULL_OBJECT    => View\NullView::class,
40 40
 ];
41 41
 
42 42
 return [
43
-    'BrightNucleus' => [
44
-        'View' => [
45
-            'EngineFinder' => $engineFinder,
46
-            'ViewFinder'   => $viewFinder,
47
-        ],
48
-    ],
43
+	'BrightNucleus' => [
44
+		'View' => [
45
+			'EngineFinder' => $engineFinder,
46
+			'ViewFinder'   => $viewFinder,
47
+		],
48
+	],
49 49
 ];
Please login to merge, or discard this patch.
src/View/Engine/NullEngine.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -46,7 +46,7 @@
 block discarded – undo
46 46
      * @param string $uri     URI to render.
47 47
      * @param array  $context Context in which to render.
48 48
      *
49
-     * @return callable Rendering callback.
49
+     * @return \Closure Rendering callback.
50 50
      */
51 51
     public function getRenderCallback(string $uri, array $context = []): callable
52 52
     {
Please login to merge, or discard this 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 Engine, NullFindable
25 25
 {
26 26
 
27
-    /**
28
-     * Check whether the Findable can handle an individual criterion.
29
-     *
30
-     * @since 0.1.0
31
-     *
32
-     * @param mixed $criterion Criterion to check.
33
-     *
34
-     * @return bool Whether the Findable can handle the criterion.
35
-     */
36
-    public function canHandle($criterion): bool
37
-    {
38
-        return true;
39
-    }
27
+	/**
28
+	 * Check whether the Findable can handle an individual criterion.
29
+	 *
30
+	 * @since 0.1.0
31
+	 *
32
+	 * @param mixed $criterion Criterion to check.
33
+	 *
34
+	 * @return bool Whether the Findable can handle the criterion.
35
+	 */
36
+	public function canHandle($criterion): bool
37
+	{
38
+		return true;
39
+	}
40 40
 
41
-    /**
42
-     * Get the rendering callback for 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 callable Rendering callback.
50
-     */
51
-    public function getRenderCallback(string $uri, array $context = []): callable
52
-    {
53
-        return function () { return ''; };
54
-    }
41
+	/**
42
+	 * Get the rendering callback for 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 callable Rendering callback.
50
+	 */
51
+	public function getRenderCallback(string $uri, array $context = []): callable
52
+	{
53
+		return function () { return ''; };
54
+	}
55 55
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -50,6 +50,6 @@
 block discarded – undo
50 50
      */
51 51
     public function getRenderCallback(string $uri, array $context = []): callable
52 52
     {
53
-        return function () { return ''; };
53
+        return function() { return ''; };
54 54
     }
55 55
 }
Please login to merge, or discard this patch.
src/View/View/ViewFinder.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -26,29 +26,29 @@
 block discarded – undo
26 26
 interface ViewFinder extends Finder
27 27
 {
28 28
 
29
-    // Constants to be used for the Config file sections.
30
-    const CLASS_NAME_KEY = 'ClassName';
31
-    const VIEWS_KEY = 'Views';
32
-    const NULL_OBJECT = 'NullObject';
29
+	// Constants to be used for the Config file sections.
30
+	const CLASS_NAME_KEY = 'ClassName';
31
+	const VIEWS_KEY = 'Views';
32
+	const NULL_OBJECT = 'NullObject';
33 33
 
34
-    /**
35
-     * Find a result based on a specific criteria.
36
-     *
37
-     * @since 0.1.0
38
-     *
39
-     * @param array       $criteria Criteria to search for.
40
-     * @param Engine|null $engine   Optional. Engine to use with the view.
41
-     *
42
-     * @return View View that was found.
43
-     */
44
-    public function find(array $criteria, Engine $engine = null): View;
34
+	/**
35
+	 * Find a result based on a specific criteria.
36
+	 *
37
+	 * @since 0.1.0
38
+	 *
39
+	 * @param array       $criteria Criteria to search for.
40
+	 * @param Engine|null $engine   Optional. Engine to use with the view.
41
+	 *
42
+	 * @return View View that was found.
43
+	 */
44
+	public function find(array $criteria, Engine $engine = null): View;
45 45
 
46
-    /**
47
-     * Get the NullObject.
48
-     *
49
-     * @since 0.1.1
50
-     *
51
-     * @return NullView NullObject for the current Finder.
52
-     */
53
-    public function getNullObject(): NullView;
46
+	/**
47
+	 * Get the NullObject.
48
+	 *
49
+	 * @since 0.1.1
50
+	 *
51
+	 * @return NullView NullObject for the current Finder.
52
+	 */
53
+	public function getNullObject(): NullView;
54 54
 }
Please login to merge, or discard this patch.
src/View/View/BaseViewFinder.php 1 patch
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -27,56 +27,56 @@
 block discarded – undo
27 27
 class BaseViewFinder extends AbstractFinder implements ViewFinder
28 28
 {
29 29
 
30
-    /**
31
-     * Find a result based on a specific criteria.
32
-     *
33
-     * @since 0.1.0
34
-     *
35
-     * @param array       $criteria Criteria to search for.
36
-     * @param Engine|null $engine   Optional. Engine to use with the view.
37
-     *
38
-     * @return View View that was found.
39
-     * @throws FailedToInstantiateFindable If the Findable could not be instantiated.
40
-     */
41
-    public function find(array $criteria, Engine $engine = null): View
42
-    {
43
-        $uri = $criteria[0];
30
+	/**
31
+	 * Find a result based on a specific criteria.
32
+	 *
33
+	 * @since 0.1.0
34
+	 *
35
+	 * @param array       $criteria Criteria to search for.
36
+	 * @param Engine|null $engine   Optional. Engine to use with the view.
37
+	 *
38
+	 * @return View View that was found.
39
+	 * @throws FailedToInstantiateFindable If the Findable could not be instantiated.
40
+	 */
41
+	public function find(array $criteria, Engine $engine = null): View
42
+	{
43
+		$uri = $criteria[0];
44 44
 
45
-        $views = $this->initializeFindables([$uri, $engine]);
45
+		$views = $this->initializeFindables([$uri, $engine]);
46 46
 
47
-        foreach ($criteria as $entry) {
48
-            foreach ($views as $viewObject) {
49
-                if ($viewObject->canHandle($entry)) {
50
-                    return $viewObject;
51
-                }
52
-            }
53
-        }
47
+		foreach ($criteria as $entry) {
48
+			foreach ($views as $viewObject) {
49
+				if ($viewObject->canHandle($entry)) {
50
+					return $viewObject;
51
+				}
52
+			}
53
+		}
54 54
 
55
-        return $this->getNullObject();
56
-    }
55
+		return $this->getNullObject();
56
+	}
57 57
 
58
-    /**
59
-     * Get the config key for the Findables definitions.
60
-     *
61
-     * @since 0.1.0
62
-     *
63
-     * @return string Config key use to define the Findables.
64
-     */
65
-    protected function getFindablesConfigKey(): string
66
-    {
67
-        return 'Views';
68
-    }
58
+	/**
59
+	 * Get the config key for the Findables definitions.
60
+	 *
61
+	 * @since 0.1.0
62
+	 *
63
+	 * @return string Config key use to define the Findables.
64
+	 */
65
+	protected function getFindablesConfigKey(): string
66
+	{
67
+		return 'Views';
68
+	}
69 69
 
70
-    /**
71
-     * Get the NullObject.
72
-     *
73
-     * @since 0.1.1
74
-     *
75
-     * @return NullView NullObject for the current Finder.
76
-     * @throws FailedToInstantiateFindable If the Findable could not be instantiated.
77
-     */
78
-    public function getNullObject(): NullView
79
-    {
80
-        return parent::getNullObject();
81
-    }
70
+	/**
71
+	 * Get the NullObject.
72
+	 *
73
+	 * @since 0.1.1
74
+	 *
75
+	 * @return NullView NullObject for the current Finder.
76
+	 * @throws FailedToInstantiateFindable If the Findable could not be instantiated.
77
+	 */
78
+	public function getNullObject(): NullView
79
+	{
80
+		return parent::getNullObject();
81
+	}
82 82
 }
Please login to merge, or discard this patch.
src/View/View/AbstractView.php 1 patch
Indentation   +177 added lines, -177 removed lines patch added patch discarded remove patch
@@ -30,181 +30,181 @@
 block discarded – undo
30 30
 abstract class AbstractView implements View
31 31
 {
32 32
 
33
-    /**
34
-     * URI of the view.
35
-     *
36
-     * The underscores are used to prevent accidental use of these properties from within the rendering closure.
37
-     *
38
-     * @since 0.1.0
39
-     *
40
-     * @var string
41
-     */
42
-    protected $_uri_;
43
-
44
-    /**
45
-     * Engine to use for the view.
46
-     *
47
-     * The underscores are used to prevent accidental use of these properties from within the rendering closure.
48
-     *
49
-     * @since 0.1.0
50
-     *
51
-     * @var Engine
52
-     */
53
-    protected $_engine_;
54
-
55
-    /**
56
-     * ViewBuilder instance.
57
-     *
58
-     * The underscores are used to prevent accidental use of these properties from within the rendering closure.
59
-     *
60
-     * @since 0.2.0
61
-     *
62
-     * @var ViewBuilder
63
-     */
64
-    protected $_builder_;
65
-
66
-    /**
67
-     * The context with which the view will be rendered.
68
-     *
69
-     * The underscores are used to prevent accidental use of these properties from within the rendering closure.
70
-     *
71
-     * @since 0.4.0
72
-     *
73
-     * @var array
74
-     */
75
-    protected $_context_ = [];
76
-
77
-    /**
78
-     * Instantiate an AbstractView object.
79
-     *
80
-     * @since 0.1.0
81
-     *
82
-     * @param string      $uri         URI for the view.
83
-     * @param Engine      $engine      Engine to use for the view.
84
-     * @param ViewBuilder $viewBuilder View builder instance to use.
85
-     */
86
-    public function __construct(string $uri, Engine $engine, ViewBuilder $viewBuilder = null)
87
-    {
88
-        $this->_uri_     = $uri;
89
-        $this->_engine_  = $engine;
90
-        $this->_builder_ = $viewBuilder ?? Views::getViewBuilder();
91
-    }
92
-
93
-    /**
94
-     * Render the view.
95
-     *
96
-     * @since 0.1.0
97
-     *
98
-     * @param array $context Optional. The context in which to render the view.
99
-     * @param bool  $echo    Optional. Whether to echo the output immediately. Defaults to false.
100
-     *
101
-     * @return string Rendered HTML.
102
-     * @throws FailedToProcessConfigException If the Config could not be processed.
103
-     */
104
-    public function render(array $context = [], bool $echo = false): string
105
-    {
106
-        $this->assimilateContext($context);
107
-
108
-        $closure = Closure::bind(
109
-            $this->_engine_->getRenderCallback($this->_uri_, $context),
110
-            $this,
111
-            static::class
112
-        );
113
-
114
-        $output = $closure();
115
-
116
-        if ($echo) {
117
-            echo $output;
118
-        }
119
-
120
-        return $output;
121
-    }
122
-
123
-    /**
124
-     * Render a partial view (or section) for a given URI.
125
-     *
126
-     * @since 0.2.0
127
-     *
128
-     * @param string      $view    View identifier to create a view for.
129
-     * @param array       $context Optional. The context in which to render the view.
130
-     * @param string|null $type    Type of view to create.
131
-     *
132
-     * @return string Rendered HTML content.
133
-     * @throws FailedToProcessConfigException If the Config could not be processed.
134
-     * @throws FailedToInstantiateView If the View could not be instantiated.
135
-     */
136
-    public function section(string $view, array $context = null, $type = null): string
137
-    {
138
-        if (null === $context) {
139
-            $context = $this->_context_;
140
-        }
141
-
142
-        $viewObject = $this->_builder_->create($view, $type);
143
-
144
-        return $viewObject->render($context);
145
-    }
146
-
147
-    /**
148
-     * Get the entire array of contextual data.
149
-     *
150
-     * @since 0.4.0
151
-     *
152
-     * @return array Array of contextual data.
153
-     */
154
-    public function getContext(): array
155
-    {
156
-        return $this->_context_;
157
-    }
158
-
159
-    /**
160
-     * Associate a view builder with this view.
161
-     *
162
-     * @since 0.2.0
163
-     *
164
-     * @param ViewBuilder $builder
165
-     *
166
-     * @return View
167
-     */
168
-    public function setBuilder(ViewBuilder $builder): View
169
-    {
170
-        $this->_builder_ = $builder;
171
-
172
-        return $this;
173
-    }
174
-
175
-    /**
176
-     * Assimilate the context to make it available as properties.
177
-     *
178
-     * @since 0.2.0
179
-     *
180
-     * @param array $context Context to assimilate.
181
-     */
182
-    protected function assimilateContext(array $context = [])
183
-    {
184
-        $this->_context_ = $context;
185
-        foreach ($context as $key => $value) {
186
-            $this->$key = $value;
187
-        }
188
-    }
189
-
190
-    /**
191
-     * Turn invokable objects as properties into methods of the view.
192
-     *
193
-     * @param string $method    Method that was called on the view.
194
-     * @param array  $arguments Array of arguments that were used.
195
-     * @return mixed Return value of the invokable object.
196
-     */
197
-    public function __call($method, $arguments) {
198
-        if ( ! property_exists($this, $method)
199
-             || ! is_callable($this->$method)) {
200
-            trigger_error(
201
-                "Call to undefined method {$method} on a view.",
202
-                E_USER_ERROR
203
-            );
204
-        }
205
-
206
-        $callable = $this->$method;
207
-
208
-        return $callable(...$arguments);
209
-    }
33
+	/**
34
+	 * URI of the view.
35
+	 *
36
+	 * The underscores are used to prevent accidental use of these properties from within the rendering closure.
37
+	 *
38
+	 * @since 0.1.0
39
+	 *
40
+	 * @var string
41
+	 */
42
+	protected $_uri_;
43
+
44
+	/**
45
+	 * Engine to use for the view.
46
+	 *
47
+	 * The underscores are used to prevent accidental use of these properties from within the rendering closure.
48
+	 *
49
+	 * @since 0.1.0
50
+	 *
51
+	 * @var Engine
52
+	 */
53
+	protected $_engine_;
54
+
55
+	/**
56
+	 * ViewBuilder instance.
57
+	 *
58
+	 * The underscores are used to prevent accidental use of these properties from within the rendering closure.
59
+	 *
60
+	 * @since 0.2.0
61
+	 *
62
+	 * @var ViewBuilder
63
+	 */
64
+	protected $_builder_;
65
+
66
+	/**
67
+	 * The context with which the view will be rendered.
68
+	 *
69
+	 * The underscores are used to prevent accidental use of these properties from within the rendering closure.
70
+	 *
71
+	 * @since 0.4.0
72
+	 *
73
+	 * @var array
74
+	 */
75
+	protected $_context_ = [];
76
+
77
+	/**
78
+	 * Instantiate an AbstractView object.
79
+	 *
80
+	 * @since 0.1.0
81
+	 *
82
+	 * @param string      $uri         URI for the view.
83
+	 * @param Engine      $engine      Engine to use for the view.
84
+	 * @param ViewBuilder $viewBuilder View builder instance to use.
85
+	 */
86
+	public function __construct(string $uri, Engine $engine, ViewBuilder $viewBuilder = null)
87
+	{
88
+		$this->_uri_     = $uri;
89
+		$this->_engine_  = $engine;
90
+		$this->_builder_ = $viewBuilder ?? Views::getViewBuilder();
91
+	}
92
+
93
+	/**
94
+	 * Render the view.
95
+	 *
96
+	 * @since 0.1.0
97
+	 *
98
+	 * @param array $context Optional. The context in which to render the view.
99
+	 * @param bool  $echo    Optional. Whether to echo the output immediately. Defaults to false.
100
+	 *
101
+	 * @return string Rendered HTML.
102
+	 * @throws FailedToProcessConfigException If the Config could not be processed.
103
+	 */
104
+	public function render(array $context = [], bool $echo = false): string
105
+	{
106
+		$this->assimilateContext($context);
107
+
108
+		$closure = Closure::bind(
109
+			$this->_engine_->getRenderCallback($this->_uri_, $context),
110
+			$this,
111
+			static::class
112
+		);
113
+
114
+		$output = $closure();
115
+
116
+		if ($echo) {
117
+			echo $output;
118
+		}
119
+
120
+		return $output;
121
+	}
122
+
123
+	/**
124
+	 * Render a partial view (or section) for a given URI.
125
+	 *
126
+	 * @since 0.2.0
127
+	 *
128
+	 * @param string      $view    View identifier to create a view for.
129
+	 * @param array       $context Optional. The context in which to render the view.
130
+	 * @param string|null $type    Type of view to create.
131
+	 *
132
+	 * @return string Rendered HTML content.
133
+	 * @throws FailedToProcessConfigException If the Config could not be processed.
134
+	 * @throws FailedToInstantiateView If the View could not be instantiated.
135
+	 */
136
+	public function section(string $view, array $context = null, $type = null): string
137
+	{
138
+		if (null === $context) {
139
+			$context = $this->_context_;
140
+		}
141
+
142
+		$viewObject = $this->_builder_->create($view, $type);
143
+
144
+		return $viewObject->render($context);
145
+	}
146
+
147
+	/**
148
+	 * Get the entire array of contextual data.
149
+	 *
150
+	 * @since 0.4.0
151
+	 *
152
+	 * @return array Array of contextual data.
153
+	 */
154
+	public function getContext(): array
155
+	{
156
+		return $this->_context_;
157
+	}
158
+
159
+	/**
160
+	 * Associate a view builder with this view.
161
+	 *
162
+	 * @since 0.2.0
163
+	 *
164
+	 * @param ViewBuilder $builder
165
+	 *
166
+	 * @return View
167
+	 */
168
+	public function setBuilder(ViewBuilder $builder): View
169
+	{
170
+		$this->_builder_ = $builder;
171
+
172
+		return $this;
173
+	}
174
+
175
+	/**
176
+	 * Assimilate the context to make it available as properties.
177
+	 *
178
+	 * @since 0.2.0
179
+	 *
180
+	 * @param array $context Context to assimilate.
181
+	 */
182
+	protected function assimilateContext(array $context = [])
183
+	{
184
+		$this->_context_ = $context;
185
+		foreach ($context as $key => $value) {
186
+			$this->$key = $value;
187
+		}
188
+	}
189
+
190
+	/**
191
+	 * Turn invokable objects as properties into methods of the view.
192
+	 *
193
+	 * @param string $method    Method that was called on the view.
194
+	 * @param array  $arguments Array of arguments that were used.
195
+	 * @return mixed Return value of the invokable object.
196
+	 */
197
+	public function __call($method, $arguments) {
198
+		if ( ! property_exists($this, $method)
199
+			 || ! is_callable($this->$method)) {
200
+			trigger_error(
201
+				"Call to undefined method {$method} on a view.",
202
+				E_USER_ERROR
203
+			);
204
+		}
205
+
206
+		$callable = $this->$method;
207
+
208
+		return $callable(...$arguments);
209
+	}
210 210
 }
Please login to merge, or discard this patch.
src/View/Location/FilesystemLocation.php 2 patches
Indentation   +154 added lines, -154 removed lines patch added patch discarded remove patch
@@ -28,158 +28,158 @@
 block discarded – undo
28 28
 class FilesystemLocation implements Location
29 29
 {
30 30
 
31
-    /**
32
-     * Path that this location points to.
33
-     *
34
-     * @since 0.1.0
35
-     *
36
-     * @var string
37
-     */
38
-    protected $path;
39
-
40
-    /**
41
-     * Extensions that this location can accept.
42
-     *
43
-     * @since 0.1.0
44
-     *
45
-     * @var Extensions
46
-     */
47
-    protected $extensions;
48
-
49
-    /**
50
-     * Instantiate a FilesystemLocation object.
51
-     *
52
-     * @since 0.1.0
53
-     *
54
-     * @param string                       $path       Path that this location points to.
55
-     * @param Extensions|array|string|null $extensions Optional. Extensions that this location can accept.
56
-     */
57
-    public function __construct(string $path, $extensions = null)
58
-    {
59
-        $this->path       = $path;
60
-        $this->extensions = $this->validateExtensions($extensions);
61
-    }
62
-
63
-    /**
64
-     * Get the first URI that matches the given criteria.
65
-     *
66
-     * @since 0.1.0
67
-     *
68
-     * @param array $criteria Criteria to match.
69
-     *
70
-     * @return string|false URI that matches the criteria or false if none found.
71
-     */
72
-    public function getURI(array $criteria)
73
-    {
74
-        $uris = $this->getURIs($criteria);
75
-
76
-        return $uris->count() > 0
77
-            ? $uris->first()
78
-            : false;
79
-    }
80
-
81
-    /**
82
-     * Get all URIs that match the given criteria.
83
-     *
84
-     * @since 0.1.1
85
-     *
86
-     * @param array $criteria Criteria to match.
87
-     *
88
-     * @return URIs URIs that match the criteria or an empty collection if none found.
89
-     */
90
-    public function getURIs(array $criteria): URIs
91
-    {
92
-        $uris = new URIs();
93
-
94
-        foreach ($this->extensions as $extension) {
95
-            $finder = new Finder();
96
-
97
-            try {
98
-                $finder->files()
99
-                    ->name($this->getNamePattern($criteria, $extension))
100
-                    ->in($this->getPathPattern());
101
-                foreach ($finder as $file) {
102
-                    /** @var SplFileInfo $file */
103
-                    $uris->add($file->getPathname());
104
-                }
105
-            } catch (Exception $exception) {
106
-                // Fail silently;
107
-            }
108
-        }
109
-
110
-        return $uris;
111
-    }
112
-
113
-    /**
114
-     * Get the name pattern to pass to the file finder.
115
-     *
116
-     * @since 0.1.3
117
-     *
118
-     * @param array  $criteria  Criteria to match.
119
-     * @param string $extension Extension to match.
120
-     *
121
-     * @return string Name pattern to pass to the file finder.
122
-     */
123
-    protected function getNamePattern(array $criteria, string $extension): string
124
-    {
125
-        $names = [];
126
-
127
-        $names[] = array_map(function ($criterion) use ($extension) {
128
-            $uriExtension = URIHelper::containsExtension($criterion);
129
-            if (! empty($extension)) {
130
-                $extension = ltrim($extension, '.');
131
-
132
-                if ($uriExtension === $extension) {
133
-                    $criterion = substr($criterion,0,-strlen(".{$extension}"));
134
-                }
135
-            } else {
136
-                $extension = URIHelper::containsExtension($criterion);
137
-                if (!empty($extension)) {
138
-                    $criterion = substr($criterion,0,-strlen(".{$extension}"));
139
-                }
140
-            }
141
-
142
-            $criterion = preg_quote(URIHelper::getFilename($criterion), chr(1));
143
-
144
-            return (empty($extension) || URIHelper::hasExtension($criterion, $extension))
145
-                ? "{$criterion}(?:\..*?)$"
146
-                : "{$criterion}\.{$extension}$";
147
-        }, $criteria)[0];
148
-
149
-        return chr(1) . implode('|', array_unique($names)) . chr(1);
150
-    }
151
-
152
-    /**
153
-     * Get the path pattern to pass to the file finder.
154
-     *
155
-     * @since 0.1.3
156
-     *
157
-     * @return string Path pattern to pass to the file finder.
158
-     */
159
-    protected function getPathPattern(): string
160
-    {
161
-        return $this->path;
162
-    }
163
-
164
-    /**
165
-     * Validate the extensions and return a collection.
166
-     *
167
-     * @since 0.1.1
168
-     *
169
-     * @param Extensions|array|string|null $extensions Extensions to validate.
170
-     *
171
-     * @return Extensions Validated extensions collection.
172
-     */
173
-    protected function validateExtensions($extensions): Extensions
174
-    {
175
-        if (empty($extensions)) {
176
-            $extensions = new Extensions(['']);
177
-        }
178
-
179
-        if (! $extensions instanceof Extensions) {
180
-            $extensions = new Extensions((array)$extensions);
181
-        }
182
-
183
-        return $extensions;
184
-    }
31
+	/**
32
+	 * Path that this location points to.
33
+	 *
34
+	 * @since 0.1.0
35
+	 *
36
+	 * @var string
37
+	 */
38
+	protected $path;
39
+
40
+	/**
41
+	 * Extensions that this location can accept.
42
+	 *
43
+	 * @since 0.1.0
44
+	 *
45
+	 * @var Extensions
46
+	 */
47
+	protected $extensions;
48
+
49
+	/**
50
+	 * Instantiate a FilesystemLocation object.
51
+	 *
52
+	 * @since 0.1.0
53
+	 *
54
+	 * @param string                       $path       Path that this location points to.
55
+	 * @param Extensions|array|string|null $extensions Optional. Extensions that this location can accept.
56
+	 */
57
+	public function __construct(string $path, $extensions = null)
58
+	{
59
+		$this->path       = $path;
60
+		$this->extensions = $this->validateExtensions($extensions);
61
+	}
62
+
63
+	/**
64
+	 * Get the first URI that matches the given criteria.
65
+	 *
66
+	 * @since 0.1.0
67
+	 *
68
+	 * @param array $criteria Criteria to match.
69
+	 *
70
+	 * @return string|false URI that matches the criteria or false if none found.
71
+	 */
72
+	public function getURI(array $criteria)
73
+	{
74
+		$uris = $this->getURIs($criteria);
75
+
76
+		return $uris->count() > 0
77
+			? $uris->first()
78
+			: false;
79
+	}
80
+
81
+	/**
82
+	 * Get all URIs that match the given criteria.
83
+	 *
84
+	 * @since 0.1.1
85
+	 *
86
+	 * @param array $criteria Criteria to match.
87
+	 *
88
+	 * @return URIs URIs that match the criteria or an empty collection if none found.
89
+	 */
90
+	public function getURIs(array $criteria): URIs
91
+	{
92
+		$uris = new URIs();
93
+
94
+		foreach ($this->extensions as $extension) {
95
+			$finder = new Finder();
96
+
97
+			try {
98
+				$finder->files()
99
+					->name($this->getNamePattern($criteria, $extension))
100
+					->in($this->getPathPattern());
101
+				foreach ($finder as $file) {
102
+					/** @var SplFileInfo $file */
103
+					$uris->add($file->getPathname());
104
+				}
105
+			} catch (Exception $exception) {
106
+				// Fail silently;
107
+			}
108
+		}
109
+
110
+		return $uris;
111
+	}
112
+
113
+	/**
114
+	 * Get the name pattern to pass to the file finder.
115
+	 *
116
+	 * @since 0.1.3
117
+	 *
118
+	 * @param array  $criteria  Criteria to match.
119
+	 * @param string $extension Extension to match.
120
+	 *
121
+	 * @return string Name pattern to pass to the file finder.
122
+	 */
123
+	protected function getNamePattern(array $criteria, string $extension): string
124
+	{
125
+		$names = [];
126
+
127
+		$names[] = array_map(function ($criterion) use ($extension) {
128
+			$uriExtension = URIHelper::containsExtension($criterion);
129
+			if (! empty($extension)) {
130
+				$extension = ltrim($extension, '.');
131
+
132
+				if ($uriExtension === $extension) {
133
+					$criterion = substr($criterion,0,-strlen(".{$extension}"));
134
+				}
135
+			} else {
136
+				$extension = URIHelper::containsExtension($criterion);
137
+				if (!empty($extension)) {
138
+					$criterion = substr($criterion,0,-strlen(".{$extension}"));
139
+				}
140
+			}
141
+
142
+			$criterion = preg_quote(URIHelper::getFilename($criterion), chr(1));
143
+
144
+			return (empty($extension) || URIHelper::hasExtension($criterion, $extension))
145
+				? "{$criterion}(?:\..*?)$"
146
+				: "{$criterion}\.{$extension}$";
147
+		}, $criteria)[0];
148
+
149
+		return chr(1) . implode('|', array_unique($names)) . chr(1);
150
+	}
151
+
152
+	/**
153
+	 * Get the path pattern to pass to the file finder.
154
+	 *
155
+	 * @since 0.1.3
156
+	 *
157
+	 * @return string Path pattern to pass to the file finder.
158
+	 */
159
+	protected function getPathPattern(): string
160
+	{
161
+		return $this->path;
162
+	}
163
+
164
+	/**
165
+	 * Validate the extensions and return a collection.
166
+	 *
167
+	 * @since 0.1.1
168
+	 *
169
+	 * @param Extensions|array|string|null $extensions Extensions to validate.
170
+	 *
171
+	 * @return Extensions Validated extensions collection.
172
+	 */
173
+	protected function validateExtensions($extensions): Extensions
174
+	{
175
+		if (empty($extensions)) {
176
+			$extensions = new Extensions(['']);
177
+		}
178
+
179
+		if (! $extensions instanceof Extensions) {
180
+			$extensions = new Extensions((array)$extensions);
181
+		}
182
+
183
+		return $extensions;
184
+	}
185 185
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -124,18 +124,18 @@  discard block
 block discarded – undo
124 124
     {
125 125
         $names = [];
126 126
 
127
-        $names[] = array_map(function ($criterion) use ($extension) {
127
+        $names[] = array_map(function($criterion) use ($extension) {
128 128
             $uriExtension = URIHelper::containsExtension($criterion);
129
-            if (! empty($extension)) {
129
+            if ( ! empty($extension)) {
130 130
                 $extension = ltrim($extension, '.');
131 131
 
132 132
                 if ($uriExtension === $extension) {
133
-                    $criterion = substr($criterion,0,-strlen(".{$extension}"));
133
+                    $criterion = substr($criterion, 0, -strlen(".{$extension}"));
134 134
                 }
135 135
             } else {
136 136
                 $extension = URIHelper::containsExtension($criterion);
137
-                if (!empty($extension)) {
138
-                    $criterion = substr($criterion,0,-strlen(".{$extension}"));
137
+                if ( ! empty($extension)) {
138
+                    $criterion = substr($criterion, 0, -strlen(".{$extension}"));
139 139
                 }
140 140
             }
141 141
 
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
                 : "{$criterion}\.{$extension}$";
147 147
         }, $criteria)[0];
148 148
 
149
-        return chr(1) . implode('|', array_unique($names)) . chr(1);
149
+        return chr(1).implode('|', array_unique($names)).chr(1);
150 150
     }
151 151
 
152 152
     /**
@@ -176,8 +176,8 @@  discard block
 block discarded – undo
176 176
             $extensions = new Extensions(['']);
177 177
         }
178 178
 
179
-        if (! $extensions instanceof Extensions) {
180
-            $extensions = new Extensions((array)$extensions);
179
+        if ( ! $extensions instanceof Extensions) {
180
+            $extensions = new Extensions((array) $extensions);
181 181
         }
182 182
 
183 183
         return $extensions;
Please login to merge, or discard this patch.
src/View/Engine/EngineFinder.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -23,17 +23,17 @@
 block discarded – undo
23 23
  */
24 24
 interface EngineFinder extends Finder
25 25
 {
26
-    // Constants to be used for the Config file sections.
27
-    const CLASS_NAME_KEY = 'ClassName';
28
-    const ENGINES_KEY = 'Engines';
29
-    const NULL_OBJECT = 'NullObject';
26
+	// Constants to be used for the Config file sections.
27
+	const CLASS_NAME_KEY = 'ClassName';
28
+	const ENGINES_KEY = 'Engines';
29
+	const NULL_OBJECT = 'NullObject';
30 30
 
31
-    /**
32
-     * Get the NullObject.
33
-     *
34
-     * @since 0.1.1
35
-     *
36
-     * @return NullEngine NullObject for the current Finder.
37
-     */
38
-    public function getNullObject(): NullEngine;
31
+	/**
32
+	 * Get the NullObject.
33
+	 *
34
+	 * @since 0.1.1
35
+	 *
36
+	 * @return NullEngine NullObject for the current Finder.
37
+	 */
38
+	public function getNullObject(): NullEngine;
39 39
 }
Please login to merge, or discard this patch.