Get Session Storage

@param ServiceLocatorInterface $serviceLocator Zend Service Locator
@param array                   $sessionConfig  Session Config

@return StorageInterface
@throws InvalidArgumentException
973349
protected function getSessionStorage(
        ServiceLocatorInterface $serviceLocator,
        $sessionConfig
    ) {
        if (empty($sessionConfig['storage'])) {
            return null;
        }

        if ($serviceLocator->has($sessionConfig['storage'])) {
            $storage = $serviceLocator->get($sessionConfig['storage']);
        } else {
            $storage = new $sessionConfig['storage'];
        }

        if (!$storage instanceof StorageInterface) {
            throw new InvalidArgumentException(
                'Session Storage class must implement '
                . 'Zend\Session\SaveHandler\SaveHandlerInterface'
            );
        }

        return $storage;
    }
1317025
public function getServiceManager()
    {
        $serviceManager = $this->getServiceLocator();
        if ($serviceManager instanceof ServiceManager) {
            return $serviceManager;
        }
        $msg = is_null($serviceManager)
            ? 'ServiceLocator not initialized for '.get_class($this)
            : 'Alternate service locator not compatible with getServiceManager() in ' . __CLASS__;
        throw new InvalidServiceManagerException($msg);
    }
838530
public function configureServiceManager(ServiceManager $serviceManager)
    {
        $config      = $serviceManager->get('Config');
        $appRootDir  = $config['parameters']['app.root_dir'];
        $appCacheDir = $config['parameters']['app.cache_dir'];
        $appCharset  = $config['parameters']['app.charset'];

        // The "framework.templating" option is deprecated. Please replace it with "framework.view"
        $config = $this->processConfiguration($config);

        // these are the templating engines currently supported
        // @todo - this needs to come from the app config.
        $knownEngineIds = array('php', 'smarty', 'twig', 'mustache', 'plates', 'latte');

        // these are the engines selected by the user
        $engineIds = isset($config['engines']) ? $config['engines'] : array('php');

        // filter templating engines
        $engineIds = array_intersect($engineIds, $knownEngineIds);
        if (empty($engineIds)) {
            throw new \RuntimeException(sprintf('At least one templating engine should be defined in your app config (in $config[\'view.engines\']). These are the available ones: "%s". Example: "$config[\'templating.engines\'] = array(\'%s\');"', implode('", ', $knownEngineIds), implode("', ", $knownEngineIds)));
        }

        /*
         * Templating Locator.
         */
        $serviceManager->setFactory('templating.locator', function ($serviceManager) use ($appCacheDir) {
            return new TemplateLocator(
                $serviceManager->get('file_locator'),
                $appCacheDir
            );
        });

        /*
         * Templating Name Parser.
         */
        $serviceManager->setFactory('templating.name_parser', function ($serviceManager) {
            return new TemplateNameParser($serviceManager->get('modulemanager'));
        });

        /*
         * Filesystem Loader.
         */
        $serviceManager->setFactory('templating.loader.filesystem', function ($serviceManager) {
            return new FileSystemLoader($serviceManager->get('templating.locator'));
        });

        /*
         * Templating assets helper.
         */
        $serviceManager->setFactory('templating.helper.assets', function ($serviceManager) {
            return new AssetsHelper($serviceManager->get('request')->getBasePath());
        });

        /*
         * Templating globals.
         */
        $serviceManager->setFactory('templating.globals', function ($serviceManager) {
            return new GlobalVariables($serviceManager->get('servicemanager'));
        });

        /*
         * PHP Engine.
         *
         * TODO: Migrate to Symfony\Bundle\FrameworkBundle\Templating\PhpEngine
         */
        $serviceManager->setFactory('templating.engine.php', function ($serviceManager) use ($appCharset) {
            $engine = new PhpEngine(
                $serviceManager->get('templating.name_parser'),
                $serviceManager->get('templating.loader'),
                array(
                    new SlotsHelper(),
                    $serviceManager->get('templating.helper.assets'),
                    new RouterHelper($serviceManager->get('router')),
                    new SessionHelper($serviceManager->get('session')),
                 )
            );

            $engine->addGlobal('app', $serviceManager->get('templating.globals'));
            $engine->setCharset($appCharset);

            return $engine;
        });

        /*
         * Twig Engine
         */
        $serviceManager->setFactory('templating.engine.twig', function ($serviceManager) {

            if (!class_exists('Twig_Environment')) {
                throw new \Exception('PPI\Framework\TwigModule not found. Composer require: ppi/twig-module');
            }

            $twigEnvironment = new \Twig_Environment(
                new \PPI\Framework\View\Twig\Loader\FileSystemLoader(
                    $serviceManager->get('templating.locator'),
                    $serviceManager->get('templating.name_parser'))
            );

            // Add some twig extension
            $twigEnvironment->addExtension(new \PPI\Framework\View\Twig\Extension\AssetsExtension($serviceManager->get('templating.helper.assets')));
            $twigEnvironment->addExtension(new \PPI\Framework\View\Twig\Extension\RouterExtension($serviceManager->get('router')));

            return new \PPI\Framework\View\Twig\TwigEngine($twigEnvironment, $serviceManager->get('templating.name_parser'),
                $serviceManager->get('templating.locator'), $serviceManager->get('templating.globals'));
        });

        /*
         * Smarty Engine.
         */
        $serviceManager->setFactory('templating.engine.smarty', function ($serviceManager) use ($appCacheDir) {

            if (!class_exists('NoiseLabs\Bundle\SmartyBundle\SmartyEngine')) {
                throw new \Exception('PPI\Framework\SmartyModule not found. Composer require: ppi/smarty-module');
            }

            $cacheDir = $appCacheDir . DIRECTORY_SEPARATOR . 'smarty';

            $smartyEngine = new \PPI\Framework\View\Smarty\SmartyEngine(
                new \Smarty(),
                $serviceManager->get('templating.locator'),
                $serviceManager->get('templating.name_parser'),
                $serviceManager->get('templating.loader'),
                array(
                    'cache_dir'     => $cacheDir . DIRECTORY_SEPARATOR . 'cache',
                    'compile_dir'   => $cacheDir . DIRECTORY_SEPARATOR . 'templates_c',
                ),
                $serviceManager->get('templating.globals'),
                $serviceManager->get('logger')
            );

            // Add some SmartyBundle extensions
            $smartyEngine->addExtension(new SmartyAssetsExtension($serviceManager->get('templating.helper.assets')));
            $smartyEngine->addExtension(new SmartyRouterExtension($serviceManager->get('router')));

            return $smartyEngine;
        });

        // Mustache Engine
        $serviceManager->setFactory('templating.engine.mustache', function ($serviceManager, $appCacheDir) {

            if (!class_exists('Mustache_Engine')) {
                throw new \Exception('PPI\Framework\MustacheModule not found. Composer require: ppi/mustache-module');
            }

            $rawMustacheEngine = new \Mustache_Engine(array(
                'loader' => new MustacheFileSystemLoader($serviceManager->get('templating.locator'),
                    $serviceManager->get('templating.name_parser')),
                'cache'  => $appCacheDir . DIRECTORY_SEPARATOR . 'mustache',
            ));

            return new MustacheEngine($rawMustacheEngine, $serviceManager->get('templating.name_parser'));
        });

        /*
         * Delegating Engine.
         */
        $serviceManager->setFactory('templating.engine.delegating', function ($serviceManager) use ($engineIds) {
            $delegatingEngine = new DelegatingEngine();
            // @todo - lazy load this
            foreach ($engineIds as $id) {
                $delegatingEngine->addEngine($serviceManager->get('templating.engine.' . $id));
            }

            return $delegatingEngine;
        });

        $serviceManager->setAlias('templating', 'templating.engine.delegating');
    }
