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


PHP Container::get方法代码示例

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


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

示例1: lang

 /**
  * Return lang by name
  *
  * @param string $name
  * @param mixed $default Default value that will be returned if lang is not found
  * @return string
  */
 function lang($name, $default = null)
 {
     if (is_null($default)) {
         $default = "Missing lang: {$name}";
     }
     return $this->langs->get($name, $default);
 }
开发者ID:abhinay100,项目名称:fengoffice_app,代码行数:14,代码来源:Localization.class.php

示例2: _resolveArgs

 /**
 * Getting required arguments with given parameters
 *
 * @param \ReflectionParameter[] $required Arguments
 * @param array                  $params   Parameters
 *
 *@return array
 */
 private function _resolveArgs($required, $params = array())
 {
     $args = array();
     foreach ($required as $param) {
         $name = $param->getName();
         $type = $param->getClass();
         if (isset($type)) {
             $type = $type->getName();
         }
         if (isset($params[$name])) {
             $args[] = $params[$name];
         } elseif (is_string($type) && isset($params[$type])) {
             $args[] = $params[$type];
         } else {
             $content = $this->_container->get($name);
             if (isset($content)) {
                 $args[] = $content;
             } elseif (is_string($type)) {
                 $args[] = $this->_container->get($type);
             } else {
                 $args[] = null;
             }
         }
     }
     return $args;
 }
开发者ID:TheBlackBloodyUnicorn,项目名称:pico_wanderblog,代码行数:34,代码来源:ReflectorItem.class.php

示例3: warmUp

 public function warmUp($cacheDir)
 {
     // we need the directory no matter the hydrator cache generation strategy.
     $hydratorCacheDir = $this->container->getParameter('doctrine_mongodb.odm.hydrator_dir');
     if (!file_exists($hydratorCacheDir)) {
         if (false === @mkdir($hydratorCacheDir, 0777, true)) {
             throw new \RuntimeException(sprintf('Unable to create the Doctrine Hydrator directory (%s)', dirname($hydratorCacheDir)));
         }
     } else {
         if (!is_writable($hydratorCacheDir)) {
             throw new \RuntimeException(sprintf('Doctrine Hydrator directory (%s) is not writable for the current system user.', $hydratorCacheDir));
         }
     }
     // if hydrators are autogenerated we don't need to generate them in the cache warmer.
     if ($this->container->getParameter('doctrine_mongodb.odm.auto_generate_hydrator_classes') === true) {
         return;
     }
     /* @var $registry \Doctrine\Common\Persistence\ManagerRegistry */
     $registry = $this->container->get('doctrine_mongodb');
     foreach ($registry->getManagers() as $dm) {
         /* @var $dm \Doctrine\ODM\MongoDB\DocumentManager */
         $classes = $dm->getMetadataFactory()->getAllMetadata();
         $dm->getHydratorFactory()->generateHydratorClasses($classes);
     }
 }
开发者ID:pnvasanth,项目名称:DoctrineMongoDBBundle,代码行数:25,代码来源:HydratorCacheWarmer.php

示例4: get

 /**
  * @param string $componentKey
  *
  * @return object|null
  */
 public function get($componentKey)
 {
     if (array_key_exists($componentKey, $this->components)) {
         return $this->components[$componentKey];
     }
     if ($this->parent !== null) {
         return $this->parent->get($componentKey);
     }
     return null;
 }
开发者ID:tsufeki,项目名称:phpcmplr,代码行数:15,代码来源:Container.php

示例5: showStatusOrder

 /**
  *
  * @param Container $container
  * @param boolean $value
  * @return string
  */
 public static function showStatusOrder($container, $value)
 {
     if ($value == 1) {
         $html = "<span class=\"label label-sm label-info\">" . $container->get('translator')->trans('Completed') . "</span>";
     } elseif ($value == 0) {
         $html = "<span class=\"label label-sm label-danger\">" . $container->get('translator')->trans('Closed') . "</span>";
     } else {
         $html = "<span class=\"label label-sm label-warning\">" . $container->get('translator')->trans('Pending') . "</span>";
     }
     return $html;
 }
开发者ID:rarekit,项目名称:posit,代码行数:17,代码来源:Html.php

