本文整理汇总了PHP中Pimple\Container::keys方法的典型用法代码示例。如果您正苦于以下问题:PHP Container::keys方法的具体用法?PHP Container::keys怎么用?PHP Container::keys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pimple\Container
的用法示例。
在下文中一共展示了Container::keys方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: commands
public function commands()
{
if ($this->commands === null) {
$this->commands = [];
foreach ($this->container->keys() as $serviceName) {
if (preg_match('/\\.command$/', $serviceName)) {
$this->commands[] = $this->container[$serviceName];
}
}
}
return $this->commands;
}
示例2: __get
public function __get($name)
{
if (in_array($name, $this->container->keys())) {
$service = $this->container[$name];
if (is_a($service, 'Sloop\\Controller\\AbstractController')) {
return $service->getRoute();
} else {
return $service;
}
}
return null;
}
示例3: it_resolve_commands
public function it_resolve_commands(Container $container, $command1, $command2)
{
$container->keys()->willReturn(['test1.command', 'test2.command']);
$container->offsetGet('test1.command')->willReturn($command1);
$container->offsetGet('test2.command')->willReturn($command2);
$this->commands()->shouldReturn([$command1, $command2]);
}
示例4: getDefinedTasks
/**
* @return array
*/
protected function getDefinedTasks()
{
$tasks = [];
foreach ($this->container->keys() as $key) {
$match = [];
if (preg_match('/^task:(.*)$/', $key, $match)) {
$tasks[] = $match[1];
}
}
return $tasks;
}
示例5: parseData
/**
* Parses the data's keys from the raw source.
*
* @param Pimple|array $data The data to format.
* @return array The data keys.
*
* @SuppressWarnings(PHPMD.ElseExpression)
*/
public static function parseData($data)
{
if ($data instanceof Pimple) {
$keys = $data->keys();
} elseif (is_array($data)) {
$keys = array_keys($data);
} else {
throw new ErrorException(sprintf('Only Pimple objects or arrays can be passed to %s. [Type: %s]', __FUNCTION__, get_class($data)));
}
sort($keys);
return $keys;
}
示例6: parseContainer
/**
* Generate a mapping of the container's values
*
* @param Container $container
* @return array
*/
protected function parseContainer(Container $container)
{
$map = array();
foreach ($container->keys() as $name) {
if (strpos($name, self::DIC_PREFIX) === 0) {
continue;
}
if ($item = $this->parseItem($container, $name)) {
$map[] = $item;
}
}
return $map;
}
示例7: buildTree
protected function buildTree(Container $container)
{
$services = $container->keys();
sort($services);
$tree = [];
foreach ($services as $service) {
try {
$tree[$service] = $this->describeObject($container[$service]);
} catch (\Exception $e) {
throw new \Exception(sprintf('An exception occurred resolving "%s": %s', $service, $e->getMessage()));
}
}
return $tree;
}
示例8: findService
/**
* Procura pelo serviço no container de acordo com o parametro.
*
* Primeiro ele verifica se o nome do parametro já não é o nome de
* algum serviço definido. Caso não seja encontrado, ele procura
* em todos os serviços disponíveis do container e retorna o
* serviço que for instância da classe type-hinteada.
*
* @param \ReflectionParameter $refl
* @return mixed|null
*/
private function findService(\ReflectionParameter $refl)
{
if ($refl->getClass()->name === 'Pimple\\Container' || $refl->getClass()->isSubclassOf('Pimple\\Container')) {
return $this->container;
}
// Tenta procurar pelo nome do parametro
$serviceName = $this->normalizeServiceName($refl->name);
if (isset($this->container[$serviceName])) {
$service = $this->container[$serviceName];
if ($refl->getClass()->isInstance($service)) {
return $service;
}
}
// Tenta procurar em todos os serviços do container se
// não tem algum que é instância daquela classe
foreach ($this->container->keys() as $key) {
$service = $this->container[$key];
if ($refl->getClass()->isInstance($service)) {
return $service;
}
}
return null;
}
示例9: testConstructor
/**
* Test __construct().
*/
public function testConstructor()
{
$app = new Application(['foo' => 'bar']);
$this->assertInstanceOf(Config::class, $app['config']);
$providers = $app->getProviders();
foreach ($providers as $provider) {
$container = new Container();
$container->register(new $provider());
$container['config'] = $app->raw('config');
$container['access_token'] = $app->raw('access_token');
$container['request'] = $app->raw('request');
$container['cache'] = $app->raw('cache');
foreach ($container->keys() as $providerName) {
$this->assertEquals($container->raw($providerName), $app->raw($providerName));
}
unset($container);
}
}
示例10: keys
public function keys()
{
return $this->pimpleContainer->keys();
}
示例11: processEnvironment
/**
* @param Container $container
* @return mixed
*/
protected function processEnvironment(Container $container)
{
$containerKeys = $container->keys();
// Note: This will only set parameters IF they already exist in some form in the configuration
foreach ($_SERVER as $key => $value) {
if (0 === stripos($key, self::ENVIRONMENT_PREFIX)) {
$key = substr($key, strlen(self::ENVIRONMENT_PREFIX));
$key = str_replace("__", ".", $key);
$key = strtolower($key);
// Look to see if the environment variable exists purely as lowercase
if (!$container->offsetExists($key)) {
// If it doesn't, then lowercase the container keys and see if we can find it there
if (($offsetKey = array_search(strtolower($key), array_map('strtolower', $containerKeys))) === false) {
// If we can't, then we shouldn't be setting this variable
continue;
}
// Otherwise, use the correct key
$key = $containerKeys[$offsetKey];
}
$container->offsetSet($key, $value);
}
}
}
示例12: register
/**
* {@inheritdoc}
*/
public function register(Container $pimple)
{
foreach ($pimple->keys() as $serviceName) {
$pimple->extend($serviceName, $this);
}
}
示例13: testKeys
public function testKeys()
{
$pimple = new Container();
$pimple['foo'] = 123;
$pimple['bar'] = 123;
$this->assertEquals(array('foo', 'bar'), $pimple->keys());
}
示例14: _parseContainer
/**
* Generate a mapping of the container's values
* @param Container $container
* @return array
*/
protected function _parseContainer(Container $container)
{
$map = array();
foreach ($container->keys() as $name) {
if ($item = $this->_parseItem($container, $name)) {
$map[] = $item;
}
}
$map = $this->_normalizeMap($map);
return $map;
}
示例15: getAvailableTransports
/**
* Return the list of registered transports
*
* @access public
* @return array
*/
public function getAvailableTransports()
{
$availableTransports = $this->transports->keys();
return array_combine($availableTransports, $availableTransports);
}