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


PHP ContainerInterface::has方法代码示例

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


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

示例1: __invoke

 public function __invoke(ContainerInterface $container, $reqName, $requestedName)
 {
     $config = $container->get('config');
     $serviceConfig = $config[AbstractDataStoreFactory::KEY_DATASTORE][$requestedName];
     if (isset($serviceConfig[DbTableAbstractFactory::KEY_TABLE_GATEWAY])) {
         if ($container->has($serviceConfig[DbTableAbstractFactory::KEY_TABLE_GATEWAY])) {
             $tableGateway = $container->get($serviceConfig[DbTableAbstractFactory::KEY_TABLE_GATEWAY]);
         } else {
             throw new DataStoreException('Can\'t create ' . $serviceConfig[DbTableAbstractFactory::KEY_TABLE_GATEWAY]);
         }
     } else {
         if (isset($serviceConfig[DbTableAbstractFactory::KEY_TABLE_NAME])) {
             $tableName = $serviceConfig[DbTableAbstractFactory::KEY_TABLE_NAME];
             $dbServiceName = isset($serviceConfig[DbTableAbstractFactory::KEY_DB_ADAPTER]) ? $serviceConfig[DbTableAbstractFactory::KEY_DB_ADAPTER] : 'db';
             $db = $container->has($dbServiceName) ? $container->get($dbServiceName) : null;
             if ($container->has('TableManagerMysql')) {
                 $tableManager = $container->get('TableManagerMysql');
             } else {
                 $tableManager = new TableManagerMysql($db);
             }
             $hasTable = $tableManager->hasTable($tableName);
             if (!$hasTable) {
                 $tableManager->rewriteTable($tableName, $this->tablePreferenceTableData);
             }
             $tableGateway = new TableGateway($tableName, $db);
         } else {
             throw new DataStoreException('There is not table name for ' . $requestedName . 'in config \'dataStore\'');
         }
     }
     $class = (isset($serviceConfig[AbstractFactoryAbstract::KEY_CLASS]) and is_a($serviceConfig[AbstractFactoryAbstract::KEY_CLASS], DbTable::class, true)) ? $serviceConfig[AbstractFactoryAbstract::KEY_CLASS] : DbTable::class;
     return new $class($tableGateway);
 }
开发者ID:victorynox,项目名称:TestR,代码行数:32,代码来源:ConfigurationTableFactory.php

示例2: __invoke

 /**
  * @param ContainerInterface $container
  * @return SessionManager
  *
  * @throws RuntimeException
  * @throws ContainerException
  * @throws InvalidArgumentException
  */
 public function __invoke(ContainerInterface $container)
 {
     $c = $container->get('config');
     $config = array_key_exists('session', $c) ? $c['session'] : ['name' => 'expressive'];
     $sessionConfig = null;
     $sessionSaveHandler = null;
     $sessionStorage = null;
     $sessionValidators = [];
     if ($container->has(ConfigInterface::class)) {
         $sessionConfig = $container->get(ConfigInterface::class);
     }
     if (array_key_exists('handler', $config)) {
         if ($container->has($config['handler'])) {
             $sessionSaveHandler = $container->get(SaveHandlerInterface::class);
         }
     }
     if ($container->has(StorageInterface::class)) {
         $sessionStorage = $container->get(StorageInterface::class);
     }
     if (array_key_exists('validators', $config)) {
         if (!is_array($config['validators'])) {
             throw new InvalidArgumentException('Session validators must be array, ' . gettype($config['validators']) . ' given');
         }
         $sessionValidators = $config['validators'];
     }
     return new SessionManager($sessionConfig, $sessionStorage, $sessionSaveHandler, $sessionValidators);
 }
开发者ID:DaGhostman,项目名称:pxb-zend-session,代码行数:35,代码来源:ManagerFactory.php