示例6: testGetDefsAndServices

 /**
  * @todo Implement testGetServices().
  */
 public function testGetDefsAndServices()
 {
     $this->container->set('foo', new \StdClass());
     $this->container->set('bar', new \StdClass());
     $this->container->set('baz', new \StdClass());
     $expect = ['foo', 'bar', 'baz'];
     $actual = $this->container->getDefs();
     $this->assertSame($expect, $actual);
     $service = $this->container->get('bar');
     $expect = ['bar'];
     $actual = $this->container->getServices();
     $this->assertSame($expect, $actual);
 }
开发者ID:walterjrp,项目名称:form-builder,代码行数:16,代码来源:ContainerTest.php

示例7: __construct

 /**
  * Constructor
  *
  * @param Container $container The container object
  * @param Output    $output    The console output
  */
 public function __construct($container, $output)
 {
     $this->container = $container;
     $this->converter = new CaseConverter();
     $this->registry = $container->get('doctrine');
     $this->filesystem = $container->get('filesystem');
     $this->output = $output;
     $parameters = $container->getParameterBag()->all();
     foreach ($parameters as $k => $v) {
         $pos = strpos($k, '.');
         $alias = substr($k, 0, $pos);
         $parameter = substr($k, $pos + 1);
         $this->parameters[$alias][$parameter] = $v;
     }
 }
开发者ID:ldnok,项目名称:GeneratorBundle,代码行数:21,代码来源:Generator.php

示例8: register

 /**
  * Register Slim's default services.
  *
  * @param Container $container A DI container implementing ArrayAccess and container-interop.
  *
  * @return void
  */
 public function register($container)
 {
     $container['errorHandler'] = function ($container) {
         return new Error($container->get('settings')['displayErrorDetails']);
     };
     $container['phpErrorHandler'] = function ($container) {
         return new PhpError($container->get('settings')['displayErrorDetails']);
     };
     $container['notFoundHandler'] = function ($container) {
         return new NotFound($container->get('settings')['displayErrorDetails']);
     };
     $container['notAllowedHandler'] = function ($container) {
         return new NotAllowed($container->get('settings')['displayErrorDetails']);
     };
 }
开发者ID:restyphp,项目名称:resty,代码行数:22,代码来源:DefaultServicesProvider.php

示例9: testGet

 /**
  *
  * Tests that a service is of the expected class.
  *
  * @param string $name The service name.
  *
  * @param string $class The expected class.
  *
  * @return null
  *
  * @dataProvider provideGet
  *
  */
 public function testGet($name, $class)
 {
     if (!$name) {
         $this->markTestSkipped('No service name passed for testGet().');
     }
     $this->assertInstanceOf($class, $this->di->get($name));
 }
开发者ID:watsonad,项目名称:opendocman,代码行数:20,代码来源:AbstractContainerTest.php

示例10: get

 /**
  * Gets a service.
  *
  * @param  string $id              The service identifier
  * @param  int    $invalidBehavior The behavior when the service does not exist
  *
  * @return object The associated service
  *
  * @throws \InvalidArgumentException if the service is not defined
  * @throws \LogicException if the service has a circular reference to itself
  *
  * @see Reference
  */
 public function get($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE)
 {
     try {
         return parent::get($id, ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE);
     } catch (\InvalidArgumentException $e) {
         if (isset($this->loading[$id])) {
             throw new \LogicException(sprintf('The service "%s" has a circular reference to itself.', $id));
         }
         if (!$this->hasDefinition($id) && isset($this->aliases[$id])) {
             return $this->get($this->aliases[$id]);
         }
         try {
             $definition = $this->getDefinition($id);
         } catch (\InvalidArgumentException $e) {
             if (ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE !== $invalidBehavior) {
                 return null;
             }
             throw $e;
         }
         $this->loading[$id] = true;
         $service = $this->createService($definition, $id);
         unset($this->loading[$id]);
         return $service;
     }
 }
开发者ID:bill97420,项目名称:symfony,代码行数:38,代码来源:Builder.php

示例11: get_admin_ids

 /**
  * Fetch admin IDs
  */
 public static function get_admin_ids()
 {
     if (!Container::get('cache')->isCached('admin_ids')) {
         Container::get('cache')->store('admin_ids', \FeatherBB\Model\Cache::get_admin_ids());
     }
     return Container::get('cache')->retrieve('admin_ids');
 }
