Skip to content

Commit d90349b

Browse files
committed
propertyAnnotation implementation
1 parent 52299b4 commit d90349b

File tree

1 file changed

+72
-3
lines changed

1 file changed

+72
-3
lines changed

src/annotations/standard/PropertyAnnotation.php

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,81 @@
1414
namespace mindplay\annotations\standard;
1515

1616
use mindplay\annotations\Annotation;
17+
use mindplay\annotations\IAnnotationParser;
18+
use mindplay\annotations\AnnotationException;
19+
use mindplay\annotations\IAnnotationFileAware;
20+
use mindplay\annotations\AnnotationFile;
1721

1822
/**
1923
* Defines a magic/virtual property and it's type
20-
*
21-
* @todo implement this
24+
* @usage('class'=>true, 'inherited'=>true)
2225
*/
23-
class PropertyAnnotation extends Annotation
26+
class PropertyAnnotation extends Annotation implements IAnnotationParser, IAnnotationFileAware
2427
{
28+
/**
29+
* @var string Specifies the property type
30+
*/
31+
public $type;
32+
/**
33+
* @var string Specifies the property name
34+
*/
35+
public $name;
36+
/**
37+
* @var string Specifies the property description
38+
*/
39+
public $description;
40+
41+
/**
42+
* Annotation file.
43+
*
44+
* @var AnnotationFile
45+
*/
46+
protected $file;
47+
48+
/**
49+
* {@inheritDoc}
50+
* @see \mindplay\annotations\IAnnotationParser::parseAnnotation()
51+
*/
52+
public static function parseAnnotation($value)
53+
{
54+
$parts = explode(' ', trim($value), 3);
55+
if (\sizeof($parts) < 2) {
56+
// Malformed value, let "initAnnotation" report about it.
57+
return array();
58+
}
59+
$result=array('type' => $parts[0], 'name' => substr($parts[1], 1));
60+
61+
if(isset($parts[2])){
62+
$result['description']=$parts[2];
63+
}
64+
return $result;
65+
}
66+
67+
/**
68+
* Initialize the annotation.
69+
*/
70+
public function initAnnotation(array $properties)
71+
{
72+
$this->map($properties, array('type','name','description'));
73+
parent::initAnnotation($properties);
74+
if (!isset($this->type)) {
75+
throw new AnnotationException(basename(__CLASS__).' requires a type property');
76+
}
77+
if (!isset($this->name)) {
78+
throw new AnnotationException(basename(__CLASS__).' requires a name property');
79+
}
80+
$this->type = $this->file->resolveType($this->type);
81+
}
82+
83+
/**
84+
* Provides information about file, that contains this annotation.
85+
*
86+
* @param AnnotationFile $file Annotation file.
87+
*
88+
* @return void
89+
*/
90+
public function setAnnotationFile(AnnotationFile $file)
91+
{
92+
$this->file = $file;
93+
}
2594
}

0 commit comments

Comments
 (0)