当前位置: 首页>>代码示例>>PHP>>正文


PHP ServiceManager::hasAlias方法代码示例

本文整理汇总了PHP中Zend\ServiceManager\ServiceManager::hasAlias方法的典型用法代码示例。如果您正苦于以下问题:PHP ServiceManager::hasAlias方法的具体用法?PHP ServiceManager::hasAlias怎么用?PHP ServiceManager::hasAlias使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\ServiceManager\ServiceManager的用法示例。


在下文中一共展示了ServiceManager::hasAlias方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testHasAlias

 /**
  * @covers Zend\ServiceManager\ServiceManager::hasAlias
  */
 public function testHasAlias()
 {
     $this->assertFalse($this->serviceManager->hasAlias('foo'));
     $this->serviceManager->setService('bar', 'baz');
     $this->serviceManager->setAlias('foo', 'bar');
     $this->assertTrue($this->serviceManager->hasAlias('foo'));
 }
开发者ID:razvansividra,项目名称:pnlzf2-1,代码行数:10,代码来源:ServiceManagerTest.php

示例2: buildGraph

 /**
  * @param $className
  *
  * @return object
  * @throws \Exception
  */
 private function buildGraph($className)
 {
     if ($this->enableObjectGraphDebug) {
         echo 'Building an object from the class: ' . $className . "<br />";
     }
     try {
         $reflection = new \ReflectionClass($className);
     } catch (\Exception $e) {
         if ($this->enableObjectGraphDebug) {
             echo 'Could not build a reflection class for ' . $className . "<br />";
         }
         return false;
     }
     if (!$reflection->getConstructor()) {
         if ($this->enableObjectGraphDebug) {
             echo 'We have build an object for class ' . $className . "<br />";
         }
         return new $className();
     }
     $constructorParameters = $reflection->getConstructor()->getParameters();
     $dependencies = [];
     foreach ($constructorParameters as $param) {
         try {
             $paramClassName = $param->getClass();
         } catch (\Exception $e) {
             throw new \Exception('Could not create dependency class "' . $param->getName() . '" for the currently building class: ' . $className);
         }
         if (!$paramClassName) {
             switch (true) {
                 case $this->controllerPluginManager->has($param->name, false):
                     if ($this->enableObjectGraphDebug) {
                         echo 'The parameter "' . $param->name . '" exists in Controller Manager' . "<br />";
                     }
                     $dependencies[] = $this->controllerPluginManager->get($param->name);
                     break;
                 case $this->serviceManager->has($param->name, false):
                     if ($this->enableObjectGraphDebug) {
                         echo 'The parameter "' . $param->name . '" exists in Service Manager' . "<br />";
                     }
                     $dependencies[] = $this->serviceManager->get($param->name);
                     break;
                 default:
                     if ($param->isOptional()) {
                         $dependencies[] = $param->getDefaultValue();
                     } else {
                         if ($this->enableObjectGraphDebug) {
                             echo 'The parameter "' . $param->name . '" does not exist in (any) Service Manager' . "<br />";
                         }
                         echo 'The parameter "' . $param->name . '" does not exist in the Service Manager' . "<br />";
                         die;
                     }
                     break;
             }
         } else {
             if ($this->enableObjectGraphDebug) {
                 echo 'Does the SM have an object for ' . $param->getClass()->name . "<br />";
             }
             switch (true) {
                 case $this->controllerPluginManager->has($param->getClass()->name, false, false):
                     if ($this->enableObjectGraphDebug) {
                         echo 'It does in the Controller Plugin Manager' . "<br />";
                     }
                     $dependencies[] = $this->controllerPluginManager->get($param->getClass()->name);
                     break;
                 case $this->viewHelperManager->has($param->getClass()->name, false, false):
                     if ($this->enableObjectGraphDebug) {
                         echo 'It does in the View Helper Manager' . "<br />";
                     }
                     $dependencies[] = $this->viewHelperManager->get($param->getClass()->name);
                     break;
                 case $this->formElementManager->has($param->getClass()->name, false, false):
                     if ($this->enableObjectGraphDebug) {
                         echo 'It does in the Form Element Manager' . "<br />";
                     }
                     $dependencies[] = $this->formElementManager->get($param->getClass()->name);
                     break;
                 case $this->serviceManager->has($param->getClass()->name, false, false):
                     if ($this->enableObjectGraphDebug) {
                         echo 'It does in the Service Manager' . "<br />";
                     }
                     $name = $param->getClass()->name;
                     if ($this->serviceManager->hasAlias($name)) {
                         $config = $this->serviceManager->get('config')['service_manager'];
                         $name = $config['aliases'][$name];
                     }
                     $dependencies[] = $this->serviceManager->get($name);
                     break;
                 default:
                     if ($this->enableObjectGraphDebug) {
                         echo 'No it It does not have an object' . "<br />";
                     }
                     if ($param->getClass()->isInterface()) {
                         continue;
                     }
//.........这里部分代码省略.........
开发者ID:middleout,项目名称:mdo-bundle-zf2-auto-dep-inject,代码行数:101,代码来源:AbstractGenericFactory.php


注:本文中的Zend\ServiceManager\ServiceManager::hasAlias方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。