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

Notice: Undefined variable: serviceLocator #149

Closed
wants to merge 3 commits into from
Closed
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
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"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",
"zendframework/zend-hydrator": "^1.1 || ^2.1",
"zendframework/zend-form": "^2.7",
"zendframework/zend-stdlib": "^2.7.5 || ^3.0",
Expand Down
256 changes: 154 additions & 102 deletions composer.lock

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

43 changes: 5 additions & 38 deletions src/Service/DiAbstractServiceFactoryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,10 @@

namespace Zend\Mvc\Service;

use Interop\Container\ContainerInterface;
use Zend\ServiceManager\Di\DiAbstractServiceFactory;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\ServiceManager\ServiceManager;

class DiAbstractServiceFactoryFactory implements FactoryInterface
/**
* @deprecated please use the {@see \Zend\ServiceManager\Di\DiAbstractServiceFactoryFactory} class instead:
* this class will be removed in release 3.0
*/
class DiAbstractServiceFactoryFactory extends \Zend\ServiceManager\Di\DiAbstractServiceFactoryFactory
{
/**
* Class responsible for instantiating a DiAbstractServiceFactory
*
* @param ContainerInterface $container
* @param string $name
* @param null|array $options
* @return DiAbstractServiceFactory
*/
public function __invoke(ContainerInterface $container, $name, array $options = null)
{
$factory = new DiAbstractServiceFactory($container->get('Di'), DiAbstractServiceFactory::USE_SL_BEFORE_DI);

if ($serviceLocator instanceof ServiceManager) {
$serviceLocator->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);
}
}
38 changes: 38 additions & 0 deletions test/Service/DiAbstractServiceFactoryFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
namespace ZendTest\Mvc\Service;

use Zend\Mvc\Service\DiAbstractServiceFactoryFactory;
use Zend\Mvc\Service\DiFactory;
use Zend\ServiceManager\Di\DiAbstractServiceFactory;
use Zend\ServiceManager\ServiceManager;

class DiAbstractServiceFactoryFactoryTest extends \PHPUnit_Framework_TestCase
{
public function testWillInitializeDiAbstractServiceFactory()
{
$serviceManager = new ServiceManager();
$serviceManager->setService('config', ['di' => ['']]);
$serviceManager->setFactory('Di', new DiFactory());
$serviceManager->setFactory(DiAbstractServiceFactoryFactory::class, new DiAbstractServiceFactoryFactory());

$factory = $serviceManager->get(DiAbstractServiceFactoryFactory::class);
$this->assertInstanceOf(DiAbstractServiceFactory::class, $factory);
}

public function testDiAbstractServiceFactoryIsAddedToAbstractFactoriesOfServiceManager()
{
$serviceManager = $this->getMockBuilder(ServiceManager::class)
->setMethods(['addAbstractFactory'])
->getMock();

$serviceManager->expects($this->once())->method('addAbstractFactory')->with($this->callback(function ($param) {
return $param instanceof DiAbstractServiceFactory;
}));

$serviceManager->setService('config', ['di' => ['']]);
$serviceManager->setFactory('Di', new DiFactory());
$serviceManager->setFactory(DiAbstractServiceFactoryFactory::class, new DiAbstractServiceFactoryFactory());

$serviceManager->get(DiAbstractServiceFactoryFactory::class);
}
}