Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jan 8, 2020. It is now read-only.
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
12 changes: 10 additions & 2 deletions library/Zend/ServiceManager/Di/DiAbstractServiceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,18 @@ public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $
*/
public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
{
return $this->instanceManager->hasSharedInstance($requestedName)
if ($this->instanceManager->hasSharedInstance($requestedName)
|| $this->instanceManager->hasAlias($requestedName)
|| $this->instanceManager->hasConfig($requestedName)
|| $this->instanceManager->hasTypePreferences($requestedName)
|| $this->definitions->hasClass($requestedName);
) {
return true;
}

if (! $this->definitions->hasClass($requestedName) || interface_exists($requestedName)) {
return false;
}

return true;
}
}
44 changes: 44 additions & 0 deletions tests/ZendTest/Mvc/Service/TranslatorServiceFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
namespace ZendTest\Mvc\Service;

use PHPUnit_Framework_TestCase as TestCase;
use Zend\Mvc\Service\RoutePluginManagerFactory;
use Zend\Mvc\Service\ServiceManagerConfig;
use Zend\Mvc\Service\TranslatorServiceFactory;
use Zend\ServiceManager\ServiceManager;

Expand Down Expand Up @@ -74,6 +76,48 @@ public function testReturnsTranslatorBasedOnConfigurationWhenNoTranslatorInterfa
);
}

public function testReturnsTranslatorBasedOnConfigurationWhenNoTranslatorInterfaceServicePresentWithMinimumBootstrap()
{
if (!extension_loaded('intl')) {
$this->markTestSkipped('This test will only run if ext/intl is present');
}

//minimum bootstrap
$applicationConfig = array(
'module_listener_options' => array(),
'modules' => array(),
);
$serviceLocator = new ServiceManager(new ServiceManagerConfig());
$serviceLocator->setService('ApplicationConfig', $applicationConfig);
$serviceLocator->get('ModuleManager')->loadModules();
$serviceLocator->get('Application')->bootstrap();

//enable to re-write Config
$ref = new \ReflectionObject($serviceLocator);
$prop = $ref->getProperty('allowOverride');
$prop->setAccessible(true);
$prop->setValue($serviceLocator, true);

$config = array(
'di' => array(),
'translator' => array(
'locale' => 'en_US',
),
);

$serviceLocator->setService('Config', $config);

//#5959
//get any plugins with AbstractPluginManagerFactory
$routePluginManagerFactory = new RoutePluginManagerFactory;
$routePluginManager = $routePluginManagerFactory->createService($serviceLocator);

$translator = $this->factory->createService($serviceLocator);
$this->assertInstanceOf('Zend\Mvc\I18n\Translator', $translator);
$this->assertInstanceOf('Zend\I18n\Translator\Translator', $translator->getTranslator());

}

/**
* @depends testReturnsTranslatorBasedOnConfigurationWhenNoTranslatorInterfaceServicePresent
*/
Expand Down