Skip to content

Commit bdad46b

Browse files
authored
Update syntax to PHP 8.1 and switch to PHP config
1 parent 277adf9 commit bdad46b

File tree

7 files changed

+40
-34
lines changed

7 files changed

+40
-34
lines changed

Command/GenerateDocsCommand.php

+1-5
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,12 @@
2424
#[AsCommand(name: 'swagger:generate-docs', description: 'Generates swagger docs')]
2525
class GenerateDocsCommand extends Command
2626
{
27-
private readonly Generator $generator;
28-
2927
/**
3028
* @param Generator $generator
3129
*/
32-
public function __construct(Generator $generator)
30+
public function __construct(private readonly Generator $generator)
3331
{
3432
parent::__construct();
35-
36-
$this->generator = $generator;
3733
}
3834

3935
/**

Config/ConfigParser.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,11 @@
2121
*/
2222
class ConfigParser
2323
{
24-
private string $configFolder;
25-
2624
/**
2725
* @param string $configFolder
2826
*/
29-
public function __construct(string $configFolder)
27+
public function __construct(private readonly string $configFolder)
3028
{
31-
$this->configFolder = $configFolder;
3229
}
3330

3431
/**

DependencyInjection/SwaggerExtension.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
use Symfony\Component\Config\FileLocator;
1616
use Symfony\Component\DependencyInjection\ContainerBuilder;
17-
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
17+
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
1818
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
1919

2020
/**
@@ -31,7 +31,7 @@ public function load(array $configs, ContainerBuilder $container): void
3131
$config = $this->processConfiguration($configuration, $configs);
3232
$container->setParameter('swagger.config_folder', $config['config_folder']);
3333

34-
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
35-
$loader->load('services.yaml');
34+
$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
35+
$loader->load('services.php');
3636
}
3737
}

Generator/Generator.php

+1-10
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,13 @@
2121
*/
2222
class Generator
2323
{
24-
private readonly Environment $twig;
25-
26-
private readonly ConfigParser $configParser;
27-
28-
private readonly string $docsFolder;
29-
3024
/**
3125
* @param Environment $twig
3226
* @param ConfigParser $configParser
3327
* @param string $docsFolder
3428
*/
35-
public function __construct(Environment $twig, ConfigParser $configParser, string $docsFolder)
29+
public function __construct(private readonly Environment $twig, private readonly ConfigParser $configParser, private readonly string $docsFolder)
3630
{
37-
$this->twig = $twig;
38-
$this->configParser = $configParser;
39-
$this->docsFolder = $docsFolder;
4031
}
4132

4233
/**

Resources/config/services.php

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/*
3+
* This file is part of the SwaggerBundle.
4+
*
5+
* (c) Stfalcon LLC <stfalcon.com>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
declare(strict_types=1);
12+
13+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
14+
15+
return static function (ContainerConfigurator $containerConfigurator): void {
16+
$services = $containerConfigurator->services();
17+
18+
$services
19+
->defaults()
20+
->autowire()
21+
->autoconfigure()
22+
->bind('$configFolder', '%swagger.config_folder%')
23+
->bind('$docsFolder', '%kernel.project_dir%/public/api/')
24+
;
25+
26+
$services->load('StfalconStudio\SwaggerBundle\\', __DIR__.'/../../{Command,Config,Generator}');
27+
};

Resources/config/services.yaml

-11
This file was deleted.

composer.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
},
2525
"require-dev": {
2626
"escapestudios/symfony2-coding-standard": "^3.12",
27-
"phpstan/phpstan": "^1.7.10",
27+
"phpstan/phpstan": "^1.8.2",
2828
"phpstan/phpstan-doctrine": "^1.3",
2929
"phpstan/phpstan-phpunit": "^1.1",
3030
"phpstan/phpstan-symfony": "^1.2",
@@ -43,5 +43,11 @@
4343
"psr-4": {
4444
"StfalconStudio\\SwaggerBundle\\Tests\\": "Tests/"
4545
}
46+
},
47+
"config": {
48+
"sort-packages": true,
49+
"allow-plugins": {
50+
"symfony/flex": true
51+
}
4652
}
4753
}

0 commit comments

Comments
 (0)