\Tale\Jade\Renderer\AdapterStream

Handles rendering via Data-URIs and a PHP Stream Wrapper.

Notice that this only works, if the php.ini setting 'allow_url_fopen' is ON This works through including the PHTML file as an URI

It's safe to use! Everything happens locally.

The following happens:

  1. The jade gets rendered to markup
  2. The markup-string is base64_encode'd
  3. A data URI is put together that looks like this: 'jade-phtml://data;
  4. The data URI is include'd

We register a PHP Stream Wrapper for the 'jade-phtml'-scheme that does the following:

  1. Strip everything until after the ';' in the URL
  2. base64_decode that shit
  3. Return the PHTML

This way, the PHTML acts like a normal PHP file

Advantages:

  • Quick to set up
  • Easy to use
  • No configuration needed
  • May or may not be easier to cache (depending on the cache system)

Disadvantages:

  • No debugging the PHTML at all. It's a base64-encoded string.
  • It may be slower than a usual file-adapter through the encoding
  • May or may not be easier to cache (depending on the cache system)

Summary

Methods
Properties
Constants
__construct()
getRenderer()
render()
No public properties found
No constants found
getOption()
No protected properties found
N/A
No private methods found
$_renderer
$_options
N/A

Properties

$_renderer

$_renderer : \Tale\Jade\Renderer

The renderer this adapter got created in.

Type

\Tale\Jade\Renderer

$_options

$_options : array

The options array for this adapter.

Type

array

Methods

__construct()

__construct(\Tale\Jade\Renderer  $renderer, array|null  $options = null) 

Creates a new stream adapter.

Possible options are: scheme: The scheme to register the wrapper as (default: 'jade-phtml')

If the stream wrapper with the given name is not registered yet, it is registered The stream wrapper used is \Tale\Jade\Renderer\Adapter\Stream\Wrapper

Parameters

\Tale\Jade\Renderer $renderer

the renderer instance this adapter was created in

array|null $options

an array of options for the adapter

getRenderer()

getRenderer() : \Tale\Jade\Renderer

Returns the attached renderer this adapter was created in.

Returns

\Tale\Jade\Renderer

render()

render(string  $path, array|null  $args = null) : string

Renders a jade file by a given path.

The extension can be omitted if it's the extension set in the Compiler-options ('.jade' by default)

The given $args-argument should be an associative array and will be passed as variables that you can use inside the rendered template file

Notice that the path is relative to the Compiler-option 'paths' or, if no paths passed, the paths in get_include_path()

You might just echo the result, cache it or do anything else with it

Parameters

string $path

the relative path to be rendered

array|null $args

the variables for the template

Returns

string —

the rendered markup

getOption()

getOption(string  $name) : mixed

Returns an option by a given name.

The existence of the option is not checked

Parameters

string $name

the name of the option

Returns

mixed —

the value of the option