1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
/** |
4
|
|
|
* This file is part of GitterBot package. |
5
|
|
|
* |
6
|
|
|
* @author Serafim <[email protected]> |
7
|
|
|
* @date 03.03.2016 15:00 |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
10
|
|
|
* file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
namespace Core\Providers; |
15
|
|
|
|
16
|
|
|
use Core\Doctrine\CacheBridge; |
17
|
|
|
use Doctrine\Common\Annotations\AnnotationReader; |
18
|
|
|
use Doctrine\Common\Annotations\AnnotationRegistry; |
19
|
|
|
use Doctrine\Common\Annotations\CachedReader; |
20
|
|
|
use Doctrine\Common\Annotations\Reader; |
21
|
|
|
use Doctrine\Common\Cache\ArrayCache; |
22
|
|
|
use Illuminate\Contracts\Config\Repository; |
23
|
|
|
use Illuminate\Contracts\Foundation\Application; |
24
|
|
|
use Illuminate\Support\ServiceProvider; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Class AnnotationsServiceProvider |
28
|
|
|
* @package Core\Providers |
29
|
|
|
*/ |
30
|
|
|
class AnnotationsServiceProvider extends ServiceProvider |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* Register class |
34
|
|
|
* @throws \InvalidArgumentException |
35
|
|
|
*/ |
36
|
|
|
public function register() |
37
|
|
|
{ |
38
|
|
|
AnnotationRegistry::registerLoader(function ($class) { |
39
|
|
|
return class_exists($class); |
40
|
|
|
}); |
41
|
|
|
|
42
|
|
|
$this->app->singleton(Reader::class, function (Application $app) { |
43
|
|
|
$debug = $app->make(Repository::class)->get('app.debug', false); |
44
|
|
|
$cache = $app->make($debug ? ArrayCache::class : CacheBridge::class); |
45
|
|
|
|
46
|
|
|
return new CachedReader(new AnnotationReader(), $cache, $debug); |
47
|
|
|
}); |
48
|
|
|
|
49
|
|
|
$this->app->alias(AnnotationReader::class, Reader::class); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|