本文整理汇总了PHP中Zend\ServiceManager\ServiceManager::setInvokableClass方法的典型用法代码示例。如果您正苦于以下问题:PHP ServiceManager::setInvokableClass方法的具体用法?PHP ServiceManager::setInvokableClass怎么用?PHP ServiceManager::setInvokableClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\ServiceManager\ServiceManager
的用法示例。
在下文中一共展示了ServiceManager::setInvokableClass方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
public function setUp()
{
$adapter = new ArrayAdapter();
$adapter->setOptions(['dummyOption' => 'dummyValue']);
$this->sm = new ServiceManager();
$this->sm->setInvokableClass('custom', Adapter\NullAdapter::class);
$this->sm->setService('Config', ['stakhanovist' => ['queues' => ['queueA' => ['name' => 'A', 'adapter' => ['adapter' => 'array', 'options' => ['dummyOption' => 'dummyValue']], 'options' => ['messageClass' => ZendMessage::class]], 'queueB' => ['name' => 'B', 'adapter' => $adapter, 'options' => ['messageClass' => ZendMessage::class]], 'queueC' => ['name' => 'C', 'adapter' => 'custom', 'options' => ['messageClass' => ZendMessage::class]]]]]);
$this->sm->addAbstractFactory(QueueAbstractServiceFactory::class);
}
示例2: setUp
public function setUp()
{
$loaderFactory = new ControllerLoaderFactory();
$config = new ArrayObject(array('di' => array()));
$this->services = new ServiceManager();
$this->services->setService('Zend\\ServiceManager\\ServiceLocatorInterface', $this->services);
$this->services->setFactory('ControllerLoader', $loaderFactory);
$this->services->setService('Config', $config);
$this->services->setFactory('ControllerPluginManager', new ControllerPluginManagerFactory());
$this->services->setFactory('Di', new DiFactory());
$this->services->setFactory('EventManager', new EventManagerFactory());
$this->services->setInvokableClass('SharedEventManager', 'Zend\\EventManager\\SharedEventManager');
}
示例3: testWillGetListenerFromServiceLocator
public function testWillGetListenerFromServiceLocator()
{
$this->services->setInvokableClass('TestListener', 'SynrgTest\\Twilio\\Controller\\TestAsset\\Listener');
$this->services->setAllowOverride(true);
$this->services->setService('Config', array('synrg-twilio' => array('TestController' => array('listener' => 'TestListener'))));
$controller = $this->controllers->get('TestController');
$this->assertInstanceOf('Synrg\\Twilio\\Controller\\TwilioController', $controller);
$responder = $controller->getResponder();
$events = $responder->getEventManager();
$expected = array('SynrgTest\\Twilio\\Controller\\TestAsset\\Listener', 'Synrg\\Twilio\\Responder\\Responder');
$identifiers = $events->getIdentifiers();
$this->assertEquals(array_values($expected), array_values($identifiers));
}
示例4: testGet
public function testGet()
{
// Via container
$this->container->foo = [];
$this->assertEquals([], $this->container->get('foo'));
// Via service manager
$this->sm->setService('foo', new \stdClass());
$this->sm->setAlias('bar', 'foo');
$this->assertInstanceOf('stdClass', $this->container->get('bar'));
$this->sm->setFactory('factory', function (ServiceManager $sm) {
return $sm->get('bar');
});
$this->assertInstanceOf('stdClass', $this->container->get('factory'));
$this->sm->setInvokableClass('invokable', 'stdClass');
$this->assertInstanceOf('stdClass', $this->container->get('invokable'));
}
示例5: testIdentityFactoryCanInjectAuthenticationServiceIfInParentServiceManager
public function testIdentityFactoryCanInjectAuthenticationServiceIfInParentServiceManager()
{
$services = new ServiceManager();
$services->setInvokableClass('Zend\Authentication\AuthenticationService', 'Zend\Authentication\AuthenticationService');
$this->helpers->setServiceLocator($services);
$identity = $this->helpers->get('identity');
$expected = $services->get('Zend\Authentication\AuthenticationService');
$this->assertSame($expected, $identity->getAuthenticationService());
}
示例6: configureServiceManager
/**
* Configure the provided service manager instance with the configuration
* in this class.
*
* In addition to using each of the internal properties to configure the
* service manager, also adds an initializer to inject ServiceManagerAware
* classes with the service manager.
*
* @param ServiceManager $serviceManager
* @return void
*/
public function configureServiceManager(ServiceManager $serviceManager)
{
foreach ($this->invokables as $name => $service) {
$serviceManager->setInvokableClass($name, $service);
}
$factories = $this->getFactories();
foreach ($factories as $name => $factory) {
$serviceManager->setFactory($name, $factory);
}
}
示例7: testInstantiatesHalJsonRenderer
public function testInstantiatesHalJsonRenderer()
{
$services = new ServiceManager();
$viewHelperManager = $this->getMockBuilder('Zend\\View\\HelperPluginManager')->disableOriginalConstructor()->getMock();
$services->setService('ViewHelperManager', $viewHelperManager);
$services->setInvokableClass(ApiProblemRenderer::class, ApiProblemRenderer::class);
$factory = new HalJsonRendererFactory();
$renderer = $factory($services, 'ZF\\Hal\\JsonRenderer');
$this->assertInstanceOf('ZF\\Hal\\View\\HalJsonRenderer', $renderer);
}
示例8: testWillInstantiateFromFQCN
public function testWillInstantiateFromFQCN()
{
$name = 'testFactory';
$factory = new StorageFactory($name);
$objectManager = $this->getMock('Doctrine\\Common\\Persistence\\ObjectManager');
$serviceManager = new ServiceManager();
$serviceManager->setInvokableClass('DoctrineModule\\Authentication\\Storage\\Session', 'Zend\\Authentication\\Storage\\Session');
$serviceManager->setService('Configuration', array('doctrine' => array('authentication' => array($name => array('objectManager' => $objectManager, 'identityClass' => 'DoctrineModuleTest\\Authentication\\Adapter\\TestAsset\\IdentityObject', 'identityProperty' => 'username', 'credentialProperty' => 'password')))));
$adapter = $factory->createService($serviceManager);
$this->assertInstanceOf('DoctrineModule\\Authentication\\Storage\\ObjectRepository', $adapter);
}
示例9: testMultipleDelegatorFactoriesWhenNotRegisteredAsServices
/**
* @covers Zend\ServiceManager\ServiceManager::create
* @covers Zend\ServiceManager\ServiceManager::createDelegatorFromFactory
* @covers Zend\ServiceManager\ServiceManager::createDelegatorCallback
* @covers Zend\ServiceManager\ServiceManager::addDelegator
*/
public function testMultipleDelegatorFactoriesWhenNotRegisteredAsServices()
{
$fooDelegator = new MockSelfReturningDelegatorFactory();
$barDelegator = new MockSelfReturningDelegatorFactory();
$this->serviceManager->addDelegator('foo-service', $fooDelegator);
$this->serviceManager->addDelegator('foo-service', $barDelegator);
$this->serviceManager->setInvokableClass('foo-service', 'stdClass');
$this->assertSame($barDelegator, $this->serviceManager->create('foo-service'));
$this->assertCount(1, $barDelegator->instances);
$this->assertCount(1, $fooDelegator->instances);
$this->assertInstanceOf('stdClass', array_shift($fooDelegator->instances));
$this->assertSame($fooDelegator, array_shift($barDelegator->instances));
}
示例10: testAutoGenerateAndEvaluateProxies
public function testAutoGenerateAndEvaluateProxies()
{
$serviceManager = new ServiceManager();
$namespace = 'ZendTestProxy' . uniqid();
$serviceManager->setService('Config', array('lazy_services' => array('class_map' => array('foo' => __CLASS__), 'proxies_namespace' => $namespace)));
$serviceManager->setFactory('foo-delegator', 'Zend\\ServiceManager\\Proxy\\LazyServiceFactoryFactory');
$serviceManager->setInvokableClass('foo', __CLASS__);
$serviceManager->addDelegator('foo', 'foo-delegator');
/* @var $proxy self|\ProxyManager\Proxy\ValueHolderInterface|\ProxyManager\Proxy\LazyLoadingInterface */
$proxy = $serviceManager->create('foo');
$proxyClassName = get_class($proxy);
$this->assertInstanceOf('ProxyManager\\Proxy\\LazyLoadingInterface', $proxy);
$this->assertInstanceOf(__CLASS__, $proxy);
$this->assertStringMatchesFormat($namespace . '\\__PM__\\ZendTest\\ServiceManager\\Proxy\\LazyServiceFactoryFactoryTest%s', $proxyClassName);
$this->assertFileNotExists(sys_get_temp_dir() . '/' . str_replace('\\', '', $proxyClassName) . '.php');
$this->assertFalse($proxy->isProxyInitialized());
$this->assertEquals($this->invalidConfigProvider(), $proxy->invalidConfigProvider());
$this->assertTrue($proxy->isProxyInitialized());
}
示例11: buildDirectoryApi
/**
* Generates a list of Action objects based on the given directory structure, handling
* each found class as an invokable service
*
* @deprecated this logic is deprecated and uses per-directory scanning. Instead, please
* map your defined service names in the 'services' config
* @param array $modules
* @return array
* @throws InvalidArgumentException
*/
protected function buildDirectoryApi(array $modules)
{
$api = array();
foreach ($modules as $moduleName => $module) {
if (!isset($module['directory']) || !is_dir($module['directory'])) {
throw new InvalidArgumentException('Invalid directory given: "' . $module['directory'] . '"');
}
if (!isset($module['namespace']) || !is_string($module['namespace'])) {
throw new InvalidArgumentException('Invalid namespace provided for module "' . $moduleName . '"');
}
$jsNamespace = rtrim(str_replace('\\', '.', $module['namespace']), '.') . '.';
$directoryScanner = new DirectoryScanner($module['directory']);
/* @var $class \Zend\Code\Scanner\DerivedClassScanner */
foreach ($directoryScanner->getClasses(true) as $class) {
// now building the service name as exposed client-side
$className = $class->getName();
$jsClassName = str_replace('\\', '.', substr($className, strlen($module['namespace']) + 1));
$jsClassNames = explode('.', $jsClassName);
$chunks = count($jsClassNames);
// lcfirst all chunks except the last one
for ($i = 1; $i < $chunks; $i += 1) {
$jsClassNames[$i - 1] = lcfirst($jsClassNames[$i - 1]);
}
$serviceName = $jsNamespace . implode('.', $jsClassNames);
if (!$this->serviceManager->has($serviceName)) {
$this->serviceManager->setInvokableClass($serviceName, $className);
}
// invoking to check if nothing went wrong - this avoids setting invalid services
$service = $this->serviceManager->get($serviceName);
$action = $this->buildAction(get_class($service));
$action->setName($serviceName);
$action->setObjectName($className);
$api[$serviceName] = $action;
}
}
return $api;
}
示例12: createServiceManager
public function createServiceManager(array $config)
{
// create ServiceManager
$serviceManager = new ServiceManager();
// set an initializer for ServiceLocatorAwareInterface
$serviceManager->addInitializer(function ($instance, ServiceLocatorInterface $serviceLocator) {
if ($instance instanceof ServiceLocatorAwareInterface) {
$instance->setServiceLocator($serviceLocator);
}
});
// add $serviceManger to the config keys so we can configure it
$this->configKeys = ['service_manager' => $serviceManager] + $this->configKeys;
// add the pluginManagers to the ServiceManager
foreach ($this->pluginManagers as $key => $className) {
$serviceManager->setInvokableClass($key, $className);
}
// add Zend\Form's view helpers to the ViewHelperManager
$viewHelperManager = $serviceManager->get('ViewHelperManager');
$vhConfig = new \Zend\Form\View\HelperConfig();
$vhConfig->configureServiceManager($viewHelperManager);
// apply configuration
$this->applyConfig($serviceManager, $config);
return $serviceManager;
}
示例13: configureServiceManager
/**
* Configure the provided service manager instance with the configuration
* in this class.
*
* @param ServiceManager $serviceManager
* @return void
*/
public function configureServiceManager(ServiceManager $serviceManager)
{
foreach ($this->invokables as $name => $service) {
$serviceManager->setInvokableClass($name, $service);
}
}
示例14: testSetAlias
/**
* @covers Zend\ServiceManager\ServiceManager::setAlias
*/
public function testSetAlias()
{
$this->serviceManager->setInvokableClass('foo', 'bar');
$ret = $this->serviceManager->setAlias('bar', 'foo');
$this->assertSame($this->serviceManager, $ret);
}
示例15: configureServiceManager
public function configureServiceManager(ServiceManager $serviceManager)
{
foreach ($this->helpers as $name => $fqcn) {
$serviceManager->setInvokableClass($name, $fqcn);
}
}