Skip to content

Commit 82cd1c4

Browse files
committed
Implementation of AOP bridge for Laravel application
1 parent 8480a7c commit 82cd1c4

File tree

2 files changed

+110
-0
lines changed

2 files changed

+110
-0
lines changed

src/GoAopServiceProvider.php

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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+
}

src/Kernel/AspectLaravelKernel.php

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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\Kernel;
12+
13+
use Go\Core\AspectContainer;
14+
use Go\Core\AspectKernel;
15+
16+
/**
17+
* Laravel aspect kernel class
18+
*/
19+
class AspectLaravelKernel extends AspectKernel
20+
{
21+
/**
22+
* {@inheritdoc}
23+
*/
24+
protected function configureAop(AspectContainer $container)
25+
{
26+
}
27+
}

0 commit comments

Comments
 (0)