当前位置: 首页>>代码示例>>PHP>>正文


PHP ContainerInterface::setService方法代码示例

本文整理汇总了PHP中Interop\Container\ContainerInterface::setService方法的典型用法代码示例。如果您正苦于以下问题:PHP ContainerInterface::setService方法的具体用法?PHP ContainerInterface::setService怎么用?PHP ContainerInterface::setService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Interop\Container\ContainerInterface的用法示例。


在下文中一共展示了ContainerInterface::setService方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __invoke

 /**
  * @internal
  * @codeCoverageIgnore
  */
 public function __invoke(\Interop\Container\ContainerInterface $container, $requestedName, array $options = null)
 {
     // Retreive database configuration from config file.
     $config = $container->get('Library\\UserConfig')['database'];
     $config['options']['buffer_results'] = true;
     // Set charset to utf8mb4 for MySQL, utf8 for everything else.
     if (stripos($config['driver'], 'mysql') === false) {
         $config['charset'] = 'utf8';
     } else {
         $config['charset'] = 'utf8mb4';
     }
     $adapter = new \Zend\Db\Adapter\Adapter($config);
     $database = \Nada\Factory::getDatabase($adapter);
     if ($database->isSqlite()) {
         $database->emulatedDatatypes = array('bool', 'date', 'decimal', 'timestamp');
     } elseif ($database->isMySql()) {
         $database->emulatedDatatypes = array('bool');
     }
     $database->setTimezone();
     // Return requested service, store instance of other service first
     if ($requestedName == 'Db') {
         $container->setService('Database\\Nada', $database);
         return $adapter;
     } else {
         $container->setService('Db', $adapter);
         return $database;
     }
 }
开发者ID:hschletz,项目名称:braintacle,代码行数:32,代码来源:AbstractDatabaseFactory.php

示例2: marshalTranslatorFromConfig

 /**
  * Attempt to marshal a translator from configuration.
  *
  * Returns:
  * - an MvcTranslator seeded with a DummyTranslator if "translator"
  *   configuration is available, and evaluates to boolean false.
  * - an MvcTranslator seed with an I18nTranslator if "translator"
  *   configuration is available, and is a non-empty array or a Traversable
  *   instance.
  * - null in all other cases, including absence of a configuration service.
  *
  * @param ContainerInterface $container
  * @return null|MvcTranslator
  */
 private function marshalTranslatorFromConfig(ContainerInterface $container)
 {
     if (!$container->has('config')) {
         return;
     }
     $config = $container->get('config');
     if (!array_key_exists('translator', $config)) {
         return;
     }
     // 'translator' => false
     if ($config['translator'] === false) {
         return new MvcTranslator(new DummyTranslator());
     }
     // Empty translator configuration
     if (is_array($config['translator']) && empty($config['translator'])) {
         return;
     }
     // Unusable translator configuration
     if (!is_array($config['translator']) && !$config['translator'] instanceof Traversable) {
         return;
     }
     // Create translator from configuration
     $i18nTranslator = I18nTranslator::factory($config['translator']);
     // Inject plugins, if present
     if ($container->has('TranslatorPluginManager')) {
         $i18nTranslator->setPluginManager($container->get('TranslatorPluginManager'));
     }
     // Inject into service manager instances
     if ($container instanceof ServiceManager) {
         $container->setService(TranslatorInterface::class, $i18nTranslator);
     }
     return new MvcTranslator($i18nTranslator);
 }
开发者ID:zendframework,项目名称:zend-mvc-i18n,代码行数:47,代码来源:TranslatorFactory.php


注:本文中的Interop\Container\ContainerInterface::setService方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。