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; }
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; }
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]); }
/** * @return array */ protected function getDefinedTasks() { $tasks = []; foreach ($this->container->keys() as $key) { $match = []; if (preg_match('/^task:(.*)$/', $key, $match)) { $tasks[] = $match[1]; } } return $tasks; }
/** * 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; }
/** * 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; }
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; }
/** * 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; }
/** * 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); } }
public function keys() { return $this->pimpleContainer->keys(); }
/** * @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); } } }
/** * {@inheritdoc} */ public function register(Container $pimple) { foreach ($pimple->keys() as $serviceName) { $pimple->extend($serviceName, $this); } }
public function testKeys() { $pimple = new Container(); $pimple['foo'] = 123; $pimple['bar'] = 123; $this->assertEquals(array('foo', 'bar'), $pimple->keys()); }
/** * 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; }
/** * Return the list of registered transports * * @access public * @return array */ public function getAvailableTransports() { $availableTransports = $this->transports->keys(); return array_combine($availableTransports, $availableTransports); }
protected function getFormatsFromContainer(Container $container) { $formats = []; foreach ($container->keys() as $key) { if (0 === strpos($key, 'distill.format.')) { $formats[] = $container[$key]; } } return $formats; }
/** * {@inheritDoc} */ public function register(PimpleContainer $slimContainer) { foreach ($this->pimpleContainer->keys() as $key) { $slimContainer[$key] = $this->pimpleContainer->raw($key); } }