本文整理汇总了PHP中Pimple\Container::offsetGet方法的典型用法代码示例。如果您正苦于以下问题:PHP Container::offsetGet方法的具体用法?PHP Container::offsetGet怎么用?PHP Container::offsetGet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pimple\Container
的用法示例。
在下文中一共展示了Container::offsetGet方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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]);
}
示例2: compile
/**
* Register the ServiceProvider in the container.
*
* @return Container
*/
public function compile()
{
if (!$this->compiled) {
$this->compiled = true;
$this->container->register(new ServiceProvider(), $this->config);
$this->container->offsetGet('console')->addCommands($this->commands);
}
return $this->container;
}
示例3: __construct
/**
* AbstractController constructor.
* @param Container $container
*/
public function __construct(Container $container)
{
$this->container = $container;
if ($twig = $this->container->offsetGet('twig')) {
$this->twig = $twig;
}
if ($response = $this->container->offsetGet('response')) {
$this->response = $response;
}
if ($request = $this->container->offsetGet('request')) {
$this->request = $request;
}
}
示例4: register
public function register(Container $container)
{
$cid = $this->cid;
$container[$cid] = $container->factory(function () use($cid, $container) {
$get = function ($key, $default = null) use($container, $cid) {
$key = $cid . '.' . $key;
return $container->offsetExists($key) ? $container->offsetGet($key) : $default;
};
$adapterName = $get('adapter');
switch ($adapterName) {
case 'redis':
$adapter = new AdapterPureRedis(['host' => $get('host'), 'port' => $get('port'), 'timeout' => $get('timeout'), 'password' => $get('password'), 'dbIndex' => $get('dbIndex')]);
break;
case 'file':
$adapter = new AdapterFile($get('dir'));
break;
default:
$adapter = new AdapternotCache();
break;
}
foreach ($get('options', []) as $k => $v) {
$adapter->setOption($k, $v);
}
return new Cache($adapter);
});
}
示例5: activateResponsiveTheme
private function activateResponsiveTheme()
{
/** @var ThemeService $themeService */
$themeService = $this->container->offsetGet('theme.service');
$themeService->activateResponsiveTheme();
return;
}
示例6: offsetGet
public function offsetGet($id)
{
$instance = parent::offsetGet($id);
if ($instance instanceof ContainerAware) {
$instance->setContainer($this);
}
return $instance;
}
示例7: register
public function register(Container $app)
{
if ($app instanceof Application) {
$app->error(function (\Exception $e, Request $request, $code) use($app) {
return $app->offsetGet("error.controller")->index($e, $request, $code);
});
}
}
示例8: register
public function register(Container $pimple)
{
if ($pimple->offsetExists('facade.aliases')) {
$aliases = $pimple->offsetGet('facade.aliases');
} else {
$aliases = null;
}
$facadeServiceLocator = new ArrayAccessAdapter($pimple);
FacadeLoader::init($facadeServiceLocator, $aliases);
}
示例9: it_calls_setLogger_and_processes_the_resource
public function it_calls_setLogger_and_processes_the_resource(Container $container, Processor $processor, NodeFilter $filter)
{
$processor->implement(LoggerAwareInterface::class);
$container->offsetGet('processor.default')->willReturn($processor);
$container->offsetSet('method_filter_pattern', '/^[let|go|it_].*$/')->shouldBeCalled();
$processor->setLogger(Argument::type(LoggerInterface::class))->shouldBeCalled();
$processor->process(__DIR__)->shouldBeCalled();
$stream = fopen('php://memory', 'rw');
$this->run(new ArrayInput(['resource' => __DIR__]), new StreamOutput($stream))->shouldBe(0);
}
示例10: register
public function register(Container $container)
{
$cid = $this->cid;
$container[$cid] = $container->factory(function () use($cid, $container) {
$get = function ($key, $default = null) use($container, $cid) {
$key = $cid . '.' . $key;
return $container->offsetExists($key) ? $container->offsetGet($key) : $default;
};
$pdo = new Database($get('dsn'), $get('user'), $get('password'), $get('options', []));
return new Db($pdo);
});
}
示例11: make
/**
* @param string $abstract
* @param array $parameters
* @return mixed
* @throws ContainerException
*/
public function make($abstract, $parameters = [])
{
$abstract = $this->getAlias($abstract);
$normalAbstract = $this->normalize($abstract);
if ($this->container->offsetExists($normalAbstract)) {
return $this->container->offsetGet($normalAbstract);
}
if (!class_exists($abstract)) {
throw new ContainerException("Class {$abstract} does not exist");
}
$reflector = new \ReflectionClass($abstract);
if (!$reflector->isInstantiable()) {
throw new ContainerException("Can't instantiate this");
}
$constructor = $reflector->getConstructor();
if (is_null($constructor)) {
return new $abstract();
}
$parameters = $constructor->getParameters();
$dependencies = $this->getDependencies($parameters);
$builder = $reflector->newInstanceArgs($dependencies);
$this->instance($normalAbstract, $builder);
return $this->container->offsetGet($normalAbstract);
}
示例12: it_should_still_allow_service_subscriber_to_be_removed_after_event_has_been_triggered
/**
* @param MockListener $listener
* @param Event $event
* @param Container $container
* @param MockServiceSubscriber $sub
*
* @throws \DomainException
* @throws \InvalidArgumentException
* @throws \LengthException
* @throws \LogicException
*/
public function it_should_still_allow_service_subscriber_to_be_removed_after_event_has_been_triggered(MockListener $listener, Event $event, Container $container, MockServiceSubscriber $sub)
{
$events = ['test1' => [[['containerID1', 'method1']]]];
$event->hasBeenHandled()->willReturn(false);
$sub->getServiceSubscribedEvents()->willReturn($events);
$this->addServiceSubscriber($sub);
$this->getServiceListeners()->shouldHaveKey('test1');
$container->offsetGet('containerID1')->willReturn($listener);
$this->setServiceContainer($container);
$listener->method1($event, 'test1', $this)->shouldBeCalled();
$this->getServiceByName('containerID1')->shouldReturn($listener);
$this->trigger('test1', $event);
$this->removeServiceSubscriber($sub);
$this->getServiceListeners()->shouldNotHaveKey('test1');
}
示例13: Container
use Shopware\Recovery\Install\Service\ConfigWriter;
use Shopware\Recovery\Install\Service\DatabaseService;
use Shopware\Recovery\Install\Service\LicenseInstaller;
use Shopware\Recovery\Install\Service\LocaleSettingsService;
use Shopware\Recovery\Install\Service\LocalLicenseUnpackService;
use Shopware\Recovery\Install\Service\ShopService;
use Shopware\Recovery\Install\Service\CurrencyService;
use Shopware\Recovery\Install\Service\ThemeService;
use Shopware\Recovery\Install\Service\TranslationService;
use Shopware\Recovery\Install\Struct\DatabaseConnectionInformation;
use Shopware\Recovery\Install\Struct\LicenseUnpackRequest;
$config = (require __DIR__ . '/../config/production.php');
$container = new Container();
$container->register(new ContainerProvider($config));
/** @var \Slim\Slim $app */
$app = $container->offsetGet('slim.app');
// After instantiation
$sessionPath = str_replace('index.php', '', $app->request()->getScriptName());
$app->config('cookies.path', $sessionPath);
if (!isset($_SESSION)) {
session_cache_limiter(false);
session_set_cookie_params(600, $sessionPath);
session_start();
}
if (!isset($_SESSION["parameters"])) {
$_SESSION["parameters"] = [];
}
if (isset($_SESSION["databaseConnectionInfo"])) {
$connectionInfo = $_SESSION["databaseConnectionInfo"];
try {
$databaseFactory = new DatabaseFactory();
示例14: setParameter
/**
* Sets a parameter.
*
* @param string $name The parameter name
* @param mixed $value The parameter value
*
* @api
*/
public function setParameter($name, $value)
{
$config = $this->pimple->offsetGet('config');
$config[$name] = $value;
$this->pimple->offsetSet('config', $config);
}
示例15: view
protected function view($name, Config $config)
{
if (!($config = $config->get("views.{$name}"))) {
throw new \LogicException("No configuration for view '{$name}'");
}
$view = parent::offsetGet('view')->create($config);
parent::offsetExists('profiler') && $view->setProfiler(parent::offsetGet('profiler'));
return $view;
}