1216068
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        $config = $this->getConfig($serviceLocator);

        if (!isset($config['cache'])) {
            return null;
        }

        $config = $config['cache'];
        /* @var $cache CacheProvider|Cache */
        $cache = null;
        $cacheFactory = $this->getCacheFactory($config);
        $cache = $cacheFactory->newInstance($config);

        if (isset($config['namespace'])) {
            $cache->setNamespace(trim($config['namespace']));
        }

        return $cache;
    }
82087
private function getConfig(ServiceLocatorInterface $serviceLocator)
    {
        /* @var $config array */
        $config = $serviceLocator->get('config');
        if (isset($config['phpdi-zf2'])) {
            $config = $config['phpdi-zf2'];
        } else {
            $config = [];
        }

        return $config;
    }
506102
public static function getInstance(AnConfigInterface $config, AnServiceInterface $container)
     {
         if (! $container->has($config->service_identifier)) {

             $person = null;

             if (PHP_SAPI != 'cli') {
                $session = AnService::get('com:sessions');
                $person = $session->has('person') ? $session->get('person') : null;
             }

             $repository = AnService::get('repos:people.person');

             if(isset($person->id)) {
                 $viewer = $repository->find(array('id' => $person->id));
             } else {

                 $viewer = $repository
                 ->getEntity()
                 ->setData(array(
                    'id' => 0,
                    'usertype' => ComPeopleDomainEntityPerson::USERTYPE_GUEST
                 ))->reset();

                 $viewer->getRepository()->extract($viewer);
             }

             $container->set($config->service_identifier, $viewer);
         }

         return $container->get($config->service_identifier);
     }
