|
| 1 | +<?php |
| 2 | +/* |
| 3 | + * Go! AOP framework |
| 4 | + * |
| 5 | + * @copyright Copyright 2016, Lisachenko Alexander <[email protected]> |
| 6 | + * |
| 7 | + * This source file is subject to the license that is bundled |
| 8 | + * with this source code in the file LICENSE. |
| 9 | + */ |
| 10 | + |
| 11 | +namespace Go\Laravel\GoAopBridge; |
| 12 | + |
| 13 | +use Go\Core\AspectContainer; |
| 14 | +use Go\Core\AspectKernel; |
| 15 | +use Go\Laravel\GoAopBridge\Kernel\AspectLaravelKernel; |
| 16 | +use Illuminate\Contracts\Foundation\Application; |
| 17 | +use Illuminate\Support\ServiceProvider; |
| 18 | + |
| 19 | +/** |
| 20 | + * Service provider for registration of Go! AOP framework |
| 21 | + */ |
| 22 | +class GoAopServiceProvider extends ServiceProvider |
| 23 | +{ |
| 24 | + /** |
| 25 | + * Bootstrap the application services. |
| 26 | + * |
| 27 | + * @return void |
| 28 | + */ |
| 29 | + public function boot() |
| 30 | + { |
| 31 | + /** @var AspectContainer $aspectContainer */ |
| 32 | + $aspectContainer = $this->app->make(AspectContainer::class); |
| 33 | + |
| 34 | + // Let's collect all aspects and just register them in the container |
| 35 | + $aspects = $this->app->tagged('goaop.aspect'); |
| 36 | + foreach ($aspects as $aspect) { |
| 37 | + $aspectContainer->registerAspect($aspect); |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * Register the application services. |
| 43 | + * |
| 44 | + * @return void |
| 45 | + */ |
| 46 | + public function register() |
| 47 | + { |
| 48 | + $this->publishes([$this->configPath() => config_path('go_aop.php')]); |
| 49 | + $this->mergeConfigFrom($this->configPath(), 'go_aop'); |
| 50 | + |
| 51 | + $this->app->singleton(AspectKernel::class, function () { |
| 52 | + $aspectKernel = AspectLaravelKernel::getInstance(); |
| 53 | + $aspectKernel->init(config('go_aop')); |
| 54 | + |
| 55 | + return $aspectKernel; |
| 56 | + }); |
| 57 | + |
| 58 | + $this->app->singleton(AspectContainer::class, function (Application $app) { |
| 59 | + /** @var AspectKernel $kernel */ |
| 60 | + $kernel = $app->make(AspectKernel::class); |
| 61 | + |
| 62 | + return $kernel->getContainer(); |
| 63 | + }); |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * @inheritDoc |
| 68 | + */ |
| 69 | + public function provides() |
| 70 | + { |
| 71 | + return [AspectKernel::class, AspectContainer::class]; |
| 72 | + } |
| 73 | + |
| 74 | + /** |
| 75 | + * Returns the path to the configuration |
| 76 | + * |
| 77 | + * @return string |
| 78 | + */ |
| 79 | + private function configPath() |
| 80 | + { |
| 81 | + return __DIR__ . '/../config/go_aop.php'; |
| 82 | + } |
| 83 | +} |
0 commit comments