Skip to content

Commit 917bd77

Browse files
committed
Use configuration from PHP instead of YAML
1 parent f244994 commit 917bd77

File tree

3 files changed

+131
-90
lines changed

3 files changed

+131
-90
lines changed

DependencyInjection/HackzillaTicketExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ 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('services.php');
3838

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

Resources/config/services.php

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
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\Command\AutoClosingCommand;
16+
use Hackzilla\Bundle\TicketBundle\Command\TicketManagerCommand;
17+
use Hackzilla\Bundle\TicketBundle\Component\TicketFeatures;
18+
use Hackzilla\Bundle\TicketBundle\EventListener\FileSubscriber;
19+
use Hackzilla\Bundle\TicketBundle\EventListener\UserLoad;
20+
use Hackzilla\Bundle\TicketBundle\Form\Type\TicketMessageType;
21+
use Hackzilla\Bundle\TicketBundle\Form\Type\TicketType;
22+
use Hackzilla\Bundle\TicketBundle\Manager\TicketManager;
23+
use Hackzilla\Bundle\TicketBundle\Manager\UserManager;
24+
use Hackzilla\Bundle\TicketBundle\TwigExtension\TicketFeatureExtension;
25+
use Hackzilla\Bundle\TicketBundle\TwigExtension\TicketGlobalExtension;
26+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
27+
use function Symfony\Component\DependencyInjection\Loader\Configurator\param;
28+
use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator;
29+
30+
return static function (ContainerConfigurator $containerConfigurator): void {
31+
// Use "service" function for creating references to services when dropping support for Symfony 4.4
32+
// Use "param" function for creating references to parameters when dropping support for Symfony 5.1
33+
$containerConfigurator->services()
34+
35+
->set('hackzilla_ticket.user_repository', EntityRepository::class)
36+
->factory([
37+
new ReferenceConfigurator('doctrine.orm.entity_manager'),
38+
'getRepository',
39+
])
40+
->args([
41+
param('hackzilla_ticket.model.user.class'),
42+
])
43+
44+
->set('hackzilla_ticket.user_manager', UserManager::class)
45+
->public()
46+
->args([
47+
new ReferenceConfigurator('security.token_storage'),
48+
new ReferenceConfigurator('hackzilla_ticket.user_repository'),
49+
new ReferenceConfigurator('security.authorization_checker'),
50+
])
51+
52+
->set('hackzilla_ticket.ticket_manager', TicketManager::class)
53+
->public()
54+
->args([
55+
param('hackzilla_ticket.model.ticket.class'),
56+
param('hackzilla_ticket.model.message.class'),
57+
])
58+
->call('setObjectManager', [
59+
new ReferenceConfigurator('doctrine.orm.entity_manager'),
60+
])
61+
->call('setTranslator', [
62+
new ReferenceConfigurator('translator'),
63+
])
64+
65+
->set('hackzilla_ticket.listener', UserLoad::class)
66+
->tag('doctrine.event_listener', [
67+
'event' => 'postLoad',
68+
])
69+
->args([
70+
new ReferenceConfigurator('hackzilla_ticket.user_manager'),
71+
])
72+
73+
->set('hackzilla_ticket.features', TicketFeatures::class)
74+
->args([
75+
param('hackzilla_ticket.features'),
76+
param('hackzilla_ticket.model.message.class'),
77+
])
78+
79+
->set('hackzilla_ticket.form.type.ticket', TicketType::class)
80+
->tag('form.type', [
81+
'alias' => 'hackzilla_ticket',
82+
])
83+
->args([
84+
param('hackzilla_ticket.model.ticket.class'),
85+
])
86+
87+
->set('hackzilla_ticket.form.type.ticket_message', TicketMessageType::class)
88+
->tag('form.type', [
89+
'alias' => 'hackzilla_ticket_message',
90+
])
91+
->args([
92+
new ReferenceConfigurator('hackzilla_ticket.user_manager'),
93+
new ReferenceConfigurator('hackzilla_ticket.features'),
94+
param('hackzilla_ticket.model.message.class'),
95+
])
96+
97+
->set('hackzilla_ticket.component.twig_extension.ticket_features', TicketFeatureExtension::class)
98+
->tag('twig.extension')
99+
->args([
100+
new ReferenceConfigurator('hackzilla_ticket.features'),
101+
])
102+
103+
->set('hackzilla_ticket.component.twig_extension.ticket_global', TicketGlobalExtension::class)
104+
->tag('twig.extension')
105+
->args([
106+
param('hackzilla_ticket.templates'),
107+
])
108+
109+
->set('hackzilla_ticket.file_upload_subscriber', FileSubscriber::class)
110+
->tag('kernel.event_subscriber')
111+
112+
->set('hackzilla_ticket.command.autoclosing', AutoClosingCommand::class)
113+
->tag('console.command', [
114+
'command' => 'ticket:autoclosing',
115+
])
116+
->args([
117+
null,
118+
new ReferenceConfigurator('hackzilla_ticket.user_manager'),
119+
])
120+
121+
->set('hackzilla_ticket.command.create', TicketManagerCommand::class)
122+
->tag('console.command', [
123+
'command' => 'ticket:create',
124+
])
125+
->args([
126+
null,
127+
new ReferenceConfigurator('hackzilla_ticket.user_manager'),
128+
]);
129+
};

Resources/config/services.yml

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

0 commit comments

Comments
 (0)