Annotation.php
1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
/**
* This file is part of the php-annotation framework.
*
* (c) Rasmus Schultz <rasmus@mindplay.dk>
*
* This software is licensed under the GNU LGPL license
* for more information, please see:
*
* <https://github.com/mindplay-dk/php-annotations>
*/
namespace mindplay\annotations;
/**
* A general-purpose base class for annotations.
*
* Annotations must implement IAnnotation, and may optionally derive
* from this base class.
*/
abstract class Annotation implements IAnnotation
{
/**
* Insulation against read-access to undeclared properties
*/
public function __get($name)
{
throw new AnnotationException(get_class($this) . "::\${$name} is not a valid property name");
}
/**
* Insulation against write-access to undeclared properties
*/
public function __set($name, $value)
{
throw new AnnotationException(get_class($this) . "::\${$name} is not a valid property name");
}
/**
* Helper method - initializes unnamed properties.
*
* @param array &$properties Array of annotation properties, as passed into IAnnotation::initAnnotation()
* @param array $indexes Array of unnamed properties
*/
protected function map(array &$properties, array $indexes)
{
foreach ($indexes as $index => $name) {
if (isset($properties[$index])) {
$this->$name = $properties[$index];
unset($properties[$index]);
}
}
}
/**
* Initializes this annotation instance.
* @see IAnnotation
*/
public function initAnnotation(array $properties)
{
foreach ($properties as $name => $value) {
$this->$name = $value;
}
}
}