本文整理匯總了PHP中Symfony\Component\DependencyInjection\ContainerInterface::set方法的典型用法代碼示例。如果您正苦於以下問題:PHP ContainerInterface::set方法的具體用法?PHP ContainerInterface::set怎麽用?PHP ContainerInterface::set使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\DependencyInjection\ContainerInterface
的用法示例。
在下文中一共展示了ContainerInterface::set方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: setUp
protected function setUp()
{
// Global $config required by unique_id
global $config, $phpbb_root_path, $phpEx;
if (!is_array($config)) {
$config = new \phpbb\config\config(array());
}
$config['rand_seed'] = '';
$config['rand_seed_last_update'] = time() + 600;
$this->request = $this->getMock('\\phpbb\\request\\request');
$this->php_ini = new \bantu\IniGetWrapper\IniGetWrapper();
$this->filesystem = new \phpbb\filesystem\filesystem();
$this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx));
$guessers = array(new \Symfony\Component\HttpFoundation\File\MimeType\FileinfoMimeTypeGuesser(), new \Symfony\Component\HttpFoundation\File\MimeType\FileBinaryMimeTypeGuesser(), new \phpbb\mimetype\content_guesser(), new \phpbb\mimetype\extension_guesser());
$guessers[2]->set_priority(-2);
$guessers[3]->set_priority(-2);
$this->mimetype_guesser = new \phpbb\mimetype\guesser($guessers);
$this->container = new phpbb_mock_container_builder($phpbb_root_path, $phpEx);
$this->container->set('files.filespec', new \phpbb\files\filespec($this->filesystem, $this->language, $this->php_ini, new \FastImageSize\FastImageSize(), $phpbb_root_path, new \phpbb\mimetype\guesser(array('mimetype.extension_guesser' => new \phpbb\mimetype\extension_guesser()))));
$this->factory = new \phpbb\files\factory($this->container);
$plupload = new \phpbb\plupload\plupload($phpbb_root_path, $config, $this->request, new \phpbb\user($this->language, '\\phpbb\\datetime'), $this->php_ini, $this->mimetype_guesser);
$this->container->set('files.types.form', new \phpbb\files\types\form($this->factory, $this->language, $this->php_ini, $plupload, $this->request), phpbb_mock_container_builder::SCOPE_PROTOTYPE);
$this->container->set('files.types.local', new \phpbb\files\types\local($this->factory, $this->language, $this->php_ini, $this->request), phpbb_mock_container_builder::SCOPE_PROTOTYPE);
$this->path = __DIR__ . '/fixture/';
$this->phpbb_root_path = $phpbb_root_path;
}
示例2: getReflectionMethod
/**
* Returns the ReflectionMethod for the given controller string.
*
* @param string $controller
*Â @return \ReflectionMethod|null
*/
public function getReflectionMethod($controller)
{
if (false === strpos($controller, '::') && 2 === substr_count($controller, ':')) {
$controller = $this->controllerNameParser->parse($controller);
}
if (preg_match('#(.+)::([\\w]+)#', $controller, $matches)) {
$class = $matches[1];
$method = $matches[2];
} elseif (preg_match('#(.+):([\\w]+)#', $controller, $matches)) {
$controller = $matches[1];
$method = $matches[2];
if ($this->container->has($controller)) {
$this->container->enterScope('request');
$this->container->set('request', new Request(), 'request');
$class = ClassUtils::getRealClass(get_class($this->container->get($controller)));
$this->container->leaveScope('request');
}
}
if (isset($class) && isset($method)) {
try {
return new \ReflectionMethod($class, $method);
} catch (\ReflectionException $e) {
}
}
return null;
}
示例3: configureIO
/**
* @param InputInterface $input
* @param OutputInterface $output
*/
protected function configureIO(InputInterface $input, OutputInterface $output)
{
parent::configureIO($input, $output);
if (null !== $this->container) {
$this->container->set('console.input', $input);
$this->container->set('console.output', $output);
}
}
示例4: mockLogger
protected function mockLogger()
{
$this->mockContainer();
// Mock the logger.factory service and a logger channel.
$factory = $this->getMock('\\Drupal\\Core\\Logger\\LoggerChannelFactoryInterface');
$channel = $this->getMock('\\Drupal\\Core\\Logger\\LoggerChannelInterface');
$factory->method('get')->willReturn($channel);
$this->container->set('logger.factory', $factory);
}
示例5: onKernelRequest
public function onKernelRequest(GetResponseEvent $event)
{
try {
$transport = TransportFactory::create($this->modulesSettings->get('Core', 'mailer_type', 'mail'), $this->modulesSettings->get('Core', 'smtp_server'), $this->modulesSettings->get('Core', 'smtp_port', 25), $this->modulesSettings->get('Core', 'smtp_username'), $this->modulesSettings->get('Core', 'smtp_password'), $this->modulesSettings->get('Core', 'smtp_secure_layer'));
$this->container->set('swiftmailer.mailer.default.transport', $transport);
} catch (PDOException $e) {
// we'll just use the mail transport thats pre-configured
}
}
示例6: setUp
protected function setUp()
{
require_once __DIR__ . '/../Fixtures/AppKernel.php';
$kernel = new AppKernel('test', true);
$kernel->boot();
$this->kernel = $kernel;
$this->container = $kernel->getContainer();
$entityManager = $this->prophesize(EntityManager::class);
$this->container->set('doctrine.orm.entity_manager', $entityManager->reveal());
$this->entityManager = $entityManager;
}
示例7: setUp
/**
* {@inheritdoc}
*/
public function setUp()
{
$framework = $this->mockContaoFramework(null, null, ['Contao\\Encryption' => $this->mockEncryptionAdapter()]);
$connection = $this->getMock('Doctrine\\DBAL\\Connection', [], [], '', false);
$this->container = $this->mockContainerWithContaoScopes();
$this->container->set('contao.framework', $framework);
$this->container->set('database_connection', $connection);
$this->command = new UserPasswordCommand();
$this->command->setContainer($this->container);
$this->command->setApplication(new Application());
}
示例8: setUp
protected function setUp()
{
global $phpbb_root_path, $phpEx;
$this->request = $this->getMock('\\phpbb\\request\\request');
$this->filesystem = new \phpbb\filesystem\filesystem();
$this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx));
$this->php_ini = new \bantu\IniGetWrapper\IniGetWrapper();
$this->container = new phpbb_mock_container_builder($phpbb_root_path, $phpEx);
$this->container->set('files.filespec', new \phpbb\files\filespec($this->filesystem, $this->language, $this->php_ini, new \FastImageSize\FastImageSize(), $phpbb_root_path, new \phpbb\mimetype\guesser(array('mimetype.extension_guesser' => new \phpbb\mimetype\extension_guesser()))));
$this->factory = new \phpbb\files\factory($this->container);
$this->path = __DIR__ . '/fixture/';
$this->phpbb_root_path = $phpbb_root_path;
}
示例9: setUp
public function setUp()
{
$this->container = new Container();
$this->container->setParameter('doctrine_mongodb.odm.persistent_collection_dir', sys_get_temp_dir());
$this->container->setParameter('doctrine_mongodb.odm.auto_generate_persistent_collection_classes', Configuration::AUTOGENERATE_NEVER);
$this->generatorMock = $this->getMockBuilder(PersistentCollectionGenerator::class)->getMock();
$dm = $this->createTestDocumentManager([__DIR__ . '/../Fixtures/Cache']);
$dm->getConfiguration()->setPersistentCollectionGenerator($this->generatorMock);
$registryStub = $this->getMockBuilder(ManagerRegistry::class)->getMock();
$registryStub->expects($this->any())->method('getManagers')->willReturn([$dm]);
$this->container->set('doctrine_mongodb', $registryStub);
$this->warmer = new PersistentCollectionCacheWarmer($this->container);
}
示例10: testConfigureOptionsResolver
public function testConfigureOptionsResolver()
{
$this->builder->configureOptionsResolver(\Mockery::mock('Symfony\\Component\\OptionsResolver\\OptionsResolver')->shouldReceive('setRequired')->once()->with(array('pdo', 'table', 'fields', 'id_field'))->andReturn(\Mockery::self())->getMock()->shouldReceive('setAllowedTypes')->once()->with(array('pdo' => 'PDO', 'table' => 'string', 'fields' => 'array', 'id_field' => 'string'))->andReturn(\Mockery::self())->getMock()->shouldReceive('addAllowedTypes')->once()->with(array('pdo' => 'string'))->andReturn(\Mockery::self())->getMock()->shouldReceive('setNormalizers')->once()->with(new EqualsMatcher(array('pdo' => function () {
})))->andReturn(\Mockery::self())->getMock());
$pdo = new MockPDO(\Mockery::mock());
$resolver = new OptionsResolver();
$this->builder->configureOptionsResolver($resolver);
$options = $resolver->resolve(array('pdo' => $pdo, 'table' => '', 'fields' => array(), 'id_field' => ''));
$this->assertSame($pdo, $options['pdo']);
$this->container->set('pdo', $pdo);
$options = $resolver->resolve(array('pdo' => 'pdo', 'table' => '', 'fields' => array(), 'id_field' => ''));
$this->assertSame($pdo, $options['pdo']);
}
示例11: add
/**
* {@inheritdoc}
*/
public function add(FieldSet $fieldSet)
{
$name = $fieldSet->getSetName();
if (isset($this->serviceIds[$name])) {
throw new InvalidArgumentException(sprintf('Unable to overwrite already registered FieldSet "%s".', $name));
}
if (!$fieldSet->isConfigLocked()) {
throw new InvalidArgumentException(sprintf('Unable to register none configuration-locked FieldSet "%s".', $name));
}
$serviceId = 'rollerworks_search.fieldset.late_registering.' . $name;
$this->serviceIds[$name] = $serviceId;
$this->container->set($serviceId, $fieldSet);
return $this;
}
示例12: testResolveFromContainer
public function testResolveFromContainer()
{
$mockServer1 = $this->getMock(ServerInterface::class);
$mockRequestHandler1 = $this->getMock(RequestHandlerInterface::class);
$this->container->set('service.foo1', $mockServer1);
$this->container->set('service.bar1', $mockRequestHandler1);
$exceptionHandler = $this->createExceptionHandler();
$exe = $this->createFactory()->create('service.foo1', 'service.bar1', $exceptionHandler);
/* @var ExecutorFakeStub $exe */
$this->assertInstanceOf(ExecutorFakeStub::class, $exe);
$this->assertSame($mockServer1, $exe->getServer());
$this->assertSame($mockRequestHandler1, $exe->getRequestHandler());
$this->assertSame($exceptionHandler, $exe->getExceptionHandler());
}
示例13: test_upload_form
/**
* @dataProvider data_upload_form
*/
public function test_upload_form($filename, $upload_ary, $expected)
{
$filespec = new \phpbb\files\filespec($this->filesystem, $this->language, $this->php_ini, new \FastImageSize\FastImageSize(), $this->phpbb_root_path, new \phpbb\mimetype\guesser(array('mimetype.extension_guesser' => new \phpbb\mimetype\extension_guesser())));
$filespec_local = new ReflectionProperty($filespec, 'local');
$filespec_local->setAccessible(true);
$filespec_local->setValue($filespec, true);
$this->container->set('files.filespec', $filespec);
$this->factory = new \phpbb\files\factory($this->container);
$type_local = new \phpbb\files\types\local($this->factory, $this->language, $this->php_ini, $this->request);
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path);
$upload->set_allowed_extensions(array('png'));
$type_local->set_upload($upload);
$file = $type_local->upload($filename, $upload_ary);
$this->assertSame($expected, $file->error);
$this->assertInstanceOf('\\phpbb\\files\\filespec', $file);
}
示例14: initializeContainer
/**
* Initializes the service container
*
* The cached version of the service container is used when fresh, otherwise the container is built.
*/
protected function initializeContainer()
{
// Retrieve container class name (applicationDevelopmentDebugProjectContainer)
$class = $this->getContainerClass();
// Getting cache instance ('data/cache/applicationDevelopmentDebugProjectContainer.php', true)
$cache = new ConfigCache($this->getCacheDir() . '/' . $class . '.php', $this->_debug);
$fresh = true;
// On vérifie que le cache est toujours valide et si ce n'est pas le cas, on le reconstruit.
// En mode debug, le cache est toujours reconstruit from scratch
if (!$cache->isFresh()) {
// On construit le container
$container = $this->buildContainer();
// On dump le container
$this->dumpContainer($cache, $container, $class, $this->getContainerBaseClass());
$fresh = false;
}
// On inclu la class du container généré
require_once $cache;
$this->_container = new $class();
$this->_container->set('kernel', $this);
// TODO cache warmer
//if (!$fresh && 'cli' !== php_sapi_name()) {
// $this->_container->get('cache_warmer')->warmUp($this->_container->getParameter('application.cache_dir'));
//}
}
示例15: test_image_upload
/**
* @dataProvider data_image_upload
*/
public function test_image_upload($is_image, $plupload_active, $config_data, $expected)
{
$filespec = $this->getMock('\\phpbb\\files\\filespec', array('init_error', 'is_image', 'move_file', 'is_uploaded'), array($this->filesystem, $this->language, $this->php_ini, new \FastImageSize\FastImageSize(), $this->phpbb_root_path, $this->mimetype_guesser, $this->plupload));
foreach ($config_data as $key => $value) {
$this->config[$key] = $value;
}
$filespec->set_upload_namespace($this->files_upload);
$filespec->expects($this->any())->method('init_error')->willReturn(false);
$filespec->expects($this->any())->method('is_image')->willReturn($is_image);
$filespec->expects($this->any())->method('is_uploaded')->willReturn(true);
$filespec->expects($this->any())->method('move_file')->willReturn(false);
$this->container->set('files.filespec', $filespec);
$factory_mock = $this->getMockBuilder('\\phpbb\\files\\factory')->disableOriginalConstructor()->getMock();
$factory_mock->expects($this->any())->method('get')->willReturn($filespec);
$this->container->set('files.types.local', new \phpbb\files\types\local($factory_mock, $this->language, $this->php_ini, $this->request));
$plupload = $this->getMockBuilder('\\phpbb\\plupload\\plupload')->disableOriginalConstructor()->getMock();
$plupload->expects($this->any())->method('is_active')->willReturn($plupload_active);
if ($plupload_active) {
$plupload->expects($this->once())->method('emit_error')->with(104, 'ATTACHED_IMAGE_NOT_IMAGE')->willReturn(false);
}
$this->upload = new \phpbb\attachment\upload($this->auth, $this->cache, $this->config, $this->files_upload, $this->language, $this->mimetype_guesser, $this->phpbb_dispatcher, $plupload, $this->user, $this->phpbb_root_path);
$filedata = $this->upload->upload('foobar', 1, true, '', false, array('realname' => 'foobar.jpg', 'type' => 'jpg', 'size' => 100));
foreach ($expected as $key => $entry) {
$this->assertEquals($entry, $filedata[$key]);
}
// Reset config data
foreach ($config_data as $key => $value) {
$this->config->delete($key);
}
}