class FragmentHandler

Renders a URI that represents a resource fragment.

This class handles the rendering of resource fragments that are included into a main resource. The handling of the rendering is managed by specialized renderers.

Methods

__construct(RequestStack $requestStack, array $renderers = array(), bool $debug = false)

No description

addRenderer(FragmentRendererInterface $renderer)

Adds a renderer.

string|null
render(string|ControllerReference $uri, string $renderer = 'inline', array $options = array())

Renders a URI and returns the Response content.

string|null
deliver(Response $response)

Delivers the Response as a string.

Details

__construct(RequestStack $requestStack, array $renderers = array(), bool $debug = false)

Parameters

RequestStack $requestStack The Request stack that controls the lifecycle of requests
array $renderers An array of FragmentRendererInterface instances
bool $debug Whether the debug mode is enabled or not

addRenderer(FragmentRendererInterface $renderer)

Adds a renderer.

Parameters

FragmentRendererInterface $renderer

string|null render(string|ControllerReference $uri, string $renderer = 'inline', array $options = array())

Renders a URI and returns the Response content.

Available options:

  • ignore_errors: true to return an empty string in case of an error

Parameters

string|ControllerReference $uri A URI as a string or a ControllerReference instance
string $renderer The renderer name
array $options An array of options

Return Value

string|null The Response content or null when the Response is streamed

Exceptions

InvalidArgumentException when the renderer does not exist
LogicException when no master request is being handled

protected string|null deliver(Response $response)

Delivers the Response as a string.

When the Response is a StreamedResponse, the content is streamed immediately instead of being returned.

Parameters

Response $response

Return Value

string|null The Response content or null when the Response is streamed

Exceptions

RuntimeException when the Response is not successful