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);
 }
 /**
  * @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);
 }
Exemplo n.º 3
0
 /**
  * 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));
         }
     }
 }
 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);
 }
Exemplo n.º 5
0
 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}"));
 }
 /**
  * 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);
 }
Exemplo n.º 7
0
 /**
  * @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;
 }
Exemplo n.º 8
0
 /**
  * @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;
 }
Exemplo n.º 9
0
 /**
  * @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);
 }
Exemplo n.º 10
0
 /**
  * @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);
 }
Exemplo n.º 11
0
 /**
  * {@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);
 }
Exemplo n.º 12
0
 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));
 }
 /**
  * @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;
 }
 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');
 }
Exemplo n.º 15
0
 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);
 }
 /**
  * @param ContainerInterface $container
  * @return TwigRenderer
  */
 public function __invoke(ContainerInterface $container)
 {
     $config = $container->has('config') ? $container->get('config') : [];
     $debug = array_key_exists('debug', $config) ? (bool) $config['debug'] : false;
     $config = isset($config['templates']) ? $config['templates'] : [];
     $cacheDir = isset($config['cache_dir']) ? $config['cache_dir'] : false;
     // Create the engine instance
     $loader = new TwigLoader();
     $environment = new TwigEnvironment($loader, ['cache' => $debug ? false : $cacheDir, 'debug' => $debug, 'strict_variables' => $debug, 'auto_reload' => $debug]);
     // Add extensions
     if ($container->has(RouterInterface::class)) {
         $environment->addExtension(new TwigExtension($container->get(RouterInterface::class), isset($config['assets_url']) ? $config['assets_url'] : '', isset($config['assets_version']) ? $config['assets_version'] : ''));
     }
     if ($debug) {
         $environment->addExtension(new TwigExtensionDebug());
     }
     // Inject environment
     $twig = new TwigRenderer($environment, isset($config['extension']) ? $config['extension'] : 'html.twig');
     // 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) {
             $twig->addPath($path, $namespace);
         }
     }
     return $twig;
 }
 /**
  * @param ContainerInterface $container
  * @return RpcServiceModelFactory
  * @throws ServiceNotCreatedException
  */
 public function __invoke(ContainerInterface $container)
 {
     if (!$container->has(ModulePathSpec::class) || !$container->has(ConfigResourceFactory::class) || !$container->has(ModuleModel::class) || !$container->has('SharedEventManager')) {
         throw new ServiceNotCreatedException(sprintf('%s is missing one or more dependencies from ZF\\Configuration', RpcServiceModelFactory::class));
     }
     return new RpcServiceModelFactory($container->get(ModulePathSpec::class), $container->get(ConfigResourceFactory::class), $container->get('SharedEventManager'), $container->get(ModuleModel::class));
 }
 /**
  * @param ContainerInterface $container
  * @return DoctrineRestServiceResource
  */
 public function __invoke(ContainerInterface $container)
 {
     if (!$container->has(DoctrineRestServiceModelFactory::class) || !$container->has(InputFilterModel::class) || !$container->has(DocumentationModel::class)) {
         throw new ServiceNotCreatedException(sprintf('%s is missing one or more dependencies', DoctrineRestServiceResource::class));
     }
     return new DoctrineRestServiceResource($container->get(DoctrineRestServiceModelFactory::class), $container->get(InputFilterModel::class), $container->get(DocumentationModel::class));
 }
 public function __invoke(ContainerInterface $container)
 {
     $config = $container->has(self::CONFIG_SERVICE_NAME) ? $container->get(self::CONFIG_SERVICE_NAME) : null;
     $checks = $container->has(self::CHECKS_SERVICE_NAME) ? $container->get(self::CHECKS_SERVICE_NAME) : null;
     $reporter = $container->has(self::REPORTER_SERVICE_NAME) ? $container->get(self::REPORTER_SERVICE_NAME) : null;
     return new Runner($config, $checks, $reporter);
 }
 public function onLocateMessageHandler(ActionEvent $actionEvent)
 {
     $messageHandlerAlias = $actionEvent->getParam(MessageBus::EVENT_PARAM_MESSAGE_HANDLER);
     if (is_string($messageHandlerAlias) && $this->serviceLocator->has($messageHandlerAlias)) {
         $actionEvent->setParam(MessageBus::EVENT_PARAM_MESSAGE_HANDLER, $this->serviceLocator->get($messageHandlerAlias));
     }
 }
 public function __invoke(ContainerInterface $container, $name, $requestedName)
 {
     $config = $container->get('config');
     $serviceConfig = $config[self::KEY_DATASTORE][self::KEY_ALL_NOTIFICATION];
     if (isset($serviceConfig[self::KEY_TABLE_GATEWAY])) {
         if ($container->has($serviceConfig[self::KEY_TABLE_GATEWAY])) {
             $tableGateway = $container->get($serviceConfig[self::KEY_TABLE_GATEWAY]);
         } else {
             throw new DataStoreException('Can\'t create ' . $serviceConfig[self::KEY_TABLE_GATEWAY]);
         }
     } else {
         if (isset($serviceConfig[self::KEY_TABLE_NAME])) {
             $tableName = $serviceConfig[self::KEY_TABLE_NAME];
             $dbServiceName = isset($serviceConfig[self::KEY_DB_ADAPTER]) ? $serviceConfig[self::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 ' . self::KEY_ALL_NOTIFICATION . 'in config \'dataStore\'');
         }
     }
     return new DbTable($tableGateway);
 }
