1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* phpDocumentor |
4
|
|
|
* |
5
|
|
|
* PHP Version 5.3 |
6
|
|
|
* |
7
|
|
|
* @copyright 2010-2014 Mike van Riel / Naenius (http://www.naenius.com) |
8
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
9
|
|
|
* @link http://phpdoc.org |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace phpDocumentor\Transformer\Router; |
13
|
|
|
|
14
|
|
|
use phpDocumentor\Descriptor\ClassDescriptor; |
15
|
|
|
use phpDocumentor\Descriptor\ConstantDescriptor; |
16
|
|
|
use phpDocumentor\Descriptor\FunctionDescriptor; |
17
|
|
|
use phpDocumentor\Descriptor\InterfaceDescriptor; |
18
|
|
|
use phpDocumentor\Descriptor\MethodDescriptor; |
19
|
|
|
use phpDocumentor\Descriptor\NamespaceDescriptor; |
20
|
|
|
use phpDocumentor\Descriptor\PackageDescriptor; |
21
|
|
|
use phpDocumentor\Descriptor\ProjectDescriptorBuilder; |
22
|
|
|
use phpDocumentor\Descriptor\PropertyDescriptor; |
23
|
|
|
use phpDocumentor\Descriptor\TraitDescriptor; |
24
|
|
|
use phpDocumentor\Descriptor\FileDescriptor; |
25
|
|
|
use phpDocumentor\Reflection\DocBlock\Tags\Reference\Fqsen; |
26
|
|
|
use phpDocumentor\Reflection\DocBlock\Tags\Reference\Url; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* The default router for phpDocumentor. |
30
|
|
|
*/ |
31
|
|
|
class StandardRouter extends RouterAbstract |
|
|
|
|
32
|
|
|
{ |
33
|
|
|
/** @var ProjectDescriptorBuilder */ |
34
|
|
|
private $projectDescriptorBuilder; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Initializes this router with a list of all elements. |
38
|
|
|
* |
39
|
|
|
* @param ProjectDescriptorBuilder $projectDescriptorBuilder |
40
|
|
|
*/ |
41
|
|
|
public function __construct(ProjectDescriptorBuilder $projectDescriptorBuilder) |
|
|
|
|
42
|
|
|
{ |
43
|
|
|
$this->projectDescriptorBuilder = $projectDescriptorBuilder; |
44
|
|
|
|
45
|
|
|
parent::__construct(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Configuration function to add routing rules to a router. |
50
|
|
|
* |
51
|
|
|
* @return void |
52
|
|
|
*/ |
53
|
|
|
public function configure() |
54
|
|
|
{ |
55
|
|
|
$projectDescriptorBuilder = $this->projectDescriptorBuilder; |
|
|
|
|
56
|
|
|
|
57
|
|
|
$fileGenerator = new UrlGenerator\Standard\FileDescriptor(); |
58
|
|
|
$namespaceGenerator = new UrlGenerator\Standard\NamespaceDescriptor(); |
59
|
|
|
$packageGenerator = new UrlGenerator\Standard\PackageDescriptor(); |
60
|
|
|
$classGenerator = new UrlGenerator\Standard\ClassDescriptor(); |
61
|
|
|
$methodGenerator = new UrlGenerator\Standard\MethodDescriptor(); |
62
|
|
|
$constantGenerator = new UrlGenerator\Standard\ConstantDescriptor(); |
63
|
|
|
$functionGenerator = new UrlGenerator\Standard\FunctionDescriptor(); |
64
|
|
|
$propertyGenerator = new UrlGenerator\Standard\PropertyDescriptor(); |
65
|
|
|
$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
|
|
|
$stringRule = function (&$node) use ($projectDescriptorBuilder) { |
70
|
|
|
$elements = $projectDescriptorBuilder->getProjectDescriptor()->getIndexes()->get('elements'); |
71
|
|
|
if (is_string($node) && isset($elements[$node])) { |
72
|
|
|
$node = $elements[$node]; |
73
|
|
|
}; |
74
|
|
|
|
75
|
|
|
return false; |
76
|
|
|
}; |
77
|
|
|
|
78
|
|
|
// @codingStandardsIgnoreStart |
79
|
|
|
$this[] = new Rule($stringRule, function () { return false; }); |
80
|
|
|
$this[] = new Rule(function ($node) { return ($node instanceof FileDescriptor); }, $fileGenerator); |
81
|
|
|
$this[] = new Rule(function ($node) { return ($node instanceof PackageDescriptor); }, $packageGenerator); |
82
|
|
|
$this[] = new Rule(function ($node) { return ($node instanceof TraitDescriptor); }, $classGenerator); |
83
|
|
|
$this[] = new Rule(function ($node) { return ($node instanceof NamespaceDescriptor); }, $namespaceGenerator); |
84
|
|
|
$this[] = new Rule(function ($node) { return ($node instanceof InterfaceDescriptor); }, $classGenerator ); |
85
|
|
|
$this[] = new Rule(function ($node) { return ($node instanceof ClassDescriptor); }, $classGenerator); |
86
|
|
|
$this[] = new Rule(function ($node) { return ($node instanceof ConstantDescriptor); }, $constantGenerator); |
87
|
|
|
$this[] = new Rule(function ($node) { return ($node instanceof MethodDescriptor); }, $methodGenerator); |
88
|
|
|
$this[] = new Rule(function ($node) { return ($node instanceof FunctionDescriptor); }, $functionGenerator); |
89
|
|
|
$this[] = new Rule(function ($node) { return ($node instanceof PropertyDescriptor); }, $propertyGenerator); |
90
|
|
|
$this[] = new Rule(function ($node) { return ($node instanceof Fqsen); }, $fqsenGenerator); |
91
|
|
|
|
92
|
|
|
// if this is a link to an external page; return that URL |
93
|
|
|
$this[] = new Rule( |
94
|
|
|
function ($node) { |
95
|
|
|
return $node instanceof Url; |
96
|
|
|
}, |
97
|
|
|
function ($node) { return (string)$node; } |
98
|
|
|
); |
99
|
|
|
|
100
|
|
|
// do not generate a file for every unknown type |
101
|
|
|
$this[] = new Rule(function () { return true; }, function () { return false; }); |
102
|
|
|
// @codingStandardsIgnoreEnd |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|