本文整理汇总了PHP中Zend\ServiceManager\ServiceLocatorInterface::get方法的典型用法代码示例。如果您正苦于以下问题:PHP ServiceLocatorInterface::get方法的具体用法?PHP ServiceLocatorInterface::get怎么用?PHP ServiceLocatorInterface::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\ServiceManager\ServiceLocatorInterface
的用法示例。
在下文中一共展示了ServiceLocatorInterface::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createService
public function createService(\Zend\ServiceManager\ServiceLocatorInterface $sm)
{
$config = $sm->get('config');
if (isset($config['session'])) {
$session = $config['session'];
$sessionConfig = null;
if (isset($session['config'])) {
$class = isset($session['config']['class']) ? $session['config']['class'] : 'Zend\\Session\\Config\\SessionConfig';
$options = isset($session['config']['options']) ? $session['config']['options'] : array();
$sessionConfig = new $class();
$sessionConfig->setOptions($options);
}
$sessionStorage = null;
if (isset($session['storage'])) {
$class = $session['storage'];
$sessionStorage = new $class();
}
$sessionSaveHandler = null;
if (isset($session['save_handler'])) {
// class should be fetched from service manager since it will require constructor arguments
$sessionSaveHandler = $sm->get($session['save_handler']);
}
$sessionManager = new self($sessionConfig, $sessionStorage, $sessionSaveHandler);
} else {
$sessionManager = new self();
}
\Zend\Session\Container::setDefaultManager($sessionManager);
return $sessionManager;
}
示例2: createService
/**
* Factory method.
*
* @param ServiceLocatorInterface $serviceLocator
* @return mixed
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
$service = new PicService();
$service->setEntityManager($serviceLocator->get('Doctrine\\ORM\\EntityManager'));
$service->setAuthService($serviceLocator->get('zfcuser_auth_service'));
return $service;
}
示例3: createService
public function createService(ServiceLocatorInterface $serviceLocator)
{
$router = $serviceLocator->get('Router');
$application = $serviceLocator->get('Application');
$options = $serviceLocator->get('zfcuser_module_options');
return new RedirectCallback($application, $router, $options);
}
示例4: createService
public function createService(ServiceLocatorInterface $serviceLocator)
{
$em = $serviceLocator->get('doctrine.entitymanager.orm_default');
$options = $serviceLocator->get('BiBoBlogOptions');
$form = new \BiBoBlog\Form\BiBoBlogForm($em, $options);
return $form;
}
示例5: createService
public function createService(ServiceLocatorInterface $serviceLocator)
{
$adapter = $serviceLocator->get('Zend\\Db\\Adapter\\Adapter');
$entity = $serviceLocator->get('Techtree\\Entity\\Research');
$table = new ResearchTable($adapter, $entity);
return $table;
}
示例6: createService
public function createService(ServiceLocatorInterface $sm)
{
$service = new TableService();
$service->setCityCodesTable($sm->get('city-codes-table'));
$service->setListingsTable($sm->get('listings-table'));
return $service;
}
示例7: createService
/**
* Create service
*
* @param ServiceLocatorInterface $serviceLocator
*
* @return mixed
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
$pluginManager = $serviceLocator->get('Phpro\\MailManager\\PluginManager');
$adapter = $serviceLocator->get('Phpro\\MailManager\\DefaultAdapter');
$instance = new Instance($pluginManager, $adapter);
return $instance;
}
示例8: createService
/**
* 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 ServiceLocatorInterface $serviceLocator
* @return AdapterInterface|stdClass
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
// 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 = $serviceLocator->get('Config');
if (!empty($config['console']) && !empty($config['console']['adapter'])) {
// use the adapter supplied in application config
$adapter = $serviceLocator->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 = $serviceLocator->get($config['console']['charset']);
$adapter->setCharset($charset);
}
return $adapter;
}
示例9: createService
/**
* Create Service Factory
*
* @param ServiceLocatorInterface $serviceLocator
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
$adapter = $serviceLocator->get('Zend\\Db\\Adapter\\Adapter');
$entity = $serviceLocator->get('Blog\\Entity\\Blog');
$table = new BlogTable($adapter, $entity);
return $table;
}
示例10: createService
public function createService(ServiceLocatorInterface $serviceLocator)
{
$options = $serviceLocator->get('cdiuser_options');
$em = $serviceLocator->get('zfcuser_doctrine_em');
$userSession = new \CdiUser\Service\UserSession($options, $em, $serviceLocator);
return $userSession;
}
示例11: createService
public function createService(ServiceLocatorInterface $serviceLocator)
{
$config = $serviceLocator->get('config');
// The parameters in Doctrine 2 and ZF2 are slightly different.
// Below is an example how we can reuse the db settings
$doctrineDbConfig = (array) $config['db'];
$doctrineDbConfig['driver'] = strtolower($doctrineDbConfig['driver']);
if (!isset($doctrineDbConfig['dbname'])) {
$doctrineDbConfig['dbname'] = $doctrineDbConfig['database'];
}
if (!isset($doctrineDbConfig['host'])) {
$doctrineDbConfig['host'] = $doctrineDbConfig['hostname'];
}
if (!isset($doctrineDbConfig['user'])) {
$doctrineDbConfig['user'] = $doctrineDbConfig['username'];
}
$doctrineConfig = Setup::createAnnotationMetadataConfiguration($config['doctrine']['entity_path'], true);
$entityManager = DoctrineEntityManager::create($doctrineDbConfig, $doctrineConfig);
if (isset($config['doctrine']['initializers'])) {
$eventManager = $entityManager->getEventManager();
foreach ($config['doctrine']['initializers'] as $initializer) {
$eventClass = new DoctrineEvent(new $initializer(), $serviceLocator);
$eventManager->addEventListener(\Doctrine\ORM\Events::postLoad, $eventClass);
}
}
if ($serviceLocator->has('doctrine-profiler')) {
$profiler = $serviceLocator->get('doctrine-profiler');
$entityManager->getConfiguration()->setSQLLogger($profiler);
}
return $entityManager;
}
示例12: createService
/**
* {@inheritDoc}
*
* @throws RuntimeException
* @return AnnotationBuilder
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
/* @var $options FormAnnotationBuilder */
$options = $serviceLocator->get(FormAnnotationBuilder::class);
$cache = $serviceLocator->has($options->getCache()) ? $serviceLocator->get($options->getCache()) : null;
$builder = new AnnotationBuilder($cache);
if ($serviceLocator->has('FormElementManager')) {
$serviceLocator->get('FormElementManager')->injectFactory($builder);
}
foreach ($options->getAnnotations() as $annotation) {
$builder->getAnnotationParser()->registerAnnotation($annotation);
}
$events = $builder->getEventManager();
foreach ($options->getListeners() as $listener) {
$listener = $serviceLocator->has($listener) ? $serviceLocator->get($listener) : new $listener();
if (!$listener instanceof ListenerAggregateInterface) {
throw new RuntimeException(sprintf('Invalid event listener (%s) provided', get_class($listener)));
}
$events->attach($listener);
}
if (null !== $options->getPreserveDefinedOrder()) {
$builder->setPreserveDefinedOrder($options->getPreserveDefinedOrder());
}
return $builder;
}
示例13: getMainItems
/**
* Retrieve array of menu items
*
* Returns only items with 'main' equal to TRUE
*
* @return array
*/
public function getMainItems()
{
$result = array_filter($this->serviceLocator->get('config')['nav'], function ($value) {
return isset($value['main']) && (bool) $value['main'];
});
return $result;
}
示例14: _getServTranslator
/**
* Retourne le translator.
*
* @var \Zend\I18n\Translator\Translator
*/
public function _getServTranslator()
{
if (!$this->_servTranslator) {
$this->_servTranslator = $this->_serviceLocator->get('translator');
}
return $this->_servTranslator;
}
示例15: createService
public function createService(ServiceLocatorInterface $serviceLocator)
{
/** @var \Zend\Mvc\Application $app */
$app = $serviceLocator->get('Application');
/** @var \Zend\Mvc\Router\Http\RouteMatch $routeMatch */
$routeMatch = $app->getMvcEvent()->getRouteMatch();
if ($routeMatch->getParam('viewModel')) {
$viewModel = $serviceLocator->get($routeMatch->getParam('viewModel'));
if (!$viewModel instanceof ViewModel) {
throw new \RuntimeException('ViewModel must be instance of ' . ViewModel::class);
}
} else {
$viewModel = new ViewModel();
}
if (!$viewModel->getTemplate()) {
$template = $routeMatch->getParam('template');
if ($template) {
if (!is_string($template)) {
throw new \RuntimeException('Parameter template must be string');
}
$viewModel->setTemplate($template);
}
}
return $viewModel;
}