本文整理汇总了PHP中Silex\Application::offsetExists方法的典型用法代码示例。如果您正苦于以下问题:PHP Application::offsetExists方法的具体用法?PHP Application::offsetExists怎么用?PHP Application::offsetExists使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Silex\Application
的用法示例。
在下文中一共展示了Application::offsetExists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: register
/**
* Registers services on the given container.
*
* This method should only be used to configure services and parameters.
* It should not get services.
*
* @param Application $app
* @return Wunderlist
*/
public function register(Application $app)
{
$app['wunderlist.lusitanian_authenticator'] = $app->share(function ($app) {
$requestStack = $app['request_stack'];
$currentRequest = $requestStack->getCurrentRequest();
$wunderlist = $app['oauth']->getService('wunderlist');
return new OAuthLibAuthentication($wunderlist, $currentRequest);
});
$app['wunderlist.default_authenticator'] = $app->share(function ($app) {
if (!$app->offsetExists('wunderlist.authenticator')) {
$app['wunderlist.authenticator'] = 'lusitanian';
}
return $app['wunderlist.' . $app['wunderlist.authenticator'] . '_authenticator'];
});
$app['wunderlist.builder'] = $app->share(function ($app) {
$builder = new ClientBuilder();
$builder->setAuthenticator($app['wunderlist.default_authenticator']);
if ($app->offsetExists('serializer')) {
$builder->setSerializer($app['serializer']);
}
if ($app->offsetExists('wunderlist.http_client')) {
$builder->setHttpClient($app['wunderlist.http_client']);
}
return $builder;
});
$app['wunderlist'] = $app->share(function ($app) {
return $app["wunderlist.builder"]->build();
});
}
示例2: getClient
protected function getClient($annotationOptions = array())
{
if (!$this->app->offsetExists('annot')) {
$this->registerAnnotations($annotationOptions);
}
$this->client = new Client($this->app, $this->clientOptions);
}
示例3: connect
/**
* Implements ControllerProviderInterface::connect() connecting this
* controller.
*
* @param Application $app
* the Application instance of the Silex application
*
* @return SilexController\Collection
* this method is expected to return the used ControllerCollection instance
*/
public function connect(Application $app)
{
if ($app->offsetExists('twig.loader.filesystem')) {
$app['twig.loader.filesystem']->addPath(__DIR__ . '/../views/', 'crud');
}
if (!$app->offsetExists('crud.layout')) {
$app['crud.layout'] = '@crud/layout.twig';
}
$class = get_class($this);
$factory = $app['controllers_factory'];
$factory->get('/resource/static', $class . '::staticFile')->bind('static');
$factory->match('/{entity}/create', $class . '::create')->bind('crudCreate');
$factory->match('/{entity}', $class . '::showList')->bind('crudList');
$factory->match('/{entity}/{id}', $class . '::show')->bind('crudShow');
$factory->match('/{entity}/{id}/edit', $class . '::edit')->bind('crudEdit');
$factory->post('/{entity}/{id}/delete', $class . '::delete')->bind('crudDelete');
$factory->match('/{entity}/{id}/{field}/file', $class . '::renderFile')->bind('crudRenderFile');
$factory->post('/{entity}/{id}/{field}/delete', $class . '::deleteFile')->bind('crudDeleteFile');
$factory->get('/setting/locale/{locale}', $class . '::setLocale')->bind('crudSetLocale');
$app->before(function (Request $request, Application $app) {
if ($app['crud']->getManageI18n()) {
$locale = $app['session']->get('locale', 'en');
$app['translator']->setLocale($locale);
}
$locale = $app['translator']->getLocale();
$app['crud']->setLocale($locale);
});
return $factory;
}
示例4: testMongoDBServiceProviderManager
public function testMongoDBServiceProviderManager()
{
$this->application->register(new ElasticSearchServiceProvider(), array('elasticsearch' => array('connections' => array('default' => array('host' => 'localhost', 'port' => 12345), 'cluster' => array('server' => array(array('host' => 'localhost', 'port' => 3), array('host' => 'localhost', 'port' => 2)))))));
if (!$this->application->offsetExists('es.manager')) {
$this->markTestSkipped('elasticsearch not found into PIMPLE');
}
$this->arrayHasKey('es.default_manager', $this->application);
$this->assertSame($this->application['es.manager']('default'), $this->application['es.default_manager']);
}
开发者ID:benjybe,项目名称:silexprovider-service_elasticsearch,代码行数:9,代码来源:ElasticSearchServiceProviderTest.php
示例5: testMongoDBServiceProviderManager
public function testMongoDBServiceProviderManager()
{
$this->application->register(new DoctrineMongoDBServiceProvider(), array('doctrine_mongodb' => array('connections' => array('default' => array('host' => 'localhost', 'database' => 'database', 'port' => 27017)), 'document_managers' => array('default' => array('mapping' => array('yml' => array('type' => 'yml', 'alias' => 'Alias', 'path' => '/path/to/yml/files', 'namespace' => 'Unit\\MongoDB\\Tests\\Yml'), 'xml' => array('type' => 'yml', 'path' => '/path/to/yml/files', 'namespace' => 'Unit\\MongoDB\\Tests\\Yml'), 'annotation' => array('type' => 'annotation', 'path' => '/path/to/annotation/classes', 'namespace' => 'Unit\\MongoDB\\Tests\\Annotation')))))));
if (!$this->application->offsetExists('doctrine_mongodb')) {
$this->markTestSkipped('doctrine_mongodb not found into PIMPLE');
}
$this->arrayHasKey('doctrine_mongodb.default_manager', $this->application);
$this->assertSame($this->application['doctrine_mongodb.document_manager']('default'), $this->application['doctrine_mongodb.default_document_manager']);
}
开发者ID:benjybe,项目名称:silexprovider-doctrine_mongodb,代码行数:9,代码来源:DoctrineMongoDBServiceProviderTest.php
示例6: __invoke
public function __invoke(array $record)
{
$record['extra']['clientIp'] = $this->getClientIp($this->app['request_stack']);
if ($this->app->offsetExists('security')) {
$record['extra']['user'] = $this->getUsername($this->app['security']);
}
$record['extra']['token'] = $this->token;
$record = $this->addRemoteRequestToken($record, $this->app['request_stack']);
return $record;
}
示例7: testServiceFactoryServiceProviderOptions
public function testServiceFactoryServiceProviderOptions()
{
$this->application->register(new ServiceFactoryServiceProvider(), array('service_factory' => array('my_class' => array('class' => '\\VPG\\Unit\\Silex\\Provider\\Tests\\MyClass', 'constructor' => array('@dispatcher', array(1, 2), 'a value', 99), 'tags' => array('setLogger' => '@url_matcher')))));
if (!$this->application->offsetExists('service.factory')) {
$this->markTestSkipped('service factory not found into PIMPLE');
}
$service = $this->application['service.factory']('my_class');
$this->assertEquals($this->application['dispatcher'], $service->eventDispatcher);
$this->assertEquals($this->application['url_matcher'], $service->matcher);
$this->assertEquals(array(1, 2), $service->values);
$this->assertEquals('a value', $service->string);
$this->assertEquals(99, $service->number);
}
示例8: testRegister
public function testRegister()
{
$app = new Application();
$app->register(new CRUDServiceProvider(), array('crud.file' => $this->crudFile, 'crud.datafactory' => $this->dataFactory));
$this->assertTrue($app->offsetExists('crud'));
$app['crud']->getEntities();
}
示例9: boot
/**
* Bootstraps the application.
*
* This method is called after all services are registered
* and should be used for "dynamic" configuration (whenever
* a service must be requested).
*/
public function boot(Application $app)
{
$src = $app->offsetExists('commands.path') ? $app['commands.path'] : $app['path.src'];
$dir = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($src));
$commands = new \ArrayObject();
/** @var RecursiveDirectoryIterator $dir */
for ($dir->rewind(); $dir->valid(); $dir->next()) {
if ($dir->isDot()) {
continue;
}
if ('php' !== $dir->getExtension()) {
continue;
}
$name = $dir->getSubPathname();
$name = substr($name, 0, -4);
$className = str_replace(DIRECTORY_SEPARATOR, '\\', $name);
$r = new ReflectionClass($className);
if ($r->isAbstract() || false === $r->isSubclassOf("Symfony\\Component\\Console\\Command\\Command")) {
continue;
}
$commands->append(new $className());
}
/** @noinspection PhpParamsInspection */
$app['console'] = $app->share($app->extend('console', function (Console $console) use($commands) {
foreach ($commands as $command) {
$console->add($command);
}
return $console;
}));
}
示例10: boot
/**
* Bootstraps the application.
*
* This method is called after all services are registers
* and should be used for "dynamic" configuration (whenever
* a service must be requested).
*/
public function boot(Application $app)
{
// Add twig template path.
if ($app->offsetExists('twig.loader.filesystem')) {
$app['twig.loader.filesystem']->addPath(__DIR__ . '/views/', 'user');
}
}
示例11: testDefaults
/**
* @covers ::register
* @covers ::boot
*/
public function testDefaults()
{
$app = new Silex();
$app['db'] = $this->getMockBuilder('Doctrine\\DBAL\\Connection')->disableOriginalConstructor()->getMock();
$console = new Console();
$app->register(new DoctrineMigrationsProvider($console));
$this->assertTrue($app->offsetExists('migrations.output_writer'));
$this->assertInstanceOf('Doctrine\\DBAL\\Migrations\\OutputWriter', $app['migrations.output_writer']);
$this->assertNull($app['migrations.namespace']);
$this->assertNull($app['migrations.directory']);
$this->assertEquals('Migrations', $app['migrations.name']);
$this->assertEquals('migration_versions', $app['migrations.table_name']);
$this->assertFalse($console->has('migrations:execute'));
$this->assertFalse($console->has('migrations:generate'));
$this->assertFalse($console->has('migrations:migrate'));
$this->assertFalse($console->has('migrations:status'));
$this->assertFalse($console->has('migrations:version'));
$this->assertFalse($console->has('migrations:diff'));
$app->boot();
$this->assertTrue($console->has('migrations:execute'));
$this->assertTrue($console->has('migrations:generate'));
$this->assertTrue($console->has('migrations:migrate'));
$this->assertTrue($console->has('migrations:status'));
$this->assertTrue($console->has('migrations:version'));
$this->assertFalse($console->has('migrations:diff'));
}
开发者ID:mikeSimonson,项目名称:silex-doctrine-migrations-provider,代码行数:30,代码来源:DoctrineMigrationsProviderTest.php
示例12: boot
/**
* Bootstraps the application.
*
* This method is called after all services are registered
* and should be used for "dynamic" configuration (whenever
* a service must be requested).
*/
public function boot(Application $app)
{
if ($app->offsetExists('facade.aliases')) {
$aliases = $app->offsetGet('facade.aliases');
ClassAliaser::register($aliases);
}
}
示例13: register
public function register(Application $app)
{
$app['cache.memcached'] = $app->share(function () use($app) {
if (!class_exists('\\Doctrine\\Common\\Cache\\MemcachedCache')) {
throw new \Exception('You need to include doctrine/common in order to use the cache service');
}
$cache = new MemcachedCache();
$cache->setMemcached($app['memcached']);
return $cache;
});
$app['cache.predis'] = $app->share(function () use($app) {
if (!class_exists('\\Doctrine\\Common\\Cache\\PredisCache')) {
throw new \Exception('You need to include doctrine/common in order to use the cache service');
}
return new PredisCache($app['predis.client']);
});
$app['cache.predis_serializer'] = $app->share(function () use($app) {
if (!class_exists('\\Doctrine\\Common\\Cache\\PredisCache')) {
throw new \Exception('You need to include doctrine/common in order to use the cache service');
}
return new SerializingPredisCache($app['predis.client']);
});
$app['cache'] = $app->share(function () use($app) {
if ($app->offsetExists('cache.default')) {
return $app[$app['cache.default']];
}
return $app['memcached'];
});
}
示例14: register
public function register(Application $app)
{
$app['lexik_form_filter.query_builder_updater'] = $app->share(function ($app) {
$frmDataExt = $app['lexik_form_filter.form_data_extractor'];
$dispatcher = $app['dispatcher'];
return new FilterBuilderUpdater($frmDataExt, $dispatcher);
});
$app['lexik_form_filter.form_data_extractor'] = $app->share(function ($app) {
$formDataExtractor = new FormDataExtractor();
$formDataExtractor->addMethod(new DefaultExtractionMethod());
$formDataExtractor->addMethod(new TextExtractionMethod());
$formDataExtractor->addMethod(new ValueKeysExtractionMethod());
if ($app->offsetExists('form-filter.data_extraction_methods')) {
foreach ($app['form-filter.data_extraction_methods'] as $extMethod) {
$formDataExtractor->addMethod($extMethod);
}
}
return $formDataExtractor;
});
$app['form.extensions'] = $app->share($app->extend('form.extensions', function ($extensions) use($app) {
$extensions[] = new FilterExtension();
return $extensions;
}));
$app['dispatcher']->addListener(FilterEvents::PREPARE, array(new PrepareListener(), 'onFilterBuilderPrepare'));
$app['dispatcher']->addSubscriber(new DoctrineSubscriber());
}
示例15: register
public function register(Application $app)
{
$app['monolog.formatter'] = $app->share(function () {
return new LineFormatter(null, 'Y-m-d H:i:s.u');
});
$app['monolog.handler'] = function () use($app) {
if (!$app['monolog.logfile']) {
return new NullHandler();
}
if (method_exists('Silex\\Provider\\MonologServiceProvider', 'translateLevel')) {
$level = MonologServiceProvider::translateLevel($app['monolog.level']);
} else {
$level = $app['monolog.level'];
}
$streamHandler = new StreamHandler($app['monolog.logfile'], $level);
$streamHandler->setFormatter($app['monolog.formatter']);
return $streamHandler;
};
$app['logger'] = $app->share($app->extend('logger', function (Logger $logger, \Pimple $app) {
$logger->pushProcessor($app['logger.request_processor']);
$logger->pushProcessor(new PsrLogMessageProcessor());
if (!($app->offsetExists('monolog.logstashfile') && $app['monolog.logstashfile'])) {
return $logger;
}
$logstashHandler = new StreamHandler($app['monolog.logstashfile'], $app['monolog.level']);
$logstashHandler->setFormatter(new LogstashFormatter($app['monolog.name']));
$extras = array();
if ($app->offsetExists('meta.service')) {
$extras['service'] = $app['meta.service'];
}
if ($app->offsetExists('meta.customer')) {
$extras['customer'] = $app['meta.customer'];
}
if ($app->offsetExists('meta.environment')) {
$extras['environment'] = $app['meta.environment'];
}
$logstashHandler->pushProcessor(new ExtraContextProcessor($extras));
$logger->pushHandler($logstashHandler);
return $logger;
}));
$app['logger.request_processor'] = $app->share(function () use($app) {
return new RequestProcessor($app);
});
}