-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
75 additions
and
5 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
packages/web-twig/src/DependencyInjection/SpiritWebTwigExtension.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Lmc\SpiritWebTwigBundle\DependencyInjection; | ||
|
||
use Symfony\Component\Config\FileLocator; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Loader; | ||
use Symfony\Component\HttpKernel\DependencyInjection\Extension; | ||
|
||
/** | ||
* This is the class that loads and manages your bundle configuration | ||
* | ||
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html} | ||
*/ | ||
class SpiritWebTwigExtension extends Extension | ||
{ | ||
public const PARAMETER_PATH = 'spirit_web_twig.path'; | ||
|
||
public const PARAMETER_PATH_ALIAS = 'spirit_web_twig.path_alias'; | ||
|
||
public function load(array $configs, ContainerBuilder $container): void | ||
{ | ||
$configuration = new Configuration(); | ||
$config = $this->processConfiguration($configuration, $configs); | ||
|
||
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); | ||
$loader->load('services.yml'); | ||
|
||
$container->setParameter(self::PARAMETER_PATH, $config['path']); | ||
$container->setParameter(self::PARAMETER_PATH_ALIAS, $config['path_alias']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
packages/web-twig/tests/DependencyInjection/SpiritWebTwigExtensionTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Lmc\SpiritWebTwigBundle\DependencyInjection; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
class SpiritWebTwigExtensionTest extends TestCase | ||
{ | ||
private ContainerBuilder $containerBuilder; | ||
|
||
protected function setUp(): void | ||
{ | ||
$config = [ | ||
'path' => 'templates/', | ||
'path_alias' => 'ui-components', | ||
]; | ||
|
||
$this->loadExtension([$config]); | ||
} | ||
|
||
private function loadExtension(array $configs): void | ||
{ | ||
$extension = new SpiritWebTwigExtension(); | ||
$this->containerBuilder = new ContainerBuilder(); | ||
$this->containerBuilder->registerExtension($extension); | ||
|
||
$extension->load($configs, $this->containerBuilder); | ||
} | ||
|
||
public function testShouldRegisterParameters(): void | ||
{ | ||
$this->assertTrue($this->containerBuilder->hasParameter('spirit_web_twig.path')); | ||
$this->assertTrue($this->containerBuilder->hasParameter('spirit_web_twig.path_alias')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters