Skip to content

Commit 6270125

Browse files
committed
pedantic #202 Use configuration from PHP instead of YAML (phansys)
This PR was merged into the 3.x branch. Discussion ---------- |Q |A | |--- |---| |Branch |3.x| |Bug fix? |no | |New feature? |no | |BC breaks? |no | |Deprecations?|no | |Tests pass? |yes| |Fixed tickets|n/a| |License |MIT| |Doc PR |n/a| Commits ------- 2c8f1fe Use configuration from PHP instead of YAML
2 parents f244994 + 2c8f1fe commit 6270125

File tree

8 files changed

+239
-90
lines changed

8 files changed

+239
-90
lines changed

DependencyInjection/HackzillaTicketExtension.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,13 @@ public function load(array $configs, ContainerBuilder $container)
3333
$configuration = new Configuration();
3434
$config = $this->processConfiguration($configuration, $configs);
3535

36-
$loader = new Loader\YamlFileLoader($container, new FileLocator(self::bundleDirectory().'/Resources/config'));
37-
$loader->load('services.yml');
36+
$loader = new Loader\PhpFileLoader($container, new FileLocator(self::bundleDirectory().'/Resources/config'));
37+
$loader->load('manager.php');
38+
$loader->load('form_types.php');
39+
$loader->load('event_listener.php');
40+
$loader->load('component.php');
41+
$loader->load('twig.php');
42+
$loader->load('commands.php');
3843

3944
$container->setParameter('hackzilla_ticket.model.user.class', $config['user_class']);
4045
$container->setParameter('hackzilla_ticket.model.ticket.class', $config['ticket_class']);

Resources/config/commands.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of HackzillaTicketBundle package.
7+
*
8+
* (c) Daniel Platt <[email protected]>
9+
*
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
12+
*/
13+
14+
use Hackzilla\Bundle\TicketBundle\Command\AutoClosingCommand;
15+
use Hackzilla\Bundle\TicketBundle\Command\TicketManagerCommand;
16+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
17+
use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator;
18+
19+
return static function (ContainerConfigurator $containerConfigurator): void {
20+
// Use "service" function for creating references to services when dropping support for Symfony 4.4
21+
// Use "param" function for creating references to parameters when dropping support for Symfony 5.1
22+
$containerConfigurator->services()
23+
24+
->set('hackzilla_ticket.command.autoclosing', AutoClosingCommand::class)
25+
->tag('console.command', [
26+
'command' => 'ticket:autoclosing',
27+
])
28+
->args([
29+
null,
30+
new ReferenceConfigurator('hackzilla_ticket.user_manager'),
31+
])
32+
33+
->set('hackzilla_ticket.command.create', TicketManagerCommand::class)
34+
->tag('console.command', [
35+
'command' => 'ticket:create',
36+
])
37+
->args([
38+
null,
39+
new ReferenceConfigurator('hackzilla_ticket.user_manager'),
40+
]);
41+
};

Resources/config/component.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of HackzillaTicketBundle package.
7+
*
8+
* (c) Daniel Platt <[email protected]>
9+
*
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
12+
*/
13+
14+
use Hackzilla\Bundle\TicketBundle\Component\TicketFeatures;
15+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
16+
17+
return static function (ContainerConfigurator $containerConfigurator): void {
18+
// Use "service" function for creating references to services when dropping support for Symfony 4.4
19+
// Use "param" function for creating references to parameters when dropping support for Symfony 5.1
20+
$containerConfigurator->services()
21+
22+
->set('hackzilla_ticket.features', TicketFeatures::class)
23+
->args([
24+
'%hackzilla_ticket.features%',
25+
'%hackzilla_ticket.model.message.class%',
26+
]);
27+
};

Resources/config/event_listener.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of HackzillaTicketBundle package.
7+
*
8+
* (c) Daniel Platt <[email protected]>
9+
*
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
12+
*/
13+
14+
use Hackzilla\Bundle\TicketBundle\EventListener\FileSubscriber;
15+
use Hackzilla\Bundle\TicketBundle\EventListener\UserLoad;
16+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
17+
use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator;
18+
19+
return static function (ContainerConfigurator $containerConfigurator): void {
20+
// Use "service" function for creating references to services when dropping support for Symfony 4.4
21+
// Use "param" function for creating references to parameters when dropping support for Symfony 5.1
22+
$containerConfigurator->services()
23+
24+
->set('hackzilla_ticket.listener', UserLoad::class)
25+
->tag('doctrine.event_listener', [
26+
'event' => 'postLoad',
27+
])
28+
->args([
29+
new ReferenceConfigurator('hackzilla_ticket.user_manager'),
30+
])
31+
32+
->set('hackzilla_ticket.file_upload_subscriber', FileSubscriber::class)
33+
->tag('kernel.event_subscriber');
34+
};

