From 397df95cb2ccc48ff92d4bcd5ca6caebc71dab17 Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Mon, 15 Oct 2018 17:14:38 -0600 Subject: [PATCH 1/4] Allow abstract factory for custom hydrator --- src/Service/DoctrineHydratorFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Service/DoctrineHydratorFactory.php b/src/Service/DoctrineHydratorFactory.php index 1dc003f..11fc9c1 100644 --- a/src/Service/DoctrineHydratorFactory.php +++ b/src/Service/DoctrineHydratorFactory.php @@ -142,7 +142,7 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o } if ($useCustomHydrator) { - $extractService = $container->get($config['hydrator']); + $extractService = $container->build($config['hydrator'], $config); $hydrateService = $extractService; } From 73aee759f4689067733bc5e3a41282893ad718cd Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Mon, 15 Oct 2018 20:40:41 -0600 Subject: [PATCH 2/4] Use build then get for custom hydrator --- src/Service/DoctrineHydratorFactory.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Service/DoctrineHydratorFactory.php b/src/Service/DoctrineHydratorFactory.php index 11fc9c1..10e80f5 100644 --- a/src/Service/DoctrineHydratorFactory.php +++ b/src/Service/DoctrineHydratorFactory.php @@ -142,7 +142,12 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o } if ($useCustomHydrator) { - $extractService = $container->build($config['hydrator'], $config); + try { + $extractService = $container->build($config['hydrator'], $config); + } catch (ServiceNotFoundException $e) { + $extractService = $container->get($config['hydrator']); + } + $hydrateService = $extractService; } From 29e2a2ea7037af22ba115b55e780ece0b8f7b6a3 Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Tue, 16 Oct 2018 12:30:42 -0600 Subject: [PATCH 3/4] New test for using build() to create custom hydrator --- .../Hydrator/CustomBuildHydratorFactory.php | 18 +++++++++++++++++ .../Service/DoctrineHydratorFactoryTest.php | 20 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 test/src/Hydrator/CustomBuildHydratorFactory.php diff --git a/test/src/Hydrator/CustomBuildHydratorFactory.php b/test/src/Hydrator/CustomBuildHydratorFactory.php new file mode 100644 index 0000000..4a0bb17 --- /dev/null +++ b/test/src/Hydrator/CustomBuildHydratorFactory.php @@ -0,0 +1,18 @@ +assertInstanceOf('Zend\Hydrator\ArraySerializable', $hydrator->getExtractService()); } + /** + * @test + */ + public function it_should_be_possible_to_configure_a_custom_hydrator_as_factory() + { + $this->serviceConfig['doctrine-hydrator']['custom-hydrator']['hydrator'] = 'custom.build.hydrator'; + $this->serviceManager->setService('config', $this->serviceConfig); + + $this->serviceManager->setFactory( + 'custom.build.hydrator', + new CustomBuildHydratorFactory() + ); + + $hydrator = $this->createOrmHydrator(); + + $this->assertInstanceOf('Zend\Hydrator\ArraySerializable', $hydrator->getHydrateService()); + $this->assertInstanceOf('Zend\Hydrator\ArraySerializable', $hydrator->getExtractService()); + } + /** * @test */ From 69f399f6b4d949b6dc48228ab65aac7bc544bae4 Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Tue, 16 Oct 2018 12:51:40 -0600 Subject: [PATCH 4/4] ServiceManager::build was not stable until 3.3.2. Remove legacy support for ServiceManager 2.x. Up ServiceManager minimum version to 3.3.2 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 107ef9a..d4b8303 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "require": { "php": "^5.6 || ^7.0", "doctrine/common": "^2.6.1", - "zendframework/zend-servicemanager": "^2.7.6 || ^3.1", + "zendframework/zend-servicemanager": "^3.3.2", "zendframework/zend-hydrator": "^1.1 || ^2.2.1", "zendframework/zend-modulemanager": "^2.7.2", "api-skeletons/zf-doctrine-module-zend-hydrator": "^1.0",