forked from php-annotations/php-annotations
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnnotationFile.php
More file actions
109 lines (97 loc) · 2.46 KB
/
AnnotationFile.php
File metadata and controls
109 lines (97 loc) · 2.46 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?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;
/**
* This class represents a php source-code file inspected for Annotations.
*/
class AnnotationFile
{
/**
* Data types considered to be simple.
*
* @var array
*/
private static $simpleTypes = array(
'array',
'bool',
'boolean',
'callback',
'double',
'float',
'int',
'integer',
'mixed',
'number',
'object',
'string',
'void',
);
/**
* @var array hash where member name => annotation data
*/
public $data;
/**
* @var string $path absolute path to php source-file
*/
public $path;
/**
* @var string $namespace fully qualified namespace
*/
public $namespace;
/**
* @var string[] $uses hash where local class-name => fully qualified class-name
*/
public $uses;
/**
* @param string $path absolute path to php source-file
* @param array $data annotation data (as provided by AnnotationParser)
*/
public function __construct($path, array $data)
{
$this->path = $path;
$this->data = $data;
$this->namespace = $data['#namespace'];
$this->uses = $data['#uses'];
}
/**
* Transforms not fully qualified class/interface name into fully qualified one.
*
* @param string $raw_type Raw type.
*
* @return string
* @see http://www.phpdoc.org/docs/latest/for-users/phpdoc/types.html#abnf
*/
public function resolveType($raw_type)
{
$type_parts = explode('[]', $raw_type, 2);
$type = $type_parts[0];
if (!$this->isSimple($type)) {
if (isset($this->uses[$type])) {
$type_parts[0] = $this->uses[$type];
} elseif ($this->namespace && substr($type, 0, 1) != '\\') {
$type_parts[0] = $this->namespace . '\\' . $type;
}
}
return implode('[]', $type_parts);
}
/**
* Determines if given data type is scalar.
*
* @param string $type Type.
*
* @return boolean
*/
protected function isSimple($type)
{
return in_array(strtolower($type), self::$simpleTypes);
}
}