Add start of IconExtension class

This commit is contained in:
Brabli
2022-07-23 19:53:26 +01:00
parent ae5c5fbf71
commit b5b51132f3
5 changed files with 67 additions and 10 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "pcm/bundle-name", "name": "pcm/icon-bundle",
"description": "bundle description", "description": "Twig icon bundle",
"type": "symfony-bundle", "type": "symfony-bundle",
"license": "MIT", "license": "MIT",
@@ -19,7 +19,8 @@
"symfony/dependency-injection": "^6.1", "symfony/dependency-injection": "^6.1",
"symfony/framework-bundle": "^6.1", "symfony/framework-bundle": "^6.1",
"symfony/yaml": "^6.1", "symfony/yaml": "^6.1",
"symfony/http-client": "^6.1" "symfony/http-client": "^6.1",
"symfony/twig-bundle": "^6.1"
}, },
"require-dev": { "require-dev": {
@@ -29,13 +30,13 @@
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"Pcm\\GeocodeBundle\\": "src/" "Pcm\\IconBundle\\": "src/"
} }
}, },
"autoload-dev": { "autoload-dev": {
"psr-4": { "psr-4": {
"Pcm\\GeocodeBundle\\Tests\\": "tests/" "Pcm\\IconBundle\\Tests\\": "tests/"
} }
} }
} }

View File

@@ -3,8 +3,12 @@ services:
autowire: true autowire: true
autoconfigure: true autoconfigure: true
pcm_example.example_service: pcm_icon.icon_extension:
alias: Pcm\ExampleBundle\Service\ExampleService alias: Pcm\IconBundle\Twig\Functions\IconExtension
public: true public: true
Pcm\ExampleBundle\Service\ExampleService: ~ Pcm\IconBundle\Twig\Functions\IconExtension:
public: false
arguments:
# $dir:
# - '%kernel.project_dir%/public/icons'

View File

@@ -2,7 +2,7 @@
declare(strict_types=1); declare(strict_types=1);
namespace Pcm\ExampleBundle; namespace Pcm\IconBundle;
use Symfony\Component\Config\FileLocator; use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -10,7 +10,7 @@ use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigura
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\HttpKernel\Bundle\AbstractBundle; use Symfony\Component\HttpKernel\Bundle\AbstractBundle;
class PcmExampleBundle extends AbstractBundle { class PcmIconBundle extends AbstractBundle {
public function loadExtension(array $config, ContainerConfigurator $container, ContainerBuilder $builder): void public function loadExtension(array $config, ContainerConfigurator $container, ContainerBuilder $builder): void
{ {
$loader = new YamlFileLoader($builder, new FileLocator(__DIR__.'/../config/')); $loader = new YamlFileLoader($builder, new FileLocator(__DIR__.'/../config/'));

View File

@@ -0,0 +1,25 @@
<?php
declare(strict_types=1);
namespace Pcm\IconBundle\Twig\Functions;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
final class IconExtension extends AbstractExtension
{
/**
* @inheritDoc
*/
public function getFunctions(): array
{
return [
new TwigFunction('icon', [$this, 'render'], [
'is_safe' => ['html']
])
];
}
}

View File

@@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
namespace Pcm\IconBundle\Tests\Twig\Functions;
use Pcm\IconBundle\Twig\Functions\IconExtension;
use PHPUnit\Framework\TestCase;
class IconExtensionTest extends TestCase
{
/**
* @var IconExtension
*/
private IconExtension $icon;
protected function setUp(): void
{
$this->icon = new IconExtension();
}
public function testInstanceOf(): void
{
$this->assertInstanceOf(IconExtension::class, $this->icon);
}
}