159016
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        /** @var PluginManager $serviceLocator */
        /** @var ServiceManager $serviceManager */
        $serviceManager = $serviceLocator->getServiceLocator();

        $writeRevisionLog = new WriteRevisionLog();

        /** @var AuthenticationService $authenticationService */
        $authenticationService = $serviceManager->get('Zend\Authentication\AuthenticationService');
        $writeRevisionLog->setAuthenticationService($authenticationService);

        /** @var RevisionRepositoryInterface $revisionRepository */
        $revisionRepository = $serviceManager->get('RevisionRepository');
        $writeRevisionLog->setRevisionRepository($revisionRepository);

        /** @var DateTimeFactoryInterface $dateTimeFactory */
        $dateTimeFactory = $serviceManager->get('DateTimeFactory');
        $writeRevisionLog->setDateTimeFactory($dateTimeFactory);

        return $writeRevisionLog;
    }
1190279
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        /** @var PluginManager $serviceLocator */
        /** @var ServiceManager $serviceManager */
        $serviceManager = $serviceLocator->getServiceLocator();

        $writeLog = new WriteLog();

        /** @var AuthenticationService $authenticationService */
        $authenticationService = $serviceManager->get('Zend\Authentication\AuthenticationService');
        $writeLog->setAuthenticationService($authenticationService);

        /** @var LogRepositoryInterface $logRepository */
        $logRepository = $serviceManager->get('LogRepository');
        $writeLog->setLogRepository($logRepository);

        /** @var DateTimeFactoryInterface $dateTimeFactory */
        $dateTimeFactory = $serviceManager->get('DateTimeFactory');
        $writeLog->setDateTimeFactory($dateTimeFactory);

        return $writeLog;
    }
1191699
public function createService(Config $config)
    {
        $options = $config->getCacheOptions();

        $storage = new FileSystem($options->getStorageOptions());

        return $storage;
    }
960970
public static function getSession()
    {
        if (is_null(self::$session)) {
            if (PHPSession::singleton()->hasAttribute(self::PHPSESSION_SESSION_KEY)) {
                $session = PHPSession::singleton()->getAttribute(self::PHPSESSION_SESSION_KEY);
                if (! $session instanceof common_session_Session) {
                    throw new common_exception_Error('Non session stored in php-session');
                }
                self::$session = $session;
            } else {
                self::$session = new common_session_AnonymousSession();
            }
        }
        if (self::$session instanceof ServiceLocatorAwareInterface) {
            self::$session->setServiceLocator(ServiceManager::getServiceManager());
        }
        return self::$session;
    }
