Completed
Push — master ( bfa80e...3adc88 )
by Alexander
02:11
created

AnnotatedReflectionMethod::getAnnotations()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
declare(strict_types = 1);
3
/*
4
 * Go! AOP framework
5
 *
6
 * @copyright Copyright 2014, Lisachenko Alexander <[email protected]>
7
 *
8
 * This source file is subject to the license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Go\Aop\Support;
13
14
use Doctrine\Common\Annotations\Reader;
15
use Go\Core\AspectKernel;
16
use ReflectionMethod;
17
18
/**
19
 * Extended version of ReflectionMethod with annotation support
20
 */
21
class AnnotatedReflectionMethod extends ReflectionMethod
22
{
23
    /**
24
     * Annotation reader
25
     *
26
     * @var Reader
27
     */
28
    private static $annotationReader;
29
30
    /**
31
     * Gets a method annotation.
32
     *
33
     * @param string $annotationName The name of the annotation.
34
     * @return mixed The Annotation or NULL, if the requested annotation does not exist.
35
     */
36
    public function getAnnotation(string $annotationName)
37
    {
38
        return self::getReader()->getMethodAnnotation($this, $annotationName);
39
    }
40
41
    /**
42
     * Gets the annotations applied to a method.
43
     */
44
    public function getAnnotations() : array
45
    {
46
        return self::getReader()->getMethodAnnotations($this);
47
    }
48
49
    /**
50
     * Returns an annotation reader
51
     */
52
    private static function getReader() : Reader
53
    {
54
        if (!self::$annotationReader) {
55
            self::$annotationReader = AspectKernel::getInstance()->getContainer()->get('aspect.annotation.reader');
56
        };
57
58
        return self::$annotationReader;
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64 7
    public function getClosure($object)
65
    {
66 7
        if (!defined('HHVM_VERSION')) {
67 7
            return parent::getClosure($object);
68
        }
69
70
        $className  = $this->getDeclaringClass()->name;
71
        $methodName = $this->name;
72
        $closure = function (...$args) use ($methodName, $className) {
73
            $result = forward_static_call_array([$className, $methodName], $args);
74
75
            return $result;
76
        };
77
78
        return $closure->bindTo($object, $this->class);
79
    }
80
}
81