/**
  * Executa a ação.
  *
  * @return mixin
  */
 public function execute()
 {
     $oAuthServiceName = $this->params('oAuthService');
     $redirectAfterResponse = $this->params()->fromQuery('redirectAfterResponse');
     $scopes = $this->params()->fromQuery('scopes', []);
     $routeToRedirectAfterResponse = null;
     if (is_string($scopes)) {
         if (trim($scopes)) {
             $scopes = explode(',', $scopes);
         } else {
             $scopes = [];
         }
     }
     if (!$oAuthServiceName) {
         return $this->error('The query param "oAuthService" is required.');
     }
     if ($redirectAfterResponse) {
         if (is_string($redirectAfterResponse)) {
             $redirectAfterResponse = CryptQueryParam::decrypt_($redirectAfterResponse);
         }
         if ($redirectAfterResponse) {
             $routeToRedirectAfterResponse = new InternalRoute($redirectAfterResponse);
         }
     }
     AskForAuthorizationResponse::storeDateToUseAfterResponse($routeToRedirectAfterResponse, $oAuthServiceName, $scopes);
     /** @var OAuthServiceInterface $oAuthService */
     $oAuthService = $this->container->get('Sta\\OAuthConnect\\OAuthService\\' . $oAuthServiceName);
     $callbackUrl = $this->getController()->url()->fromRoute('sta/oAuthConnect/response', [], ['force_canonical' => true]);
     $authorizeRedirectUri = $oAuthService->getUrlToAskAuthorization($callbackUrl, $scopes);
     if (!$authorizeRedirectUri) {
         return $this->error('OAuth Service implementation class method ' . get_class($oAuthService) . '::getUrlToAskAuthorization() must return a valid URL.');
     }
     return $this->getController()->redirect()->toUrl($authorizeRedirectUri);
 }
 /**
  * @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));
 }
 /**
  * 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));
 }
 /**
  * @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;
 }
 /**
  * @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;
 }
 /**
  * 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));
 }
 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);
 }
 /**
  * Create and return an instance of the Middleware.
  *
  * @param  Interop\Container\ContainerInterface $container
  * @param  string $requestedName
  * @param  array $options
  * @return MiddlewareInterface
  */
 public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
 {
     $rqlParser = new Rest\Rql\RqlParser();
     $responseEncoder = new Rest\ResponseEncoder();
     $resourceName = $requestedName;
     //is there config for this resource?
     $config = $container->get('config');
     if (isset($config['resource'][$resourceName]['storeMiddleware'])) {
         $storeMiddlewareServiceName = $config['resource'][$resourceName]['storeMiddleware'];
         $storeMiddleware = $container->get($storeMiddlewareServiceName);
         return new restActionPipe($rqlParser, $storeMiddleware, $responseEncoder);
     }
     //is there table with same name?
     $db = $container->has('db') ? $container->get('db') : null;
     if (isset($db)) {
         $dbMetadata = new Zend\Db\Metadata\Metadata($db);
         $tableNames = $dbMetadata->getTableNames();
         if (isset($tableNames[$resourceName])) {
             $tableGateway = new TableGateway($resourceName, $db);
             $dataStore = new DbTable($tableGateway);
             $storeMiddleware = new StoreMiddleware($dataStore);
             return new Rest\RestActionPipe($rqlParser, $storeMiddleware, $responseEncoder);
         }
     }
     throw new DataStoresException('Can\'t make RestActionPipe' . ' for resource: ' . $resourceName);
 }
Пример #9
0
 /**
  * Tears down the fixture, for example, closes a network connection.
  * This method is called after a test is executed.
  */
 protected function tearDown()
 {
     $adapter = $this->container->get('db');
     $tableManagerMysql = new TableManagerMysql($adapter);
     $tableManagerMysql->deleteTable($this->object->getStore()->getTable());
     $tableManagerMysql->deleteTable($this->object->getQueue()->getStore()->getTable());
 }
 /**
  * @param ContainerInterface $container
  * @return TeacherAction
  */
 public function __invoke(ContainerInterface $container)
 {
     $router = $container->get(RouterInterface::class);
     $userService = $container->get(TeacherService::class);
     $studentWebService = $container->get('StudentWebService');
     return new TeacherAction($router, $userService, $studentWebService);
 }
