Repository navigation
Expand file tree
/
Copy pathVarAnnotation.php
More file actions
79 lines (69 loc) · 1.79 KB
/
Copy pathVarAnnotation.php
File metadata and controls
79 lines (69 loc) · 1.79 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
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
/*
* This file is part of the php-annotation framework.
*
* (c) Rasmus Schultz <[email protected]>
*
* This software is licensed under the GNU LGPL license
* for more information, please see:
*
* <http://code.google.com/p/php-annotations>
*/
namespace Mindplay\Annotation\Standard;
use Mindplay\Annotation\Annotation;
use Mindplay\Annotation\AnnotationException;
use Mindplay\Annotation\IAnnotationParser;
/**
* Specifies the required data-type of a property.
*
* @usage('property'=>true, 'inherited'=>true)
*/
class VarAnnotation extends Annotation implements IAnnotationParser
{
/**
* @var string Specifies the type of value (e.g. for validation, for
* parsing or conversion purposes; case insensitive)
*
* The following type-names are recommended:
*
* bool
* int
* float
* string
* mixed
* object
* resource
* array
* callback (e.g. array($object|$class, $method') or 'function-name')
*
* The following aliases are also acceptable:
*
* number (float)
* res (resource)
* boolean (bool)
* integer (int)
* double (float)
*/
public $type;
/**
* Parse the standard PHP-DOC @var annotation
*/
public static function parseAnnotation($value)
{
$parts = explode(' ', trim($value), 2);
return array('type' => array_shift($parts));
}
/**
* Initialize the annotation.
*/
public function initAnnotation($properties)
{
$this->_map($properties, array('type'));
parent::initAnnotation($properties);
if (!isset($this->type))
{
throw new AnnotationException('VarAnnotation requires a type property');
}
$this->type = strtolower($this->type);
}
}