1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* Copyright (c) 2011-2015, Celestino Diaz <[email protected]> |
5
|
|
|
* |
6
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
7
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
8
|
|
|
* in the Software without restriction, including without limitation the rights |
9
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
10
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
11
|
|
|
* furnished to do so, subject to the following conditions: |
12
|
|
|
* |
13
|
|
|
* The above copyright notice and this permission notice shall be included in |
14
|
|
|
* all copies or substantial portions of the Software. |
15
|
|
|
* |
16
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
17
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
18
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
19
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
20
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
21
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
22
|
|
|
* THE SOFTWARE. |
23
|
|
|
*/ |
24
|
|
|
|
25
|
|
|
namespace Brickoo\Component\Annotation; |
26
|
|
|
|
27
|
|
|
use Brickoo\Component\Common\Assert; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Annotation |
31
|
|
|
* |
32
|
|
|
* Implements an annotation containing the target, name and values. |
33
|
|
|
* @author Celestino Diaz <[email protected]> |
34
|
|
|
*/ |
35
|
|
|
class Annotation { |
36
|
|
|
|
37
|
|
|
/** @const annotation targets */ |
38
|
|
|
const TARGET_CLASS = 1; |
39
|
|
|
const TARGET_METHOD = 2; |
40
|
|
|
const TARGET_PROPERTY = 4; |
41
|
|
|
|
42
|
|
|
/** @var integer */ |
43
|
|
|
protected $target; |
44
|
|
|
|
45
|
|
|
/** @var string */ |
46
|
|
|
protected $targetLocation; |
47
|
|
|
|
48
|
|
|
/** @var string */ |
49
|
|
|
protected $name; |
50
|
|
|
|
51
|
|
|
/** @var array */ |
52
|
|
|
protected $values; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Class constructor. |
56
|
|
|
* @param integer $target |
57
|
|
|
* @param string $targetLocation |
58
|
|
|
* @param string $name the annotation name |
59
|
|
|
* @param array $values the annotation values |
60
|
|
|
*/ |
61
|
2 |
|
public function __construct($target, $targetLocation, $name, array $values = []) { |
62
|
2 |
|
Assert::isInteger($target); |
63
|
2 |
|
Assert::isString($targetLocation); |
64
|
2 |
|
Assert::isString($name); |
65
|
2 |
|
$this->target = $target; |
66
|
2 |
|
$this->targetLocation = $targetLocation; |
67
|
2 |
|
$this->name = $name; |
68
|
2 |
|
$this->values = $values; |
69
|
2 |
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Returns the annotation target |
73
|
|
|
* @return integer the annotation target |
74
|
|
|
*/ |
75
|
1 |
|
public function getTarget() { |
76
|
1 |
|
return $this->target; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Returns the target location. |
81
|
|
|
* @return string the target location |
82
|
|
|
*/ |
83
|
1 |
|
public function getTargetLocation() { |
84
|
1 |
|
return $this->targetLocation; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Returns the annotation name. |
89
|
|
|
* @return string annotation name |
90
|
|
|
*/ |
91
|
1 |
|
public function getName() { |
92
|
1 |
|
return $this->name; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Returns the annotation values. |
97
|
|
|
* @return array annotations values |
98
|
|
|
*/ |
99
|
1 |
|
public function getValues() { |
100
|
1 |
|
return $this->values; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Checks if the annotation has a value. |
105
|
|
|
* @return boolean check result |
106
|
|
|
*/ |
107
|
1 |
|
public function hasValues() { |
108
|
1 |
|
return (!empty($this->values)); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
} |
112
|
|
|
|