Skip to content

Commit

Permalink
Fix Hateoas annotation driver dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
loic425 committed Apr 26, 2024
1 parent 33a7971 commit 934b048
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/Bundle/DependencyInjection/Compiler/HateoasPass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler;

use Sylius\Resource\Hateas\Configuration\Metadata\Driver\ExtensionDriver;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

final class HateoasPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container): void
{
if (
$container->hasDefinition('annotation_reader') ||
!$container->hasDefinition('hateoas.configuration.metadata.annotation_driver')
) {
return;
}

$container->removeDefinition('hateoas.configuration.metadata.annotation_driver');

$this->decorateExtensionDriver($container);
}

private function decorateExtensionDriver(ContainerBuilder $container): void
{
$container
->register('sylius.hateoas_configuration.metadata.extension_driver', ExtensionDriver::class)
->setDecoratedService('hateoas.configuration.metadata.extension_driver')
->setPublic(false);
}
}
2 changes: 2 additions & 0 deletions src/Bundle/SyliusResourceBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\CsrfTokenManagerPass;
use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\DoctrineContainerRepositoryFactoryPass;
use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\DoctrineTargetEntitiesResolverPass;
use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\HateoasPass;
use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\Helper\TargetEntitiesResolver;
use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\PagerfantaBridgePass;
use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\RegisterFormBuilderPass;
Expand Down Expand Up @@ -58,6 +59,7 @@ public function build(ContainerBuilder $container): void
$container->addCompilerPass(new RegisterResourceStateMachinePass());
$container->addCompilerPass(new TwigPass());
$container->addCompilerPass(new WinzouStateMachinePass());
$container->addCompilerPass(new HateoasPass());

$container->registerExtension(new PagerfantaExtension(true));
$container->addCompilerPass(new PagerfantaBridgePass(true), PassConfig::TYPE_BEFORE_OPTIMIZATION, -1); // Should run after all passes from BabDevPagerfantaBundle
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\Resource\Hateas\Configuration\Metadata\Driver;

use Metadata\ClassMetadata;
use Metadata\Driver\DriverInterface;

final class ExtensionDriver implements DriverInterface
{
public function loadMetadataForClass(\ReflectionClass $class): ?ClassMetadata
{
return null;
}
}

0 comments on commit 934b048

Please sign in to comment.