-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlugin.php
More file actions
66 lines (56 loc) · 1.92 KB
/
Plugin.php
File metadata and controls
66 lines (56 loc) · 1.92 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
<?php
declare(strict_types=1);
/*
* This file is part of the dotfiles project.
*
* (c) Anthonius Munthi <me@itstoni.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Dotfiles\Core;
use Dotfiles\Core\Util\Toolkit;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
/**
* Class Plugin.
*/
abstract class Plugin extends Extension
{
public function getName(): string
{
$class = get_class($this);
$exp = explode('\\', $class);
$baseClassName = $exp[count($exp) - 1];
$pluginName = strtolower(str_replace('Plugin', '', $baseClassName));
return $pluginName;
}
/**
* {@inheritdoc}
*/
public function load(array $config, ContainerBuilder $container): void
{
$r = new \ReflectionClass(get_class($this));
$resourceDir = dirname($r->getFileName()).'/Resources';
$serviceConfig = $resourceDir.DIRECTORY_SEPARATOR.'services.yaml';
if (is_file($serviceConfig)) {
$locator = new FileLocator($resourceDir);
$loader = new YamlFileLoader($container, $locator);
$loader->load($serviceConfig);
}
$configuration = $this->getConfiguration($config, $container);
if ($configuration instanceof ConfigurationInterface) {
$configs = $this->processConfiguration($configuration, $config);
Toolkit::flattenArray($configs, $this->getName());
$configs = $this->configure($configs);
$container->getParameterBag()->add($configs);
}
}
protected function configure($configs)
{
return $configs;
}
}