本文整理汇总了PHP中Pimple\Container::extend方法的典型用法代码示例。如果您正苦于以下问题:PHP Container::extend方法的具体用法?PHP Container::extend怎么用?PHP Container::extend使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pimple\Container
的用法示例。
在下文中一共展示了Container::extend方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: register
public function register(Container $c)
{
// TODO dar opção de mudar o loader, não só annotations
$c['extra.options'] = array('root_dir' => null, 'controller_namespace' => null, 'cache_dir' => sys_get_temp_dir());
$c['extra.route_loader'] = function ($c) {
return new AnnotationDirectoryLoader(new FileLocator($c['extra.options']['root_dir']), new AnnotatedRouteControllerLoader($c['annotation.reader']));
};
$c['extra.router'] = function ($c) {
$router = new Router($c['routes'], $c['extra.route_loader'], $c['extra.options']['controller_namespace'], array('cache_dir' => $c['extra.options']['cache_dir'], 'debug' => $c['debug'], 'generator_dumper_class' => 'Symfony\\Component\\Routing\\Generator\\Dumper\\PhpGeneratorDumper', 'generator_cache_class' => 'BrodaUrlGenerator', 'matcher_dumper_class' => 'Symfony\\Component\\Routing\\Matcher\\Dumper\\PhpMatcherDumper', 'matcher_cache_class' => 'BrodaRequestMatcher', 'resource_type' => 'annotation'), $c['routing.request_context']);
return $router;
};
$c->extend('routing.url_generator', function ($generator, $c) {
/* @var $router Router */
$router = $c['extra.router'];
$router->setOption('generator_class', get_class($generator));
$router->setOption('generator_base_class', get_class($generator));
return $router;
});
$c->extend('routing.request_matcher', function ($matcher, $c) {
/* @var $router Router */
$router = $c['extra.router'];
$router->setOption('matcher_class', get_class($matcher));
$router->setOption('matcher_base_class', get_class($matcher));
return $router;
});
}
示例2: register
public function register(Container $container)
{
$container['bootstrap.template_dir'] = __DIR__ . '/../Resources/views';
$container['bootstrap.icon_prefix'] = 'glyphicon';
$container['bootstrap.icon_tag'] = 'span';
$container['bootstrap.flash'] = function () use($container) {
return new FlashMessage($container['session']);
};
$container['form.type.extensions'] = $container->extend('form.type.extensions', function ($extensions) use($container) {
$extensions[] = new ButtonTypeExtension();
$extensions[] = new InputGroupButtonExtension();
$extensions[] = new StaticControlExtension();
$extensions[] = new TypeSetterExtension();
return $extensions;
});
$container['form.extensions'] = $container->extend('form.extensions', function ($extensions) use($container) {
$extensions[] = new BootstrapExtension();
return $extensions;
});
$container['twig'] = $container->extend('twig', function (\Twig_Environment $twig) use($container) {
$twig->addExtension(new BootstrapIconExtension($container['bootstrap.icon_prefix'], $container['bootstrap.icon_tag']));
$twig->addExtension(new BootstrapLabelExtension());
$twig->addExtension(new BootstrapBadgeExtension());
$twig->addExtension(new BootstrapFormExtension());
return $twig;
});
$container['twig.loader.filesystem'] = $container->extend('twig.loader.filesystem', function (\Twig_Loader_Filesystem $twigLoaderFilesystem) use($container) {
$twigLoaderFilesystem->addPath($container['bootstrap.template_dir'], 'SaxulumBootstrapProvider');
return $twigLoaderFilesystem;
});
}
示例3: register
public function register(Container $app)
{
$app->extend('data_collectors', function ($collectors, $app) {
$collectors['db'] = function ($app) {
$collector = new DoctrineDataCollector($app['dbs']);
$timeLogger = new DbalLogger($app['logger'], $app['stopwatch']);
foreach ($app['dbs.options'] as $name => $params) {
/** @var Connection $db */
$db = $app['dbs'][$name];
$loggerChain = new LoggerChain();
$logger = new DebugStack();
$loggerChain->addLogger($logger);
$loggerChain->addLogger($timeLogger);
$db->getConfiguration()->setSQLLogger($loggerChain);
$collector->addLogger($name, $logger);
}
return $collector;
};
return $collectors;
});
$app['data_collector.templates'] = $app->extend('data_collector.templates', function ($templates) {
$templates[] = array('db', '@DoctrineBundle/Collector/db.html.twig');
return $templates;
});
$app['twig.loader.filesystem'] = $app->extend('twig.loader.filesystem', function ($loader) {
/** @var \Twig_Loader_Filesystem $loader */
$loader->addPath(dirname(__DIR__) . '/Resources/views', 'DoctrineBundle');
return $loader;
});
}
示例4: register
public function register(Container $app)
{
if (!isset($app['request_context'])) {
throw new \LogicException('Register RoutingServiceProvider first');
}
$app['controllers_path'] = array();
$app['router.options'] = array();
$app['router.loader'] = function () use($app) {
return new AnnotationDirectoryLoader(new FileLocator($app['controllers_path']), new AnnotationClassLoader($app['annotation.reader']));
};
$app['router'] = function () use($app) {
$router = new Router($app['router.loader'], '', array('cache_dir' => $app['router.options']['cache_dir'], 'debug' => $app['debug'], 'generator_class' => 'Symfony\\Component\\Routing\\Generator\\UrlGenerator', 'generator_cache_class' => 'BrodaUrlGenerator', 'matcher_class' => 'Silex\\Provider\\Routing\\RedirectableUrlMatcher', 'matcher_cache_class' => 'BrodaUrlMatcher'), $app['request_context']);
return $router;
};
$app->extend('routes', function ($oldRoutes) use($app) {
$routes = $app['router']->getRouteCollection();
$routes->addCollection($oldRoutes);
// aggregates old-school defined routes
return $routes;
});
$app->extend('url_matcher', function () use($app) {
return $app['router'];
});
$app->extend('url_generator', function () use($app) {
return $app['router'];
});
}
示例5: register
public function register(Container $app)
{
$app['menu_manager'] = function ($app) {
return new MenuManager($app, $app['menu']);
};
$app['menu_manager.security'] = function ($app) {
return new MenuSecurityService($app);
};
$app['twig.loader.filesystem'] = $app->extend('twig.loader.filesystem', function ($filesystem, $app) {
$filesystem->addPath(__DIR__ . '/../Resource/views', 'MenuManager');
return $filesystem;
});
$app['twig'] = $app->extend('twig', function ($twig, $app) {
$twig->addFunction(new \Twig_SimpleFunction('menu', function ($which = 'main', Item $item = null, $paramList = [], $activeOnly = false) use($app) {
return $app['menu_manager']->render($which, $item, $paramList, $activeOnly);
}));
$twig->addFunction(new \Twig_SimpleFunction('breadcrumb', function ($paramList = []) use($app) {
return $app['menu_manager']->renderBreadcrumb($paramList);
}));
return $twig;
});
// Current route name
$app->before(function (Request $request) use($app) {
$app['menu_manager']->setCurrentRoute($request->get('_route'));
});
}
示例6: register
/**
* register
*
* @see ServiceProviderInterface
*/
public function register(Container $app)
{
$app->extend('data_collectors', function ($collectors, $app) {
$collectors['db'] = function ($app) {
return new DatabaseDataCollector($app['pomm']);
};
return $collectors;
});
$app['data_collector.templates'] = $app->extend('data_collector.templates', function ($templates) {
$templates[] = ['db', '@Pomm/Profiler/db.html.twig'];
return $templates;
});
$app['twig'] = $app->extend('twig', function ($twig, $app) {
if (!$twig->hasExtension('yaml')) {
$twig->addExtension(new YamlExtension());
}
return $twig;
});
$app->extend('twig.loader.filesystem', function ($loader, $app) {
$loader->addPath($app['pomm.templates_path'], 'Pomm');
return $loader;
});
$app['pomm.templates_path'] = function () {
$r = new \ReflectionClass('PommProject\\Silex\\ProfilerServiceProvider\\DatabaseDataCollector');
return dirname(dirname(dirname($r->getFileName()))) . '/views';
};
}
示例7: register
/**
* {@inheritdoc}
*/
public function register(Container $app)
{
$app['puli.factory'] = function () {
$factoryClass = PULI_FACTORY_CLASS;
return new $factoryClass();
};
$app['puli.repository'] = function ($app) {
return $app['puli.factory']->createRepository();
};
$app['puli.discovery'] = function ($app) {
return $app['puli.factory']->createDiscovery();
};
$app['puli.url_generator'] = function ($app) {
return $app['puli.factory']->createUrlGenerator($app['puli.discovery']);
};
if (isset($app['twig'])) {
if (interface_exists('Puli\\UrlGenerator\\Api\\UrlGenerator')) {
$app->extend('twig', function ($twig, $app) {
$twig->addExtension(new PuliExtension($app['puli.repository'], $app['puli.url_generator']));
return $twig;
});
}
$app->extend('twig.loader', function ($loader, $app) {
$loader->addLoader(new PuliTemplateLoader($app['puli.repository']));
return $loader;
});
}
}
示例8: register
/**
* {@inheritdoc}
*/
public function register(Container $app)
{
// @todo crear DoctrineOrmManagerRegistryProvider
// o poner en boot estos servicios
$app->extend('form.extensions', function ($extensions, $app) {
$extensions[] = new DoctrineOrmExtension($app['doctrine']);
return $extensions;
});
$app['doctrine.orm.validator.unique_validator'] = function ($app) {
return new UniqueEntityValidator($app['doctrine']);
};
if (!isset($app['validator.validator_service_ids'])) {
$app['validator.validator_service_ids'] = [];
}
$app['validator.validator_service_ids'] = array_merge($app['validator.validator_service_ids'], ['doctrine.orm.validator.unique' => 'doctrine.orm.validator.unique_validator']);
$app->extend('validator.object_initializers', function (array $objectInitializers, $app) {
$objectInitializers[] = new DoctrineInitializer($app['doctrine']);
return $objectInitializers;
});
$app['doctrine'] = function ($app) {
return new ManagerRegistry($app);
};
$app['orm.em'] = function ($app) {
$em = EntityManager::create($app['db'], $app['orm.config'], $app['db.event_manager']);
return $em;
};
// Entity manager alias
$app['em'] = function ($app) {
return $app['orm.em'];
};
$app['orm.config'] = function ($app) {
$config = new Configuration();
// @todo path!
$config->setProxyDir(sprintf('%s/../../../../../../var/cache/doctrine/proxies', __DIR__));
$config->setProxyNamespace('DoctrineProxies');
$config->setAutoGenerateProxyClasses($app['debug']);
// The strongly recommended FALSE in production
$chain = new MappingDriverChain();
// Pulsar
$path = realpath(sprintf('%s/../Entity', __DIR__));
$driver = $config->newDefaultAnnotationDriver((array) $path, false);
$chain->addDriver($driver, 'Pulsar\\Entity');
// App
$path = realpath(sprintf('%s/../../../../../../src/App', __DIR__));
$driver = $config->newDefaultAnnotationDriver((array) $path, false);
$chain->addDriver($driver, 'App\\Entity');
$config->setMetadataCacheImpl($app['orm.cache']);
$config->setMetadataDriverImpl($chain);
return $config;
};
$app['orm.cache'] = function () {
return new ArrayCache();
};
}
示例9: register
public function register(Container $container)
{
$container['doctrine'] = function ($container) {
return new ManagerRegistry($container);
};
if (isset($container['form.extensions']) && class_exists('Symfony\\Bridge\\Doctrine\\Form\\DoctrineOrmExtension')) {
$container['form.extensions'] = $container->extend('form.extensions', function ($extensions, $container) {
$extensions[] = new DoctrineOrmExtension($container['doctrine']);
return $extensions;
});
}
if (isset($container['validator']) && class_exists('Symfony\\Bridge\\Doctrine\\Validator\\Constraints\\UniqueEntityValidator')) {
$container['doctrine.orm.validator.unique_validator'] = function ($container) {
return new UniqueEntityValidator($container['doctrine']);
};
if (!isset($container['validator.validator_service_ids'])) {
$container['validator.validator_service_ids'] = array();
}
$container['validator.validator_service_ids'] = array_merge($container['validator.validator_service_ids'], array('doctrine.orm.validator.unique' => 'doctrine.orm.validator.unique_validator'));
$container['validator.object_initializers'] = $container->extend('validator.object_initializers', function (array $objectInitializers) use($container) {
$objectInitializers[] = new DoctrineInitializer($container['doctrine']);
return $objectInitializers;
});
}
if (class_exists('Saxulum\\DoctrineOrmCommands\\Command\\CreateDatabaseDoctrineCommand')) {
if (isset($container['console'])) {
$container['console'] = $container->extend('console', function (ConsoleApplication $consoleApplication) use($container) {
$helperSet = $consoleApplication->getHelperSet();
$helperSet->set(new ManagerRegistryHelper($container['doctrine']), 'doctrine');
return $consoleApplication;
});
}
if (isset($container['console.commands'])) {
$container['console.commands'] = $container->extend('console.commands', function ($commands) use($container) {
$commands[] = new CreateDatabaseDoctrineCommand();
$commands[] = new DropDatabaseDoctrineCommand();
$commands[] = new CreateSchemaDoctrineCommand();
$commands[] = new UpdateSchemaDoctrineCommand();
$commands[] = new DropSchemaDoctrineCommand();
$commands[] = new RunDqlDoctrineCommand();
$commands[] = new RunSqlDoctrineCommand();
$commands[] = new ConvertMappingDoctrineCommand();
$commands[] = new ClearMetadataCacheDoctrineCommand();
$commands[] = new ClearQueryCacheDoctrineCommand();
$commands[] = new ClearResultCacheDoctrineCommand();
$commands[] = new InfoDoctrineCommand();
$commands[] = new ValidateSchemaCommand();
$commands[] = new EnsureProductionSettingsDoctrineCommand();
return $commands;
});
}
}
}
开发者ID:transmitsms,项目名称:saxulum-doctrine-orm-manager-registry-provider,代码行数:53,代码来源:DoctrineOrmManagerRegistryProvider.php
示例10: register
/**
* Register the services required to render forms for the web application
*
* @param Container $container
*/
public function register(Container $container)
{
$container->extend('twig.environment', function (Environment $twig) use($container) {
$renderer = new FormRenderer(new FormTheme($twig, $container['forms']['theme']));
$twig->addExtension(new FormExtension($renderer));
return $twig;
});
$container->extend('twig.loader', function (Loader $loader) {
$loader->addPath(__DIR__ . '/../../../../../vendor/comphppuebla/easy-forms/src/EasyForms/Bridges/Twig');
return $loader;
});
}
示例11: register
/**
* @param Container $app
*/
public function register(Container $app)
{
if (!isset($app['form.factory'])) {
throw new \LogicException('You must register the FormServiceProvider to use the FormFilterServiceProvider.');
}
$app['lexik_form_filter.query_builder_updater'] = function () use($app) {
return new FilterBuilderUpdater($app['lexik_form_filter.form_data_extractor'], $app['dispatcher']);
};
// Alias
$app['form_filter'] = function () use($app) {
return $app['lexik_form_filter.query_builder_updater'];
};
// Filter Types
$app['form.types'] = $app->extend('form.types', function ($types) use($app) {
$types = array_merge($types, [new Type\TextFilterType(), new Type\NumberFilterType(), new Type\NumberRangeFilterType(), new Type\CheckboxFilterType(), new Type\BooleanFilterType(), new Type\ChoiceFilterType(), new Type\DateFilterType(), new Type\DateRangeFilterType(), new Type\DateTimeFilterType(), new Type\DateTimeRangeFilterType(), new Type\CollectionAdapterFilterType(), new Type\SharedableFilterType()]);
if (isset($app['doctrine'])) {
$types[] = new Type\EntityFilterType($app['doctrine']);
}
return $types;
});
// Type extension
$app['form.type.extensions'] = $app->extend('form.type.extensions', function ($extensions) {
$extensions[] = new FilterTypeExtension();
return $extensions;
});
// Form data extraction
$app['lexik_form_filter.form_data_extractor'] = function () {
$extractor = new FormDataExtractor();
$extractor->addMethod(new DefaultExtractionMethod());
$extractor->addMethod(new TextExtractionMethod());
$extractor->addMethod(new ValueKeysExtractionMethod());
return $extractor;
};
$app['lexik_form_filter.filter_prepare'] = function () {
return new PrepareListener();
};
// Subscriber to get filter condition
$app['lexik_form_filter.get_filter.doctrine_orm'] = function () {
return new DoctrineORMSubscriber();
};
$app['lexik_form_filter.get_filter.doctrine_dbal'] = function () {
return new DoctrineDBALSubscriber();
};
// Listener to apply filter conditions
$app['lexik_form_filter.apply_filter.doctrine_orm'] = function () {
return new DoctrineApplyFilterListener(null);
};
$app['lexik_form_filter.apply_filter.doctrine_dbal'] = function () {
return new DoctrineApplyFilterListener(null);
};
}
示例12: register
/**
* {@inheritDoc}
*/
public function register(Container $app)
{
$app['sentry.options'] = [];
$levels = ['debug' => Logger::DEBUG, 'info' => Logger::INFO, 'notice' => Logger::NOTICE, 'warning' => Logger::WARNING, 'error' => Logger::ERROR, 'critical' => Logger::CRITICAL, 'alert' => Logger::ALERT, 'emergency' => Logger::EMERGENCY];
$app['sentry'] = function ($app) {
if (!isset($app['sentry.options']['dsn']) || empty($app['sentry.options']['dsn'])) {
throw new RuntimeException('sentry dsn is empty.');
}
$options = $app['sentry.options'];
unset($options['dsn']);
if (isset($options['level'])) {
unset($options['level']);
}
if (!isset($options['tags'])) {
$options['tags'] = [];
}
$options['tags']['php_version'] = phpversion();
return new Raven_Client($app['sentry.options']['dsn'], $options);
};
$app['monolog'] = $app->extend('monolog', function (LoggerInterface $monolog, $app) use($levels) {
$level = Logger::NOTICE;
if (isset($app['sentry.options']['level']) && isset($levels[$app['sentry.options']['level']])) {
$level = $levels[$app['sentry.options']['level']];
}
$monolog->pushHandler(new RavenHandler($app['sentry'], $level));
return $monolog;
});
}
示例13: register
/**
* {@inheritdoc}
*/
public function register(Container $app)
{
if (!isset($app['console'])) {
throw new \LogicException('You must register the ConsoleServiceProvider to use the DoctrineConsoleServiceProvider.');
}
if (!isset($app['orm'])) {
throw new \LogicException('You must register the DoctrineOrmServiceProvider to use the DoctrineConsoleServiceProvider.');
}
$app['console'] = $app->extend('console', function (ConsoleApplication $console) use($app) {
$helper = $console->getHelperSet();
$helper->set(new ConnectionHelper($app['db']), 'db');
$helper->set(new EntityManagerHelper($app['orm']), 'em');
$console->add(new ImportCommand());
$console->add(new ReservedWordsCommand());
$console->add(new RunSqlCommand());
$console->add(new MetadataCommand());
$console->add(new ResultCommand());
$console->add(new QueryCommand());
$console->add(new CreateCommand());
$console->add(new UpdateCommand());
$console->add(new DropCommand());
$console->add(new EnsureProductionSettingsCommand());
$console->add(new ConvertDoctrine1SchemaCommand());
$console->add(new GenerateRepositoriesCommand());
$console->add(new GenerateEntitiesCommand());
$console->add(new GenerateProxiesCommand());
$console->add(new ConvertMappingCommand());
$console->add(new RunDqlCommand());
$console->add(new ValidateSchemaCommand());
$console->add(new InfoCommand());
$console->add(new MappingDescribeCommand());
return $console;
});
}
开发者ID:sergiors,项目名称:doctrine-console-service-provider,代码行数:37,代码来源:DoctrineConsoleServiceProvider.php
示例14: register
public function register(Container $app)
{
if (!isset($app['validator'])) {
throw new \LogicException('You must register the ValidatorServiceProvider to use the DoctrineManagerRegistryServiceProvider.');
}
$app['doctrine'] = function () use($app) {
$container = new Container();
$ems = $app['ems'];
$dbs = $app['dbs'];
$connections = array_map(function ($name) use($container, $dbs) {
$container['dbs.' . $name] = $dbs[$name];
return 'dbs.' . $name;
}, $dbs->keys());
$managers = array_map(function ($name) use($container, $ems) {
$container['ems.' . $name] = $ems[$name];
return 'ems.' . $name;
}, $ems->keys());
return new ManagerRegistry($container, $connections, $managers, $app['dbs.default'], $app['ems.default']);
};
$app['validator.unique'] = function () use($app) {
if (!class_exists('Symfony\\Bridge\\Doctrine\\Validator\\Constraints\\UniqueEntityValidator')) {
return;
}
return new UniqueEntityValidator($app['doctrine']);
};
$app['validator.validator_service_ids'] = array_merge($app['validator.validator_service_ids'], ['doctrine.orm.validator.unique' => 'validator.unique']);
if (isset($app['form.extensions'])) {
$app['form.extensions'] = $app->extend('form.extensions', function ($extensions) use($app) {
if (class_exists('Symfony\\Bridge\\Doctrine\\Form\\DoctrineOrmExtension')) {
$extensions[] = new DoctrineOrmExtension($app['doctrine']);
}
return $extensions;
});
}
}
开发者ID:sergiors,项目名称:doctrine-manager-registry-service-provider,代码行数:35,代码来源:DoctrineManagerRegistryServiceProvider.php
示例15: testDump
public function testDump()
{
$container = new Container();
$container['debug'] = false;
$container['charset'] = 'utf-8';
$logger = $this->getLogger();
$container['logger'] = $logger;
$container->register(new TwigServiceProvider());
$twigPath = $this->getTwigPath();
$container['twig.loader.filesystem'] = $container->extend('twig.loader.filesystem', function (\Twig_Loader_Filesystem $twigLoaderFilesystem) use($twigPath) {
$twigLoaderFilesystem->addPath($twigPath, 'SaxulumAsseticTwig');
return $twigLoaderFilesystem;
});
$container->register(new AsseticTwigProvider(), array('assetic.asset.root' => $this->getFixturesPath(), 'assetic.asset.asset_root' => $this->getAssetPath()));
/** @var Dumper $dumper */
$dumper = $container['assetic.asset.dumper'];
$dumper->dump();
if (count($logger->entries)) {
var_dump($logger->entries);
}
$this->assertCount(0, $logger->entries);
$this->fileComparsion('css/test-copyfile.css');
$this->fileComparsion('image/test.png');
$this->fileComparsion('css/test-less.css');
$this->fileComparsion('css/test-scss.css');
$this->fileComparsion('css/test-cssmin.css');
$this->fileComparsion('css/test-csscompress.css');
$this->fileComparsion('js/test.js');
}