Sort of get config to work
This commit is contained in:
@@ -7,5 +7,5 @@ To get started, add a bundle name and description inside of `composer.json`. Add
|
||||
Change the **class name** and **namespace** of the bundle file in `/src`. Change the **file name** to match the class name also.
|
||||
|
||||
# Conventions
|
||||
- `YAML` files must end with `.yml`
|
||||
- `YAML` files must end with `.yaml`
|
||||
- Namespaces should always start with `Pcm\ExampleBundle` (change `Example` to whatever is appropriate)
|
||||
|
||||
5
config/bundles.php
Normal file
5
config/bundles.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
Pcm\IconBundle\PcmIconBundle::class => ['all' => true],
|
||||
];
|
||||
19
config/packages/pcm_icon.yaml
Normal file
19
config/packages/pcm_icon.yaml
Normal file
@@ -0,0 +1,19 @@
|
||||
when@dev:
|
||||
pcm_icon:
|
||||
directories:
|
||||
- '%kernel.project_dir%/public/icons'
|
||||
palletes: []
|
||||
|
||||
when@prod:
|
||||
pcm_icon:
|
||||
directories:
|
||||
- '%kernel.project_dir%/public/icons'
|
||||
palletes: []
|
||||
|
||||
when@test:
|
||||
pcm_icon:
|
||||
directories:
|
||||
- '%kernel.project_dir%/tests/icons'
|
||||
palletes:
|
||||
- []
|
||||
|
||||
@@ -4,13 +4,12 @@ services:
|
||||
autoconfigure: true
|
||||
|
||||
pcm_icon.icon_extension:
|
||||
alias: Pcm\IconBundle\Twig\Functions\IconExtension
|
||||
public: true
|
||||
|
||||
class: Pcm\IconBundle\Twig\Functions\IconExtension
|
||||
arguments:
|
||||
$directories: []
|
||||
$palletes: []
|
||||
|
||||
Pcm\IconBundle\Twig\Functions\IconExtension:
|
||||
tags: ['twig.extension']
|
||||
public: false
|
||||
arguments:
|
||||
$directories:
|
||||
- '%kernel.project_dir%/public/icons'
|
||||
alias: pcm_icon.icon_extension
|
||||
30
src/DependencyInjection/Configuration.php
Normal file
30
src/DependencyInjection/Configuration.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pcm\IconBundle\DependencyInjection;
|
||||
|
||||
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
||||
use Symfony\Component\Config\Definition\ConfigurationInterface;
|
||||
|
||||
class Configuration implements ConfigurationInterface
|
||||
{
|
||||
public function getConfigTreeBuilder(): TreeBuilder
|
||||
{
|
||||
$treeBuilder = new TreeBuilder('pcm_icon');
|
||||
|
||||
$treeBuilder->getRootNode()
|
||||
->children()
|
||||
->arrayNode('directories')
|
||||
->scalarPrototype()
|
||||
->end()
|
||||
->end()
|
||||
->arrayNode('palletes')->variablePrototype()->end()
|
||||
|
||||
->end()
|
||||
->end()
|
||||
;
|
||||
|
||||
return $treeBuilder;
|
||||
}
|
||||
}
|
||||
32
src/DependencyInjection/PcmIconExtension.php
Normal file
32
src/DependencyInjection/PcmIconExtension.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pcm\IconBundle\DependencyInjection;
|
||||
|
||||
use Pcm\IconBundle\DependencyInjection\Configuration;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Extension\Extension;
|
||||
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
|
||||
|
||||
class PcmIconExtension extends Extension
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function load(array $configs, ContainerBuilder $container): void
|
||||
{
|
||||
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../../config'));
|
||||
$loader->load('services.yaml');
|
||||
|
||||
$configuration = new Configuration();
|
||||
$config = $this->processConfiguration($configuration, $configs);
|
||||
|
||||
$definition = $container->getDefinition('pcm_icon.icon_extension');
|
||||
|
||||
$definition->replaceArgument('$directories', $config['directories']);
|
||||
$definition->replaceArgument('$palletes', $config['palletes']);
|
||||
dump($configs);
|
||||
}
|
||||
}
|
||||
@@ -4,16 +4,21 @@ declare(strict_types=1);
|
||||
|
||||
namespace Pcm\IconBundle;
|
||||
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Pcm\IconBundle\DependencyInjection\PcmIconExtension;
|
||||
use Symfony\Component\Config\Definition\Configurator\DefinitionConfigurator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
|
||||
use Symfony\Component\HttpKernel\Bundle\AbstractBundle;
|
||||
|
||||
class PcmIconBundle extends AbstractBundle {
|
||||
public function loadExtension(array $config, ContainerConfigurator $container, ContainerBuilder $builder): void
|
||||
class PcmIconBundle extends AbstractBundle
|
||||
{
|
||||
public function getContainerExtension(): ?ExtensionInterface
|
||||
{
|
||||
$loader = new YamlFileLoader($builder, new FileLocator(__DIR__.'/../config/'));
|
||||
$loader->load('services.yml');
|
||||
if (null === $this->extension) {
|
||||
$this->extension = new PcmIconExtension();
|
||||
}
|
||||
|
||||
return $this->extension;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,9 @@ final class IconExtension extends AbstractExtension
|
||||
'size' => self::DEFAULT_SIZE
|
||||
];
|
||||
|
||||
public function __construct(private array $directories) {}
|
||||
public function __construct(private array $directories, private array $palletes) {
|
||||
dump($this->directories);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
|
||||
@@ -5,11 +5,10 @@ declare(strict_types=1);
|
||||
namespace Pcm\IconBundle\Tests;
|
||||
|
||||
use Pcm\IconBundle\PcmIconBundle;
|
||||
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
|
||||
use Symfony\Component\Config\Loader\LoaderInterface;
|
||||
use Symfony\Component\HttpKernel\Kernel;
|
||||
|
||||
class AppKernel extends Kernel
|
||||
class TestKernel extends Kernel
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
@@ -17,7 +16,6 @@ class AppKernel extends Kernel
|
||||
public function registerBundles(): array
|
||||
{
|
||||
return [
|
||||
new FrameworkBundle(),
|
||||
new PcmIconBundle()
|
||||
];
|
||||
}
|
||||
@@ -27,6 +25,6 @@ class AppKernel extends Kernel
|
||||
*/
|
||||
public function registerContainerConfiguration(LoaderInterface $loader): void
|
||||
{
|
||||
$loader->load(__DIR__.'/services_'.$this->getEnvironment().'.yml');
|
||||
$loader->load(__DIR__.'/../config/packages/pcm_icon.yaml');
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace Pcm\IconBundle\Tests\Twig\Functions;
|
||||
|
||||
use Pcm\IconBundle\Tests\AppKernel;
|
||||
use Pcm\IconBundle\DependencyInjection\PcmIconExtension;
|
||||
use Pcm\IconBundle\Tests\TestKernel;
|
||||
use Pcm\IconBundle\Twig\Functions\IconExtension;
|
||||
use Pcm\IconBundle\Twig\Functions\IconNotFound;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
@@ -20,7 +21,7 @@ class IconExtensionTest extends TestCase
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$kernel = new AppKernel('test', false);
|
||||
$kernel = new TestKernel('test', true);
|
||||
$kernel->boot();
|
||||
$this->icon = $kernel->getContainer()->get('pcm_icon.icon_extension');
|
||||
}
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
# This config is only here to stop a deprecation notice for Symfony 7
|
||||
framework:
|
||||
http_method_override: false
|
||||
|
||||
services:
|
||||
pcm_icon.icon_extension:
|
||||
alias: Pcm\IconBundle\Twig\Functions\IconExtension
|
||||
public: true
|
||||
|
||||
Pcm\IconBundle\Twig\Functions\IconExtension:
|
||||
arguments:
|
||||
$directories:
|
||||
- '%kernel.project_dir%/tests/icons'
|
||||
Reference in New Issue
Block a user