Пример #11
0
 /**
  * __invoke
  *
  * @param ContainerInterface $container
  *
  * @return AxosoftLoggerPsr
  */
 public function __invoke($container)
 {
     $configRoot = $container->get('Config');
     $loggerOptions = $configRoot['Reliv\\RcmAxosoft']['errorLogger'];
     $api = $container->get('Reliv\\AxosoftApi\\Service\\AxosoftApi');
     return new AxosoftLoggerPsr($api, $loggerOptions);
 }
Пример #12
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);
 }
Пример #13
0
 public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
 {
     /* @var $aclCache \Zend\Cache\Storage\StorageInterface */
     $aclCache = $container->get('AclCache');
     $acl = $aclCache->getItem('Acl');
     if (!$acl) {
         /* @var $userApi UserApiInterface */
         $userApi = $container->get(UserApiInterface::SERVICE_NAME);
         $acl = new Acl();
         $resources = $userApi->getPermissions();
         foreach ($resources as $resource) {
             $acl->addResource($resource);
         }
         $roles = $userApi->getRolesAndParent();
         foreach ($roles as $role => $parents) {
             $this->addRoleToAcl($role, $roles, $acl);
         }
         $rolePermissions = $userApi->getRolePermissions();
         foreach ($rolePermissions as $role => $permissions) {
             $acl->allow($role, $permissions);
         }
         $deniedRolePermissions = $userApi->getDeniedRolePermissions();
         foreach ($deniedRolePermissions as $role => $permissions) {
             $acl->deny($role, $permissions);
         }
         $aclCache->setItem('Acl', $acl);
     }
     return $acl;
 }
 /**
  * @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;
 }
Пример #15
0
 /**
  * @param ContainerInterface $container
  * @return EventStore
  */
 public function __invoke(ContainerInterface $container)
 {
     $config = $container->get('config');
     if (!isset($config['prooph'])) {
         throw ConfigurationException::configurationError('Missing prooph config key in application config');
     }
     if (!isset($config['prooph']['event_store'])) {
         throw ConfigurationException::configurationError('Missing key event_store in prooph configuration');
     }
     $config = $config['prooph']['event_store'];
     if (!isset($config['adapter']['type'])) {
         throw ConfigurationException::configurationError(sprintf('Event store adapter is missing in configuration'));
     }
     $adapter = $container->get($config['adapter']['type']);
     if (!isset($config['event_emitter'])) {
         $eventEmitter = new ProophActionEventEmitter();
     } else {
         $eventEmitter = $container->get($config['event_emitter']);
     }
     $eventStore = new EventStore($adapter, $eventEmitter);
     $plugins = isset($config['plugins']) ? $config['plugins'] : [];
     foreach ($plugins as $pluginAlias) {
         $plugin = $container->get($pluginAlias);
         if (!$plugin instanceof Plugin) {
             throw ConfigurationException::configurationError(sprintf('Plugin %s does not implement the Plugin interface', $pluginAlias));
         }
         $plugin->setUp($eventStore);
     }
     return $eventStore;
 }
Пример #16
0
 public function __invoke(ContainerInterface $container) : callable
 {
     $pipeline = new MiddlewarePipe();
     $pipeline->pipe($container->get('Mwop\\Auth\\UserSession'));
     $pipeline->pipe(new Page($container->get(TemplateRendererInterface::class), $container->get(UnauthorizedResponseFactory::class)));
     return $pipeline;
 }
Пример #17
0
 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);
 }
 /**
  * Create and return a Console adapter instance.
  * In case we're not in a Console environment, return a dummy stdClass object.
  *
  * In order to disable adapter auto-detection and use a specific adapter (and charset),
  * add the following fields to application configuration, for example:
  *
  *     'console' => array(
  *         'adapter' => 'MyConsoleAdapter',     // always use this console adapter
  *         'charset' => 'MyConsoleCharset',     // always use this console charset
  *      ),
  *      'service_manager' => array(
  *          'invokables' => array(
  *              'MyConsoleAdapter' => 'Zend\Console\Adapter\Windows',
  *              'MyConsoleCharset' => 'Zend\Console\Charset\DESCG',
  *          )
  *      )
  *
  * @param  ContainerInterface $container
  * @param  string $name
  * @param  null|array $options
  * @return AdapterInterface|stdClass
  */
 public function __invoke(ContainerInterface $container, $name, array $options = null)
 {
     // First, check if we're actually in a Console environment
     if (!Console::isConsole()) {
         // SM factory cannot currently return null, so we return dummy object
         return new stdClass();
     }
     // Read app config and determine Console adapter to use
     $config = $container->get('config');
     if (!empty($config['console']) && !empty($config['console']['adapter'])) {
         // use the adapter supplied in application config
         $adapter = $container->get($config['console']['adapter']);
     } else {
         // try to detect best console adapter
         $adapter = Console::detectBestAdapter();
         $adapter = new $adapter();
     }
     // check if we have a valid console adapter
     if (!$adapter instanceof AdapterInterface) {
         // SM factory cannot currently return null, so we convert it to dummy object
         return new stdClass();
     }
     // Optionally, change Console charset
     if (!empty($config['console']) && !empty($config['console']['charset'])) {
         // use the charset supplied in application config
         $charset = $container->get($config['console']['charset']);
         $adapter->setCharset($charset);
     }
     return $adapter;
 }