457589
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        /**
         * @var array $config
         */
        $config = $serviceLocator->get('config');

        /**
         * @var \Zend\View\HelperPluginManager $serverUrl
         */
        $serverUrl = $serviceLocator->get('ViewHelperManager');

        /**
         * @var \Zend\Mvc\I18n\Translator $translator
         */
        $translator = $serviceLocator->get('translator');

        return new Search(
            $config,
            $serverUrl,
            $translator
        );
    }
563666
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        $config = $serviceLocator->get('config');

        if (! array_key_exists('prooph.link.fileconnector', $config)) throw new \InvalidArgumentException('Missing prooph.link.fileconnector root config key');
        if (! is_array($config['prooph.link.fileconnector'])) throw new \InvalidArgumentException("Config for prooph.link.fileconnector must be an array");
        if (! array_key_exists('file_types', $config['prooph.link.fileconnector'])) throw new \InvalidArgumentException('Missing file_types in prooph.link.fileconnector config');

        $fileTypeAdapters = new FileTypeAdapterManager(new Config($config['prooph.link.fileconnector']['file_types']));

        $fileTypeAdapters->setServiceLocator($serviceLocator);

        return $fileTypeAdapters;
    }
1162539
private function getStorage(ConfigObject $config = null)
    {
        if (!isset($this->storage)) {
            try {
                $driver = $config->get('Storage.Driver', NativeStorage::class);
                $this->storage = $this->factory($driver, CookieStorageInterface::class, [$config]);
            } catch (Exception $e) {
                throw new CookieException($e->getMessage());
            }
        }

        return $this->storage;
    }
1028694
protected function getServiceList()
    {
        $name = $this->poolConfig->getName();
        if ($this->poolConfig->isUseProvider() && App::hasBean('providerSelector')) {
            $type = $this->poolConfig->getProvider();

            return provider()->select($type)->getServiceList($name);
        }

        $uri = $this->poolConfig->getUri();
        if (empty($uri)) {
            $error = sprintf('Service does not configure uri name=%s', $name);
            App::error($error);
            throw new \InvalidArgumentException($error);
        }

        return $uri;
    }
294639
public static function getInstance(AnConfigInterface $config, AnServiceInterface $container)
    {
        if (! $container->has($config->service_identifier)) {
            $registry = $container->get('application.registry', array('key' => $config->service_identifier));

            if (! $registry->offsetExists('scopes')) {
                $components = $container->get('repos:components.component')->fetchSet();

                $dispatcher = $container->get('anahita:event.dispatcher');
                $components->registerEventDispatcher($dispatcher);

                $event = new AnEvent(array('scope' => array()));
                $dispatcher->dispatchEvent('onBeforeFetch', $event);

                $scopes = new self();

                foreach ($event->scope as $scope) {
                    $scope = AnConfig::unbox($scope);

                    if (is_array($scope)) {
                        $scope = $container->get('com:components.domain.entity.scope', $scope);
                    }

                    $scopes[$scope->getKey()] = $scope;
                }

                $registry->offsetSet('scopes', $scopes);
            }

            $container->set($config->service_identifier, $registry->offsetGet('scopes'));
        }

        return $container->get($config->service_identifier);
    }
1235932
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        /** @var \Eye4web\Zf2Board\Options\ModuleOptions $options */
        $options = $serviceLocator->get('Eye4web\Zf2Board\Options\ModuleOptions');

        /** @var \Zend\Authentication\AuthenticationService $service */
        $service = $serviceLocator->get($options->getAuthenticationService());

        return $service;
    }
1326494
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        $config     = $serviceLocator->get('Config');
        $appRootDir = $config['parameters']['app.root_dir'];

        return new FileLocator($serviceLocator->get('ModuleManager'), $appRootDir);
    }