本文整理汇总了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);
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
}
示例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']);
};
}
示例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));
}
示例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;
}
}
示例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');
}
示例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');
}
示例13: attachEvents
public function attachEvents()
{
Container::get('hooks')->bind('model.plugins.getLatest', function ($plugins) {
// $plugins = $plugins->where_not_equal('id', 1);
return $plugins;
});
}
示例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;
}
示例15: testSetParameter
public function testSetParameter()
{
$container = new Container();
$testValue = 'testValue';
$container->set('value', $testValue);
$this->assertEquals($testValue, $container->get('value'));
}