Skip to content

Commit

Permalink
Update syntax to PHP 8.1 and switch to PHP config
Browse files Browse the repository at this point in the history
  • Loading branch information
fre5h authored Jul 28, 2022
1 parent 277adf9 commit bdad46b
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 34 deletions.
6 changes: 1 addition & 5 deletions Command/GenerateDocsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,12 @@
#[AsCommand(name: 'swagger:generate-docs', description: 'Generates swagger docs')]
class GenerateDocsCommand extends Command
{
private readonly Generator $generator;

/**
* @param Generator $generator
*/
public function __construct(Generator $generator)
public function __construct(private readonly Generator $generator)
{
parent::__construct();

$this->generator = $generator;
}

/**
Expand Down
5 changes: 1 addition & 4 deletions Config/ConfigParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,11 @@
*/
class ConfigParser
{
private string $configFolder;

/**
* @param string $configFolder
*/
public function __construct(string $configFolder)
public function __construct(private readonly string $configFolder)
{
$this->configFolder = $configFolder;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions DependencyInjection/SwaggerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

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

$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yaml');
$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.php');
}
}
11 changes: 1 addition & 10 deletions Generator/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,13 @@
*/
class Generator
{
private readonly Environment $twig;

private readonly ConfigParser $configParser;

private readonly string $docsFolder;

/**
* @param Environment $twig
* @param ConfigParser $configParser
* @param string $docsFolder
*/
public function __construct(Environment $twig, ConfigParser $configParser, string $docsFolder)
public function __construct(private readonly Environment $twig, private readonly ConfigParser $configParser, private readonly string $docsFolder)
{
$this->twig = $twig;
$this->configParser = $configParser;
$this->docsFolder = $docsFolder;
}

/**
Expand Down
27 changes: 27 additions & 0 deletions Resources/config/services.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/*
* This file is part of the SwaggerBundle.
*
* (c) Stfalcon LLC <stfalcon.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();

$services
->defaults()
->autowire()
->autoconfigure()
->bind('$configFolder', '%swagger.config_folder%')
->bind('$docsFolder', '%kernel.project_dir%/public/api/')
;

$services->load('StfalconStudio\SwaggerBundle\\', __DIR__.'/../../{Command,Config,Generator}');
};
11 changes: 0 additions & 11 deletions Resources/config/services.yaml

This file was deleted.

8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"require-dev": {
"escapestudios/symfony2-coding-standard": "^3.12",
"phpstan/phpstan": "^1.7.10",
"phpstan/phpstan": "^1.8.2",
"phpstan/phpstan-doctrine": "^1.3",
"phpstan/phpstan-phpunit": "^1.1",
"phpstan/phpstan-symfony": "^1.2",
Expand All @@ -43,5 +43,11 @@
"psr-4": {
"StfalconStudio\\SwaggerBundle\\Tests\\": "Tests/"
}
},
"config": {
"sort-packages": true,
"allow-plugins": {
"symfony/flex": true
}
}
}

0 comments on commit bdad46b

Please sign in to comment.