1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* 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
|
|
|
* @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com) |
11
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
12
|
|
|
* @link http://phpdoc.org |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace phpDocumentor\Reflection; |
16
|
|
|
|
17
|
|
|
use InvalidArgumentException; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Value Object for Fqsen. |
21
|
|
|
* |
22
|
|
|
* @link https://github.com/phpDocumentor/fig-standards/blob/master/proposed/phpdoc-meta.md |
23
|
|
|
*/ |
24
|
|
|
final class Fqsen |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var string full quallified class name |
28
|
|
|
*/ |
29
|
|
|
private $fqsen; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var string name of the element without path. |
33
|
|
|
*/ |
34
|
|
|
private $name; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Initializes the object. |
38
|
|
|
* |
39
|
|
|
* @throws InvalidArgumentException when $fqsen is not matching the format. |
40
|
|
|
*/ |
41
|
17 |
|
public function __construct(string $fqsen) |
42
|
|
|
{ |
43
|
17 |
|
$matches = []; |
44
|
17 |
|
$result = preg_match( |
45
|
17 |
|
'/^\\\\([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff\\\\]*)?(?:[:]{2}\\$?([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*))?(?:\\(\\))?$/', |
46
|
17 |
|
$fqsen, |
47
|
17 |
|
$matches |
48
|
|
|
); |
49
|
|
|
|
50
|
17 |
|
if ($result === 0) { |
51
|
4 |
|
if(strpos($fqsen, "\\class@anonymous") === 0) { |
52
|
|
|
$matches=[null,null,$fqsen]; |
53
|
|
|
} else { |
54
|
4 |
|
throw new InvalidArgumentException( |
55
|
4 |
|
sprintf('"%s" is not a valid Fqsen.', $fqsen) |
56
|
|
|
); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
60
|
13 |
|
$this->fqsen = $fqsen; |
61
|
|
|
|
62
|
13 |
|
if (isset($matches[2])) { |
63
|
3 |
|
$this->name = $matches[2]; |
64
|
|
|
} else { |
65
|
10 |
|
$matches = explode('\\', $fqsen); |
66
|
10 |
|
$this->name = trim(end($matches), '()'); |
67
|
|
|
} |
68
|
13 |
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* converts this class to string. |
72
|
|
|
*/ |
73
|
1 |
|
public function __toString(): string |
74
|
|
|
{ |
75
|
1 |
|
return $this->fqsen; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Returns the name of the element without path. |
80
|
|
|
*/ |
81
|
|
|
public function getName(): string |
82
|
|
|
{ |
83
|
|
|
return $this->name; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|