Exemplo n.º 22
0
 /**
  * @return array
  */
 protected function middleware()
 {
     $middleware = [];
     if ($this->container->has('command-bus.middleware')) {
         $middleware = $this->container->get('command-bus.middleware');
     }
     return $middleware;
 }
Exemplo n.º 23
0
 /**
  * {@inheritdoc}
  */
 public function has($id)
 {
     $metadata = ['id' => $id];
     $benchmark = $this->profiler->start('Container::has', $metadata, 'Container-Interop');
     $has = $this->container->has($id);
     $this->profiler->stop($benchmark);
     return $has;
 }
Exemplo n.º 24
0
 /**
  * Adds value.
  *
  * @param string $id
  * @param mixed $value
  * @return $this
  * @throws Exception\Container
  */
 public function add(string $id, $value)
 {
     if ($this->delegateMaster && $this->delegateMaster->has($id)) {
         throw new Exception\Container('Value "%s" assignment will not take effect since master ' . 'container have value with the same id.', $id);
     }
     $this->values[$id] = $value;
     return $this;
 }
 public function testRedis()
 {
     $redisCache = $this->prophesize(RedisCache::class);
     $this->container->has(RedisCache::class)->willReturn(true);
     $this->container->get(RedisCache::class)->willReturn($redisCache->reveal());
     $doctrineCache = $this->callFactory();
     static::assertInstanceOf(RedisCache::class, $doctrineCache);
 }
Exemplo n.º 26
0
 public function __invoke($requestedName)
 {
     if (!$this->container->has($requestedName)) {
         throw new \Exception("DataStore: " . $requestedName . " not found in container");
     }
     $dataStore = $this->container->get($requestedName);
     return new ConfigureGenerator($dataStore);
 }
Exemplo n.º 27
0
 /**
  * {@inheritDoc}
  * @throws \Interop\Container\Exception\ContainerException
  * @throws \Interop\Container\Exception\NotFoundException
  */
 public function resolve($identifier)
 {
     if (!$this->container->has($identifier)) {
         $this->logger->error(sprintf('Could not find object defined by id "%s"', $identifier));
         return null;
     }
     return $this->container->get($identifier);
 }
 /**
  * @param ContainerInterface $container
  * @return MongoDbEventStoreAdapter
  */
 public function __invoke(ContainerInterface $container)
 {
     $config = $container->get('config');
     $config = $this->options($config)['adapter']['options'];
     $mongoClient = isset($config['mongo_connection_alias']) ? $container->get($config['mongo_connection_alias']) : new \MongoClient();
     $messageFactory = $container->has(MessageFactory::class) ? $container->get(MessageFactory::class) : new FQCNMessageFactory();
     $messageConverter = $container->has(MessageConverter::class) ? $container->get(MessageConverter::class) : new NoOpMessageConverter();
     return new MongoDbEventStoreAdapter($messageFactory, $messageConverter, $mongoClient, $config['db_name'], $config['write_concern'], $config['transaction_timeout'], $config['stream_collection_map']);
 }
 public function testFactoryWithTemplate()
 {
     $factory = new HomePageFactory();
     $this->container->has(TemplateInterface::class)->willReturn(true);
     $this->container->get(TemplateInterface::class)->willReturn($this->prophesize(TemplateInterface::class));
     $this->assertTrue($factory instanceof HomePageFactory);
     $homePage = $factory($this->container->reveal());
     $this->assertTrue($homePage instanceof HomePageAction);
 }
Exemplo n.º 30
0
 public function __invoke(ContainerInterface $container)
 {
     if (!$container->has(Configuration::class) || !$container->has(EventManager::class)) {
         throw new ContainerNotRegisteredException('Doctrine\\Common\\EventManager::class and
         Doctrine\\ORM\\Configuration::class must be registered in the container');
     }
     $config = $container->get('config');
     return DriverManager::getConnection(isset($config['doctrine']['connection']) ? $config['doctrine']['connection'] : [], $container->get(Configuration::class), $container->get(EventManager::class));
 }