LinkRenderer
in package
Renders an HTML anchor pointing to the location of the provided element.
Table of Contents
- PRESENTATION_CLASS_SHORT = 'class:short'
- PRESENTATION_FILE_SHORT = 'file:short'
- PRESENTATION_NORMAL = 'normal'
- PRESENTATION_URL = 'url'
- $convertToRootPath : bool
- $destination : string
- $project : ProjectDescriptor|null
- $router : Router
- __construct() : mixed
- convertToRootPath() : string|null
- Converts the given path to be relative to the root of the documentation target directory.
- doNotConvertUrlsToRootPath() : self
- getDestination() : string
- Returns the target directory relative to the Project's Root.
- link() : string
- render() : array<string|int, string>|string
- setDestination() : void
- withDestination() : self
- Sets the destination directory relative to the Project's Root.
- withProject() : self
- createFqsenFromReference() : Fqsen
- getPathPrefixBasedOnDepth() : string
- Calculates how deep the given destination is and returns a prefix.
- isReferenceToFqsen() : bool
- renderAbstractListLinks() : string
- renderASeriesOfLinks() : array<int, string>
- Returns a series of anchors and strings for the given collection of routable items.
- renderLink() : string
- renderType() : array<int, string>
- withoutLeadingSlash() : string
Constants
PRESENTATION_CLASS_SHORT
public
mixed
PRESENTATION_CLASS_SHORT
= 'class:short'
PRESENTATION_FILE_SHORT
public
mixed
PRESENTATION_FILE_SHORT
= 'file:short'
PRESENTATION_NORMAL
public
mixed
PRESENTATION_NORMAL
= 'normal'
PRESENTATION_URL
public
mixed
PRESENTATION_URL
= 'url'
Properties
$convertToRootPath
private
bool
$convertToRootPath
= true
$destination
private
string
$destination
= ''
$project
private
ProjectDescriptor|null
$project
$router
private
Router
$router
Methods
__construct()
public
__construct(Router $router) : mixed
Parameters
- $router : Router
Return values
mixed —convertToRootPath()
Converts the given path to be relative to the root of the documentation target directory.
public
convertToRootPath(string $pathOrReference[, bool $force = false ]) : string|null
It is not possible to use absolute paths in documentation templates since they may be used locally, or in a subfolder. As such we need to calculate the number of levels to go up from the current document's directory and then append the given path.
For example:
Suppose you are in <root>/classes/my/class.html and you want open
<root>/my/index.html then you provide 'my/index.html' to this method
and it will convert it into ../../my/index.html (<root>/classes/my is
two nesting levels until the root).
This method does not try to normalize or optimize the paths in order to save on development time and performance, and because it adds no real value.
In addition, when a path starts with an @-sign, it is interpreted as a reference to a structural element and we use the router to try and find a path to which this refers.
Parameters
- $pathOrReference : string
- $force : bool = false
Tags
Return values
string|null —doNotConvertUrlsToRootPath()
public
doNotConvertUrlsToRootPath() : self
Return values
self —getDestination()
Returns the target directory relative to the Project's Root.
public
getDestination() : string
Return values
string —link()
public
link(Descriptor|Fqsen|Uri $value) : string
Parameters
- $value : Descriptor|Fqsen|Uri
Return values
string —render()
public
render(array<string|int, Type>|Type|DescriptorAbstract|Fqsen|Reference|Path|string|iteratable<string|int, mixed> $value, string $presentation) : array<string|int, string>|string
Parameters
- $value : array<string|int, Type>|Type|DescriptorAbstract|Fqsen|Reference|Path|string|iteratable<string|int, mixed>
- $presentation : string
Return values
array<string|int, string>|string —setDestination()
public
setDestination(string $destination) : void
Parameters
- $destination : string
Tags
Return values
void —withDestination()
Sets the destination directory relative to the Project's Root.
public
withDestination(string $destination) : self
The destination is the target directory containing the resulting file. This destination is relative to the Project's root and can be used for the calculation of nesting depths, etc.
For this specific extension the destination is provided in the Twig writer itself.
Parameters
- $destination : string
Return values
self —withProject()
public
withProject(ProjectDescriptor $projectDescriptor) : self
Parameters
- $projectDescriptor : ProjectDescriptor
Return values
self —createFqsenFromReference()
private
createFqsenFromReference(string $path) : Fqsen
Parameters
- $path : string
Return values
Fqsen —getPathPrefixBasedOnDepth()
Calculates how deep the given destination is and returns a prefix.
private
getPathPrefixBasedOnDepth() : string
The calculated prefix is used to get back to the root (i.e. three levels deep means ../../..
) or an empty
string is returned when you are already at the same level as the root.
This prefix will include a trailing forward slash (/) when it actually needs to direct the caller to go elsewhere.
Return values
string —isReferenceToFqsen()
private
isReferenceToFqsen(string $path) : bool
Parameters
- $path : string
Return values
bool —renderAbstractListLinks()
private
renderAbstractListLinks(AbstractList $node, string $presentation) : string
Parameters
- $node : AbstractList
- $presentation : string
Return values
string —renderASeriesOfLinks()
Returns a series of anchors and strings for the given collection of routable items.
private
renderASeriesOfLinks(iteratable<string|int, mixed> $value, string $presentation) : array<int, string>
Parameters
- $value : iteratable<string|int, mixed>
- $presentation : string
Return values
array<int, string> —renderLink()
private
renderLink(string|Path|Type|DescriptorAbstract|Fqsen|Fqsen $node, string $presentation) : string
Parameters
- $node : string|Path|Type|DescriptorAbstract|Fqsen|Fqsen
- $presentation : string
Return values
string —renderType()
private
renderType(iteratable<string|int, Type> $value) : array<int, string>
Parameters
- $value : iteratable<string|int, Type>
Return values
array<int, string> —withoutLeadingSlash()
private
withoutLeadingSlash(string $path) : string
Parameters
- $path : string