Skip to content

Use configuration from PHP instead of YAML #202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions DependencyInjection/HackzillaTicketExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down
41 changes: 41 additions & 0 deletions Resources/config/commands.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

/*
* This file is part of HackzillaTicketBundle package.
*
* (c) Daniel Platt <github@ofdan.co.uk>
*
* 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'),
]);
};
27 changes: 27 additions & 0 deletions Resources/config/component.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

/*
* This file is part of HackzillaTicketBundle package.
*
* (c) Daniel Platt <github@ofdan.co.uk>
*
* 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%',
]);
};
34 changes: 34 additions & 0 deletions Resources/config/event_listener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

/*
* This file is part of HackzillaTicketBundle package.
*
* (c) Daniel Platt <github@ofdan.co.uk>
*
* 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');
};
41 changes: 41 additions & 0 deletions Resources/config/form_types.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

/*
* This file is part of HackzillaTicketBundle package.
*
* (c) Daniel Platt <github@ofdan.co.uk>
*
* 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%',
]);
};
54 changes: 54 additions & 0 deletions Resources/config/manager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

declare(strict_types=1);

/*
* This file is part of HackzillaTicketBundle package.
*
* (c) Daniel Platt <github@ofdan.co.uk>
*
* 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'),
]);
};
88 changes: 0 additions & 88 deletions Resources/config/services.yml

This file was deleted.

35 changes: 35 additions & 0 deletions Resources/config/twig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

/*
* This file is part of HackzillaTicketBundle package.
*
* (c) Daniel Platt <github@ofdan.co.uk>
*
* 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%',
]);
};