开发者ID:featherbb,项目名称:featherbb,代码行数:10,代码来源:AdminUtils.php

示例12: validate_search_word

 public function validate_search_word($word, $idx)
 {
     static $stopwords;
     // If the word is a keyword we don't want to index it, but we do want to be allowed to search it
     if ($this->is_keyword($word)) {
         return !$idx;
     }
     if (!isset($stopwords)) {
         if (!Container::get('cache')->isCached('stopwords')) {
             Container::get('cache')->store('stopwords', \FeatherBB\Model\Cache::get_config(), '+1 week');
         }
         $stopwords = Container::get('cache')->retrieve('stopwords');
     }
     // If it is a stopword it isn't valid
     if (in_array($word, $stopwords)) {
         return false;
     }
     // If the word is CJK we don't want to index it, but we do want to be allowed to search it
     if ($this->is_cjk($word)) {
         return !$idx;
     }
     // Exclude % and * when checking whether current word is valid
     $word = str_replace(array('%', '*'), '', $word);
     // Check the word is within the min/max length
     $num_chars = Utils::strlen($word);
     return $num_chars >= ForumEnv::get('FEATHER_SEARCH_MIN_WORD') && $num_chars <= ForumEnv::get('FEATHER_SEARCH_MAX_WORD');
 }
开发者ID:featherbb,项目名称:featherbb,代码行数:27,代码来源:Search.php

示例13: attachEvents

 public function attachEvents()
 {
     Container::get('hooks')->bind('model.plugins.getLatest', function ($plugins) {
         // $plugins = $plugins->where_not_equal('id', 1);
         return $plugins;
     });
 }
开发者ID:beaver-dev,项目名称:featherbb-marketplace,代码行数:7,代码来源:Test.php

示例14: print_users

 public function print_users($username, $start_from, $sort_by, $sort_dir, $show_group)
 {
     $userlist_data = array();
     $username = Container::get('hooks')->fire('model.userlist.print_users_start', $username, $start_from, $sort_by, $sort_dir, $show_group);
     // Retrieve a list of user IDs, LIMIT is (really) expensive so we only fetch the IDs here then later fetch the remaining data
     $result = DB::for_table('users')->select('u.id')->table_alias('u')->where_gt('u.id', 1)->where_not_equal('u.group_id', ForumEnv::get('FEATHER_UNVERIFIED'));
     if ($username != '') {
         $result = $result->where_like('u.username', str_replace('*', '%', $username));
     }
     if ($show_group > -1) {
         $result = $result->where('u.group_id', $show_group);
     }
     $result = $result->order_by($sort_by, $sort_dir)->order_by_asc('u.id')->limit(50)->offset($start_from);
     $result = Container::get('hooks')->fireDB('model.userlist.print_users_query', $result);
     $result = $result->find_many();
     if ($result) {
         $user_ids = array();
         foreach ($result as $cur_user_id) {
             $user_ids[] = $cur_user_id['id'];
         }
         // Grab the users
         $result['select'] = array('u.id', 'u.username', 'u.title', 'u.num_posts', 'u.registered', 'g.g_id', 'g.g_user_title');
         $result = DB::for_table('users')->table_alias('u')->select_many($result['select'])->left_outer_join('groups', array('g.g_id', '=', 'u.group_id'), 'g')->where_in('u.id', $user_ids)->order_by($sort_by, $sort_dir)->order_by_asc('u.id');
         $result = Container::get('hooks')->fireDB('model.userlist.print_users_grab_query', $result);
         $result = $result->find_many();
         foreach ($result as $user_data) {
             $userlist_data[] = $user_data;
         }
     }
     $userlist_data = Container::get('hooks')->fire('model.userlist.print_users', $userlist_data);
     return $userlist_data;
 }
开发者ID:featherbb,项目名称:featherbb,代码行数:32,代码来源:Userlist.php

示例15: testSetParameter

 public function testSetParameter()
 {
     $container = new Container();
     $testValue = 'testValue';
     $container->set('value', $testValue);
     $this->assertEquals($testValue, $container->get('value'));
 }
开发者ID:frizzy,项目名称:container,代码行数:7,代码来源:ContainerTest.php


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