示例3: resolve

 /**
  * Resolve toResolve into a closure that that the router can dispatch.
  *
  * If toResolve is of the format 'class:method', then try to extract 'class'
  * from the container otherwise instantiate it and then dispatch 'method'.
  *
  * @return \Closure
  *
  * @throws RuntimeException if the callable does not exist
  * @throws RuntimeException if the callable is not resolvable
  */
 private function resolve()
 {
     // if it's callable, then it's already resolved
     if (is_callable($this->toResolve)) {
         $this->resolved = $this->toResolve;
         // check for slim callable as "class:method"
     } elseif (is_string($this->toResolve)) {
         $callable_pattern = '!^([^\\:]+)\\:([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)$!';
         if (preg_match($callable_pattern, $this->toResolve, $matches)) {
             $class = $matches[1];
             $method = $matches[2];
             if ($this->container->has($class)) {
                 $this->resolved = [$this->container->get($class), $method];
             } else {
                 if (!class_exists($class)) {
                     throw new RuntimeException(sprintf('Callable %s does not exist', $class));
                 }
                 $this->resolved = [new $class(), $method];
             }
             if (!is_callable($this->resolved)) {
                 throw new RuntimeException(sprintf('%s is not resolvable', $this->toResolve));
             }
         } else {
             throw new RuntimeException(sprintf('%s is not resolvable', $this->toResolve));
         }
     }
 }
开发者ID:Whiskey24,项目名称:GoingDutchApi,代码行数:38,代码来源:CallableResolver.php

示例4: __invoke

 public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
 {
     $config = $container->get('config');
     if ($this::$flag) {
         $serviceConfig = $config[self::KEY_DATASTORE][self::KEY_CACHEABLE_NOTIFICATION_TYPE];
     } else {
         $serviceConfig = $config[self::KEY_DATASTORE][self::KEY_CACHEABLE_NOTIFICATION];
     }
     $requestedClassName = $serviceConfig[self::KEY_CLASS];
     if (isset($serviceConfig[self::KEY_DATASOURCE])) {
         if ($container->has($serviceConfig[self::KEY_DATASOURCE])) {
             $getAll = $container->get($serviceConfig[self::KEY_DATASOURCE]);
             if (method_exists($getAll, 'setNotificationType')) {
                 $getAll->setNotificationType($requestedName);
             }
         } else {
             throw new DataStoreException('There is DataSource not created ' . $requestedName . 'in config \'dataStore\'');
         }
     } else {
         throw new DataStoreException('There is DataSource for ' . $requestedName . 'in config \'dataStore\'');
     }
     $serviceConfig[self::KEY_CACHEABLE] = 'Notification' . ucfirst($requestedName);
     if ($container->has($serviceConfig[self::KEY_CACHEABLE])) {
         $cashStore = $container->get($serviceConfig[self::KEY_CACHEABLE]);
     } else {
         throw new DataStoreException('There is DataSource for ' . $serviceConfig[self::KEY_CACHEABLE] . 'in config \'dataStore\'');
     }
     //$cashStore = isset($serviceConfig['cashStore']) ?  new $serviceConfig['cashStore']() : null;
     return new $requestedClassName($getAll, $cashStore);
 }
开发者ID:victorynox,项目名称:TestR,代码行数:30,代码来源:NotificationCacheableStoreFactory.php

示例5: __get

 public function __get($property)
 {
     if ($this->container->has($property)) {
         return $this->container->get($property);
     }
     throw new \RuntimeException(sprintf('Property %s does not exist', get_class($this) . "::{$property}"));
 }
开发者ID:orx0r,项目名称:slim3-controller,代码行数:7,代码来源:Controller.php

示例6: getSharedInstance

 /**
  * Get shared instance
  *
  * @param $classOrAlias
  * @return mixed
  */
 public function getSharedInstance($classOrAlias)
 {
     if ($this->container->has($classOrAlias)) {
         return $this->container->get($classOrAlias);
     }
     return $this->diInstanceManager->getSharedInstance($classOrAlias);
 }
开发者ID:zendframework,项目名称:zend-servicemanager-di,代码行数:13,代码来源:DiInstanceManagerProxy.php

示例7: register

 /**
  * @param string $eventName
  * @param string $handlerName
  * @throws EventBusException
  */
 public function register($eventName, $handlerName)
 {
     if (!$this->locator->has($handlerName)) {
         throw new EventBusException(sprintf("Event handler '%s' cannot be found by locator", $handlerName));
     }
     $this->map[$eventName][] = $handlerName;
 }
