forked from TYPO3-Documentation/render-guides
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAttachFileObjectsToFileTextRoleTransformer.php
More file actions
82 lines (72 loc) · 2.46 KB
/
AttachFileObjectsToFileTextRoleTransformer.php
File metadata and controls
82 lines (72 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @link https://phpdoc.org
*/
namespace T3Docs\Typo3DocsTheme\Compiler\NodeTransformers;
use phpDocumentor\Guides\Compiler\CompilerContextInterface;
use phpDocumentor\Guides\Compiler\NodeTransformer;
use phpDocumentor\Guides\Nodes\Node;
use T3Docs\Typo3DocsTheme\Nodes\Inline\FileInlineNode;
use T3Docs\Typo3DocsTheme\ReferenceResolvers\ObjectsInventory\DataObject;
use T3Docs\Typo3DocsTheme\ReferenceResolvers\ObjectsInventory\FileObject;
use T3Docs\Typo3DocsTheme\ReferenceResolvers\ObjectsInventory\ObjectInventory;
/** @implements NodeTransformer<FileInlineNode> */
final class AttachFileObjectsToFileTextRoleTransformer implements NodeTransformer
{
public function __construct(
private readonly ObjectInventory $objectInventory,
) {}
public function enterNode(Node $node, CompilerContextInterface $compilerContext): Node
{
if (!$node instanceof FileInlineNode) {
return $node;
}
/** @var DataObject[] $fileObjects */
$fileObjects = $this->objectInventory->getGroup(FileObject::KEY);
foreach ($fileObjects as $fileObject) {
if (!$fileObject instanceof FileObject) {
continue;
}
if ($fileObject->id === $node->getFileLink()) {
$node->setFileObject($fileObject);
return $node;
}
if (preg_match($fileObject->regex, $node->getFileLink())) {
$node->setFileObject($fileObject);
break;
}
}
foreach ($fileObjects as $fileObject) {
if (!$fileObject instanceof FileObject) {
continue;
}
if ($fileObject->regex === '') {
continue;
}
if (preg_match($fileObject->regex, $node->getFileLink())) {
$node->setFileObject($fileObject);
break;
}
}
return $node;
}
public function leaveNode(Node $node, CompilerContextInterface $compilerContext): Node
{
return $node;
}
public function supports(Node $node): bool
{
return $node instanceof FileInlineNode;
}
public function getPriority(): int
{
// After CollectFileObjectsTransformer
return 2000;
}
}