Added RenderInterface

This commit is contained in:
Matias Griese
2019-03-28 12:52:34 +02:00
parent bb719c5d53
commit d5e9cc4bfe
5 changed files with 43 additions and 26 deletions

View File

@@ -245,7 +245,7 @@ class FlexCollection extends ObjectCollection implements FlexCollectionInterface
* {@inheritdoc}
* @see FlexCollectionInterface::render()
*/
public function render($layout = null, array $context = [])
public function render(string $layout = null, array $context = [])
{
if (null === $layout) {
$layout = 'default';

View File

@@ -221,7 +221,7 @@ class FlexIndex extends ObjectIndex implements FlexCollectionInterface, FlexInde
* {@inheritdoc}
* @see FlexCollectionInterface::render()
*/
public function render($layout = null, array $context = [])
public function render(string $layout = null, array $context = [])
{
return $this->__call('render', [$layout, $context]);
}

View File

@@ -357,7 +357,7 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface
* {@inheritdoc}
* @see FlexObjectInterface::render()
*/
public function render($layout = null, array $context = [])
public function render(string $layout = null, array $context = [])
{
if (null === $layout) {
$layout = 'default';

View File

@@ -11,11 +11,8 @@ declare(strict_types=1);
namespace Grav\Framework\Flex\Interfaces;
use Grav\Framework\ContentBlock\ContentBlockInterface;
use Grav\Framework\ContentBlock\HtmlBlock;
use Grav\Framework\Flex\FlexDirectory;
use Twig\Error\LoaderError;
use Twig\Error\SyntaxError;
use Grav\Framework\Interfaces\RenderInterface;
/**
* Defines common interface shared with both Flex Objects and Collections.
@@ -23,7 +20,7 @@ use Twig\Error\SyntaxError;
* @used-by \Grav\Framework\Flex\FlexObject
* @since 1.6
*/
interface FlexCommonInterface
interface FlexCommonInterface extends RenderInterface
{
/**
* Get Flex Type of the object / collection.
@@ -64,22 +61,4 @@ interface FlexCommonInterface
* @return string Returns cache checksum.
*/
public function getCacheChecksum(): string;
/**
* Renders the object / collection.
*
* @example {% render object layout 'edit' with { limited: true } %}
* @example {% render collection layout 'list' %}
*
* @param string $layout Layout name.
* @param array $context Context given to the renderer.
*
* @return ContentBlockInterface|HtmlBlock Returns `HtmlBlock` containing the rendered output.
* @throws \Exception
* @throws \Throwable
* @throws LoaderError
* @throws SyntaxError
* @api
*/
public function render($layout = null, array $context = []);
}

View File

@@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
/**
* @package Grav\Framework\Interfaces
*
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
namespace Grav\Framework\Interfaces;
use Grav\Framework\ContentBlock\ContentBlockInterface;
use Grav\Framework\ContentBlock\HtmlBlock;
/**
* Defines common interface to render any object.
*
* @used-by \Grav\Framework\Flex\FlexObject
* @since 1.6
*/
interface RenderInterface
{
/**
* Renders the object.
*
* @example $block = $object->render('custom', ['variable' => 'value']);
* @example {% render object layout 'custom' with { variable: 'value' } %}
*
* @param string|null $layout Layout to be used.
* @param array|null $context Extra context given to the renderer.
*
* @return ContentBlockInterface|HtmlBlock Returns `HtmlBlock` containing the rendered output.
* @api
*/
public function render(string $layout = null, array $context = []);
}