Skip to content

Commit eabe48a

Browse files
Merge pull request #18 from victorwelling/master
Changes for v2.0
2 parents 45ab73f + 04571b3 commit eabe48a

17 files changed

Lines changed: 102 additions & 77 deletions

CHANGELOG.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
# Changelog
22
All notable changes to Shoot will be documented in this file.
33

4+
## [2.0.0] - 2019-03-04
5+
### Added
6+
- Documentation on nesting presentation models and the `optional` tag.
7+
- An `Installer` class which sets up Shoot for an instance of Twig.
8+
9+
### Changed
10+
- Shoot now requires PHP 7.2.
11+
- The Twig dependency has been bumped to v2.6.
12+
- PHPUnit has been bumped to v8.0, and all tests have been updated accordingly.
13+
- The `SuppressionMiddleware` is no longer enabled by the default. You'll have to pass it to the `Pipeline` constructor
14+
along with any other middleware you use.
15+
- The `LoggingMiddleware` now also logs errors. Kind of odd it did not do that before.
16+
17+
### Fixed
18+
- The optional tag would still output any contents from before the exception was thrown. This is now fixed.
19+
- Models now work as expected when using extends, embed and blocks – removing what was previously a limitation of Shoot.
20+
21+
422
## [1.0.0] - 2018-08-27
523
### Added
624
- The `optional` tag was added. This allows runtime exceptions to be suppressed so parts which are not essential to the
@@ -14,7 +32,7 @@ page can be left out in case of failure.
1432
- The `getPresenter` method of `HasPresenterInterface` was renamed to `getPresenterName` as it more accurately describes
1533
its purpose.
1634
- `HasDataTrait` has been moved to a `Utilities` namespace.
17-
- The Twig dependency has been bumped to v2.5
35+
- The Twig dependency has been bumped to v2.5.
1836
- Lots of housekeeping in code and documentation.
1937

2038
### Deprecated

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Shoot is an extension for [Twig][link-twig], a popular template engine for PHP.
77
your templates more manageable. Think of Shoot as a DI container for template data.
88

99
## Prerequisites
10-
Shoot assumes you're using PHP 7 and Twig to render templates in a [PSR-7][link-psr7] HTTP context. It also needs a
10+
Shoot assumes you're using PHP 7.2 and Twig to render templates in a [PSR-7][link-psr7] HTTP context. It also needs a
1111
[PSR-11][link-psr11] compatible DI container.
1212

