1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* This file is part of phpDocumentor. |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
* |
11
|
|
|
* @link http://phpdoc.org |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace phpDocumentor\Reflection\DocBlock\Tags; |
15
|
|
|
|
16
|
|
|
use phpDocumentor\Reflection\DocBlock\Description; |
17
|
|
|
use phpDocumentor\Reflection\DocBlock\DescriptionFactory; |
18
|
|
|
use phpDocumentor\Reflection\Fqsen; |
19
|
|
|
use phpDocumentor\Reflection\FqsenResolver; |
20
|
|
|
use phpDocumentor\Reflection\Types\Context as TypeContext; |
21
|
|
|
use phpDocumentor\Reflection\Utils; |
22
|
|
|
use Webmozart\Assert\Assert; |
23
|
|
|
use function array_key_exists; |
24
|
|
|
use function explode; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Reflection class for a {@}uses tag in a Docblock. |
28
|
|
|
*/ |
29
|
|
|
final class Uses extends BaseTag implements Factory\StaticMethod |
|
|
|
|
30
|
|
|
{ |
31
|
|
|
/** @var string */ |
32
|
|
|
protected $name = 'uses'; |
33
|
|
|
|
34
|
|
|
/** @var Fqsen */ |
35
|
|
|
protected $refers; |
36
|
|
|
|
37
|
|
|
/** |
38
|
3 |
|
* Initializes this tag. |
39
|
|
|
*/ |
40
|
3 |
|
public function __construct(Fqsen $refers, ?Description $description = null) |
41
|
3 |
|
{ |
42
|
3 |
|
$this->refers = $refers; |
43
|
|
|
$this->description = $description; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public static function create( |
47
|
5 |
|
string $body, |
48
|
|
|
?FqsenResolver $resolver = null, |
49
|
|
|
?DescriptionFactory $descriptionFactory = null, |
50
|
|
|
?TypeContext $context = null |
51
|
|
|
) : self { |
52
|
|
|
Assert::notNull($resolver); |
53
|
5 |
|
Assert::notNull($descriptionFactory); |
54
|
4 |
|
|
55
|
|
|
$parts = Utils::pregSplit('/\s+/Su', $body, 2); |
56
|
1 |
|
|
57
|
|
|
return new static( |
58
|
1 |
|
self::resolveFqsen($parts[0], $resolver, $context), |
59
|
1 |
|
$descriptionFactory->create($parts[1] ?? '', $context) |
60
|
1 |
|
); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
private static function resolveFqsen(string $parts, ?FqsenResolver $fqsenResolver, ?TypeContext $context) : Fqsen |
64
|
|
|
{ |
65
|
|
|
Assert::notNull($fqsenResolver); |
66
|
|
|
$fqsenParts = explode('::', $parts); |
67
|
|
|
$resolved = $fqsenResolver->resolve($fqsenParts[0], $context); |
68
|
|
|
|
69
|
1 |
|
if (!array_key_exists(1, $fqsenParts)) { |
70
|
|
|
return $resolved; |
71
|
1 |
|
} |
72
|
|
|
|
73
|
|
|
return new Fqsen($resolved . '::' . $fqsenParts[1]); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Returns the structural element this tag refers to. |
78
|
|
|
*/ |
79
|
1 |
|
public function getReference() : Fqsen |
80
|
|
|
{ |
81
|
1 |
|
return $this->refers; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Returns a string representation of this tag. |
86
|
|
|
*/ |
87
|
|
|
public function __toString() : string |
88
|
|
|
{ |
89
|
|
|
return $this->refers . ' ' . (string) $this->description; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.