Код: Выделить всё
my.service.image:
class: My\Service\ImageService
arguments: ["@service_container"]
< /code>
Каким -то образом я хотел бы указать допустимое количество размеров изображений. Я рассмотрел использование тегов, но я не уверен, уместны ли они в этой ситуации. В идеальном мире я, вероятно, хочу получить что-то, что выглядит так: < /p>
my.service.image:
class: My\Service\ImageService
arguments: ["@service_container"]
sizes:
- { name: small, width: 100, height: 100 }
- { name: medium, width: 100, height: 100 }
- { name: large, width: 100, height: 100 }
Я использовал теги для реализации различных размеров: < /p>
Код: Выделить всё
my.service.image:
class: My\Service\ImageService
arguments: ["@service_container"]
tags:
- { name: my.service.image.size, alias: small, width: 100, height: 100 }
- { name: my.service.image.size, alias: medium, width: 200, height: 200 }
- { name: my.service.image.size, alias: large, width: 300, height: 300 }
< /code>
Пытаясь следовать документации поваренной книги, я закончил создать класс *CompilerPass в моем пакете: < /p>
namespace My\Bundle\MyImageBundle\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Reference;
class ImageServiceSizeCompilerPass implements CompilerPassInterface {
public function process( ContainerBuilder $container )
{
$definition = $container->get(
'my.service.image'
);
$taggedServices = $container->findTaggedServiceIds(
'my.service.image.size'
);
foreach( $taggedServices as $defintion => $attributes )
{
foreach( $attributes as $attribute )
{
$definition->addSize( $attribute['alias'], $attribute['width'], $attribute['height'] );
}
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/183 ... ustom-tags
Мобильная версия