开发者ID:averor,项目名称:cqrs,代码行数:12,代码来源:EventHandlerLocator.php

示例8: resolveParameters

 /**
  * @param AbstractFunctionCallDefinition $definition
  * @param \ReflectionFunctionAbstract    $functionReflection
  * @param array                          $parameters
  *
  * @throws DefinitionException A parameter has no value defined or guessable.
  * @return array Parameters to use to call the function.
  */
 public function resolveParameters(AbstractFunctionCallDefinition $definition = null, \ReflectionFunctionAbstract $functionReflection = null, array $parameters = array())
 {
     $args = array();
     if (!$functionReflection) {
         return $args;
     }
     foreach ($functionReflection->getParameters() as $index => $parameter) {
         if (array_key_exists($parameter->getName(), $parameters)) {
             // Look in the $parameters array
             $value = $parameters[$parameter->getName()];
         } elseif ($definition && $definition->hasParameter($index)) {
             // Look in the definition
             $value = $definition->getParameter($index);
         } else {
             // If the parameter is optional and wasn't specified, we take its default value
             if ($parameter->isOptional()) {
                 $args[] = $this->getParameterDefaultValue($parameter, $functionReflection);
                 continue;
             }
             throw new DefinitionException(sprintf("The parameter '%s' of %s has no value defined or guessable", $parameter->getName(), $this->getFunctionName($functionReflection)));
         }
         if ($value instanceof EntryReference) {
             // If the container cannot produce the entry, we can use the default parameter value
             if (!$this->container->has($value->getName()) && $parameter->isOptional()) {
                 $value = $this->getParameterDefaultValue($parameter, $functionReflection);
             } else {
                 $value = $this->container->get($value->getName());
             }
         }
         $args[] = $value;
     }
     return $args;
 }
开发者ID:Clon450,项目名称:batata,代码行数:41,代码来源:ParameterResolver.php

示例9: __invoke

 /**
  * @param \Psr\Http\Message\ServerRequestInterface $request
  * @param \Psr\Http\Message\ResponseInterface $response
  * @param callable|null $next
  *
  * @throws \Wiring\Exception\MethodNotAllowedException
  * @throws \Wiring\Exception\NotFoundException
  * @return \Psr\Http\Message\ResponseInterface
  */
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null)
 {
     $routeInfo = $this->fastRoute->dispatch($request->getMethod(), $request->getUri()->getPath());
     if ($routeInfo[0] == Dispatcher::FOUND) {
         // Get request params
         foreach ($routeInfo[2] as $param => $value) {
             $request = $request->withAttribute($param, $value);
         }
         // Get request with attribute
         $request = $request->withAttribute($this->attribute, $routeInfo[1]);
         return $next($request, $response);
     }
     if ($routeInfo[0] == Dispatcher::METHOD_NOT_ALLOWED) {
         // Check has handler
         if (!$this->container->has(MethodNotAllowedHandlerInterface::class)) {
             throw new MethodNotAllowedException($request, $response, $routeInfo[1]);
         }
         /** @var callable $notAllowedHandler */
         $notAllowedHandler = $this->container->get(MethodNotAllowedHandlerInterface::class);
         return $notAllowedHandler($request, $response, $routeInfo[1]);
     }
     // Check has handler
     if (!$this->container->has(NotFoundHandlerInterface::class)) {
         throw new NotFoundException($request, $response);
     }
     /** @var callable $notFoundHandler */
     $notFoundHandler = $this->container->get(NotFoundHandlerInterface::class);
     return $notFoundHandler($request, $response);
 }
开发者ID:aracaw,项目名称:wiring,代码行数:38,代码来源:FastRouteMiddleware.php

