1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* This file is part of phpDocumentor. |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
* |
10
|
|
|
* @author Mike van Riel <[email protected]> |
11
|
|
|
* @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com) |
12
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
13
|
|
|
* @link http://phpdoc.org |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
namespace phpDocumentor\Transformer\Router; |
17
|
|
|
|
18
|
|
|
use phpDocumentor\Descriptor\ClassDescriptor; |
19
|
|
|
use phpDocumentor\Descriptor\ConstantDescriptor; |
20
|
|
|
use phpDocumentor\Descriptor\FileDescriptor; |
21
|
|
|
use phpDocumentor\Descriptor\FunctionDescriptor; |
22
|
|
|
use phpDocumentor\Descriptor\InterfaceDescriptor; |
23
|
|
|
use phpDocumentor\Descriptor\MethodDescriptor; |
24
|
|
|
use phpDocumentor\Descriptor\NamespaceDescriptor; |
25
|
|
|
use phpDocumentor\Descriptor\PackageDescriptor; |
26
|
|
|
use phpDocumentor\Descriptor\ProjectDescriptorBuilder; |
27
|
|
|
use phpDocumentor\Descriptor\PropertyDescriptor; |
28
|
|
|
use phpDocumentor\Descriptor\TraitDescriptor; |
29
|
|
|
use phpDocumentor\Reflection\DocBlock\Tags\Reference\Fqsen; |
30
|
|
|
use phpDocumentor\Reflection\DocBlock\Tags\Reference\Url; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* The default router for phpDocumentor. |
34
|
|
|
*/ |
35
|
|
|
class StandardRouter extends RouterAbstract |
36
|
|
|
{ |
37
|
|
|
/** @var ProjectDescriptorBuilder */ |
38
|
|
|
private $projectDescriptorBuilder; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Initializes this router with a list of all elements. |
42
|
|
|
*/ |
43
|
1 |
|
public function __construct(ProjectDescriptorBuilder $projectDescriptorBuilder) |
44
|
|
|
{ |
45
|
1 |
|
$this->projectDescriptorBuilder = $projectDescriptorBuilder; |
46
|
|
|
|
47
|
1 |
|
parent::__construct(); |
48
|
1 |
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Configuration function to add routing rules to a router. |
52
|
|
|
*/ |
53
|
13 |
|
public function configure() |
54
|
|
|
{ |
55
|
13 |
|
$projectDescriptorBuilder = $this->projectDescriptorBuilder; |
56
|
|
|
|
57
|
13 |
|
$fileGenerator = new UrlGenerator\Standard\FileDescriptor(); |
58
|
13 |
|
$namespaceGenerator = new UrlGenerator\Standard\NamespaceDescriptor(); |
59
|
13 |
|
$packageGenerator = new UrlGenerator\Standard\PackageDescriptor(); |
60
|
13 |
|
$classGenerator = new UrlGenerator\Standard\ClassDescriptor(); |
61
|
13 |
|
$methodGenerator = new UrlGenerator\Standard\MethodDescriptor(); |
62
|
13 |
|
$constantGenerator = new UrlGenerator\Standard\ConstantDescriptor(); |
63
|
13 |
|
$functionGenerator = new UrlGenerator\Standard\FunctionDescriptor(); |
64
|
13 |
|
$propertyGenerator = new UrlGenerator\Standard\PropertyDescriptor(); |
65
|
13 |
|
$fqsenGenerator = new UrlGenerator\Standard\FqsenDescriptor(); |
66
|
|
|
|
67
|
|
|
// Here we cheat! If a string element is passed to this rule then we try to transform it into a Descriptor |
68
|
|
|
// if the node is translated we do not let it match and instead fall through to one of the other rules. |
69
|
13 |
|
$stringRule = function (&$node) use ($projectDescriptorBuilder) { |
70
|
13 |
|
$elements = $projectDescriptorBuilder->getProjectDescriptor()->getIndexes()->get('elements'); |
71
|
13 |
|
if (is_string($node) && isset($elements[$node])) { |
72
|
1 |
|
$node = $elements[$node]; |
73
|
|
|
} |
74
|
|
|
|
75
|
13 |
|
return false; |
76
|
13 |
|
}; |
77
|
|
|
|
78
|
|
|
// @codingStandardsIgnoreStart |
79
|
13 |
|
$this[] = new Rule($stringRule, function () { |
80
|
|
|
return false; |
81
|
13 |
|
}); |
82
|
13 |
|
$this[] = new Rule(function ($node) { |
83
|
13 |
|
return $node instanceof FileDescriptor; |
84
|
13 |
|
}, $fileGenerator); |
85
|
13 |
|
$this[] = new Rule(function ($node) { |
86
|
12 |
|
return $node instanceof PackageDescriptor; |
87
|
13 |
|
}, $packageGenerator); |
88
|
13 |
|
$this[] = new Rule(function ($node) { |
89
|
11 |
|
return $node instanceof TraitDescriptor; |
90
|
13 |
|
}, $classGenerator); |
91
|
13 |
|
$this[] = new Rule(function ($node) { |
92
|
10 |
|
return $node instanceof NamespaceDescriptor; |
93
|
13 |
|
}, $namespaceGenerator); |
94
|
13 |
|
$this[] = new Rule(function ($node) { |
95
|
9 |
|
return $node instanceof InterfaceDescriptor; |
96
|
13 |
|
}, $classGenerator); |
97
|
13 |
|
$this[] = new Rule(function ($node) { |
98
|
8 |
|
return $node instanceof ClassDescriptor; |
99
|
13 |
|
}, $classGenerator); |
100
|
13 |
|
$this[] = new Rule(function ($node) { |
101
|
7 |
|
return $node instanceof ConstantDescriptor; |
102
|
13 |
|
}, $constantGenerator); |
103
|
13 |
|
$this[] = new Rule(function ($node) { |
104
|
6 |
|
return $node instanceof MethodDescriptor; |
105
|
13 |
|
}, $methodGenerator); |
106
|
13 |
|
$this[] = new Rule(function ($node) { |
107
|
4 |
|
return $node instanceof FunctionDescriptor; |
108
|
13 |
|
}, $functionGenerator); |
109
|
13 |
|
$this[] = new Rule(function ($node) { |
110
|
3 |
|
return $node instanceof PropertyDescriptor; |
111
|
13 |
|
}, $propertyGenerator); |
112
|
13 |
|
$this[] = new Rule(function ($node) { |
113
|
2 |
|
return $node instanceof Fqsen; |
114
|
13 |
|
}, $fqsenGenerator); |
115
|
|
|
|
116
|
|
|
// if this is a link to an external page; return that URL |
117
|
13 |
|
$this[] = new Rule( |
118
|
13 |
|
function ($node) { |
119
|
1 |
|
return $node instanceof Url; |
120
|
13 |
|
}, |
121
|
13 |
|
function ($node) { |
122
|
1 |
|
return (string) $node; |
123
|
13 |
|
} |
124
|
|
|
); |
125
|
|
|
|
126
|
|
|
// do not generate a file for every unknown type |
127
|
|
|
$this[] = new Rule(function () { |
128
|
|
|
return true; |
129
|
|
|
}, function () { |
130
|
|
|
return false; |
131
|
13 |
|
}); |
132
|
|
|
// @codingStandardsIgnoreEnd |
133
|
13 |
|
} |
134
|
|
|
} |
135
|
|
|
|