Twig
extends WriterAbstract
in package
implements
Initializable, WithCustomSettings
uses
IoTrait
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 Documentation Set 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.
Tags
Table of Contents
Interfaces
- Initializable
- WithCustomSettings
- Declares that the service implementing this interface yields its own settings.
Properties
- $environment : Environment
- $environmentFactory : EnvironmentFactory
- $pathGenerator : PathGenerator
- $queryEngine : Engine
Methods
- __construct() : mixed
- __toString() : string
- checkRequirements() : void
- This method verifies whether PHP has all requirements needed to run this writer.
- getDefaultSettings() : array<string, bool|string>
- getName() : string
- Name of this writer, used to identify this writer.
- initialize() : void
- transform() : void
- This method combines the ProjectDescriptor and the given target template and creates a static html page at the artifact location.
- copy() : void
- persistTo() : void
- readSourceFile() : string
- copyDirectory() : void
- getTemplatePath() : string
- Returns the path belonging to the template.
- isGlobalTemplateReference() : bool
- normalizeDestination() : string
- normalizeSourcePath() : string
- stripFirstPartOfPath() : string
- transformNode() : void
- transformNodeCollection() : void
Properties
$environment
private
Environment
$environment
$environmentFactory read-only
private
EnvironmentFactory
$environmentFactory
$pathGenerator read-only
private
PathGenerator
$pathGenerator
$queryEngine read-only
private
Engine
$queryEngine
Methods
__construct()
public
__construct(EnvironmentFactory $environmentFactory, PathGenerator $pathGenerator, Engine $queryEngine) : mixed
Parameters
- $environmentFactory : EnvironmentFactory
- $pathGenerator : PathGenerator
- $queryEngine : Engine
__toString()
public
__toString() : string
Return values
stringcheckRequirements()
This method verifies whether PHP has all requirements needed to run this writer.
public
checkRequirements() : void
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.
Tags
getDefaultSettings()
public
getDefaultSettings() : array<string, bool|string>
Return values
array<string, bool|string>getName()
Name of this writer, used to identify this writer.
public
getName() : string
This name is also used in Collection as key and should match the name provided in the template definitions' transformations.
Return values
stringinitialize()
public
initialize(ProjectDescriptor $project, DocumentationSetDescriptor $documentationSet, Template $template) : void
Parameters
- $project : ProjectDescriptor
- $documentationSet : DocumentationSetDescriptor
- $template : Template
transform()
This method combines the ProjectDescriptor and the given target template and creates a static html page at the artifact location.
public
transform(Transformation $transformation, ProjectDescriptor $project, DocumentationSetDescriptor $documentationSet) : void
Parameters
- $transformation : Transformation
-
Transformation to execute.
- $project : ProjectDescriptor
-
Document containing the structure.
- $documentationSet : DocumentationSetDescriptor
Tags
copy()
protected
copy(Transformation $transformation, string $path, string $destination) : void
Parameters
- $transformation : Transformation
- $path : string
- $destination : string
persistTo()
protected
persistTo(Transformation $transformation, string $path, string $contents) : void
Parameters
- $transformation : Transformation
- $path : string
- $contents : string
readSourceFile()
protected
readSourceFile(Transformation $transformation, string $path) : string
Parameters
- $transformation : Transformation
- $path : string
Return values
stringcopyDirectory()
private
copyDirectory(Transformation $transformation, string $path, string $destination) : void
Parameters
- $transformation : Transformation
- $path : string
- $destination : string
getTemplatePath()
Returns the path belonging to the template.
private
getTemplatePath(Transformation $transformation) : string
Parameters
- $transformation : Transformation
Return values
stringisGlobalTemplateReference()
private
isGlobalTemplateReference(string $path) : bool
Parameters
- $path : string
Return values
boolnormalizeDestination()
private
normalizeDestination(string $destination) : string
Parameters
- $destination : string
Return values
stringnormalizeSourcePath()
private
normalizeSourcePath(string $path) : string
Parameters
- $path : string
Return values
stringstripFirstPartOfPath()
private
stripFirstPartOfPath(string $path) : string
Parameters
- $path : string
Return values
stringtransformNode()
private
transformNode(Descriptor $node, Transformation $transformation, DocumentationSetDescriptor $documentationSet, string $templatePath, array<string|int, mixed> $extraParameters) : void
Parameters
- $node : Descriptor
- $transformation : Transformation
- $documentationSet : DocumentationSetDescriptor
- $templatePath : string
- $extraParameters : array<string|int, mixed>
transformNodeCollection()
private
transformNodeCollection(Collection<string|int, Descriptor> $nodes, Transformation $transformation, DocumentationSetDescriptor $documentationSet, string $templatePath, array<string|int, mixed> $extraParameters) : void
Parameters
- $nodes : Collection<string|int, Descriptor>
- $transformation : Transformation
- $documentationSet : DocumentationSetDescriptor
- $templatePath : string
- $extraParameters : array<string|int, mixed>