本文整理汇总了PHP中Pimple类的典型用法代码示例。如果您正苦于以下问题:PHP Pimple类的具体用法?PHP Pimple怎么用?PHP Pimple使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Pimple类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: register
public function register(\Pimple $container)
{
$container['logger'] = function () use($container) {
return $container['monolog'];
};
if ($bridge = class_exists('Symfony\\Bridge\\Monolog\\Logger')) {
$container['monolog.handler.debug'] = function () use($container) {
return new DebugHandler($container['monolog.level']);
};
}
$container['monolog.logger.class'] = $bridge ? 'Symfony\\Bridge\\Monolog\\Logger' : 'Monolog\\Logger';
$container['monolog'] = $container->share(function ($container) {
$log = new $container['monolog.logger.class']($container['monolog.name']);
$log->pushHandler($container['monolog.handler']);
if ($container['debug'] && isset($container['monolog.handler.debug'])) {
$log->pushHandler($container['monolog.handler.debug']);
}
return $log;
});
$container['monolog.handler'] = function () use($container) {
return new StreamHandler($container['monolog.logfile'], $container['monolog.level']);
};
$container['monolog.level'] = function () {
return Logger::DEBUG;
};
$container['monolog.name'] = 'container';
}
示例2: register
/**
* Registers services on the given container.
*
* This method should only be used to configure services and parameters.
* It should not get services.
*
* @param \Pimple $mainContainer An Container instance
*/
public function register(\Pimple $mainContainer)
{
$container = new \Pimple();
$container['profiler'] = $mainContainer->share(function ($container) use($mainContainer) {
$profiler = new Profiler(new FileStorage($mainContainer['config']->get('profiler_path')));
$profiler->addCollector($container['collector.cache']);
$profiler->addCollector($container['collector.database']);
return $profiler;
});
$container['session_storage'] = $mainContainer->share(function () use($mainContainer) {
return new SessionStorage($mainContainer['session']);
});
$container['profiler_manager'] = $mainContainer->share(function ($container) {
return new ProfilerManager($container['profiler']);
});
$container['collector.cache'] = $mainContainer->share(function () {
return new CacheDataCollector();
});
$container['collector.listener'] = $mainContainer->share(function () use($mainContainer) {
return new ListenerDataCollector($mainContainer['core']['dispatcher']);
});
$container['collector.database'] = $mainContainer->share(function () {
return new DatabaseDataCollector();
});
$container['collector.xhprof'] = $mainContainer->share(function () {
return new XhprofDataCollector();
});
$container['listener'] = $mainContainer->share(function ($container) {
return new ProfilerListener($container['profiler']);
});
$container['template_finder'] = $mainContainer->share(function () {
return new Finder();
});
$mainContainer['profiler'] = $container;
}
示例3: createDIContainer
/**
* @return a new DI container with prefilled values for the news app
*/
function createDIContainer()
{
$container = new \Pimple();
/**
* BASE
*/
$container['API'] = $container->share(function ($c) {
return new API('apptemplate_advanced');
});
$container['Security'] = $container->share(function ($c) {
return new Security($c['API']->getAppName());
});
$container['Request'] = $container->share(function ($c) {
return new Request($_GET, $_POST);
});
/**
* CONTROLLERS
*/
$container['IndexController'] = function ($c) {
return new IndexController($c['API'], $c['Request']);
};
$container['SettingsController'] = function ($c) {
return new SettingsController($c['API'], $c['Request']);
};
$container['AjaxController'] = function ($c) {
return new AjaxController($c['API'], $c['Request']);
};
return $container;
}
示例4: register
public function register(Application $app)
{
$app['mongodbs.options.initializer'] = $app->protect(function () use($app) {
static $initialized = false;
if ($initialized) {
return;
}
$initialized = true;
if (!isset($app['mongodbs.options'])) {
$app['mongodbs.options'] = ['default' => isset($app['mongodb.options']) ? $app['mongodb.options'] : []];
}
$app['mongodbs.options'] = array_map(function ($options) use($app) {
return array_replace($app['mongodb.default_options'], $options);
}, $app['mongodbs.options']);
if (!isset($app['mongodbs.default'])) {
$app['mongodbs.default'] = array_keys(array_slice($app['mongodbs.options'], 0, 1))[0];
}
});
$app['mongodbs'] = $app->share(function (Application $app) {
$app['mongodbs.options.initializer']();
$container = new \Pimple();
foreach ($app['mongodbs.options'] as $name => $options) {
$container[$name] = $container->share(function () use($options) {
return new Manager($options['uri'], $options['options'], $options['driverOptions']);
});
}
return $container;
});
$app['mongodb.default_options'] = ['uri' => 'mongodb://localhost:27017', 'options' => [], 'driverOptions' => []];
// shortcuts for the "first" MongoDB
$app['mongodb'] = $app->share(function (Application $app) {
$dbs = $app['mongodbs'];
return $dbs[$app['mongodbs.default']];
});
}
示例5: it_normalizes_expressions
public function it_normalizes_expressions($parser, \Pimple $container)
{
$container->offsetExists('_normalize')->willReturn(true);
$container->offsetGet('_normalize')->willReturn(array('foo' => 'bar'));
$parser->evaluate('foo', array('foo' => 'bar'))->willReturn('bar')->shouldBeCalled();
$this->normalize('?foo', $container)->shouldReturn('bar');
}
示例6: register
/**
* Registers services on the given container.
*
* This method should only be used to configure services and parameters.
* It should not get services.
*
* @param \Pimple $mainContainer An Container instance
*/
public function register(\Pimple $mainContainer)
{
$mainContainer['core']['db'] = $mainContainer->share(function () {
return \Pelican_Db::getInstance();
});
$mainContainer['core']['listener.ajax_response_render'] = $mainContainer->share(function () {
return new AjaxRenderResponseListener(new \Pelican_Ajax_Adapter_Jquery());
});
}
示例7: registerFilters
public static function registerFilters(\Pimple $container)
{
$container['inspector.filter_listener'] = $container->share($container->extend('inspector.filter_listener', function ($listener, $c) {
$listener->addAvailableFilter('gitignore', function () {
return new Filter\GitIgnoreFilter();
});
return $listener;
}));
}
示例8: register
/**
* Registers services on the given container.
*
* This method should only be used to configure services and parameters.
* It should not get services.
*
* @param \Pimple $mainContainer An Container instance
*/
public function register(\Pimple $mainContainer)
{
$container = new \Pimple();
$container['dispatcher'] = $mainContainer->share(function () {
$dispatcher = new EventDispatcher();
// Add listeners
return $dispatcher;
});
$mainContainer['core'] = $container;
}
示例9: register
/**
* {@inheritDoc}
*/
public static function register(\Pimple $container)
{
$container['event_dispatcher.class'] = 'Zend\\EventManager\\EventManager';
if (class_exists($container['event_dispatcher.class'])) {
$container['event_dispatcher'] = $container->share(function ($c) {
return new $c['event_dispatcher.class']();
});
} else {
throw new Exception\Provider\ClassNotFoundException('Event Dispatcher', $container['event_dispatcher.class']);
}
}
示例10: it_creates_a_array_parameter_and_merges_existing_data
public function it_creates_a_array_parameter_and_merges_existing_data(Parameter $parameterConf, \Pimple $container)
{
$parameterConf->getParameterName()->willReturn('db.options');
$parameterConf->getParameterValue()->willReturn(array('host' => 'example.org'));
$parameterConf->getMergeStrategy(Argument::type('array'))->willReturn('array_replace_recursive');
$parameterConf->mergeExisting()->willReturn(true);
$container->offsetExists('db.options')->willReturn(true);
$container->offsetGet('db.options')->willReturn(array('host' => 'localhost', 'user' => 'root', 'password' => 'test'));
$container->offsetSet('db.options', array('host' => 'example.org', 'user' => 'root', 'password' => 'test'))->shouldBeCalled();
$container = $this->create($parameterConf, $container);
}
示例11: register
public function register(\Pimple $container)
{
$container['knp_menu.route.voter'] = $container->share(function (\Pimple $container) {
$voter = new RouteVoter();
$voter->setRequest($container['request_stack']->getCurrentRequest());
return $voter;
});
$container['knp_menu.matcher.configure'] = $container->protect(function (Matcher $matcher) use($container) {
$matcher->addVoter($container['knp_menu.route.voter']);
});
}
示例12: register
/**
* Registers services on the given container.
*
* This method should only be used to configure services and parameters.
* It should not get services.
*
* @param \Pimple $container An Container instance
*/
public function register(\Pimple $container)
{
$services = new \Pimple();
$services['factory'] = $container->share(function () use($container) {
return new \Itkg\Core\Cache\Factory($container['cache']['adapters']);
});
$services['listener'] = $container->share(function () use($services, $container) {
return new CacheListener($services['factory']->create($container['config']['cache']['adapter'], $container['config']['cache']), $container['core']['dispatcher']);
});
$container['cache'] = $services;
}
示例13: createApplication
public function createApplication()
{
$pimple = new \Pimple();
$dependencies = array('beforeTokenChecker' => $pimple->protect(function () {
}));
require SPIKA_ROOT . '/etc/app.php';
$mailer = $this->getMockBuilder('\\Silex\\Provider\\SwiftmailerServiceProvider')->setMethods(array('send'))->disableOriginalConstructor()->getMock();
$mailer->expects(once())->method('send')->with(isInstanceOf('Swift_Message'));
$app['mailer'] = $mailer;
return $app;
}
示例14: registerApplication
public static function registerApplication(\Pimple $container)
{
$container['console.application'] = $container->share(function ($c) {
$app = new $c['console.application.class']($c);
foreach ($c['console.command'] as $command) {
$app->add($command());
}
return $app;
});
$container['console.command'] = new \ArrayObject();
self::registerCommands($container);
}
示例15: testGetMenuAsClosure
public function testGetMenuAsClosure()
{
$pimple = new \Pimple();
$menu = $this->getMock('Knp\\Menu\\ItemInterface');
$pimple['menu'] = $pimple->protect(function ($options, $c) use($menu) {
$c['options'] = $options;
return $menu;
});
$provider = new PimpleProvider($pimple, array('default' => 'menu'));
$this->assertSame($menu, $provider->get('default', array('foo' => 'bar')));
$this->assertEquals(array('foo' => 'bar'), $pimple['options']);
}