Resources/config/form_types.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of HackzillaTicketBundle package.
7+
*
8+
* (c) Daniel Platt <[email protected]>
9+
*
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
12+
*/
13+
14+
use Hackzilla\Bundle\TicketBundle\Form\Type\TicketMessageType;
15+
use Hackzilla\Bundle\TicketBundle\Form\Type\TicketType;
16+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
17+
use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator;
18+
19+
return static function (ContainerConfigurator $containerConfigurator): void {
20+
// Use "service" function for creating references to services when dropping support for Symfony 4.4
21+
// Use "param" function for creating references to parameters when dropping support for Symfony 5.1
22+
$containerConfigurator->services()
23+
24+
->set('hackzilla_ticket.form.type.ticket', TicketType::class)
25+
->tag('form.type', [
26+
'alias' => 'hackzilla_ticket',
27+
])
28+
->args([
29+
'%hackzilla_ticket.model.ticket.class%',
30+
])
31+
32+
->set('hackzilla_ticket.form.type.ticket_message', TicketMessageType::class)
33+
->tag('form.type', [
34+
'alias' => 'hackzilla_ticket_message',
35+
])
36+
->args([
37+
new ReferenceConfigurator('hackzilla_ticket.user_manager'),
38+
new ReferenceConfigurator('hackzilla_ticket.features'),
39+
'%hackzilla_ticket.model.message.class%',
40+
]);
41+
};

Resources/config/manager.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of HackzillaTicketBundle package.
7+
*
8+
* (c) Daniel Platt <[email protected]>
9+
*
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
12+
*/
13+
14+
use Doctrine\ORM\EntityRepository;
15+
use Hackzilla\Bundle\TicketBundle\Manager\TicketManager;
16+
use Hackzilla\Bundle\TicketBundle\Manager\UserManager;
17+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
18+
use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator;
19+
20+
return static function (ContainerConfigurator $containerConfigurator): void {
21+
// Use "service" function for creating references to services when dropping support for Symfony 4.4
22+
// Use "param" function for creating references to parameters when dropping support for Symfony 5.1
23+
$containerConfigurator->services()
24+
25+
->set('hackzilla_ticket.user_repository', EntityRepository::class)
26+
->factory([
27+
new ReferenceConfigurator('doctrine.orm.entity_manager'),
28+
'getRepository',
29+
])
30+
->args([
31+
'%hackzilla_ticket.model.user.class%',
32+
])
33+
34+
->set('hackzilla_ticket.user_manager', UserManager::class)
35+
->public()
36+
->args([
37+
new ReferenceConfigurator('security.token_storage'),
38+
new ReferenceConfigurator('hackzilla_ticket.user_repository'),
39+
new ReferenceConfigurator('security.authorization_checker'),
40+
])
41+
42+
->set('hackzilla_ticket.ticket_manager', TicketManager::class)
43+
->public()
44+
->args([
45+
'%hackzilla_ticket.model.ticket.class%',
46+
'%hackzilla_ticket.model.message.class%',
47+
])
48+
->call('setObjectManager', [
49+
new ReferenceConfigurator('doctrine.orm.entity_manager'),
50+
])
51+
->call('setTranslator', [
52+
new ReferenceConfigurator('translator'),
53+
]);
54+
};

Resources/config/services.yml

Lines changed: 0 additions & 88 deletions
This file was deleted.

Resources/config/twig.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of HackzillaTicketBundle package.
7+
*
8+
* (c) Daniel Platt <[email protected]>
9+
*
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
12+
*/
13+
14+
use Hackzilla\Bundle\TicketBundle\TwigExtension\TicketFeatureExtension;
15+
use Hackzilla\Bundle\TicketBundle\TwigExtension\TicketGlobalExtension;
16+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
17+
use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator;
18+
19+
return static function (ContainerConfigurator $containerConfigurator): void {
20+
// Use "service" function for creating references to services when dropping support for Symfony 4.4
21+
// Use "param" function for creating references to parameters when dropping support for Symfony 5.1
22+
$containerConfigurator->services()
23+
24+
->set('hackzilla_ticket.component.twig_extension.ticket_features', TicketFeatureExtension::class)
25+
->tag('twig.extension')
26+
->args([
27+
new ReferenceConfigurator('hackzilla_ticket.features'),
28+
])
29+
30+
->set('hackzilla_ticket.component.twig_extension.ticket_global', TicketGlobalExtension::class)
31+
->tag('twig.extension')
32+
->args([
33+
'%hackzilla_ticket.templates%',
34+
]);
35+
};

0 commit comments

Comments
 (0)