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\UrlGenerator\Standard; |
17
|
|
|
|
18
|
|
|
use phpDocumentor\Reflection\DocBlock\Tags\Reference\Fqsen; |
19
|
|
|
use phpDocumentor\Transformer\Router\UrlGenerator\UrlGeneratorInterface as UrlGenerator; |
20
|
|
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Generates a relative URL with properties for use in the generated HTML documentation. |
24
|
|
|
*/ |
25
|
|
|
class FqsenDescriptor implements UrlGenerator |
26
|
|
|
{ |
27
|
|
|
private $urlGenerator; |
28
|
|
|
private $converter; |
29
|
|
|
|
30
|
|
|
public function __construct(UrlGeneratorInterface $urlGenerator, QualifiedNameToUrlConverter $converter) |
31
|
|
|
{ |
32
|
|
|
$this->urlGenerator = $urlGenerator; |
33
|
|
|
$this->converter = $converter; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Generates a URL from the given node or returns false if unable. |
38
|
|
|
* |
39
|
|
|
* @param string|Fqsen $node |
40
|
|
|
* |
41
|
|
|
* @return string|false |
42
|
|
|
*/ |
43
|
4 |
|
public function __invoke($node) |
44
|
|
|
{ |
45
|
|
|
assert($node instanceof Fqsen); |
46
|
4 |
|
$fqsenParts = explode('::', (string) $node); |
47
|
4 |
|
$className = $this->converter->fromClass($fqsenParts[0]); |
48
|
|
|
|
49
|
4 |
|
if (count($fqsenParts) === 1) { |
50
|
1 |
|
return $this->urlGenerator->generate( |
51
|
1 |
|
'class', |
52
|
|
|
[ |
53
|
1 |
|
'className' => $className, |
54
|
|
|
] |
55
|
|
|
); |
56
|
|
|
} |
57
|
|
|
|
58
|
3 |
|
if (strpos($fqsenParts[1], '$') !== false) { |
59
|
1 |
|
$propertyName = explode('$', $fqsenParts[1]); |
60
|
1 |
|
return $this->urlGenerator->generate( |
61
|
1 |
|
'property', |
62
|
|
|
[ |
63
|
1 |
|
'className' => $className, |
64
|
1 |
|
'propertyName' => $propertyName[1] |
65
|
|
|
] |
66
|
|
|
); |
67
|
|
|
} |
68
|
|
|
|
69
|
2 |
|
if (strpos($fqsenParts[1], '()') !== false) { |
70
|
1 |
|
$methodName = explode('()', $fqsenParts[1]); |
71
|
1 |
|
return $this->urlGenerator->generate( |
72
|
1 |
|
'method', |
73
|
|
|
[ |
74
|
1 |
|
'className' => $className, |
75
|
1 |
|
'methodName' => $methodName[0] |
76
|
|
|
] |
77
|
|
|
); |
78
|
|
|
} |
79
|
|
|
|
80
|
1 |
|
return $this->urlGenerator->generate( |
81
|
1 |
|
'class_constant', |
82
|
|
|
[ |
83
|
1 |
|
'className' => $className, |
84
|
1 |
|
'constantName' => $fqsenParts[1] |
85
|
|
|
] |
86
|
|
|
); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|