|
| 1 | +<?php declare(strict_types=1); |
| 2 | +/** |
| 3 | + * This file is part of the CleverAge/CacheProcessBundle package. |
| 4 | + * |
| 5 | + * Copyright (C) 2017-2019 Clever-Age |
| 6 | + * |
| 7 | + * For the full copyright and license information, please view the LICENSE |
| 8 | + * file that was distributed with this source code. |
| 9 | + */ |
| 10 | + |
| 11 | +namespace CleverAge\CacheProcessBundle\DependencyInjection; |
| 12 | + |
| 13 | +use Symfony\Component\Config\FileLocator; |
| 14 | +use Symfony\Component\DependencyInjection\ContainerBuilder; |
| 15 | +use Symfony\Component\DependencyInjection\Extension\Extension; |
| 16 | +use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
| 17 | +use Symfony\Component\Finder\Finder; |
| 18 | + |
| 19 | +/** |
| 20 | + * This is the class that loads and manages your bundle configuration. |
| 21 | + * |
| 22 | + * @see http://symfony.com/doc/current/cookbook/bundles/extension.html |
| 23 | + */ |
| 24 | +class CleverAgeCacheProcessExtension extends Extension |
| 25 | +{ |
| 26 | + public function load(array $configs, ContainerBuilder $container): void |
| 27 | + { |
| 28 | + $this->findServices($container, __DIR__.'/../../config/services'); |
| 29 | + } |
| 30 | + |
| 31 | + /** |
| 32 | + * Recursively import config files into container. |
| 33 | + */ |
| 34 | + protected function findServices(ContainerBuilder $container, string $path, string $extension = 'yaml'): void |
| 35 | + { |
| 36 | + $finder = new Finder(); |
| 37 | + $finder->in($path) |
| 38 | + ->name('*.'.$extension)->files(); |
| 39 | + $loader = new YamlFileLoader($container, new FileLocator($path)); |
| 40 | + foreach ($finder as $file) { |
| 41 | + $loader->load($file->getFilename()); |
| 42 | + } |
| 43 | + } |
| 44 | +} |
0 commit comments