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\Types; |
15
|
|
|
|
16
|
|
|
use phpDocumentor\Reflection\Fqsen; |
17
|
|
|
use phpDocumentor\Reflection\Type; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Represents a collection type as described in the PSR-5, the PHPDoc Standard. |
21
|
|
|
* |
22
|
|
|
* A collection can be represented in two forms: |
23
|
|
|
* |
24
|
|
|
* 1. `ACollectionObject<aValueType>` |
25
|
|
|
* 2. `ACollectionObject<aValueType,aKeyType>` |
26
|
|
|
* |
27
|
|
|
* - ACollectionObject can be 'array' or an object that can act as an array |
28
|
|
|
* - aValueType and aKeyType can be any type expression |
29
|
|
|
*/ |
30
|
|
|
final class Collection extends AbstractList |
31
|
|
|
{ |
32
|
|
|
/** @var Fqsen|null */ |
33
|
|
|
private $fqsen; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Initializes this representation of an array with the given Type or Fqsen. |
37
|
|
|
*/ |
38
|
|
|
public function __construct(?Fqsen $fqsen, Type $valueType, ?Type $keyType = null) |
39
|
|
|
{ |
40
|
|
|
parent::__construct($valueType, $keyType); |
41
|
|
|
|
42
|
|
|
$this->fqsen = $fqsen; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Returns the FQSEN associated with this object. |
47
|
|
|
*/ |
48
|
|
|
public function getFqsen() : ?Fqsen |
49
|
|
|
{ |
50
|
|
|
return $this->fqsen; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Returns a rendered output of the Type as it would be used in a DocBlock. |
55
|
|
|
*/ |
56
|
4 |
|
public function __toString() : string |
57
|
|
|
{ |
58
|
4 |
|
$objectType = (string) ($this->fqsen ?? 'object'); |
59
|
|
|
|
60
|
4 |
|
if ($this->keyType === null) { |
61
|
2 |
|
return $objectType . '<' . $this->valueType . '>'; |
62
|
|
|
} |
63
|
|
|
|
64
|
2 |
|
return $objectType . '<' . $this->keyType . ',' . $this->valueType . '>'; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|