Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Better zend-servicemanager <-> zend-di integration deprecation #159

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"php": "^5.5 || ^7.0",
"zendframework/zend-eventmanager": "^2.6.2 || ^3.0",
"zendframework/zend-servicemanager": "^2.7.5 || ^3.0.3",
"zendframework/zend-servicemanager-di": "^1.0.1",
"zendframework/zend-hydrator": "^1.1 || ^2.1",
"zendframework/zend-form": "^2.7",
"zendframework/zend-stdlib": "^2.7.5 || ^3.0",
Expand All @@ -42,7 +41,7 @@
"zendframework/zend-validator": "^2.6",
"zendframework/zend-version": "^2.5",
"zendframework/zend-view": "^2.6.3",
"fabpot/php-cs-fixer": "1.7.*",
"friendsofphp/php-cs-fixer": "1.7.*",
"phpunit/PHPUnit": "^4.5",
"sebastian/version": "^1.0.4"
},
Expand All @@ -59,6 +58,7 @@
"zendframework/zend-log": "Zend\\Log component",
"zendframework/zend-modulemanager": "Zend\\ModuleManager component",
"zendframework/zend-serializer": "Zend\\Serializer component",
"zendframework/zend-servicemanager-di": "^1.0.1, if using zend-servicemanager v3 and requiring the zend-di integration",
"zendframework/zend-session": "Zend\\Session component for FlashMessenger, PRG, and FPRG plugins",
"zendframework/zend-text": "Zend\\Text component",
"zendframework/zend-uri": "Zend\\Uri component",
Expand Down
257 changes: 103 additions & 154 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 50 additions & 7 deletions src/Service/DiAbstractServiceFactoryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,60 @@

namespace Zend\Mvc\Service;

use Zend\ServiceManager\Di\DiAbstractServiceFactoryFactory as OriginalFactory;
use Interop\Container\ContainerInterface;
use Zend\Mvc\Exception;
use Zend\ServiceManager\Di\DiAbstractServiceFactory;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\ServiceManager\ServiceManager;

/**
* Since 2.7.9, this class now extends the version defined in zend-servicemanager-di,
* ensuring backwards compatibility with zend-servicemanger v2 and forwards
* compatibility with zend-servicemanager v3.
*
* @deprecated Since 2.7.9. The factory is now defined in zend-servicemanager-di,
* and removed in 3.0.0. Use Zend\ServiceManager\Di\DiAbstractServiceFactoryFactory
* from zend-servicemanager-di instead if you rely on this feature.
* from zend-servicemanager-di if you are using zend-servicemanager v3, and/or when
* ready to migrate to zend-mvc 3.0.
*/
class DiAbstractServiceFactoryFactory extends OriginalFactory
class DiAbstractServiceFactoryFactory implements FactoryInterface
{
/**
* Class responsible for instantiating a DiAbstractServiceFactory
*
* @param ContainerInterface $container
* @param string $name
* @param null|array $options
* @return DiAbstractServiceFactory
* @throws Exception\RuntimeException if zend-servicemanager v3 is in use.
*/
public function __invoke(ContainerInterface $container, $name, array $options = null)
{
if (! class_exists(DiAbstractServiceFactory::class)) {
throw new Exception\RuntimeException(sprintf(
"%s is not compatible with zend-servicemanager v3, which you are currently using. \n"
. "Please run 'composer require zendframework/zend-servicemanager-di', and then update\n"
. "your configuration to use Zend\ServiceManager\Di\DiAbstractServiceFactoryFactory instead.",
__CLASS__
));
}

$factory = new DiAbstractServiceFactory($container->get('Di'), DiAbstractServiceFactory::USE_SL_BEFORE_DI);

if ($container instanceof ServiceManager) {
$container->addAbstractFactory($factory, false);
}

return $factory;
}

/**
* Create and return DiAbstractServiceFactory instance
*
* For use with zend-servicemanager v2; proxies to __invoke().
*
* @param ServiceLocatorInterface $container
* @return DiAbstractServiceFactory
*/
public function createService(ServiceLocatorInterface $container)
{
return $this($container, DiAbstractServiceFactory::class);
}
}
Loading