1313
Although not a requirement, a framework with support for [PSR-15][link-psr15] HTTP middleware does make your life a
@@ -39,7 +39,7 @@ rendering your templates and Shoot loads the data as needed. Enjoy this ASCII il
3939
```
4040

4141
For this to work, Shoot introduces a few concepts:
42-
* _Presentation models_ – Think of them as data contracts for your templates, ie. _Views_.
42+
* _Presentation models_ – Think of them as data contracts for your templates, i.e. _Views_.
4343
* _Presenters_ – These do the actual work. A presenter is coupled to a specific presentation model, and loads just the
4444
data it needs. These presenters are automatically invoked by Shoot as your templates are rendered.
4545
* _Middleware_ – As each template is rendered, it passes through Shoot's middleware pipeline. Invoking the presenters is

src/Extension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function __construct(Pipeline $pipeline)
4040
*
4141
* @internal
4242
*/
43-
public function process(View $view)
43+
public function process(View $view): void
4444
{
4545
$this->pipeline->process($view);
4646
}

src/Middleware/InspectorMiddleware.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function process(View $view, ServerRequestInterface $request, callable $n
4040
*
4141
* @return void
4242
*/
43-
private function value($value, string $label = '')
43+
private function value($value, string $label = ''): void
4444
{
4545
if (is_scalar($value)) {
4646
$this->scalar($value, $label);
@@ -57,7 +57,7 @@ private function value($value, string $label = '')
5757
*
5858
* @return void
5959
*/
60-
private function scalar($scalar, string $label = '')
60+
private function scalar($scalar, string $label = ''): void
6161
{
6262
if (is_bool($scalar)) {
6363
$scalar = $scalar ? 'true' : 'false';
@@ -80,7 +80,7 @@ private function scalar($scalar, string $label = '')
8080
*
8181
* @return void
8282
*/
83-
private function iterable(array $iterable, string $label = '')
83+
private function iterable(array $iterable, string $label = ''): void
8484
{
8585
if ($label === '') {
8686
$label = '...';
@@ -105,7 +105,7 @@ private function iterable(array $iterable, string $label = '')
105105
*
106106
* @return void
107107
*/
108-
private function object($object, string $label = '')
108+
private function object($object, string $label = ''): void
109109
{
110110
if ($object instanceof PresentationModel) {
111111
$this->presentationModel($object, $label);
@@ -121,7 +121,7 @@ private function object($object, string $label = '')
121121
*
122122
* @return void
123123
*/
124-
private function view(View $view)
124+
private function view(View $view): void
125125
{
126126
$this->group($view->getName(), false);
127127
$this->presentationModel($view->getPresentationModel(), 'presentationModel');
@@ -134,7 +134,7 @@ private function view(View $view)
134134
*
135135
* @return void
136136
*/
137-
private function presentationModel(PresentationModel $presentationModel, string $label = '')
137+
private function presentationModel(PresentationModel $presentationModel, string $label = ''): void
138138
{
139139
if ($label === '') {
140140
$label = $presentationModel->getName();
@@ -167,7 +167,7 @@ private function escape(string $string): string
167167
*
168168
* @return void
169169
*/
170-
private function group(string $label, bool $collapsed = true)
170+
private function group(string $label, bool $collapsed = true): void
171171
{
172172
$label = $this->escape($label);
173173

@@ -181,23 +181,23 @@ private function group(string $label, bool $collapsed = true)
181181
/**
182182
* @return void
183183
*/
184-
private function groupEnd()
184+
private function groupEnd(): void
185185
{
186186
echo 'console.groupEnd();';
187187
}
188188

189189
/**
190190
* @return void
191191
*/
192-
private function script()
192+
private function script(): void
193193
{
194194
echo '<script>';
195195
}
196196

197197
/**
198198
* @return void
199199
*/
200-
private function scriptEnd()
200+
private function scriptEnd(): void
201201
{
202202
echo '</script>';
203203
}

src/Pipeline.php

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ final class Pipeline
2626
*/
2727
public function __construct(array $middleware = [])
2828
{
29-
$middleware = $this->addSuppressionMiddleware($middleware);
30-
3129
$this->middleware = $this->chainMiddleware($middleware);
3230
}
3331

@@ -58,7 +56,7 @@ public function withRequest(ServerRequestInterface $request, callable $callback)
5856
*
5957
* @internal
6058
*/
61-
public function process(View $view)
59+
public function process(View $view): void
6260
{
6361
if ($this->request === null) {
6462
throw new MissingRequestException('Cannot process a view without a request set. This method should be called from the callback passed to Pipeline::withRequest');
@@ -67,26 +65,6 @@ public function process(View $view)
6765
call_user_func($this->middleware, $view);
6866
}
6967

70-
/**
71-
* @param MiddlewareInterface[] $middleware
72-
*
73-
* @return MiddlewareInterface[]
74-
*
75-
* @deprecated 2.0.0 Should not have been default behaviour. Will be removed as of the next major release.
76-
*/
77-
private function addSuppressionMiddleware(array $middleware): array
78-
{
79-
foreach ($middleware as $instance) {
80-
if ($instance instanceof SuppressionMiddleware) {
81-
return $middleware;
82-
}
83-
}
84-
85-
$middleware[] = new SuppressionMiddleware();
86-
87-
return $middleware;
88-
}
89-
9068
/**
9169
* @param MiddlewareInterface[] $middleware
9270
*

src/PresentationModel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ final public function withVariables(array $variables): self
7272
*
7373
* @return void
7474
*/
75-
private function setVariables(array $variables)
75+
private function setVariables(array $variables): void
7676
{
7777
foreach ($variables as $variable => $value) {
7878
if ($this->variableExists($variable)) {

src/Twig/Node/DisplayEndNode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function __construct(ModuleNode $module)
3838
*
3939
* @return void
4040
*/
41-
public function compile(Compiler $compiler)
41+
public function compile(Compiler $compiler): void
4242
{
4343
if ($this->module->hasAttribute('is_embedded')) {
4444
return;

src/Twig/Node/DisplayStartNode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function __construct(ModuleNode $module, FindPresentationModelInterface $
4141
*
4242
* @return void
4343
*/
44-
public function compile(Compiler $compiler)
44+
public function compile(Compiler $compiler): void
4545
{
4646
if ($this->module->hasAttribute('is_embedded')) {
4747
return;

src/Twig/Node/OptionalNode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function __construct(Node $body, int $lineNumber, string $tag)
3030
*
3131
* @return void
3232
*/
33-
public function compile(Compiler $compiler)
33+
public function compile(Compiler $compiler): void
3434
{
3535
$runtimeErrorClass = RuntimeError::class;
3636
$suppressedExceptionClass = SuppressedException::class;

src/Twig/NodeVisitor/ModelNodeVisitor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function getPriority(): int
9494
*
9595
* @throws LogicException
9696
*/
97-
private function assign(string $view, string $presentationModel)
97+
private function assign(string $view, string $presentationModel): void
9898
{
9999
if (isset($this->presentationModels[$view])) {
100100
throw new ModelAlreadyAssignedException("A presentation model has already been assigned to {$view}");

0 commit comments

Comments
 (0)