示例10: __invoke

 /**
  * @param ContainerInterface $container
  * @param string $requestedName
  * @param array|null $options
  * @return mixed
  * @throws DataStoreException
  */
 public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
 {
     if ($this::$KEY_IN_CREATE) {
         throw new DataStoreException("Create will be called without pre call canCreate method");
     }
     $this::$KEY_IN_CREATE = 1;
     $config = $container->get('config');
     $serviceConfig = $config[self::KEY_DATASTORE][$requestedName];
     $requestedClassName = $serviceConfig[self::KEY_CLASS];
     if (isset($serviceConfig[self::KEY_DATASOURCE])) {
         if ($container->has($serviceConfig[self::KEY_DATASOURCE])) {
             $getAll = $container->get($serviceConfig[self::KEY_DATASOURCE]);
         } else {
             $this::$KEY_IN_CREATE = 0;
             throw new DataStoreException('There is DataSource not created ' . $requestedName . 'in config \'dataStore\'');
         }
     } else {
         $this::$KEY_IN_CREATE = 0;
         throw new DataStoreException('There is DataSource for ' . $requestedName . 'in config \'dataStore\'');
     }
     if (isset($serviceConfig[self::KEY_CACHEABLE])) {
         if ($container->has($serviceConfig[self::KEY_CACHEABLE])) {
             $cashStore = $container->get($serviceConfig[self::KEY_CACHEABLE]);
         } else {
             $this::$KEY_IN_CREATE = 0;
             throw new DataStoreException('There is DataSource for ' . $serviceConfig[self::KEY_CACHEABLE] . 'in config \'dataStore\'');
         }
     } else {
         $cashStore = null;
     }
     $this::$KEY_IN_CREATE = 0;
     //$cashStore = isset($serviceConfig['cashStore']) ?  new $serviceConfig['cashStore']() : null;
     return new $requestedClassName($getAll, $cashStore);
 }
开发者ID:avz-cmf,项目名称:zaboy-rest,代码行数:41,代码来源:CacheableAbstractFactory.php

示例11: __invoke

 /**
  * {@inherit}
  *
  * {@inherit}
  */
 public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
 {
     $config = $container->get('config');
     $this->tableName = isset($config[self::KEY][self::KEY_TABLE_NAME]) ? $config[self::KEY][self::KEY_TABLE_NAME] : (isset($options[self::KEY_TABLE_NAME]) ? $options[self::KEY_TABLE_NAME] : self::TABLE_NAME);
     $this->db = $container->has('db') ? $container->get('db') : null;
     if (is_null($this->db)) {
         throw new QueueException('Can\'t create db Adapter');
     }
     if ($container->has(TableManagerMysql::KEY_IN_CONFIG)) {
         $tableManager = $container->get(TableManagerMysql::KEY_IN_CONFIG);
     } else {
         $tableManager = new TableManagerMysql($this->db);
     }
     $hasPromiseStoreTable = $tableManager->hasTable($this->tableName);
     if (!$hasPromiseStoreTable) {
         $tableManager->rewriteTable($this->tableName, $this->promiseTableData);
     }
     $messagesStore = $container->has(Message\Factory\StoreFactory::KEY) ? $container->get(Message\Factory\StoreFactory::KEY) : null;
     if (is_null($messagesStore)) {
         throw new QueueException('Can\'t create Messages Store');
     }
     $promisesStore = $container->has(Promise\Factory\StoreFactory::KEY) ? $container->get(Promise\Factory\StoreFactory::KEY) : null;
     if (is_null($promisesStore)) {
         throw new QueueException('Can\'t create Promises Store');
     }
     return new Store($this->tableName, $this->db, $messagesStore, $promisesStore);
 }
开发者ID:avz-cmf,项目名称:zaboy-async,代码行数:32,代码来源:StoreFactory.php

