MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
AnnotationReader.php
Ir para a documentação deste ficheiro.
1
<?php
2
/*
3
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
*
15
* This software consists of voluntary contributions made by many individuals
16
* and is licensed under the LGPL. For more information, see
17
* <http://www.doctrine-project.org>.
18
*/
19
20
namespace
Doctrine\Common\Annotations
;
21
22
use Closure,
23
ReflectionClass,
24
ReflectionMethod,
25
ReflectionProperty,
26
Doctrine\Common\Cache\Cache
;
27
37
class
AnnotationReader
38
{
45
private
static
$CACHE_SALT =
'@<Annot>'
;
46
52
private
$parser;
53
59
private
$cache;
60
67
public
function
__construct
(
Cache
$cache =
null
,
Parser
$parser =
null
)
68
{
69
$this->parser = $parser ?:
new
Parser
;
70
$this->cache = $cache ?: new \Doctrine\Common\Cache\ArrayCache;
71
}
72
79
public
function
setDefaultAnnotationNamespace
($defaultNamespace)
80
{
81
$this->parser->setDefaultAnnotationNamespace($defaultNamespace);
82
}
83
96
public
function
setAnnotationCreationFunction
(Closure $func)
97
{
98
$this->parser->setAnnotationCreationFunction($func);
99
}
100
107
public
function
setAnnotationNamespaceAlias
($namespace, $alias)
108
{
109
$this->parser->setAnnotationNamespaceAlias($namespace, $alias);
110
}
111
121
public
function
setAutoloadAnnotations
($bool)
122
{
123
$this->parser->setAutoloadAnnotations($bool);
124
}
125
132
public
function
getAutoloadAnnotations
()
133
{
134
return
$this->parser->getAutoloadAnnotations();
135
}
136
144
public
function
getClassAnnotations
(ReflectionClass $class)
145
{
146
$cacheKey = $class->getName() . self::$CACHE_SALT;
147
148
// Attempt to grab data from cache
149
if
(($data = $this->cache->fetch($cacheKey)) !==
false
) {
150
return
$data;
151
}
152
153
$annotations = $this->parser->parse($class->getDocComment(),
'class '
. $class->getName());
154
$this->cache->save($cacheKey, $annotations,
null
);
155
156
return
$annotations;
157
}
158
166
public
function
getClassAnnotation
(ReflectionClass $class, $annotation)
167
{
168
$annotations = $this->
getClassAnnotations
($class);
169
170
return
isset($annotations[$annotation]) ? $annotations[$annotation] :
null
;
171
}
172
181
public
function
getPropertyAnnotations
(ReflectionProperty $property)
182
{
183
$cacheKey = $property->getDeclaringClass()->getName() .
'$'
. $property->getName() . self::$CACHE_SALT;
184
185
// Attempt to grab data from cache
186
if
(($data = $this->cache->fetch($cacheKey)) !==
false
) {
187
return
$data;
188
}
189
190
$context =
'property '
. $property->getDeclaringClass()->getName() .
"::\$"
. $property->getName();
191
$annotations = $this->parser->parse($property->getDocComment(), $context);
192
$this->cache->save($cacheKey, $annotations,
null
);
193
194
return
$annotations;
195
}
196
204
public
function
getPropertyAnnotation
(ReflectionProperty $property, $annotation)
205
{
206
$annotations = $this->
getPropertyAnnotations
($property);
207
208
return
isset($annotations[$annotation]) ? $annotations[$annotation] :
null
;
209
}
210
219
public
function
getMethodAnnotations
(ReflectionMethod $method)
220
{
221
$cacheKey = $method->getDeclaringClass()->getName() .
'#'
. $method->getName() . self::$CACHE_SALT;
222
223
// Attempt to grab data from cache
224
if
(($data = $this->cache->fetch($cacheKey)) !==
false
) {
225
return
$data;
226
}
227
228
$context =
'method '
. $method->getDeclaringClass()->getName() .
'::'
. $method->getName() .
'()'
;
229
$annotations = $this->parser->parse($method->getDocComment(), $context);
230
$this->cache->save($cacheKey, $annotations,
null
);
231
232
return
$annotations;
233
}
234
242
public
function
getMethodAnnotation
(ReflectionMethod $method, $annotation)
243
{
244
$annotations = $this->
getMethodAnnotations
($method);
245
246
return
isset($annotations[$annotation]) ? $annotations[$annotation] :
null
;
247
}
248
}
Doctrine\Common\Annotations\AnnotationReader
Definição
AnnotationReader.php:38
Doctrine\Common\Annotations\AnnotationReader\setAnnotationNamespaceAlias
setAnnotationNamespaceAlias($namespace, $alias)
Definição
AnnotationReader.php:107
Doctrine\Common\Annotations\AnnotationReader\getClassAnnotation
getClassAnnotation(ReflectionClass $class, $annotation)
Definição
AnnotationReader.php:166
Doctrine\Common\Annotations\AnnotationReader\getAutoloadAnnotations
getAutoloadAnnotations()
Definição
AnnotationReader.php:132
Doctrine\Common\Annotations\AnnotationReader\__construct
__construct(Cache $cache=null, Parser $parser=null)
Definição
AnnotationReader.php:67
Doctrine\Common\Annotations\AnnotationReader\setAutoloadAnnotations
setAutoloadAnnotations($bool)
Definição
AnnotationReader.php:121
Doctrine\Common\Annotations\AnnotationReader\setAnnotationCreationFunction
setAnnotationCreationFunction(Closure $func)
Definição
AnnotationReader.php:96
Doctrine\Common\Annotations\AnnotationReader\setDefaultAnnotationNamespace
setDefaultAnnotationNamespace($defaultNamespace)
Definição
AnnotationReader.php:79
Doctrine\Common\Annotations\AnnotationReader\getClassAnnotations
getClassAnnotations(ReflectionClass $class)
Definição
AnnotationReader.php:144
Doctrine\Common\Annotations\AnnotationReader\getPropertyAnnotations
getPropertyAnnotations(ReflectionProperty $property)
Definição
AnnotationReader.php:181
Doctrine\Common\Annotations\AnnotationReader\getPropertyAnnotation
getPropertyAnnotation(ReflectionProperty $property, $annotation)
Definição
AnnotationReader.php:204
Doctrine\Common\Annotations\AnnotationReader\getMethodAnnotations
getMethodAnnotations(ReflectionMethod $method)
Definição
AnnotationReader.php:219
Doctrine\Common\Annotations\AnnotationReader\getMethodAnnotation
getMethodAnnotation(ReflectionMethod $method, $annotation)
Definição
AnnotationReader.php:242
Doctrine\Common\Annotations\Parser
Definição
Parser.php:39
Doctrine\Common\Cache\Cache
Definição
Cache.php:37
Doctrine\Common\Annotations
Definição
Annotation.php:22
classes
extensions
doctrine-dbal
Doctrine
Common
Annotations
AnnotationReader.php
Gerado por
1.10.0