Skip to content

Commit 223c618

Browse files
author
Alexander Obuhovich
committed
Make both TypeAnnotation and VarAnnotation classes available
1 parent d40f8d0 commit 223c618

File tree

3 files changed

+103
-81
lines changed

3 files changed

+103
-81
lines changed

src/annotations/AnnotationManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class AnnotationManager
9292
'type' => 'mindplay\annotations\standard\TypeAnnotation',
9393
'usage' => 'mindplay\annotations\UsageAnnotation',
9494
'uses' => false,
95-
'var' => 'mindplay\annotations\standard\TypeAnnotation',
95+
'var' => 'mindplay\annotations\standard\VarAnnotation',
9696
'version' => false,
9797
);
9898

src/annotations/standard/TypeAnnotation.php

Lines changed: 1 addition & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -13,89 +13,10 @@
1313

1414
namespace mindplay\annotations\standard;
1515

16-
use mindplay\annotations\Annotation;
17-
use mindplay\annotations\AnnotationException;
18-
use mindplay\annotations\AnnotationFile;
19-
use mindplay\annotations\IAnnotationFileAware;
20-
use mindplay\annotations\IAnnotationParser;
21-
2216
/**
2317
* Specifies the required data-type of a property.
24-
*
25-
* @usage('property'=>true, 'inherited'=>true)
2618
*/
27-
class TypeAnnotation extends Annotation implements IAnnotationParser, IAnnotationFileAware
19+
class TypeAnnotation extends VarAnnotation
2820
{
29-
/**
30-
* @var string Specifies the type of value (e.g. for validation, for
31-
* parsing or conversion purposes; case insensitive)
32-
*
33-
* The following type-names are recommended:
34-
*
35-
* bool
36-
* int
37-
* float
38-
* string
39-
* mixed
40-
* object
41-
* resource
42-
* array
43-
* callback (e.g. array($object|$class, $method') or 'function-name')
44-
*
45-
* The following aliases are also acceptable:
46-
*
47-
* number (float)
48-
* res (resource)
49-
* boolean (bool)
50-
* integer (int)
51-
* double (float)
52-
*/
53-
public $type;
54-
55-
/**
56-
* Annotation file.
57-
*
58-
* @var AnnotationFile
59-
*/
60-
protected $file;
61-
62-
/**
63-
* Parse the standard PHP-DOC annotation
64-
* @param string $value
65-
* @return array
66-
*/
67-
public static function parseAnnotation($value)
68-
{
69-
$parts = explode(' ', trim($value), 2);
70-
71-
return array('type' => array_shift($parts));
72-
}
73-
74-
/**
75-
* Initialize the annotation.
76-
*/
77-
public function initAnnotation(array $properties)
78-
{
79-
$this->map($properties, array('type'));
80-
81-
parent::initAnnotation($properties);
82-
83-
if (!isset($this->type)) {
84-
throw new AnnotationException('TypeAnnotation requires a type property');
85-
}
86-
87-
$this->type = $this->file->resolveType($this->type);
88-
}
8921

90-
/**
91-
* Provides information about file, that contains this annotation.
92-
*
93-
* @param AnnotationFile $file Annotation file.
94-
*
95-
* @return void
96-
*/
97-
public function setAnnotationFile(AnnotationFile $file)
98-
{
99-
$this->file = $file;
100-
}
10122
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the php-annotation framework.
5+
*
6+
* (c) Rasmus Schultz <[email protected]>
7+
*
8+
* This software is licensed under the GNU LGPL license
9+
* for more information, please see:
10+
*
11+
* <https://github.com/mindplay-dk/php-annotations>
12+
*/
13+
14+
namespace mindplay\annotations\standard;
15+
16+
use mindplay\annotations\Annotation;
17+
use mindplay\annotations\AnnotationException;
18+
use mindplay\annotations\AnnotationFile;
19+
use mindplay\annotations\IAnnotationFileAware;
20+
use mindplay\annotations\IAnnotationParser;
21+
22+
/**
23+
* Specifies the required data-type of a property.
24+
*
25+
* @usage('property'=>true, 'inherited'=>true)
26+
*/
27+
class VarAnnotation extends Annotation implements IAnnotationParser, IAnnotationFileAware
28+
{
29+
/**
30+
* @var string Specifies the type of value (e.g. for validation, for
31+
* parsing or conversion purposes; case insensitive)
32+
*
33+
* The following type-names are recommended:
34+
*
35+
* bool
36+
* int
37+
* float
38+
* string
39+
* mixed
40+
* object
41+
* resource
42+
* array
43+
* callback (e.g. array($object|$class, $method') or 'function-name')
44+
*
45+
* The following aliases are also acceptable:
46+
*
47+
* number (float)
48+
* res (resource)
49+
* boolean (bool)
50+
* integer (int)
51+
* double (float)
52+
*/
53+
public $type;
54+
55+
/**
56+
* Annotation file.
57+
*
58+
* @var AnnotationFile
59+
*/
60+
protected $file;
61+
62+
/**
63+
* Parse the standard PHP-DOC annotation
64+
* @param string $value
65+
* @return array
66+
*/
67+
public static function parseAnnotation($value)
68+
{
69+
$parts = explode(' ', trim($value), 2);
70+
71+
return array('type' => array_shift($parts));
72+
}
73+
74+
/**
75+
* Initialize the annotation.
76+
*/
77+
public function initAnnotation(array $properties)
78+
{
79+
$this->map($properties, array('type'));
80+
81+
parent::initAnnotation($properties);
82+
83+
if (!isset($this->type)) {
84+
throw new AnnotationException(basename(__CLASS__).' requires a type property');
85+
}
86+
87+
$this->type = $this->file->resolveType($this->type);
88+
}
89+
90+
/**
91+
* Provides information about file, that contains this annotation.
92+
*
93+
* @param AnnotationFile $file Annotation file.
94+
*
95+
* @return void
96+
*/
97+
public function setAnnotationFile(AnnotationFile $file)
98+
{
99+
$this->file = $file;
100+
}
101+
}

0 commit comments

Comments
 (0)