示例12: __invoke

 public function __invoke(ContainerInterface $container)
 {
     if (!$container->has(Configuration::class) || !$container->has(EventManager::class) || !$container->has(Connection::class)) {
         throw new ContainerNotRegisteredException('Doctrine\\Common\\EventManager::class,
         Doctrine\\ORM\\Configuration::class and Doctrine\\DBAL\\Connection::class
         must be registered in the container');
     }
     $config = $container->has('config') ? $container->get('config') : [];
     $underscoreNamingStrategy = isset($config['doctrine']['orm']['underscore_naming_strategy']) ? $config['doctrine']['orm']['underscore_naming_strategy'] : false;
     /** @var Configuration $configuration */
     $configuration = $container->get(Configuration::class);
     $configuration->setProxyDir(isset($config['doctrine']['orm']['proxy_dir']) ? $config['doctrine']['orm']['proxy_dir'] : 'data/cache/EntityProxy');
     $configuration->setProxyNamespace(isset($config['doctrine']['orm']['proxy_namespace']) ? $config['doctrine']['orm']['proxy_namespace'] : 'EntityProxy');
     $configuration->setAutoGenerateProxyClasses(isset($config['doctrine']['orm']['auto_generate_proxy_classes']) ? $config['doctrine']['orm']['auto_generate_proxy_classes'] : false);
     // ORM mapping by Annotation
     AnnotationRegistry::registerFile('vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php');
     $driver = new AnnotationDriver(new AnnotationReader(), ['data/cache/doctrine']);
     $configuration->setMetadataDriverImpl($driver);
     // Cache
     $cache = $container->get(Cache::class);
     $configuration->setQueryCacheImpl($cache);
     $configuration->setResultCacheImpl($cache);
     $configuration->setMetadataCacheImpl($cache);
     return EntityManager::create($container->get(Connection::class), $configuration, $container->get(EventManager::class));
 }
开发者ID:mobicms,项目名称:expressive-doctrine,代码行数:25,代码来源:OrmFactory.php

示例13: __invoke

 /**
  * @param ContainerInterface $container
  * @returns ZendViewRenderer
  */
 public function __invoke(ContainerInterface $container)
 {
     $config = $container->has('config') ? $container->get('config') : [];
     $config = isset($config['templates']) ? $config['templates'] : [];
     // Configuration
     $resolver = new Resolver\AggregateResolver();
     $resolver->attach(new Resolver\TemplateMapResolver(isset($config['map']) ? $config['map'] : []), 100);
     // Create the renderer
     $renderer = new PhpRenderer();
     $renderer->setResolver($resolver);
     $manager = $container->has(HelperPluginManager::class) ? $container->get(HelperPluginManager::class) : new HelperPluginManager();
     // Inject helpers
     $this->injectHelpers($renderer, $manager);
     // Initialize renderer for HelperPluginManager
     $manager->setRenderer($renderer);
     // Inject renderer
     $view = new ZendViewRenderer($renderer, isset($config['layout']) ? $config['layout'] : null);
     // Add template paths
     $allPaths = isset($config['paths']) && is_array($config['paths']) ? $config['paths'] : [];
     foreach ($allPaths as $namespace => $paths) {
         $namespace = is_numeric($namespace) ? null : $namespace;
         foreach ((array) $paths as $path) {
             $view->addPath($path, $namespace);
         }
     }
     return $view;
 }
开发者ID:fabiocarneiro,项目名称:zend-expressive-zendviewrenderer,代码行数:31,代码来源:ZendViewRendererFactory.php

示例14: __invoke

 public function __invoke(ContainerInterface $container)
 {
     $template = $container->has('Zend\\Expressive\\Template\\TemplateRendererInterface') ? $container->get('Zend\\Expressive\\Template\\TemplateRendererInterface') : null;
     $config = $container->has('config') ? $container->get('config') : [];
     $config = isset($config['zend-expressive']['error_handler']) ? $config['zend-expressive']['error_handler'] : [];
     return new TemplatedErrorHandler($template, isset($config['template_404']) ? $config['template_404'] : 'error/404', isset($config['template_error']) ? $config['template_error'] : 'error/error');
 }
开发者ID:Xerkus,项目名称:zend-expressive,代码行数:7,代码来源:TemplatedErrorHandlerFactory.php

示例15: testFactoryWithTemplate

 public function testFactoryWithTemplate()
 {
     $factory = new PageFactory();
     $this->container->has(TemplateRendererInterface::class)->willReturn(true);
     $this->container->get(TemplateRendererInterface::class)->willReturn($this->prophesize(TemplateRendererInterface::class));
     $this->assertTrue($factory instanceof PageFactory);
 }
开发者ID:codingmatters,项目名称:kernel,代码行数:7,代码来源:PageFactoryTest.php


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