diff --git a/DependencyInjection/HackzillaTicketExtension.php b/DependencyInjection/HackzillaTicketExtension.php index a9e27910..836f4fa8 100644 --- a/DependencyInjection/HackzillaTicketExtension.php +++ b/DependencyInjection/HackzillaTicketExtension.php @@ -33,8 +33,13 @@ public function load(array $configs, ContainerBuilder $container) $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); - $loader = new Loader\YamlFileLoader($container, new FileLocator(self::bundleDirectory().'/Resources/config')); - $loader->load('services.yml'); + $loader = new Loader\PhpFileLoader($container, new FileLocator(self::bundleDirectory().'/Resources/config')); + $loader->load('manager.php'); + $loader->load('form_types.php'); + $loader->load('event_listener.php'); + $loader->load('component.php'); + $loader->load('twig.php'); + $loader->load('commands.php'); $container->setParameter('hackzilla_ticket.model.user.class', $config['user_class']); $container->setParameter('hackzilla_ticket.model.ticket.class', $config['ticket_class']); diff --git a/Resources/config/commands.php b/Resources/config/commands.php new file mode 100644 index 00000000..332d65c1 --- /dev/null +++ b/Resources/config/commands.php @@ -0,0 +1,41 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Hackzilla\Bundle\TicketBundle\Command\AutoClosingCommand; +use Hackzilla\Bundle\TicketBundle\Command\TicketManagerCommand; +use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; +use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator; + +return static function (ContainerConfigurator $containerConfigurator): void { + // Use "service" function for creating references to services when dropping support for Symfony 4.4 + // Use "param" function for creating references to parameters when dropping support for Symfony 5.1 + $containerConfigurator->services() + + ->set('hackzilla_ticket.command.autoclosing', AutoClosingCommand::class) + ->tag('console.command', [ + 'command' => 'ticket:autoclosing', + ]) + ->args([ + null, + new ReferenceConfigurator('hackzilla_ticket.user_manager'), + ]) + + ->set('hackzilla_ticket.command.create', TicketManagerCommand::class) + ->tag('console.command', [ + 'command' => 'ticket:create', + ]) + ->args([ + null, + new ReferenceConfigurator('hackzilla_ticket.user_manager'), + ]); +}; diff --git a/Resources/config/component.php b/Resources/config/component.php new file mode 100644 index 00000000..fcdb394d --- /dev/null +++ b/Resources/config/component.php @@ -0,0 +1,27 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Hackzilla\Bundle\TicketBundle\Component\TicketFeatures; +use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; + +return static function (ContainerConfigurator $containerConfigurator): void { + // Use "service" function for creating references to services when dropping support for Symfony 4.4 + // Use "param" function for creating references to parameters when dropping support for Symfony 5.1 + $containerConfigurator->services() + + ->set('hackzilla_ticket.features', TicketFeatures::class) + ->args([ + '%hackzilla_ticket.features%', + '%hackzilla_ticket.model.message.class%', + ]); +}; diff --git a/Resources/config/event_listener.php b/Resources/config/event_listener.php new file mode 100644 index 00000000..e4593e01 --- /dev/null +++ b/Resources/config/event_listener.php @@ -0,0 +1,34 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Hackzilla\Bundle\TicketBundle\EventListener\FileSubscriber; +use Hackzilla\Bundle\TicketBundle\EventListener\UserLoad; +use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; +use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator; + +return static function (ContainerConfigurator $containerConfigurator): void { + // Use "service" function for creating references to services when dropping support for Symfony 4.4 + // Use "param" function for creating references to parameters when dropping support for Symfony 5.1 + $containerConfigurator->services() + + ->set('hackzilla_ticket.listener', UserLoad::class) + ->tag('doctrine.event_listener', [ + 'event' => 'postLoad', + ]) + ->args([ + new ReferenceConfigurator('hackzilla_ticket.user_manager'), + ]) + + ->set('hackzilla_ticket.file_upload_subscriber', FileSubscriber::class) + ->tag('kernel.event_subscriber'); +}; diff --git a/Resources/config/form_types.php b/Resources/config/form_types.php new file mode 100644 index 00000000..9d0d3a53 --- /dev/null +++ b/Resources/config/form_types.php @@ -0,0 +1,41 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Hackzilla\Bundle\TicketBundle\Form\Type\TicketMessageType; +use Hackzilla\Bundle\TicketBundle\Form\Type\TicketType; +use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; +use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator; + +return static function (ContainerConfigurator $containerConfigurator): void { + // Use "service" function for creating references to services when dropping support for Symfony 4.4 + // Use "param" function for creating references to parameters when dropping support for Symfony 5.1 + $containerConfigurator->services() + + ->set('hackzilla_ticket.form.type.ticket', TicketType::class) + ->tag('form.type', [ + 'alias' => 'hackzilla_ticket', + ]) + ->args([ + '%hackzilla_ticket.model.ticket.class%', + ]) + + ->set('hackzilla_ticket.form.type.ticket_message', TicketMessageType::class) + ->tag('form.type', [ + 'alias' => 'hackzilla_ticket_message', + ]) + ->args([ + new ReferenceConfigurator('hackzilla_ticket.user_manager'), + new ReferenceConfigurator('hackzilla_ticket.features'), + '%hackzilla_ticket.model.message.class%', + ]); +}; diff --git a/Resources/config/manager.php b/Resources/config/manager.php new file mode 100644 index 00000000..b717b27d --- /dev/null +++ b/Resources/config/manager.php @@ -0,0 +1,54 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Doctrine\ORM\EntityRepository; +use Hackzilla\Bundle\TicketBundle\Manager\TicketManager; +use Hackzilla\Bundle\TicketBundle\Manager\UserManager; +use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; +use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator; + +return static function (ContainerConfigurator $containerConfigurator): void { + // Use "service" function for creating references to services when dropping support for Symfony 4.4 + // Use "param" function for creating references to parameters when dropping support for Symfony 5.1 + $containerConfigurator->services() + + ->set('hackzilla_ticket.user_repository', EntityRepository::class) + ->factory([ + new ReferenceConfigurator('doctrine.orm.entity_manager'), + 'getRepository', + ]) + ->args([ + '%hackzilla_ticket.model.user.class%', + ]) + + ->set('hackzilla_ticket.user_manager', UserManager::class) + ->public() + ->args([ + new ReferenceConfigurator('security.token_storage'), + new ReferenceConfigurator('hackzilla_ticket.user_repository'), + new ReferenceConfigurator('security.authorization_checker'), + ]) + + ->set('hackzilla_ticket.ticket_manager', TicketManager::class) + ->public() + ->args([ + '%hackzilla_ticket.model.ticket.class%', + '%hackzilla_ticket.model.message.class%', + ]) + ->call('setObjectManager', [ + new ReferenceConfigurator('doctrine.orm.entity_manager'), + ]) + ->call('setTranslator', [ + new ReferenceConfigurator('translator'), + ]); +}; diff --git a/Resources/config/services.yml b/Resources/config/services.yml deleted file mode 100644 index c6d97bcf..00000000 --- a/Resources/config/services.yml +++ /dev/null @@ -1,88 +0,0 @@ -services: - hackzilla_ticket.listener: - class: Hackzilla\Bundle\TicketBundle\EventListener\UserLoad - arguments: - - '@hackzilla_ticket.user_manager' - tags: - - { name: doctrine.event_listener, event: postLoad } - - hackzilla_ticket.user_manager: - class: Hackzilla\Bundle\TicketBundle\Manager\UserManager - arguments: - - '@security.token_storage' - - '@hackzilla_ticket.user_repository' - - '@security.authorization_checker' - public: true - - hackzilla_ticket.user_repository: - class: Doctrine\ORM\EntityRepository - factory: ['@doctrine.orm.entity_manager', getRepository] - arguments: - - '%hackzilla_ticket.model.user.class%' - - hackzilla_ticket.ticket_manager: - class: Hackzilla\Bundle\TicketBundle\Manager\TicketManager - arguments: - - '%hackzilla_ticket.model.ticket.class%' - - '%hackzilla_ticket.model.message.class%' - calls: - - [ setObjectManager, ['@doctrine.orm.entity_manager'] ] - - [ setTranslator, ['@translator'] ] - public: true - - hackzilla_ticket.form.type.ticket: - class: Hackzilla\Bundle\TicketBundle\Form\Type\TicketType - arguments: - - '%hackzilla_ticket.model.ticket.class%' - tags: - - { name: form.type, alias: hackzilla_ticket } - - hackzilla_ticket.form.type.ticket_message: - class: Hackzilla\Bundle\TicketBundle\Form\Type\TicketMessageType - arguments: - - '@hackzilla_ticket.user_manager' - - '@hackzilla_ticket.features' - - '%hackzilla_ticket.model.message.class%' - tags: - - { name: form.type, alias: hackzilla_ticket_message } - - hackzilla_ticket.features: - class: Hackzilla\Bundle\TicketBundle\Component\TicketFeatures - arguments: - - '%hackzilla_ticket.features%' - - '%hackzilla_ticket.model.message.class%' - - hackzilla_ticket.component.twig_extension.ticket_features: - class: Hackzilla\Bundle\TicketBundle\TwigExtension\TicketFeatureExtension - arguments: - - '@hackzilla_ticket.features' - tags: - - { name: twig.extension } - - hackzilla_ticket.component.twig_extension.ticket_global: - class: Hackzilla\Bundle\TicketBundle\TwigExtension\TicketGlobalExtension - arguments: - - '%hackzilla_ticket.templates%' - tags: - - { name: twig.extension } - - hackzilla_ticket.file_upload_subscriber: - class: Hackzilla\Bundle\TicketBundle\EventListener\FileSubscriber - tags: - - { name: kernel.event_subscriber } - - hackzilla_ticket.command.autoclosing: - class: Hackzilla\Bundle\TicketBundle\Command\AutoClosingCommand - arguments: - - null - - '@hackzilla_ticket.user_manager' - tags: - - { name: console.command, command: 'ticket:autoclosing' } - - hackzilla_ticket.command.create: - class: Hackzilla\Bundle\TicketBundle\Command\TicketManagerCommand - arguments: - - null - - '@hackzilla_ticket.user_manager' - tags: - - { name: console.command, command: 'ticket:create' } diff --git a/Resources/config/twig.php b/Resources/config/twig.php new file mode 100644 index 00000000..cf0e9209 --- /dev/null +++ b/Resources/config/twig.php @@ -0,0 +1,35 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Hackzilla\Bundle\TicketBundle\TwigExtension\TicketFeatureExtension; +use Hackzilla\Bundle\TicketBundle\TwigExtension\TicketGlobalExtension; +use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; +use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator; + +return static function (ContainerConfigurator $containerConfigurator): void { + // Use "service" function for creating references to services when dropping support for Symfony 4.4 + // Use "param" function for creating references to parameters when dropping support for Symfony 5.1 + $containerConfigurator->services() + + ->set('hackzilla_ticket.component.twig_extension.ticket_features', TicketFeatureExtension::class) + ->tag('twig.extension') + ->args([ + new ReferenceConfigurator('hackzilla_ticket.features'), + ]) + + ->set('hackzilla_ticket.component.twig_extension.ticket_global', TicketGlobalExtension::class) + ->tag('twig.extension') + ->args([ + '%hackzilla_ticket.templates%', + ]); +};