-
Notifications
You must be signed in to change notification settings - Fork 134
Expand file tree
/
Copy pathKernel.php
More file actions
86 lines (72 loc) · 2.48 KB
/
Copy pathKernel.php
File metadata and controls
86 lines (72 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
declare(strict_types=1);
namespace AspectMock;
use AspectMock\Core\Registry;
use AspectMock\Intercept\BeforeMockTransformer;
use Go\Core\AspectContainer;
use Go\Core\AspectKernel;
use Go\Core\AdviceMatcher;
use Go\Core\CachedAspectLoader;
use Go\Instrument\ClassLoading\CachePathManager;
use Go\Instrument\ClassLoading\SourceTransformingLoader;
use Go\Instrument\Transformer\CachingTransformer;
use Go\Instrument\Transformer\FilterInjectorTransformer;
use Go\Instrument\Transformer\MagicConstantTransformer;
use Symfony\Component\Finder\Finder;
require_once __DIR__ . '/Core/Registry.php';
class Kernel extends AspectKernel
{
public function init(array $options = []): void
{
if (!isset($options['excludePaths'])) {
$options['excludePaths'] = [];
} elseif (!is_array($options['excludePaths'])) {
$options['excludePaths'] = [ $options['excludePaths'] ];
}
$options['debug'] = true;
$options['excludePaths'][] = __DIR__;
parent::init($options);
}
protected function configureAop(AspectContainer $container): void
{
Registry::setMocker(new Core\Mocker);
}
/**
* Scans a directory provided and includes all PHP files from it.
* All files will be parsed and aspects will be added.
*
* @param string|string[] $dir
*/
public function loadPhpFiles($dir)
{
$files = Finder::create()->files()->name('*.php')->in($dir);
foreach ($files as $file) {
$this->loadFile($file->getRealpath());
}
}
/**
* Includes file and injects aspect pointcuts into int
*/
public function loadFile(string $file)
{
include FilterInjectorTransformer::rewrite($file);
}
protected function registerTransformers(): array
{
$cachePathManager = $this->getContainer()->getService(CachePathManager::class);
$sourceTransformers = [
new FilterInjectorTransformer($this, SourceTransformingLoader::getId(), $cachePathManager),
new MagicConstantTransformer($this),
new BeforeMockTransformer(
$this,
$this->getContainer()->getService(AdviceMatcher::class),
$cachePathManager,
$this->getContainer()->getService(CachedAspectLoader::class)
)
];
return [
new CachingTransformer($this, $sourceTransformers, $cachePathManager)
];
}
}
require __DIR__ . '/Intercept/before_mock.php';