/**
  * Create and return a NoRecordExists validator.
  *
  * @param ContainerInterface $container
  * @param string $requestedName
  * @param null|array $options
  * @return NoRecordExists
  */
 public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
 {
     if (isset($options['adapter'])) {
         return new NoRecordExists(ArrayUtils::merge($options, ['adapter' => $container->get($options['adapter'])]));
     }
     return new NoRecordExists($options);
 }
 public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
 {
     $config = $container->get('config');
     $collectorConfig = ['service_name' => isset($config['hermes']['service_name']) ? $config['hermes']['service_name'] : '', 'api_key' => isset($config['kharon']['api_key']) ? $config['kharon']['api_key'] : null, 'kharon_dir' => isset($config['kharon']['agent_dir']) ? $config['kharon']['agent_dir'] : 'data/kharon'];
     $collectorConfig['kharon_dir'] .= '/hermes';
     return new Collector($collectorConfig);
 }
 /**
  * @param ContainerInterface $container
  *
  * @return PhpRenderer
  */
 public function __invoke(ContainerInterface $container)
 {
     $helper = $container->get(HelperPluginManager::class);
     $renderer = new PhpRenderer();
     $renderer->setHelperPluginManager($helper);
     return $renderer;
 }
 public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
 {
     $config = $container->has('config') ? $container->get('config') : [];
     $debug = array_key_exists('debug', $config) ? (bool) $config['debug'] : false;
     $options = $config['session']['psr7'];
     return new SessionMiddleware(new Sha256(), $options['signature_key'], $options['verification_key'], SetCookie::create($options['cookie_name'])->withSecure($options['cookie_secure'])->withHttpOnly(true), new Parser(), $options['expiration_time']);
 }
 public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
 {
     $client = $container->get('NewRelic\\Client');
     $options = $container->get('NewRelic\\ModuleOptions');
     $logger = $container->get('NewRelic\\Logger');
     return new ErrorListener($client, $options, $logger);
 }
Beispiel #6
0
 public function __construct(FrameBuffer $frameBuffer, ContainerInterface $container)
 {
     $this->frameBuffer = $frameBuffer;
     $this->container = $container;
     $this->bitmapLoader = $container->get(BitmapLoader::class);
     $this->sprites = [];
 }
 /**
  * Create an object
  *
  * @param  ContainerInterface $container
  * @param  string $requestedName
  * @param  null|array $options
  * @return object|\Swift_Mailer
  * @throws ServiceNotFoundException if unable to resolve the service.
  * @throws ServiceNotCreatedException if an exception is raised when
  *     creating a service.
  * @throws ContainerException if any other error occurs
  */
 public function __invoke(ContainerInterface $container, $requestedName, array $options = null) : \Swift_Mailer
 {
     $mailConfig = $container->get('config')['mail'];
     $smtp = $mailConfig['smtp'];
     $transport = \Swift_SmtpTransport::newInstance($smtp['server'], $smtp['port'], $smtp['ssl'])->setUsername($smtp['username'])->setPassword($smtp['password']);
     return new \Swift_Mailer($transport);
 }
 /**
  * @param  ContainerInterface $container
  * @param  string $name
  * @param  null|array $options
  * @return DefaultRenderingStrategy
  */
 public function __invoke(ContainerInterface $container, $name, array $options = null)
 {
     $strategy = new DefaultRenderingStrategy($container->get(View::class));
     $config = $this->getConfig($container);
     $this->injectLayoutTemplate($strategy, $config);
     return $strategy;
 }
 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));
 }
 /**
  * Create service
  *
  * @param ContainerInterface $container
  * @return mixed
  */
 public function __invoke(ContainerInterface $container)
 {
     $config = $container->get('config');
     $cacheEnabled = isset($config['view']['cache']) ? (bool) $config['view']['cache'] : false;
     $layout = isset($config['view']['layout']) && is_string($config['view']['layout']) ? $config['view']['layout'] : 'CargoUI/view/layout/layout.phtml';
     return new Main($layout, $cacheEnabled, $container->get(RiotCompiler::class));
 }
 /**
  * @param ContainerInterface $container
  * @return ModuleVersioningModelFactory
  * @throws ServiceNotCreatedException
  */
 public function __invoke(ContainerInterface $container)
 {
     if (!$container->has(ConfigResourceFactory::class) || !$container->has(ModulePathSpec::class)) {
         throw new ServiceNotCreatedException(sprintf('%s is missing one or more dependencies from ZF\\Configuration', ModuleVersioningModelFactory::class));
     }
     return new ModuleVersioningModelFactory($container->get(ConfigResourceFactory::class), $container->get(ModulePathSpec::class));
 }
 /**
  * Constructor
  *
  * @param string $action Type of action to validate
  * @param ServerRequestInterface $request Request Http
  * @param ContainerInterface $container Dependency Injection
  */
 public function __construct($action, ServerRequestInterface $request, ContainerInterface $container)
 {
     $this->action = $action;
     $this->idUser = $request->getAttribute('id');
     $this->data = $request->getParsedBody();
     $this->entityManager = $container->get('EntityManager');
 }
 public function __invoke(ContainerInterface $ci)
 {
     $settings = $ci->get('settings');
     $view = new Twig($settings['twig']['view_path'], $settings['twig']['settings']);
     $view->addExtension(new TwigExtension($ci['router'], $ci['request']->getUri()));
     return $view;
 }
 public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
 {
     $entityManager = $container->get('doctrine.entitymanager.orm_default');
     $config = $container->get('Config')['svycka_social_user'];
     $options = ['social_user_entity' => $config['social_user_entity']];
     return new Doctrine($entityManager, $options);
 }
 /**
  * @inheritDoc
  */
 public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
 {
     $config = $container->get('config');
     $config = isset($config['asset_manager']) ? $config['asset_manager'] : array();
     $resolver = new AggregateResolver();
     if (empty($config['resolvers'])) {
         return $resolver;
     }
     foreach ($config['resolvers'] as $resolverService => $priority) {
         $resolverService = $container->get($resolverService);
         if (!$resolverService instanceof ResolverInterface) {
             throw new Exception\RuntimeException('Service does not implement the required interface ResolverInterface.');
         }
         if ($resolverService instanceof AggregateResolverAwareInterface) {
             $resolverService->setAggregateResolver($resolver);
         }
         if ($resolverService instanceof MimeResolverAwareInterface) {
             $resolverService->setMimeResolver($container->get(MimeResolver::class));
         }
         if ($resolverService instanceof AssetFilterManagerAwareInterface) {
             $resolverService->setAssetFilterManager($container->get(AssetFilterManager::class));
         }
         $resolver->attach($resolverService, $priority);
     }
     return $resolver;
 }
 /**
  * Fetch configuration from the container, if possible.
  *
  * @param ContainerInterface $container
  * @return array
  */
 private function fetchConfig(ContainerInterface $container)
 {
     if (!$container->has('config')) {
         return [];
     }
     return $container->get('config');
 }
 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');
 }
 public function __invoke(ContainerInterface $container)
 {
     $config = $container->get('config');
     $expressive_redirect_handler_config = isset($config['expressive-redirect-handler']) ? $config['expressive-redirect-handler'] : [];
     $router = $container->get(RouterInterface::class);
     return new RedirectHandlerAction($expressive_redirect_handler_config, $router);
 }
