Skip to content

Commit

Permalink
Move NijensOpenapiExtension::getSymfonyVersion to NijensOpenapiBundle
Browse files Browse the repository at this point in the history
  • Loading branch information
niels-nijens committed Oct 27, 2023
1 parent 4a4da07 commit f4cfa95
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
21 changes: 2 additions & 19 deletions src/DependencyInjection/NijensOpenapiExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@
use Nijens\OpenapiBundle\ExceptionHandling\EventSubscriber\ProblemExceptionToJsonResponseSubscriber;
use Nijens\OpenapiBundle\ExceptionHandling\EventSubscriber\ThrowableToProblemExceptionSubscriber;
use Nijens\OpenapiBundle\ExceptionHandling\ThrowableToProblemExceptionTransformer;
use Nijens\OpenapiBundle\NijensOpenapiBundle;
use Nijens\OpenapiBundle\Routing\RouteLoader;
use Nijens\OpenapiBundle\Validation\EventSubscriber\RequestValidationSubscriber;
use Nijens\OpenapiBundle\Validation\RequestValidator\RequestParameterValidator;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\HttpKernel\Kernel;

/**
* Loads and manages the bundle configuration and services.
Expand Down Expand Up @@ -64,7 +63,7 @@ public function load(array $configs, ContainerBuilder $container): void
private function loadDeprecatedServices(XmlFileLoader $loader): void
{
$deprecatedServicesFileSuffix = '';
if ($this->getSymfonyVersion() >= 50100) {
if (NijensOpenapiBundle::getSymfonyVersion() >= 50100) {
$deprecatedServicesFileSuffix = '_5.1';
}
$loader->load(sprintf('services_deprecated%s.xml', $deprecatedServicesFileSuffix));
Expand Down Expand Up @@ -109,20 +108,4 @@ private function registerExceptionHandlingConfiguration(array $config, Container
$container->removeDefinition('nijens_openapi.service.exception_json_response_builder');
}
}

private function getSymfonyVersion(): int
{
$kernel = new class('symfony_version', false) extends Kernel {
public function registerBundles(): iterable
{
return [];
}

public function registerContainerConfiguration(LoaderInterface $loader)
{
}
};

return $kernel::VERSION_ID;
}
}
18 changes: 18 additions & 0 deletions src/NijensOpenapiBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@

namespace Nijens\OpenapiBundle;

use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Serializer\DependencyInjection\SerializerPass;

/**
Expand All @@ -30,4 +32,20 @@ public function build(ContainerBuilder $container): void
new SerializerPass('nijens_openapi.serializer', 'nijens_openapi.serializer.normalizer')
);
}

public static function getSymfonyVersion(): int
{
$kernel = new class('symfony_version', false) extends Kernel {
public function registerBundles(): iterable
{
return [];
}

public function registerContainerConfiguration(LoaderInterface $loader): void
{
}
};

return $kernel::VERSION_ID;
}
}

0 comments on commit f4cfa95

Please sign in to comment.