FragmentHandler

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.

This listener works in 2 modes:

  • 2.3 compatibility mode where you must call setRequest whenever the Request changes.
  • 2.4+ mode where you must pass a RequestStack instance in the constructor.

Methods

__construct(RequestStack $requestStack = null, FragmentRendererInterface[] $renderers = array(), bool $debug = false)

RequestStack will become required in 3.0.

addRenderer(FragmentRendererInterface $renderer)

Adds a renderer.

setRequest(Request $request = null) deprecated

Sets the current Request.

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

Renders a URI and returns the Response content.

Details

__construct(RequestStack $requestStack = null, FragmentRendererInterface[] $renderers = array(), bool $debug = false)

RequestStack will become required in 3.0.

Parameters

RequestStack $requestStack The Request stack that controls the lifecycle of requests
FragmentRendererInterface[] $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

setRequest(Request $request = null) deprecated

deprecated

since version 2.4, to be removed in 3.0.

Sets the current Request.

This method was used to synchronize the Request, but as the HttpKernel is doing that automatically now, you should never call it directly. It is kept public for BC with the 2.3 version.

Parameters

Request $request A Request instance

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

© 2004–2017 Fabien Potencier
Licensed under the MIT License.
http://api.symfony.com/2.8/Symfony/Component/HttpKernel/Fragment/FragmentHandler.html