Пример #19
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));
 }
 public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
 {
     $api = $container->get(UserApiInterface::SERVICE_NAME);
     $acl = $container->get('Acl');
     $aclCache = $container->get('AclCache');
     return new RoleController($api, $acl, $aclCache);
 }
Пример #21
0
 public function testFactoryRouter()
 {
     $factory = new ApiFactory();
     $router = $this->prophesize(RouterInterface::class);
     $this->container->get(RouterInterface::class)->willReturn($router);
     $this->assertTrue($factory instanceof ApiFactory);
 }
 /**
  * @param ContainerInterface $container
  * @param string $requestedName
  * @param array $options, optional
  *
  * @return Application
  */
 public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
 {
     $cliApplication = new Application('AsseticBundle', '1.7.0');
     $cliApplication->add(new BuildCommand($container->get('AsseticService')));
     $cliApplication->add(new SetupCommand($container->get('AsseticService')));
     return $cliApplication;
 }
Пример #23
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));
     });
 }
 /**
  * @param ContainerInterface $container
  * @return IndexAction
  */
 public function __invoke(ContainerInterface $container)
 {
     $router = $container->get(RouterInterface::class);
     $template = $container->has(TemplateRendererInterface::class) ? $container->get(TemplateRendererInterface::class) : null;
     $albumService = $container->get(AlbumServiceInterface::class);
     return new IndexAction($router, $template, $albumService);
 }
 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, $requestedName, array $options = null)
 {
     $config = $container->get('Configuration');
     $config = $config['smarty'];
     /** @var $pathResolver \Zend\View\Resolver\TemplatePathStack */
     $pathResolver = clone $container->get('ViewTemplatePathStack');
     $pathResolver->setDefaultSuffix($config['suffix']);
     /** @var $resolver \Zend\View\Resolver\AggregateResolver */
     $resolver = $container->get('ViewResolver');
     $resolver->attach($pathResolver);
     $engine = new \Smarty();
     $engine->setCompileDir($config['compile_dir']);
     $engine->setEscapeHtml($config['escape_html']);
     $engine->setTemplateDir($pathResolver->getPaths()->toArray());
     $engine->setCaching($config['caching']);
     $engine->setCacheDir($config['cache_dir']);
     $engine->addPluginsDir($config['plugins_dir']);
     if (file_exists($config['config_file'])) {
         $engine->configLoad($config['config_file']);
     }
     $renderer = new Renderer();
     $renderer->setEngine($engine);
     $renderer->setSuffix($config['suffix']);
     $renderer->setResolver($resolver);
     return $renderer;
 }
Пример #27
0
 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);
 }
Пример #28
0
 /**
  * Create the action.
  *
  * @param ContainerInterface $container The app container.
  *
  * @return callable The action class.
  */
 public function __invoke(ContainerInterface $container)
 {
     $templateRenderer = $container->get(TemplateRendererInterface::class);
     $repositoryManager = $container->get(RepositoryManagerInterface::class);
     $site = $container->get('site');
     return new $this->actionClass($templateRenderer, $repositoryManager, $site);
 }
Пример #29
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);
 }
 /**
  * @param ContainerInterface $container
  * @return BookingService
  */
 public function __invoke(ContainerInterface $container)
 {
     $config = $container->get('config');
     //$locations = $config['locations']?? [];
     $locations = isset($config['locations']) ? $config['locations'] : array();
     return new BookingService($container->get(CargoRepositoryInterface::class), $container->get(TransactionManager::class), $container->get(RoutingServiceInterface::class), $locations);
 }