bytic /
view
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | declare(strict_types=1); |
||||||
| 4 | |||||||
| 5 | namespace Nip\View\Extensions; |
||||||
| 6 | |||||||
| 7 | use League\Plates\Engine; |
||||||
| 8 | use Nip\View; |
||||||
| 9 | use Nip\View\Traits\HasMethodsTrait; |
||||||
| 10 | use Nip\View\ViewInterface; |
||||||
| 11 | use function is_array; |
||||||
| 12 | |||||||
| 13 | /** |
||||||
| 14 | * Class LegacyLoadExtension. |
||||||
| 15 | */ |
||||||
| 16 | class LegacyLoadExtension extends AbstractExtension |
||||||
| 17 | { |
||||||
| 18 | /** |
||||||
| 19 | * @param ViewInterface|HasMethodsTrait|View $engine |
||||||
| 20 | * |
||||||
| 21 | * @return void |
||||||
| 22 | */ |
||||||
| 23 | public function register(Engine $engine) |
||||||
| 24 | { |
||||||
| 25 | $engine->registerFunction('load', function (...$arguments) use ($engine) { |
||||||
| 26 | $view = array_shift($arguments); |
||||||
| 27 | $variables = array_shift($arguments); |
||||||
| 28 | $return = array_shift($arguments); |
||||||
| 29 | if (is_array($view)) { |
||||||
| 30 | $view = $engine->buildPath($view); |
||||||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||||||
| 31 | } |
||||||
| 32 | $variables = is_array($variables) ? $variables : []; |
||||||
| 33 | |||||||
| 34 | $content = $engine->getContents($view, $variables); |
||||||
|
0 ignored issues
–
show
The method
getContents() does not exist on League\Plates\Engine. Are you sure you never get this type here, but always one of the subclasses?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 35 | if (true === $return) { |
||||||
| 36 | return $content; |
||||||
| 37 | } |
||||||
| 38 | echo $content; |
||||||
| 39 | }); |
||||||
| 40 | } |
||||||
| 41 | } |
||||||
| 42 |