|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* \AppserverIo\Psr\MetaobjectProtocol\Dbc\Annotations\Requires |
|
5
|
|
|
* |
|
6
|
|
|
* NOTICE OF LICENSE |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
|
9
|
|
|
* that is available through the world-wide-web at this URL: |
|
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
|
11
|
|
|
* |
|
12
|
|
|
* PHP version 5 |
|
13
|
|
|
* |
|
14
|
|
|
* @author Bernhard Wick <[email protected]> |
|
15
|
|
|
* @copyright 2015 TechDivision GmbH - <[email protected]> |
|
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
17
|
|
|
* @link https://github.com/appserver-io-psr/mop |
|
18
|
|
|
* @link http://www.appserver.io/ |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace AppserverIo\Psr\MetaobjectProtocol\Dbc\Annotations; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Annotation class which is used to identify the pre-condition a method execution or property access must fulfill |
|
25
|
|
|
* |
|
26
|
|
|
* @author Bernhard Wick <[email protected]> |
|
27
|
|
|
* @copyright 2015 TechDivision GmbH - <[email protected]> |
|
28
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
29
|
|
|
* @link https://github.com/appserver-io-psr/mop |
|
30
|
|
|
* @link http://www.appserver.io/ |
|
31
|
|
|
* |
|
32
|
|
|
* @Annotation |
|
33
|
|
|
* @Target({"METHOD"}) |
|
34
|
|
|
*/ |
|
35
|
|
|
class Requires |
|
36
|
|
|
{ |
|
37
|
|
|
/** |
|
38
|
|
|
* The annotation which identifies this annotation class |
|
39
|
|
|
* |
|
40
|
|
|
* @var string |
|
41
|
|
|
*/ |
|
42
|
|
|
const ANNOTATION = 'Requires'; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* The assertion type to use. |
|
46
|
|
|
* |
|
47
|
|
|
* @var string |
|
48
|
|
|
*/ |
|
49
|
|
|
protected $type; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* The constraint to use for assertion. |
|
53
|
|
|
* |
|
54
|
|
|
* @var string |
|
55
|
|
|
*/ |
|
56
|
|
|
protected $constraint; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* The constructor the initializes the instance with the |
|
60
|
|
|
* data passed with the token. |
|
61
|
|
|
* |
|
62
|
|
|
* @param array $values The annotation values |
|
63
|
|
|
*/ |
|
64
|
|
|
public function __construct(array $values = array()) |
|
65
|
|
|
{ |
|
66
|
|
|
|
|
67
|
|
|
// set the name attribute, if available |
|
68
|
|
|
if (isset($values[AnnotationKeys::TYPE])) { |
|
69
|
|
|
$this->name = $values[AnnotationKeys::TYPE]; |
|
|
|
|
|
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
// set the constraint attribute, if available |
|
73
|
|
|
if (isset($values[AnnotationKeys::CONSTRAINT])) { |
|
74
|
|
|
$this->constraint = $values[AnnotationKeys::CONSTRAINT]; |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* This method returns the class name as a string |
|
80
|
|
|
* |
|
81
|
|
|
* @return string |
|
82
|
|
|
*/ |
|
83
|
|
|
public static function __getClass() |
|
84
|
|
|
{ |
|
85
|
|
|
return __CLASS__; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Returns the value of the name attribute. |
|
90
|
|
|
* |
|
91
|
|
|
* @return string|null The annotations name attribute |
|
92
|
|
|
*/ |
|
93
|
|
|
public function getType() |
|
94
|
|
|
{ |
|
95
|
|
|
return $this->type; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Returns the value of the constraint attribute. |
|
100
|
|
|
* |
|
101
|
|
|
* @return string|null The annotations constraint attribute |
|
102
|
|
|
*/ |
|
103
|
|
|
public function getConstraint() |
|
104
|
|
|
{ |
|
105
|
|
|
return $this->constraint; |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: