Skip to content

Commit d243745

Browse files
authored
Merge pull request #59 from slimphp/FixDocblocsLicenses
Fix docblocs and license information
2 parents a463332 + 6b2a1fb commit d243745

File tree

5 files changed

+64
-81
lines changed

5 files changed

+64
-81
lines changed

phpcs.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
<arg name="colors"/>
99

1010
<!-- inherit rules from: -->
11-
<rule ref="PSR12"/>
11+
<rule ref="PSR2"/>
1212
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
1313

1414
<!-- Paths to check -->
1515
<file>src</file>
1616
<file>tests</file>
17-
</ruleset>
17+
</ruleset>

src/Exception/PhpTemplateNotFoundException.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
<?php
2+
/**
3+
* Slim Framework (https://slimframework.com)
4+
*
5+
* @license https://github.com/slimphp/PHP-View/blob/3.x/LICENSE.md (MIT License)
6+
*/
27

38
declare(strict_types=1);
49

src/PhpRenderer.php

Lines changed: 42 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,38 @@
11
<?php
2-
3-
declare(strict_types=1);
4-
52
/**
6-
* Slim Framework (http://slimframework.com)
3+
* Slim Framework (https://slimframework.com)
74
*
8-
* @link https://github.com/slimphp/PHP-View
9-
* @copyright Copyright (c) 2011-2015 Josh Lockhart
10-
* @license https://github.com/slimphp/PHP-View/blob/master/LICENSE.md (MIT License)
5+
* @license https://github.com/slimphp/PHP-View/blob/3.x/LICENSE.md (MIT License)
116
*/
7+
8+
declare(strict_types=1);
9+
1210
namespace Slim\Views;
1311

1412
use InvalidArgumentException;
1513
use Psr\Http\Message\ResponseInterface;
1614
use Slim\Views\Exception\PhpTemplateNotFoundException;
1715
use Throwable;
1816

19-
/**
20-
* Class PhpRenderer
21-
* @package Slim\Views
22-
*
23-
* Render PHP view scripts into a PSR-7 Response object
24-
*/
2517
class PhpRenderer
2618
{
2719
/**
2820
* @var string
2921
*/
3022
protected $templatePath;
31-
32-
/**
23+
/**
3324
* @var array
3425
*/
3526
protected $attributes;
36-
37-
/**
27+
/**
3828
* @var string
3929
*/
4030
protected $layout;
41-
31+
/**
32+
* @param string $templatePath
33+
* @param array $attributes
34+
* @param string $layout
35+
*/
4236
public function __construct(string $templatePath = '', array $attributes = [], string $layout = '')
4337
{
4438
$this->templatePath = rtrim($templatePath, '/\\') . '/';
@@ -47,33 +41,31 @@ public function __construct(string $templatePath = '', array $attributes = [], s
4741
}
4842

4943
/**
50-
* Render a template
44+
* @param ResponseInterface $response
45+
* @param string $template
46+
* @param array $data
5147
*
52-
* @note $data cannot contain template as a key
48+
* @return ResponseInterface
5349
*
54-
* @throws InvalidArgumentException
55-
* @throws PhpTemplateNotFoundException if $templatePath . $template does not exist
5650
* @throws Throwable
5751
*/
5852
public function render(ResponseInterface $response, string $template, array $data = []): ResponseInterface
5953
{
6054
$output = $this->fetch($template, $data, true);
61-
6255
$response->getBody()->write($output);
63-
6456
return $response;
6557
}
6658

6759
/**
68-
* Get layout template
60+
* @return string
6961
*/
7062
public function getLayout(): string
7163
{
7264
return $this->layout;
7365
}
7466

7567
/**
76-
* Set layout template
68+
* @param string $layout
7769
*/
7870
public function setLayout(string $layout): void
7971
{
@@ -89,33 +81,38 @@ public function setLayout(string $layout): void
8981
}
9082

9183
/**
92-
* Get the attributes for the renderer
84+
* @return array
9385
*/
9486
public function getAttributes(): array
9587
{
9688
return $this->attributes;
9789
}
9890

9991
/**
100-
* Set the attributes for the renderer
92+
* @param array $attributes
93+
*
94+
* @return void
10195
*/
102-
public function setAttributes(array $attributes)
96+
public function setAttributes(array $attributes): void
10397
{
10498
$this->attributes = $attributes;
10599
}
106100

107101
/**
108-
* Add an attribute
102+
* @param string $key
103+
* @param $value
104+
*
105+
* @return void
109106
*/
110107
public function addAttribute(string $key, $value): void
111108
{
112109
$this->attributes[$key] = $value;
113110
}
114111

115112
/**
116-
* Retrieve an attribute
113+
* @param string $key
117114
*
118-
* @return mixed
115+
* @return bool|mixed
119116
*/
120117
public function getAttribute(string $key)
121118
{
@@ -127,34 +124,33 @@ public function getAttribute(string $key)
127124
}
128125

129126
/**
130-
* Get the template path
127+
* @return string
131128
*/
132129
public function getTemplatePath(): string
133130
{
134131
return $this->templatePath;
135132
}
136133

137134
/**
138-
* Set the template path
135+
* @param string $templatePath
139136
*/
140137
public function setTemplatePath(string $templatePath): void
141138
{
142139
$this->templatePath = rtrim($templatePath, '/\\') . '/';
143140
}
144141

145142
/**
146-
* Renders a template and returns the result as a string
143+
* @param string $template
144+
* @param array $data
145+
* @param bool $useLayout
147146
*
148-
* @note $data cannot contain template as a key
147+
* @return string
149148
*
150-
* @throws InvalidArgumentException
151-
* @throws PhpTemplateNotFoundException
152149
* @throws Throwable
153150
*/
154151
public function fetch(string $template, array $data = [], bool $useLayout = false): string
155152
{
156153
$output = $this->fetchTemplate($template, $data);
157-
158154
if ($this->layout !== null && $useLayout) {
159155
$data['content'] = $output;
160156
$output = $this->fetchTemplate($this->layout, $data);
@@ -164,12 +160,11 @@ public function fetch(string $template, array $data = [], bool $useLayout = fals
164160
}
165161

166162
/**
167-
* Renders a template and returns the result as a string
163+
* @param string $template
164+
* @param array $data
168165
*
169-
* @note $data cannot contain template as a key
166+
* @return string
170167
*
171-
* @throws InvalidArgumentException
172-
* @throws PhpTemplateNotFoundException
173168
* @throws Throwable
174169
*/
175170
public function fetchTemplate(string $template, array $data = []): string
@@ -184,7 +179,6 @@ public function fetchTemplate(string $template, array $data = []): string
184179
}
185180

186181
$data = array_merge($this->attributes, $data);
187-
188182
try {
189183
ob_start();
190184
$this->protectedIncludeScope($this->templatePath . $template, $data);
@@ -198,7 +192,10 @@ public function fetchTemplate(string $template, array $data = []): string
198192
}
199193

200194
/**
201-
* Include template within a separate scope for extracted $data
195+
* @param string $template
196+
* @param array $data
197+
*
198+
* @return void
202199
*/
203200
protected function protectedIncludeScope(string $template, array $data): void
204201
{

0 commit comments

Comments
 (0)