Skip to content

Commit d18a2d2

Browse files
committed
Move Symfony DI config from XML to PHP format
1 parent af2ee3a commit d18a2d2

File tree

8 files changed

+143
-88
lines changed

8 files changed

+143
-88
lines changed

.github/workflows/code_checks.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on: ["push", "pull_request"]
66
jobs:
77
js-tests:
88
name: "JS Tests"
9-
runs-on: ubuntu-20.04
9+
runs-on: ubuntu-22.04
1010
steps:
1111
- name: Checkout
1212
uses: actions/checkout@v3
@@ -20,7 +20,7 @@ jobs:
2020
cd Resources && npm run test
2121
phpunit:
2222
name: "PHP ${{ matrix.php }} + ${{ matrix.dependencies }} dependencies + Symfony ${{ matrix.symfony }}"
23-
runs-on: ubuntu-20.04
23+
runs-on: ubuntu-22.04
2424
strategy:
2525
fail-fast: false
2626
matrix:

DependencyInjection/FOSJsRoutingExtension.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\DependencyInjection\Alias;
1919
use Symfony\Component\DependencyInjection\ContainerBuilder;
2020
use Symfony\Component\DependencyInjection\Extension\Extension;
21+
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
2122
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
2223

2324
/**
@@ -31,14 +32,14 @@ public function load(array $configs, ContainerBuilder $container): void
3132
$configuration = new Configuration();
3233
$config = $processor->processConfiguration($configuration, $configs);
3334

34-
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
35-
$loader->load('services.xml');
36-
$loader->load('controllers.xml');
35+
$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
36+
$loader->load('services.php');
37+
$loader->load('controllers.php');
3738

3839
if (isset($config['serializer'])) {
3940
$container->setAlias('fos_js_routing.serializer', new Alias($config['serializer'], false));
4041
} else {
41-
$loader->load('serializer.xml');
42+
$loader->load('serializer.php');
4243
}
4344

4445
$container->setAlias(

Resources/config/controllers.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the FOSJsRoutingBundle package.
7+
*
8+
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
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+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
15+
16+
use FOS\JsRoutingBundle\Controller\Controller;
17+
18+
return static function (ContainerConfigurator $containerConfigurator): void {
19+
$containerConfigurator->parameters()
20+
->set('fos_js_routing.controller.class', Controller::class);
21+
22+
$containerConfigurator->services()
23+
->set('fos_js_routing.controller', '%fos_js_routing.controller.class%')
24+
->public()
25+
->args([
26+
service('fos_js_routing.routes_response'),
27+
service('fos_js_routing.serializer'),
28+
service('fos_js_routing.extractor'),
29+
param('fos_js_routing.cache_control'),
30+
param('kernel.debug'),
31+
]);
32+
};

Resources/config/controllers.xml

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

Resources/config/serializer.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the FOSJsRoutingBundle package.
7+
*
8+
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
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+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
15+
16+
use FOS\JsRoutingBundle\Serializer\Denormalizer\RouteCollectionDenormalizer;
17+
use FOS\JsRoutingBundle\Serializer\Normalizer\RouteCollectionNormalizer;
18+
use FOS\JsRoutingBundle\Serializer\Normalizer\RoutesResponseNormalizer;
19+
use Symfony\Component\Serializer\Encoder\JsonEncoder;
20+
use Symfony\Component\Serializer\Serializer;
21+
22+
return static function (ContainerConfigurator $containerConfigurator): void {
23+
$containerConfigurator->parameters()
24+
->set('fos_js_routing.normalizer.route_collection.class', RouteCollectionNormalizer::class)
25+
->set('fos_js_routing.normalizer.routes_response.class', RoutesResponseNormalizer::class)
26+
->set('fos_js_routing.denormalizer.route_collection.class', RouteCollectionDenormalizer::class);
27+
28+
$containerConfigurator->services()
29+
->set('fos_js_routing.serializer', Serializer::class)
30+
->public()
31+
->args([
32+
[
33+
service('fos_js_routing.normalizer.route_collection'),
34+
service('fos_js_routing.normalizer.routes_response'),
35+
service('fos_js_routing.denormalizer.route_collection'),
36+
],
37+
[
38+
'json' => service('fos_js_routing.encoder'),
39+
],
40+
])
41+
42+
->set('fos_js_routing.normalizer.route_collection', '%fos_js_routing.normalizer.route_collection.class%')
43+
44+
->set('fos_js_routing.normalizer.routes_response', '%fos_js_routing.normalizer.routes_response.class%')
45+
46+
->set('fos_js_routing.denormalizer.route_collection', '%fos_js_routing.denormalizer.route_collection.class%')
47+
48+
->set('fos_js_routing.encoder', JsonEncoder::class);
49+
};

Resources/config/serializer.xml

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

Resources/config/services.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the FOSJsRoutingBundle package.
7+
*
8+
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
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+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
15+
16+
use FOS\JsRoutingBundle\Command\DumpCommand;
17+
use FOS\JsRoutingBundle\Command\RouterDebugExposedCommand;
18+
use FOS\JsRoutingBundle\Extractor\ExposedRoutesExtractor;
19+
use FOS\JsRoutingBundle\Response\RoutesResponse;
20+
21+
return static function (ContainerConfigurator $containerConfigurator): void {
22+
$containerConfigurator->parameters()
23+
->set('fos_js_routing.extractor.class', ExposedRoutesExtractor::class)
24+
->set('fos_js_routing.routes_response.class', RoutesResponse::class);
25+
26+
$containerConfigurator->services()
27+
->set('fos_js_routing.extractor', '%fos_js_routing.extractor.class%')
28+
->public()
29+
->args([
30+
service('fos_js_routing.router'),
31+
abstract_arg('routes to expose'),
32+
param('kernel.cache_dir'),
33+
param('kernel.bundles'),
34+
])
35+
36+
->set('fos_js_routing.routes_response', '%fos_js_routing.routes_response.class%')
37+
->public()
38+
39+
->set('fos_js_routing.dump_command', DumpCommand::class)
40+
->tag('console.command')
41+
->args([
42+
service('fos_js_routing.routes_response'),
43+
service('fos_js_routing.extractor'),
44+
service('fos_js_routing.serializer'),
45+
param('kernel.project_dir'),
46+
param('fos_js_routing.request_context_base_url'),
47+
])
48+
49+
->set('fos_js_routing.router_debug_exposed_command', RouterDebugExposedCommand::class)
50+
->tag('console.command')
51+
->args([
52+
service('fos_js_routing.extractor'),
53+
service('router'),
54+
]);
55+
};

Resources/config/services.xml

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

0 commit comments

Comments
 (0)