diff --git a/README.md b/README.md index d5679ad..b51ed5d 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,8 @@ return [ Create Symfony Health Check Bundle Config: ---------------------------------- +> **Note:** XML configuration is no longer supported. Please use YAML or PHP configuration format in your project. + Configurating health check - all available you can see [here](https://github.com/MacPaw/symfony-health-check-bundle/tree/master/src/Check). ```yaml @@ -74,7 +76,7 @@ Create Symfony Health Check Bundle Routing Config: ```yaml health_check: - resource: '@SymfonyHealthCheckBundle/Resources/config/routes.xml' + resource: '@SymfonyHealthCheckBundle/Resources/config/routes.php' ``` Step 3: Configuration diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon deleted file mode 100644 index 16cab88..0000000 --- a/phpstan-baseline.neon +++ /dev/null @@ -1,10 +0,0 @@ -parameters: - ignoreErrors: - - - message: '#Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\NodeParentInterface::variableNode\(\).#' - count: 1 - path: ./src/DependencyInjection - - - message: '#Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\TreeBuilder::root\(\).#' - count: 1 - path: ./src/DependencyInjection diff --git a/phpstan.neon b/phpstan.neon index bc0f2c3..91e6453 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,6 +1,3 @@ -includes: - - phpstan-baseline.neon - parameters: level: 5 paths: diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index e97982d..5418520 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -15,9 +15,10 @@ public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('symfony_health_check'); - /** @var ArrayNodeDefinition $root */ + /** @var ArrayNodeDefinition $root */ $root = method_exists(TreeBuilder::class, 'getRootNode') ? $treeBuilder->getRootNode() + // @phpstan-ignore-next-line - BC layer for Symfony <4.2 : $treeBuilder->root('symfony_health_check'); $root diff --git a/src/DependencyInjection/SymfonyHealthCheckExtension.php b/src/DependencyInjection/SymfonyHealthCheckExtension.php index 43657af..82c4796 100644 --- a/src/DependencyInjection/SymfonyHealthCheckExtension.php +++ b/src/DependencyInjection/SymfonyHealthCheckExtension.php @@ -9,7 +9,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\Extension\Extension; -use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; +use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; use SymfonyHealthCheckBundle\Controller\HealthController; use SymfonyHealthCheckBundle\Controller\PingController; @@ -20,8 +20,8 @@ public function load(array $configs, ContainerBuilder $container): void $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); - $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); - $loader->load('controller.xml'); + $loader = new PhpFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); + $loader->load('controller.php'); $this->loadHealthChecks($config, $loader, $container); @@ -31,10 +31,10 @@ public function load(array $configs, ContainerBuilder $container): void private function loadHealthChecks( array $config, - XmlFileLoader $loader, + PhpFileLoader $loader, ContainerBuilder $container ): void { - $loader->load('health_checks.xml'); + $loader->load('health_checks.php'); $healthCheckCollection = $container->findDefinition(HealthController::class); diff --git a/src/Resources/config/controller.php b/src/Resources/config/controller.php new file mode 100644 index 0000000..61affb1 --- /dev/null +++ b/src/Resources/config/controller.php @@ -0,0 +1,25 @@ +services(); + $parameters = $container->parameters(); + + $services->defaults() + ->autowire() + ->autoconfigure(); + + $services->set(HealthController::class, HealthController::class) + ->public() + ->tag('container.service_subscriber'); + + $services->set(PingController::class, PingController::class) + ->public() + ->tag('container.service_subscriber'); +}; diff --git a/src/Resources/config/controller.xml b/src/Resources/config/controller.xml deleted file mode 100644 index 6607053..0000000 --- a/src/Resources/config/controller.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - diff --git a/src/Resources/config/health_checks.php b/src/Resources/config/health_checks.php new file mode 100644 index 0000000..48a418d --- /dev/null +++ b/src/Resources/config/health_checks.php @@ -0,0 +1,47 @@ +services(); + $parameters = $container->parameters(); + + $services->defaults() + ->public() + ->autowire() + ->autoconfigure(); + + $services->set('symfony_health_check.redis_adapter_wrapper', RedisAdapterWrapper::class) + ->private(); + + $services->set('symfony_health_check.doctrine_check', DoctrineORMCheck::class) + ->args([service('service_container')]) + ->deprecate( + 'macpaw/symfony-health-check-bundle', + '1.4.2', + 'The "%service_id%" service alias is deprecated, use symfony_health_check.doctrine_orm_check instead' + ); + + $services->set('symfony_health_check.doctrine_orm_check', DoctrineORMCheck::class) + ->args([service('service_container')]); + + $services->set('symfony_health_check.doctrine_odm_check', DoctrineODMCheck::class) + ->args([service('service_container')]); + + $services->set('symfony_health_check.redis_check', RedisCheck::class) + ->args([service('symfony_health_check.redis_adapter_wrapper')]); + + $services->set('symfony_health_check.environment_check', EnvironmentCheck::class) + ->args([service('service_container')]); + + $services->set('symfony_health_check.status_up_check', StatusUpCheck::class); +}; diff --git a/src/Resources/config/health_checks.xml b/src/Resources/config/health_checks.xml deleted file mode 100644 index b950e8a..0000000 --- a/src/Resources/config/health_checks.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - The "%service_id%" service alias is deprecated, use symfony_health_check.doctrine_orm_check instead - - - - - - - - - - - - - - - - diff --git a/src/Resources/config/routes.php b/src/Resources/config/routes.php new file mode 100644 index 0000000..444cc59 --- /dev/null +++ b/src/Resources/config/routes.php @@ -0,0 +1,19 @@ +add('health', '/health') + ->controller([HealthController::class, 'check']) + ->methods(['GET']); + + $routes->add('ping', '/ping') + ->controller([PingController::class, 'check']) + ->methods(['GET']); +}; diff --git a/src/Resources/config/routes.xml b/src/Resources/config/routes.xml deleted file mode 100644 index 2eede32..0000000 --- a/src/Resources/config/routes.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - diff --git a/tests/config.yml b/tests/config.yml index 71f2dbd..41a6b51 100644 --- a/tests/config.yml +++ b/tests/config.yml @@ -1,5 +1,5 @@ framework: secret: secret router: - resource: "%kernel.project_dir%/Resources/config/routes.xml" + resource: "%kernel.project_dir%/Resources/config/routes.php" test: ~