Beispiel #19
0
 /**
  * @inheritdoc
  */
 protected function setUpExceptionHandler(SapiInterface $sapi, ContainerInterface $container)
 {
     error_reporting(E_ALL);
     $createHandler = function () use($container) {
         $has = $container->has(ExceptionHandlerInterface::class);
         $handler = $has === true ? $container->get(ExceptionHandlerInterface::class) : new DefaultHandler();
         return $handler;
     };
     $throwableHandler = function (Throwable $throwable) use($sapi, $container, $createHandler) {
         /** @var ExceptionHandlerInterface $handler */
         $handler = $createHandler();
         $handler->handleThrowable($throwable, $sapi, $container);
     };
     $exceptionHandler = function (Exception $exception) use($sapi, $container, $createHandler) {
         /** @var ExceptionHandlerInterface $handler */
         $handler = $createHandler();
         $handler->handleException($exception, $sapi, $container);
     };
     set_exception_handler(PHP_MAJOR_VERSION >= 7 ? $throwableHandler : $exceptionHandler);
     set_error_handler(function ($severity, $message, $fileName, $lineNumber) use($exceptionHandler) {
         $errorException = new ErrorException($message, 0, $severity, $fileName, $lineNumber);
         $exceptionHandler($errorException);
         throw $errorException;
     });
     // handle fatal error
     register_shutdown_function(function () use($container, $createHandler) {
         $error = error_get_last();
         if ($error !== null && (int) $error['type'] & (E_ERROR | E_COMPILE_ERROR)) {
             /** @var ExceptionHandlerInterface $handler */
             $handler = $createHandler();
             $handler->handleFatal($error, $container);
         }
     });
 }
Beispiel #20
0
 public function testFactoryRouter()
 {
     $factory = new ApiFactory();
     $router = $this->prophesize(RouterInterface::class);
     $this->container->get(RouterInterface::class)->willReturn($router);
     $this->assertTrue($factory instanceof ApiFactory);
 }
 /**
  * Factory for zend-servicemanager v3.
  *
  * @param ContainerInterface $container
  * @param string $name
  * @param null|array $options
  * @return Logger
  */
 public function __invoke(ContainerInterface $container, $name, array $options = null)
 {
     // Configure the logger
     $config = $container->get('config');
     $logConfig = isset($config['log']) ? $config['log'] : [];
     return new Logger($logConfig);
 }
 /**
  * @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;
 }
 /**
  * @param  ContainerInterface $container
  * @return WorkerCommand
  */
 public function __invoke(ContainerInterface $container) : WorkerCommand
 {
     /** @var AwsSdk $awsSdk */
     $awsSdk = $container->get(AwsSdk::class);
     $sqsClient = $awsSdk->createSqs();
     return new WorkerCommand($sqsClient, new HttpClient());
 }
