本文整理汇总了PHP中Symfony\Component\DependencyInjection\ContainerBuilder::set方法的典型用法代码示例。如果您正苦于以下问题:PHP ContainerBuilder::set方法的具体用法?PHP ContainerBuilder::set怎么用?PHP ContainerBuilder::set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\DependencyInjection\ContainerBuilder
的用法示例。
在下文中一共展示了ContainerBuilder::set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: it_does_not_fail_if_the_synthetic_service_has_been_provided_already
/**
* @test
*/
public function it_does_not_fail_if_the_synthetic_service_has_been_provided_already()
{
$this->containerBuilder->setDefinition('synthetic_service', $this->createSyntheticDefinition());
$this->containerBuilder->set('synthetic_service', new \stdClass());
$constraint = new ContainerBuilderHasSyntheticServiceConstraint('synthetic_service');
$this->assertConstraintPasses($constraint);
}
示例2: setUp
protected function setUp()
{
$this->extension = new GGTeamBreadcrumbExtension();
$this->container = new ContainerBuilder();
$this->container->registerExtension($this->extension);
$this->container->set('templating', $this->getMockTemplatingEngine());
}
示例3: buildContainer
/**
* @return mixed
*/
protected function buildContainer(ContainerBuilder $container)
{
$cacheDir = THELIA_CACHE_DIR . "test";
if (!is_dir($cacheDir)) {
mkdir($cacheDir);
}
$archiveBuilders = [new ZipArchiveBuilder(), new TarArchiveBuilder(), new TarBz2ArchiveBuilder(), new TarGzArchiveBuilder()];
$archiveBuilderManager = new ArchiveBuilderManager("test");
/**
* @var \Thelia\Core\FileFormat\Archive\AbstractArchiveBuilder $archiveBuilder
*/
foreach ($archiveBuilders as $key => $archiveBuilder) {
if (!$archiveBuilder->isAvailable()) {
unset($archiveBuilders[$key]);
} else {
$archiveBuilderManager->add($archiveBuilder);
}
}
if (empty($archiveBuilders)) {
$this->markTestSkipped("You don't have any archive builder, you can't run this test");
}
$container->set("thelia.manager.archive_builder_manager", $archiveBuilderManager);
$formatterManager = (new FormatterManager())->add(new XMLFormatter())->add(new JsonFormatter())->add(new CSVFormatter());
$container->set("thelia.manager.formatter_manager", $formatterManager);
}
示例4: getContainer
protected function getContainer()
{
$container = new ContainerBuilder();
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../../../Resources/config'));
$loader->load('monolog.xml');
$definition = $container->getDefinition('monolog.logger_prototype');
$container->set('monolog.handler.test', new Definition('%monolog.handler.null.class%', array(100, false)));
$definition->addMethodCall('pushHandler', array(new Reference('monolog.handler.test')));
// Handlers
$container->set('monolog.handler.a', new Definition('%monolog.handler.null.class%', array(100, false)));
$container->set('monolog.handler.b', new Definition('%monolog.handler.null.class%', array(100, false)));
$container->set('monolog.handler.c', new Definition('%monolog.handler.null.class%', array(100, false)));
// Channels
foreach (array('test', 'foo', 'bar') as $name) {
$service = new Definition('TestClass', array('false', new Reference('logger')));
$service->addTag('monolog.logger', array('channel' => $name));
$container->setDefinition($name, $service);
}
$container->setParameter('monolog.handlers_to_channels', array('monolog.handler.a' => array('type' => 'inclusive', 'elements' => array('test')), 'monolog.handler.b' => null, 'monolog.handler.c' => array('type' => 'exclusive', 'elements' => array('foo'))));
$container->getCompilerPassConfig()->setOptimizationPasses(array());
$container->getCompilerPassConfig()->setRemovingPasses(array());
$container->addCompilerPass(new LoggerChannelPass());
$container->compile();
return $container;
}
示例5: setUp
protected function setUp()
{
if (!class_exists('Assetic\\AssetManager')) {
$this->markTestSkipped('Assetic is not available.');
}
if (!class_exists('Twig_Environment')) {
$this->markTestSkipped('Twig is not available.');
}
$this->kernel = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\KernelInterface')->getMock();
$this->container = new ContainerBuilder();
// Symfony 2.3 BC
if (!method_exists('Symfony\\Component\\DependencyInjection\\Definition', 'setShared')) {
$this->container->addScope(new Scope('request'));
$this->container->register('request', 'Symfony\\Component\\HttpFoundation\\Request')->setScope('request');
}
// Symfony <2.7 BC
if (class_exists('Symfony\\Bundle\\FrameworkBundle\\Templating\\Helper\\AssetsHelper')) {
$this->container->register('assets.packages', $this->getMockClass('Symfony\\Component\\Asset\\Packages'));
$this->container->register('templating.helper.assets', $this->getMockClass('Symfony\\Bundle\\FrameworkBundle\\Templating\\Helper\\AssetsHelper'))->addArgument(new Reference('assets.packages'));
} elseif (class_exists('Symfony\\Component\\Templating\\Helper\\CoreAssetsHelper')) {
$this->container->register('templating.helper.assets', $this->getMockClass('Symfony\\Component\\Templating\\Helper\\CoreAssetsHelper'))->addArgument(new Definition($this->getMockClass('Symfony\\Component\\Templating\\Asset\\PackageInterface')));
}
$this->container->register('templating.helper.router', $this->getMockClass('Symfony\\Bundle\\FrameworkBundle\\Templating\\Helper\\RouterHelper'))->addArgument(new Definition($this->getMockClass('Symfony\\Component\\Routing\\RouterInterface')));
$this->container->register('twig', 'Twig_Environment')->addArgument(new Definition($this->getMockClass('Twig_LoaderInterface')));
$this->container->setParameter('kernel.bundles', array());
$this->container->setParameter('kernel.cache_dir', __DIR__);
$this->container->setParameter('kernel.debug', false);
$this->container->setParameter('kernel.root_dir', __DIR__);
$this->container->setParameter('kernel.charset', 'UTF-8');
$this->container->set('kernel', $this->kernel);
$this->container->addCompilerPass(new StaticAsseticHelperPass());
}
示例6: testLoad
public function testLoad()
{
$container = new ContainerBuilder();
// fake entity manager and security context services
$container->set('doctrine.orm.entity_manager', $this->getSqliteEntityManager());
$container->set('security.authorization_checker', $this->getMockAuthorizationChecker());
$container->set('event_dispatcher', new EventDispatcher());
$container->set('next_state_condition', new \stdClass());
// simple config
$extension = new WorkflowExtension();
$extension->load(array($this->getSimpleConfig()), $container);
$this->assertTrue($container->getDefinition('lexik_workflow.process.document_proccess') instanceof Definition);
// config with a process
$extension = new WorkflowExtension();
$extension->load(array($this->getConfig()), $container);
$this->assertTrue($container->getDefinition('lexik_workflow.process.document_proccess') instanceof Definition);
$this->assertTrue($container->getDefinition('lexik_workflow.process.document_proccess.step.step_create_doc') instanceof Definition);
$this->assertTrue($container->getDefinition('lexik_workflow.process.document_proccess.step.step_validate_doc') instanceof Definition);
$this->assertTrue($container->getDefinition('lexik_workflow.process.document_proccess.step.step_remove_doc') instanceof Definition);
$this->assertTrue($container->getDefinition('lexik_workflow.handler.document_proccess') instanceof Definition);
$processHandlerFactory = $container->get('lexik_workflow.process_aggregator');
$this->assertTrue($processHandlerFactory instanceof ProcessAggregator);
$this->assertTrue($processHandlerFactory->getProcess('document_proccess') instanceof Process);
$processHandler = $container->get('lexik_workflow.handler.document_proccess');
$this->assertTrue($processHandler instanceof ProcessHandler);
}
示例7: createContainer
/**
* Create a new container.
*
* @return ContainerInterface
*/
protected function createContainer()
{
$container = new ContainerBuilder();
// Default configuration.
$container->set('application', $this);
$container->set('configuration.loader', $this->configurationLoader);
$container->set('extension_manager', $this->extensionManager);
// Initialize extensions.
$this->extensionManager->initialize($container);
// Load configuration.
try {
$rawConfigs = $this->configurationLoader->loadConfiguration();
$this->extensionManager->load($rawConfigs, $container);
} catch (ConfigurationLoadingException $e) {
// No configuration file found.
// Continue with restricted services if `ignoreMissingConfiguration`
// has been specified.
if (!$this->ignoreMissingConfiguration) {
throw $e;
}
}
// Process compiler pass & compile container
$container->compile();
return $container;
}
示例8: createContainer
public static function createContainer()
{
$logDir = __DIR__ . '/../data/logs';
if (!file_exists($logDir)) {
mkdir($logDir);
}
$container = new ContainerBuilder();
$container->set('doctrine_phpcr.default_session', self::createSession());
$logger = new Logger('test');
$logger->pushHandler(new StreamHandler($logDir . '/test.log'));
$dispatcher = new ContainerAwareEventDispatcher($container);
$container->set('sulu_document_manager.event_dispatcher', $dispatcher);
$config = ['sulu_document_manager.default_locale' => 'en', 'sulu_document_manager.mapping' => ['full' => ['alias' => 'full', 'phpcr_type' => 'mix:test', 'class' => 'Sulu\\Component\\DocumentManager\\Tests\\Functional\\Model\\FullDocument']], 'sulu_document_manager.namespace_mapping' => ['system' => 'nsys', 'system_localized' => 'lsys', 'content' => 'ncont', 'content_localized' => 'lcont']];
foreach ($config as $parameterName => $parameterValue) {
$container->setParameter($parameterName, $parameterValue);
}
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../symfony-di'));
$loader->load('core.xml');
$loader->load('subscribers.xml');
foreach (array_keys($container->findTaggedServiceIds('sulu_document_manager.event_subscriber')) as $subscriberId) {
$def = $container->get($subscriberId);
$dispatcher->addSubscriberService($subscriberId, get_class($def));
}
return $container;
}
示例9: testConfigLoad
public function testConfigLoad()
{
$builder = new ContainerBuilder();
// external services
$builder->set('doctrine.orm.entity_manager', new \stdClass());
$builder->set('security.token_storage', new \stdClass());
$bundle = new ModeraBackendDashboardBundle();
$bundle->build($builder);
$ext = new ModeraBackendDashboardExtension();
$ext->load(array(), $builder);
$builder->compile();
$this->assertTrue($builder->has('modera_backend_dashboard.contributions.menu_items_provider'));
$menuProvider = $builder->getDefinition('modera_backend_dashboard.contributions.menu_items_provider');
$this->assertEquals('Modera\\BackendDashboardBundle\\Contributions\\MenuItemsProvider', $menuProvider->getClass());
$this->assertTrue($menuProvider->hasTag('modera_mjr_integration.menu.menu_items_provider'));
// service provided by Expander bundle
$this->assertTrue($builder->has('modera_backend_dashboard.dashboard_provider'));
$this->assertTrue($builder->has('modera_backend_dashboard.dashboard_service'));
$arg = $builder->getDefinition('modera_backend_dashboard.dashboard_service')->getArgument(0);
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Reference', $arg);
/* @var \Symfony\Component\DependencyInjection\Reference $arg */
$this->assertEquals('modera_backend_dashboard.dashboard_provider', $arg->__toString());
$this->assertTrue($builder->has('modera_backend_dashboard.contributions.config_mergers_provider'));
$configProvider = $builder->getDefinition('modera_backend_dashboard.contributions.config_mergers_provider');
$this->assertTrue($configProvider->hasTag('modera_mjr_integration.config.config_mergers_provider'));
}
示例10: createContainer
protected function createContainer()
{
$container = new ContainerBuilder();
$container->set('config', $this->config);
$container->set('client', $this->client);
return $container;
}
示例11: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
$container = new ContainerBuilder();
$bin_dir = dirname(__DIR__) . '/';
$loader = new YamlFileLoader($container, new FileLocator($bin_dir));
$loader->load('services.yml');
$test_directory = sys_get_temp_dir() . '/' . uniqid('tl');
mkdir($test_directory);
file_put_contents($test_directory . '/.tl.yml', Yaml::dump(['url' => 'http://example.com']));
$container->setParameter('directory', $test_directory);
$mock_connector = $this->getMock(Connector::class);
$container->set('connector', $mock_connector);
$configuration_processor = $this->getMock(Processor::class);
$configuration_processor->expects($this->any())->method('processConfiguration')->willReturn([]);
$container->set('config.processor', $configuration_processor);
$this->container = $container;
$this->application = new Application('Time logger', 'testing', $container);
if ($this->installSchema) {
$install = $container->get('app.command.install');
$install->setApplication($this->application);
$input = new ArrayInput(['command' => 'install']);
$output = $this->getMock(OutputInterface::class);
$install->run($input, $output);
}
}
示例12: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->container = new ContainerBuilder();
$cache_contexts_manager = $this->prophesize(CacheContextsManager::class)->reveal();
$this->container->set('cache_contexts_manager', $cache_contexts_manager);
\Drupal::setContainer($this->container);
}
示例13: setUp
public function setUp()
{
parent::setUp();
global $auth, $cache, $config, $db, $phpbb_container, $phpbb_dispatcher, $user, $request, $phpEx, $phpbb_root_path, $user_loader;
// Database
$this->db = $this->new_dbal();
$db = $this->db;
// Auth
$auth = $this->getMock('\\phpbb\\auth\\auth');
$auth->expects($this->any())->method('acl_get')->with($this->stringContains('_'), $this->anything())->will($this->returnValueMap(array(array('f_noapprove', 1, true), array('f_postcount', 1, true), array('m_edit', 1, false))));
// Config
$config = new \phpbb\config\config(array('num_topics' => 1, 'num_posts' => 1, 'allow_board_notifications' => true));
$cache_driver = new \phpbb\cache\driver\dummy();
$cache = new \phpbb\cache\service($cache_driver, $config, $db, $phpbb_root_path, $phpEx);
// Event dispatcher
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
// User
$user = $this->getMock('\\phpbb\\user', array(), array(new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)), '\\phpbb\\datetime'));
$user->ip = '';
$user->data = array('user_id' => 2, 'username' => 'user-name', 'is_registered' => true, 'user_colour' => '');
// Request
$type_cast_helper = $this->getMock('\\phpbb\\request\\type_cast_helper_interface');
$request = $this->getMock('\\phpbb\\request\\request');
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
$user_loader = new \phpbb\user_loader($db, $phpbb_root_path, $phpEx, USERS_TABLE);
// Container
$phpbb_container = new ContainerBuilder();
$loader = new YamlFileLoader($phpbb_container, new FileLocator(__DIR__ . '/fixtures'));
$loader->load('services_notification.yml');
$phpbb_container->set('user_loader', $user_loader);
$phpbb_container->set('user', $user);
$phpbb_container->set('config', $config);
$phpbb_container->set('dbal.conn', $db);
$phpbb_container->set('auth', $auth);
$phpbb_container->set('cache.driver', $cache_driver);
$phpbb_container->set('cache', $cache);
$phpbb_container->set('text_formatter.utils', new \phpbb\textformatter\s9e\utils());
$phpbb_container->set('dispatcher', $phpbb_dispatcher);
$phpbb_container->setParameter('core.root_path', $phpbb_root_path);
$phpbb_container->setParameter('core.php_ext', $phpEx);
$phpbb_container->setParameter('tables.notifications', 'phpbb_notifications');
$phpbb_container->setParameter('tables.user_notifications', 'phpbb_user_notifications');
$phpbb_container->setParameter('tables.notification_types', 'phpbb_notification_types');
$phpbb_container->set('content.visibility', new \phpbb\content_visibility($auth, $config, $phpbb_dispatcher, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE));
$phpbb_container->compile();
// Notification Types
$notification_types = array('quote', 'bookmark', 'post', 'post_in_queue', 'topic', 'topic_in_queue', 'approve_topic', 'approve_post');
$notification_types_array = array();
foreach ($notification_types as $type) {
$class = $phpbb_container->get('notification.type.' . $type);
$notification_types_array['notification.type.' . $type] = $class;
}
// Methods Types
$notification_methods_array = array('notification.method.board' => $phpbb_container->get('notification.method.board'));
// Notification Manager
$phpbb_notifications = new \phpbb\notification\manager($notification_types_array, $notification_methods_array, $phpbb_container, $user_loader, $phpbb_dispatcher, $db, $cache, $user, NOTIFICATION_TYPES_TABLE, USER_NOTIFICATIONS_TABLE);
$phpbb_container->set('notification_manager', $phpbb_notifications);
}
示例14: testLoadServicesWithDefaults
public function testLoadServicesWithDefaults()
{
$this->extension->load(array('alter_ego' => array('app_id' => '123456')), $this->container);
$this->container->set('buzz', $this->getMockBuilder('Buzz\\Browser')->disableOriginalConstructor()->getMock());
$this->container->set('router', $this->getMock('Symfony\\Component\\Routing\\Generator\\UrlGeneratorInterface'));
$this->assertService('AlterEgo\\Symfony\\Authorization', 'alter_ego.auth');
$this->assertService('AlterEgo\\Client', 'alter_ego.client');
$this->assertAlias('alter_ego.client', 'alter_ego');
}
示例15: testSplitDriver
public function testSplitDriver()
{
$this->container->setParameter('kernel.debug', false);
// Mock channel, otherwise php-amqplib will try to connect to AMQP server
$this->container->set('seven_service_bus.amqp_channel', $this->createMock(AMQPChannel::class));
$this->load(['service' => ['name' => 'phpunit'], 'jsonrpc' => [], 'amqp' => []]);
$driver = $this->container->get('seven_service_bus.driver');
$this->assertInstanceOf(SplitDriver::class, $driver);
}