Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
annotationreader.php
1<?php
2
4
6
8{
10
12
16 public function __construct()
17 {
18 if (
19 extension_loaded('Zend Optimizer+') &&
20 (ini_get('zend_optimizerplus.save_comments') === "0" || ini_get('opcache.save_comments') === "0"))
21 {
22 throw new SystemException( "You have to enable opcache.save_comments=1 or zend_optimizerplus.save_comments=1.");
23 }
24
25 if (extension_loaded('Zend OPcache') && ini_get('opcache.save_comments') == 0)
26 {
27 throw new SystemException( "You have to enable opcache.save_comments=1 or zend_optimizerplus.save_comments=1.");
28 }
29 }
30
31 public function getMethodAnnotations(\ReflectionMethod $method)
32 {
33 $doc = $method->getDocComment();
34
35 preg_match_all("/@(?=(.*)[ ]*(?:@|\r\n|\n))/U", $doc, $matches);
36
37 if (!$matches)
38 {
39 return null;
40 }
41
42 $annotations = array();
43 foreach ($matches[1] as $match)
44 {
45 if ($this->collectRules & self::RULE_FIRST_CAPITAL_LETTER)
46 {
47 if ($match !== ucfirst($match))
48 {
49 continue;
50 }
51 }
52
53 $annotations[] = $match;
54 }
55
56 $parameters = array();
57 foreach ($annotations as $annotation)
58 {
59 preg_match("/(\w+)(?:\‍((.*)\‍))?/", $annotation, $matches);
60 if ($matches)
61 {
62 $parameters[$matches[1]] = $this->extractParameters($matches[2]);
63 }
64 }
65
66 return $parameters;
67 }
68
69 private function extractParameters($string)
70 {
71 if (!$string)
72 {
73 return null;
74 }
75
76 $parameters = array();
77
78 $parts = preg_split("/(\w+)\=([.^\=]*)/", $string, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
79
80 for ($i = 0; $i < count($parts); $i++)
81 {
82 //there is key by even number and value is by the next odd number
83 if ($i % 2 === 0)
84 {
85 $rawValue = trim($parts[$i + 1], ', ');
86
87 $parameters[$parts[$i]] = $rawValue;
88 }
89 }
90
91 foreach ($parameters as $name => &$rawValue)
92 {
93 $rawValue = trim($rawValue);
94 $rawValue = $this->extractParameter($rawValue);
95 }
96
97 return $parameters;
98 }
99
100 private function extractParameter($valueInString)
101 {
102 if (!$valueInString)
103 {
104 return null;
105 }
106
107 $value = null;
108
109 if ($valueInString === 'false')
110 {
111 $value = false;
112 }
113 elseif ($valueInString === 'true')
114 {
115 $value = true;
116 }
117 elseif (is_numeric($valueInString))
118 {
119 if ($valueInString === (string)(int)$valueInString)
120 {
121 $value = (int)$valueInString;
122 }
123 else
124 {
125 $value = (float)$valueInString;
126 }
127 }
128 elseif (mb_substr($valueInString, 0, 1) === '[' && mb_substr($valueInString, -1, 1) === ']')
129 {
130 $list = array();
131 $valueInString = mb_substr($valueInString, 1, -1);
132 foreach (explode(',', $valueInString) as $listValue)
133 {
134 $listValue = trim($listValue);
135 if (!$listValue)
136 {
137 continue;
138 }
139
140 $list[] = $this->extractParameter($listValue);
141 }
142
143 $value = $list;
144 }
145 else
146 {
147 $value = trim($valueInString, '"');
148 }
149
150 return $value;
151 }
152}
getMethodAnnotations(\ReflectionMethod $method)