Beispiel #24
0
 /**
  * @expectedException \RuntimeException
  */
 public function testGetCallThrowsExceptionAndStillTriggersProfiler()
 {
     $this->profiler->expects($this->once())->method('start')->will($this->returnValue(new Benchmark('test')));
     $this->profiler->expects($this->once())->method('stop')->will($this->returnValue(new Benchmark('test')));
     $this->container->expects($this->once())->method('get')->will($this->throwException(new \RuntimeException()));
     $instance = $this->adapter->get('sample-id');
 }
 /**
  * Create and return a DocumentationModel instance.
  *
  * @param ContainerInterface $container
  * @param string $requestedName
  * @param null|array $options
  * @return DocumentationModel
  * @throws ServiceNotCreatedException
  */
 public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
 {
     if (!$container->has(ConfigResourceFactory::class)) {
         throw new ServiceNotCreatedException(sprintf('%s requires that the %s service be present; service not found', DocumentationModel::class, ConfigResourceFactory::class));
     }
     return new DocumentationModel($container->get(ConfigResourceFactory::class), $container->get(ModuleUtils::class));
 }
 /**
  * Create and return a UrlHelperMiddleware instance.
  *
  * @param ContainerInterface $container
  * @return UrlHelperMiddleware
  * @throws Exception\MissingHelperException if the UrlHelper service is
  *     missing
  */
 public function __invoke(ContainerInterface $container)
 {
     if (!$container->has(UrlHelper::class)) {
         throw new Exception\MissingHelperException(sprintf('%s requires a %s service at instantiation; none found', UrlHelperMiddleware::class, UrlHelper::class));
     }
     return new UrlHelperMiddleware($container->get(UrlHelper::class));
 }
Beispiel #27
0
 public function __invoke(ContainerInterface $Container)
 {
     $pdo = $Container->get(StorageInterface::class);
     $router = $Container->get(RouterInterface::class);
     $template = $Container->has(TemplateRendererInterface::class) ? $Container->get(TemplateRendererInterface::class) : null;
     return new RoleAction($pdo, $router, $template);
 }
Beispiel #28
0
 /**
  * @return void
  */
 public function register()
 {
     $this->container->add(ResponseInterface::class, \Zend\Diactoros\Response::class);
     $this->container->add(Router::class, function () {
         return new Router($this->container->get(RouteInterface::class));
     });
 }
 /**
  * Extend the array by adding a new service to it.
  * The array is created if it does not exist yet.
  *
  * @param ContainerInterface $container
  * @param callable|null      $getPrevious
  *
  * @return array
  */
 public function __invoke(ContainerInterface $container, callable $getPrevious = null)
 {
     // Let's check if a previous value exists. If yes, let's resolve it.
     $previous = $getPrevious === null ? [] : $getPrevious();
     $previous[] = $container->get($this->serviceName);
     return $previous;
 }
Beispiel #30
0
 /**
  * @param ServerRequestInterface $request
  * @param Closure                $next
  * @param ContainerInterface     $container
  *
  * @return ResponseInterface
  */
 public static function handle(ServerRequestInterface $request, Closure $next, ContainerInterface $container)
 {
     /** @var AnalyzerInterface $analyzer */
     $analyzer = $container->get(AnalyzerInterface::class);
     $cors = $analyzer->analyze($request);
     switch ($cors->getRequestType()) {
         case AnalysisResultInterface::TYPE_REQUEST_OUT_OF_CORS_SCOPE:
             // call next middleware handler
             return $next($request);
         case AnalysisResultInterface::TYPE_ACTUAL_REQUEST:
             // actual CORS request
             /** @var ResponseInterface $response */
             $response = $next($request);
             $corsHeaders = $cors->getResponseHeaders();
             // add CORS headers to Response $response
             foreach ($corsHeaders as $name => $value) {
                 $response = $response->withHeader($name, $value);
             }
             return $response;
         case AnalysisResultInterface::TYPE_PRE_FLIGHT_REQUEST:
             $corsHeaders = $cors->getResponseHeaders();
             // return 200 HTTP with $corsHeaders
             return new EmptyResponse(200, $corsHeaders);
         case AnalysisResultInterface::ERR_NO_HOST_HEADER:
         case AnalysisResultInterface::ERR_ORIGIN_NOT_ALLOWED:
         case AnalysisResultInterface::ERR_METHOD_NOT_SUPPORTED:
         case AnalysisResultInterface::ERR_HEADERS_NOT_SUPPORTED:
         default:
             // return 4XX HTTP error
             return new EmptyResponse(400);
     }
 }