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
|
|
|
* @copyright 2010-2018 Mike van Riel<[email protected]> |
11
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
12
|
|
|
* @link http://phpdoc.org |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace phpDocumentor\Reflection\Php; |
16
|
|
|
|
17
|
|
|
use InvalidArgumentException; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Value object for visibility values of classes, properties, ect. |
21
|
|
|
*/ |
22
|
|
|
final class Visibility |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* constant for protected visibility |
26
|
|
|
*/ |
27
|
|
|
const PUBLIC_ = 'public'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* constant for protected visibility |
31
|
|
|
*/ |
32
|
|
|
const PROTECTED_ = 'protected'; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* constant for private visibility |
36
|
|
|
*/ |
37
|
|
|
const PRIVATE_ = 'private'; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var string value can be public, protected or private |
41
|
|
|
*/ |
42
|
|
|
private $visibility; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Initializes the object. |
46
|
|
|
* |
47
|
|
|
* @throws InvalidArgumentException when visibility does not match public|protected|private |
48
|
|
|
*/ |
49
|
5 |
|
public function __construct(string $visibility) |
50
|
|
|
{ |
51
|
5 |
|
$visibility = strtolower($visibility); |
52
|
|
|
|
53
|
5 |
|
if ($visibility !== static::PUBLIC_ && $visibility !== static::PROTECTED_ && $visibility !== static::PRIVATE_) { |
54
|
1 |
|
throw new InvalidArgumentException( |
55
|
1 |
|
sprintf('""%s" is not a valid visibility value.', $visibility) |
56
|
|
|
); |
57
|
|
|
} |
58
|
|
|
|
59
|
4 |
|
$this->visibility = $visibility; |
60
|
4 |
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Will return a string representation of visibility. |
64
|
|
|
*/ |
65
|
4 |
|
public function __toString(): string |
66
|
|
|
{ |
67
|
4 |
|
return $this->visibility; |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|