Completed
Push — master ( 4ada12...4bd1d2 )
by yuuki
13s
created

AnnotationManager::createApcuDriver()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
/**
4
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
5
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
6
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
7
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
8
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
9
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
10
 * THE SOFTWARE.
11
 *
12
 * This software consists of voluntary contributions made by many individuals
13
 * and is licensed under the MIT license.
14
 *
15
 * Copyright (c) 2015-2016 Yuuki Takezawa
16
 *
17
 */
18
namespace Ytake\LaravelAspect;
19
20
use Illuminate\Support\Manager;
21
use Doctrine\Common\Annotations\AnnotationReader;
22
use Ytake\LaravelAspect\Annotation\Reader\ApcuReader;
23
use Ytake\LaravelAspect\Annotation\Reader\FileReader;
24
use Ytake\LaravelAspect\Annotation\Reader\ArrayReader;
25
26
/**
27
 * Class AnnotationManager
28
 * @method \Doctrine\Common\Annotations\Reader getReader() getReader
29
 */
30
class AnnotationManager extends Manager
31
{
32
    /**
33
     * default annotation reader(no caching other than in memory [in php arrays])
34
     *
35
     * @return string
36
     */
37
    public function getDefaultDriver()
38
    {
39
        return $this->app['config']->get('ytake-laravel-aop.annotation.default');
40
    }
41
42
    /**
43
     * @return ArrayReader
44
     */
45
    protected function createArrayDriver()
46
    {
47
        $this->ignoredAnnotations($this->app['config']->get('ytake-laravel-aop.annotation.ignores', []));
48
49
        return new ArrayReader();
50
    }
51
52
    /**
53
     * @return FileReader
54
     */
55
    protected function createFileDriver()
56
    {
57
        $this->ignoredAnnotations($this->app['config']->get('ytake-laravel-aop.annotation.ignores', []));
58
59
        return new FileReader($this->getConfigure('file'));
60
    }
61
62
    /**
63
     * @return ApcuReader
64
     */
65
    protected function createApcuDriver()
66
    {
67
        $this->ignoredAnnotations($this->app['config']->get('ytake-laravel-aop.annotation.ignores', []));
68
69
        return new ApcuReader($this->getConfigure('file'));
70
    }
71
72
    /**
73
     * @param string $driver
74
     *
75
     * @return string[]
76
     */
77
    protected function getConfigure($driver)
78
    {
79
        $annotationConfigure = $this->app['config']->get('ytake-laravel-aop.annotation.drivers');
80
        $annotationConfigure[$driver]['debug'] = $this->app['config']->get('ytake-laravel-aop.annotation.debug', false);
81
82
        return $annotationConfigure[$driver];
83
    }
84
85
    /**
86
     * Add a new annotation to the globally ignored annotation names with regard to exception handling.
87
     *
88
     * @param array $ignores
89
     */
90
    private function ignoredAnnotations(array $ignores = [])
91
    {
92
        foreach ($ignores as $ignore) {
93
            AnnotationReader::addGlobalIgnoredName($ignore);
94
        }
95
    }
96
}
97