\phpDocumentor\Transformer\WriterTwig

A specialized writer which uses the Twig templating engine to convert templates to HTML output.

This writer support the Query attribute of a Transformation to generate multiple templates in one transformation.

The Query attribute supports a simplified version of Twig queries and will use each individual result as the 'node' global variable in the Twig template.

Example:

Suppose a Query indexes.classes is given then this writer will be invoked as many times as there are classes in the project and the 'node' global variable in twig will be filled with each individual

When using the Query attribute in the transformation it is important to use a variable in the Artifact attribute as well (otherwise the same file would be overwritten several times).

A simple example transformation line could be:

<transformation
    writer="twig"
    source="templates/twig/index.twig"
    artifact="index.html"
/>

This example transformation would use this writer to transform the index.twig template file in the twig template folder into index.html at the destination location. Since no Query is provided the 'node' global variable will contain the Project Descriptor of the Object Graph.

A complex example transformation line could be:

<transformation
    query="indexes.classes"
    writer="twig"
    source="templates/twig/class.twig"
    artifact="{{name}}.html"/>

This example transformation would use this writer to transform the class.twig template file in the twig template folder into a file with the 'name' property for an individual class inside the Object Graph. Since a Query is provided will the 'node' global variable contain a specific instance of a class applicable to the current iteration.

Summary

Methods
Properties
Constants
checkRequirements()
transform()
__toString()
__construct()
initialize()
No public properties found
No constants found
copy()
readSourceFile()
persistTo()
No protected properties found
N/A
copyDirectory()
stripFirstPartOfPath()
isGlobalTemplateReference()
normalizeSourcePath()
normalizeDestination()
getTemplatePath()
$environmentFactory
$pathGenerator
$environment
N/A

Properties

$environmentFactory

$environmentFactory : \phpDocumentor\Transformer\Writer\Twig\EnvironmentFactory

Type

EnvironmentFactory

$pathGenerator

$pathGenerator : \phpDocumentor\Transformer\Writer\PathGenerator

Type

PathGenerator

$environment

$environment : \Twig\Environment

Type

\Twig\Environment —

Methods

checkRequirements()

checkRequirements() : void

This method verifies whether PHP has all requirements needed to run this writer.

If one of the requirements is missing for this Writer then an exception of type RequirementMissing should be thrown; this indicates to the calling process that this writer will not function.

Throws

\phpDocumentor\Transformer\Writer\Exception\RequirementMissing

When a requirements is missing stating which one.

transform()

transform(\phpDocumentor\Descriptor\ProjectDescriptor  $project, \phpDocumentor\Transformer\Transformation  $transformation) : void

This method combines the ProjectDescriptor and the given target template and creates a static html page at the artifact location.

Parameters

\phpDocumentor\Descriptor\ProjectDescriptor $project

Document containing the structure.

\phpDocumentor\Transformer\Transformation $transformation

Transformation to execute.

Throws

\Twig\Error\LoaderError
\Twig\Error\RuntimeError
\Twig\Error\SyntaxError

__toString()

__toString() : string

Returns

string —

__construct()

__construct(\phpDocumentor\Transformer\Writer\Twig\EnvironmentFactory  $environmentFactory, \phpDocumentor\Transformer\Writer\PathGenerator  $pathGenerator) : mixed

Parameters

\phpDocumentor\Transformer\Writer\Twig\EnvironmentFactory $environmentFactory
\phpDocumentor\Transformer\Writer\PathGenerator $pathGenerator

Returns

mixed —

initialize()

initialize(\phpDocumentor\Descriptor\ProjectDescriptor  $project, \phpDocumentor\Transformer\Template  $template) : void

Parameters

\phpDocumentor\Descriptor\ProjectDescriptor $project
\phpDocumentor\Transformer\Template $template

copy()

copy(\phpDocumentor\Transformer\Transformation  $transformation, string  $path, string  $destination) : void

Parameters

\phpDocumentor\Transformer\Transformation $transformation
string $path
string $destination

readSourceFile()

readSourceFile(\phpDocumentor\Transformer\Transformation  $transformation, string  $path) : string

Parameters

\phpDocumentor\Transformer\Transformation $transformation
string $path

Returns

string —

persistTo()

persistTo(\phpDocumentor\Transformer\Transformation  $transformation, string  $path, string  $contents) : void

Parameters

\phpDocumentor\Transformer\Transformation $transformation
string $path
string $contents

copyDirectory()

copyDirectory(\phpDocumentor\Transformer\Transformation  $transformation, string  $path, string  $destination) : void

Parameters

\phpDocumentor\Transformer\Transformation $transformation
string $path
string $destination

stripFirstPartOfPath()

stripFirstPartOfPath(string  $path) : string

Parameters

string $path

Returns

string —

isGlobalTemplateReference()

isGlobalTemplateReference(string  $path) : bool

Parameters

string $path

Returns

bool —

normalizeSourcePath()

normalizeSourcePath(string  $path) : string

Parameters

string $path

Returns

string —

normalizeDestination()

normalizeDestination(string  $destination) : string

Parameters

string $destination

Returns

string —

getTemplatePath()

getTemplatePath(\phpDocumentor\Transformer\Transformation  $transformation) : string

Returns the path belonging to the template.

Parameters

\phpDocumentor\Transformer\Transformation $transformation

Returns

string —