diff --git a/composer.json b/composer.json index 77cb5c17e..112398e5b 100644 --- a/composer.json +++ b/composer.json @@ -44,6 +44,7 @@ "require-dev": { "akeneo/phpspec-skip-example-extension": "^4.0", "doctrine/orm": "^2.5", + "gedmo/doctrine-extensions": "^2.4", "lakion/api-test-case": "^3.1.0", "matthiasnoback/symfony-dependency-injection-test": "^3.0", "phpspec/phpspec": "^5.0", diff --git a/src/Bundle/Doctrine/ResourceMappingDriver.php b/src/Bundle/Doctrine/ResourceMappingDriverChain.php similarity index 75% rename from src/Bundle/Doctrine/ResourceMappingDriver.php rename to src/Bundle/Doctrine/ResourceMappingDriverChain.php index 716c6d5cf..20a5d2549 100644 --- a/src/Bundle/Doctrine/ResourceMappingDriver.php +++ b/src/Bundle/Doctrine/ResourceMappingDriverChain.php @@ -15,39 +15,33 @@ use Doctrine\Common\Persistence\Mapping\ClassMetadata; use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver; +use Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain; use Sylius\Component\Resource\Metadata\RegistryInterface; -final class ResourceMappingDriver implements MappingDriver +/** + * It needs to extend MappingDriverChain in order to be compatible with Gedmo/DoctrineExtensions. + * + * @see \Gedmo\Mapping\ExtensionMetadataFactory::getDriver() + */ +final class ResourceMappingDriverChain extends MappingDriverChain { - /** @var MappingDriver */ - private $mappingDriver; - /** @var RegistryInterface */ private $resourceRegistry; public function __construct(MappingDriver $mappingDriver, RegistryInterface $resourceRegistry) { - $this->mappingDriver = $mappingDriver; $this->resourceRegistry = $resourceRegistry; + + $this->setDefaultDriver($mappingDriver); } public function loadMetadataForClass($className, ClassMetadata $metadata): void { - $this->mappingDriver->loadMetadataForClass($className, $metadata); + parent::loadMetadataForClass($className, $metadata); $this->convertResourceMappedSuperclass($metadata); } - public function getAllClassNames(): iterable - { - return $this->mappingDriver->getAllClassNames(); - } - - public function isTransient($className): bool - { - return $this->mappingDriver->isTransient($className); - } - private function convertResourceMappedSuperclass(ClassMetadata $metadata): void { if (!isset($metadata->isMappedSuperclass)) { diff --git a/src/Bundle/Resources/config/services/integrations/doctrine.xml b/src/Bundle/Resources/config/services/integrations/doctrine.xml index d4d7225f4..9838e57eb 100644 --- a/src/Bundle/Resources/config/services/integrations/doctrine.xml +++ b/src/Bundle/Resources/config/services/integrations/doctrine.xml @@ -15,10 +15,10 @@ - - + diff --git a/src/Bundle/test/app/AppKernel.php b/src/Bundle/test/app/AppKernel.php index ba1e1fb54..a4317407e 100644 --- a/src/Bundle/test/app/AppKernel.php +++ b/src/Bundle/test/app/AppKernel.php @@ -40,6 +40,7 @@ public function registerBundles() new Bazinga\Bundle\HateoasBundle\BazingaHateoasBundle(), new Symfony\Bundle\TwigBundle\TwigBundle(), new \winzou\Bundle\StateMachineBundle\winzouStateMachineBundle(), + new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(), new Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundle(), new Nelmio\Alice\Bridge\Symfony\NelmioAliceBundle(), new AppBundle\AppBundle(), diff --git a/src/Bundle/test/app/config/config.yml b/src/Bundle/test/app/config/config.yml index 2e0dece28..4af2f0bd7 100644 --- a/src/Bundle/test/app/config/config.yml +++ b/src/Bundle/test/app/config/config.yml @@ -42,6 +42,12 @@ fos_rest: rules: - { path: '^/', priorities: ['json'], fallback_format: json, prefer_extension: true } +stof_doctrine_extensions: + default_locale: "%locale%" + orm: + default: + sortable: true + services: test.translation_locale_provider: class: Sylius\Component\Resource\Translation\Provider\ImmutableTranslationLocaleProvider diff --git a/src/Bundle/test/app/config/resources.yml b/src/Bundle/test/app/config/resources.yml index ed0edf7f1..80a70e9b5 100644 --- a/src/Bundle/test/app/config/resources.yml +++ b/src/Bundle/test/app/config/resources.yml @@ -17,3 +17,7 @@ sylius_resource: app.comic_book: classes: model: AppBundle\Entity\ComicBook + + app.gedmo: + classes: + model: AppBundle\Entity\GedmoExtendedExample diff --git a/src/Bundle/test/app/config/routing.yml b/src/Bundle/test/app/config/routing.yml index 8e02a099b..628312bf5 100644 --- a/src/Bundle/test/app/config/routing.yml +++ b/src/Bundle/test/app/config/routing.yml @@ -3,6 +3,11 @@ app_book: alias: app.book type: sylius.resource_api +app_gedmo: + resource: | + alias: app.gedmo + type: sylius.resource_api + app_book_sortable_index: path: /sortable-books/ methods: [GET] diff --git a/src/Bundle/test/src/AppBundle/Entity/GedmoBaseExample.php b/src/Bundle/test/src/AppBundle/Entity/GedmoBaseExample.php new file mode 100644 index 000000000..5caed336c --- /dev/null +++ b/src/Bundle/test/src/AppBundle/Entity/GedmoBaseExample.php @@ -0,0 +1,40 @@ +id; + } + + public function getPosition(): ?int + { + return $this->position; + } + + public function setPosition(?int $position): void + { + $this->position = $position; + } +} diff --git a/src/Bundle/test/src/AppBundle/Entity/GedmoExtendedExample.php b/src/Bundle/test/src/AppBundle/Entity/GedmoExtendedExample.php new file mode 100644 index 000000000..22396f9c0 --- /dev/null +++ b/src/Bundle/test/src/AppBundle/Entity/GedmoExtendedExample.php @@ -0,0 +1,30 @@ +extra; + } + + public function setExtra(?string $extra): void + { + $this->extra = $extra; + } +} diff --git a/src/Bundle/test/src/AppBundle/Resources/config/doctrine/GedmoBaseExample.orm.yml b/src/Bundle/test/src/AppBundle/Resources/config/doctrine/GedmoBaseExample.orm.yml new file mode 100644 index 000000000..76956f3ae --- /dev/null +++ b/src/Bundle/test/src/AppBundle/Resources/config/doctrine/GedmoBaseExample.orm.yml @@ -0,0 +1,14 @@ +AppBundle\Entity\GedmoBaseExample: + type: mappedSuperclass + table: gedmo + id: + id: + type: integer + id: true + generator: + strategy: AUTO + fields: + position: + type: integer + gedmo: + - sortablePosition diff --git a/src/Bundle/test/src/AppBundle/Resources/config/doctrine/GedmoExtendedExample.orm.yml b/src/Bundle/test/src/AppBundle/Resources/config/doctrine/GedmoExtendedExample.orm.yml new file mode 100644 index 000000000..d4d866fbc --- /dev/null +++ b/src/Bundle/test/src/AppBundle/Resources/config/doctrine/GedmoExtendedExample.orm.yml @@ -0,0 +1,6 @@ +AppBundle\Entity\GedmoExtendedExample: + type: mappedSuperclass + table: gedmo + fields: + extra: + type: string diff --git a/src/Bundle/test/src/Tests/Controller/GedmoApiTest.php b/src/Bundle/test/src/Tests/Controller/GedmoApiTest.php new file mode 100644 index 000000000..917b83a46 --- /dev/null +++ b/src/Bundle/test/src/Tests/Controller/GedmoApiTest.php @@ -0,0 +1,45 @@ +client->request('POST', '/gedmos/', [], [], ['CONTENT_TYPE' => 'application/json'], $data); + $response = $this->client->getResponse(); + $this->assertResponse($response, 'gedmos/create_response', Response::HTTP_CREATED); + } +} diff --git a/src/Bundle/test/src/Tests/Responses/Expected/gedmos/create_response.json b/src/Bundle/test/src/Tests/Responses/Expected/gedmos/create_response.json new file mode 100644 index 000000000..e5a797c8d --- /dev/null +++ b/src/Bundle/test/src/Tests/Responses/Expected/gedmos/create_response.json @@ -0,0 +1,5 @@ +{ + "id": @integer@, + "position": 0, + "extra": "Some info" +}