1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* PHP version 7.1 |
4
|
|
|
* |
5
|
|
|
* This source file is subject to the license that is bundled with this package in the file LICENSE. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace PhUml\Code; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* It represents a class attribute |
12
|
|
|
* |
13
|
|
|
* It does not distinguish yet static attributes |
14
|
|
|
*/ |
15
|
|
|
class Attribute extends Variable |
16
|
|
|
{ |
17
|
|
|
/** @var Visibility */ |
18
|
|
|
private $modifier; |
19
|
|
|
|
20
|
|
|
protected function __construct(string $name, Visibility $modifier, TypeDeclaration $type) |
21
|
|
|
{ |
22
|
|
|
parent::__construct($name, $type); |
23
|
|
|
$this->modifier = $modifier; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public static function public(string $name, TypeDeclaration $type = null): Attribute |
27
|
|
|
{ |
28
|
|
|
return new Attribute($name, Visibility::public(), $type ?? TypeDeclaration::absent()); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public static function protected(string $name, TypeDeclaration $type = null): Attribute |
32
|
|
|
{ |
33
|
|
|
return new Attribute($name, Visibility::protected(), $type ?? TypeDeclaration::absent()); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public static function private(string $name, TypeDeclaration $type = null): Attribute |
37
|
|
|
{ |
38
|
|
|
return new Attribute($name, Visibility::private(), $type ?? TypeDeclaration::absent()); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function isTyped(): bool |
42
|
|
|
{ |
43
|
|
|
return $this->type->isPresent(); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function hasVisibility(Visibility $modifier): bool |
47
|
|
|
{ |
48
|
|
|
return $this->modifier()->equals($modifier); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function modifier(): Visibility |
52
|
|
|
{ |
53
|
|
|
return $this->modifier; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* It doesn't currently support information type |
58
|
|
|
* |
59
|
|
|
* @see GraphvizProcessor#getClassDefinition In its original version |
60
|
|
|
*/ |
61
|
|
|
public function __toString() |
62
|
|
|
{ |
63
|
|
|
return sprintf('%s%s', $this->modifier, $this->name); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|