本文整理汇总了PHP中Symfony\Component\DependencyInjection\ContainerBuilder::addResource方法的典型用法代码示例。如果您正苦于以下问题:PHP ContainerBuilder::addResource方法的具体用法?PHP ContainerBuilder::addResource怎么用?PHP ContainerBuilder::addResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\DependencyInjection\ContainerBuilder
的用法示例。
在下文中一共展示了ContainerBuilder::addResource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: realpath
/**
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
* @param \Doctrine\Common\Annotations\AnnotationReader $annotationReader
* @param \FSi\Bundle\AdminBundle\Finder\AdminClassFinder $adminClassFinder
*/
function it_registers_annotated_admin_classes_as_services($container, $annotationReader, $adminClassFinder)
{
$container->getParameter('kernel.bundles')->willReturn(array('FSi\\Bundle\\AdminBundle\\spec\\fixtures\\MyBundle', 'FSi\\Bundle\\AdminBundle\\FSiAdminBundle', 'Symfony\\Bundle\\FrameworkBundle\\FrameworkBundle'));
$baseDir = __DIR__ . '/../../../../../..';
$adminClassFinder->findClasses(array(realpath($baseDir . '/spec/fixtures/Admin'), realpath($baseDir . '/Admin')))->willReturn(array('FSi\\Bundle\\AdminBundle\\spec\\fixtures\\Admin\\SimpleAdminElement', 'FSi\\Bundle\\AdminBundle\\spec\\fixtures\\Admin\\CRUDElement'));
$annotationReader->getClassAnnotation(Argument::allOf(Argument::type('ReflectionClass'), Argument::which('getName', 'FSi\\Bundle\\AdminBundle\\spec\\fixtures\\Admin\\CRUDElement')), 'FSi\\Bundle\\AdminBundle\\Annotation\\Element')->willReturn(null);
$annotationReader->getClassAnnotation(Argument::allOf(Argument::type('ReflectionClass'), Argument::which('getName', 'FSi\\Bundle\\AdminBundle\\spec\\fixtures\\Admin\\SimpleAdminElement')), 'FSi\\Bundle\\AdminBundle\\Annotation\\Element')->willReturn(new Element(array()));
$container->addResource(Argument::allOf(Argument::type('Symfony\\Component\\Config\\Resource\\DirectoryResource'), Argument::which('getResource', realpath($baseDir . '/spec/fixtures/Admin')), Argument::which('getPattern', '/\\.php$/')))->shouldBeCalled();
$container->addResource(Argument::allOf(Argument::type('Symfony\\Component\\Config\\Resource\\DirectoryResource'), Argument::which('getResource', realpath($baseDir . '/Admin')), Argument::which('getPattern', '/\\.php$/')))->shouldBeCalled();
$container->addDefinitions(Argument::that(function ($definitions) {
if (count($definitions) !== 1) {
return false;
}
/** @var \Symfony\Component\DependencyInjection\Definition $definition */
$definition = $definitions[0];
if ($definition->getClass() !== 'FSi\\Bundle\\AdminBundle\\spec\\fixtures\\Admin\\SimpleAdminElement') {
return false;
}
if (!$definition->hasTag('admin.element')) {
return false;
}
return true;
}))->shouldBeCalled();
$this->process($container);
}
示例2: prepend
/**
* Allow an extension to prepend the extension configurations.
*
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
*/
public function prepend(ContainerBuilder $container)
{
$configFile = __DIR__ . '/../Resources/config/templates.yml';
$config = Yaml::parse(file_get_contents($configFile));
$container->prependExtensionConfig('ezpublish', $config);
$container->addResource(new FileResource($configFile));
}
示例3: load
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuredMenus = array();
if (is_file($file = $container->getParameter('kernel.root_dir') . '/config/navigation.yml')) {
$configuredMenus = $this->parseFile($file);
$container->addResource(new FileResource($file));
}
foreach ($container->getParameter('kernel.bundles') as $bundle) {
$reflection = new \ReflectionClass($bundle);
if (is_file($file = dirname($reflection->getFilename()) . '/Resources/config/navigation.yml')) {
$configuredMenus = array_replace_recursive($configuredMenus, $this->parseFile($file));
$container->addResource(new FileResource($file));
}
}
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yml');
// validate menu configurations
foreach ($configuredMenus as $rootName => $menuConfiguration) {
$configuration = new NavigationConfiguration();
$configuration->setMenuRootName($rootName);
$menuConfiguration[$rootName] = $this->processConfiguration($configuration, array($rootName => $menuConfiguration));
}
// Set configuration to be used in a custom service
$container->setParameter('jb_config.menu.configuration', $configuredMenus);
// Last argument of this service is always the menu configuration
$container->getDefinition('jb_config.menu.provider')->addArgument($configuredMenus);
}
示例4: prepend
/**
* Loads DemoBundle configuration.
*
* @param ContainerBuilder $container
*/
public function prepend(ContainerBuilder $container)
{
// Add legacy bundle settings only if it's present.
if ($container->hasExtension('ez_publish_legacy')) {
$legacyConfigFile = __DIR__ . '/../Resources/config/legacy_settings.yml';
$config = Yaml::parse(file_get_contents($legacyConfigFile));
$container->prependExtensionConfig('ez_publish_legacy', $config);
$container->addResource(new FileResource($legacyConfigFile));
}
$configFile = __DIR__ . '/../Resources/config/ezdemo.yml';
$config = Yaml::parse(file_get_contents($configFile));
$container->prependExtensionConfig('ezpublish', $config);
$container->addResource(new FileResource($configFile));
$configFile = __DIR__ . '/../Resources/config/image_variations.yml';
$config = Yaml::parse(file_get_contents($configFile));
$container->prependExtensionConfig('ezpublish', $config);
$container->addResource(new FileResource($configFile));
$ezpageConfigFile = __DIR__ . '/../Resources/config/ezpage.yml';
$ezpageConfig = Yaml::parse(file_get_contents($ezpageConfigFile));
$container->prependExtensionConfig('ezpublish', $ezpageConfig);
$container->addResource(new FileResource($ezpageConfigFile));
$ezCommentsConfigFile = __DIR__ . '/../Resources/config/ezcomments.yml';
$ezCommentsConfig = Yaml::parse(file_get_contents($ezCommentsConfigFile));
$container->prependExtensionConfig('ez_comments', $ezCommentsConfig);
$container->addResource(new FileResource($ezCommentsConfigFile));
}
示例5: testParameters
public function testParameters()
{
$path = Path::join([DATAFIXTURES_DIR, 'config', 'test-parameters.json']);
$this->locator->locate('test-parameters.json')->willReturn($path);
$this->container->addResource(Argument::that(function (FileResource $resource) use($path) {
return $resource->getResource() === $path;
}))->shouldBeCalled();
$this->container->loadFromExtension('test-parameters', ['name' => 'test'])->shouldBeCalled();
$this->container->setParameter('test', 'value')->shouldBeCalled();
$this->loader->load('test-parameters.json');
}
示例6: testProcess
public function testProcess()
{
$container = new ContainerBuilder();
$container->addResource(new DirectoryResource(__DIR__ . '/Fixtures/a'));
$container->addResource(new DirectoryResource(__DIR__ . '/Fixtures/a/b'));
$container->addResource(new DirectoryResource(__DIR__ . '/Fixtures/c'));
$this->process($container);
$resources = $container->getResources();
$this->assertEquals(1, count($resources));
$this->assertInstanceOf('JMS\\DiExtraBundle\\Config\\FastDirectoriesResource', $resources[0]);
$this->assertEquals(array(__DIR__ . '/Fixtures/a', __DIR__ . '/Fixtures/c'), $resources[0]->getResource());
$this->assertAttributeEquals('*', 'filePattern', $resources[0]);
}
示例7: process
public function process(ContainerBuilder $container)
{
if ($container->has('form.extension')) {
$container->getDefinition('twig.extension.form')->addTag('twig.extension');
$reflClass = new \ReflectionClass('Symfony\\Bridge\\Twig\\Extension\\FormExtension');
$container->getDefinition('twig.loader.filesystem')->addMethodCall('addPath', array(dirname(dirname($reflClass->getFileName())) . '/Resources/views/Form'));
}
if ($container->has('translator')) {
$container->getDefinition('twig.extension.trans')->addTag('twig.extension');
}
if ($container->has('router')) {
$container->getDefinition('twig.extension.routing')->addTag('twig.extension');
}
if ($container->has('fragment.handler')) {
$container->getDefinition('twig.extension.httpkernel')->addTag('twig.extension');
// inject Twig in the hinclude service if Twig is the only registered templating engine
if (!$container->hasParameter('templating.engines') || array('twig') == $container->getParameter('templating.engines')) {
$container->getDefinition('fragment.renderer.hinclude')->addTag('kernel.fragment_renderer', array('alias' => 'hinclude'))->replaceArgument(0, new Reference('twig'));
}
}
if ($container->has('request_stack')) {
$container->getDefinition('twig.extension.httpfoundation')->addTag('twig.extension');
}
if ($container->getParameter('kernel.debug')) {
$container->getDefinition('twig.extension.profiler')->addTag('twig.extension');
$container->getDefinition('twig.extension.debug')->addTag('twig.extension');
}
if (!$container->has('templating')) {
$loader = $container->getDefinition('twig.loader.native_filesystem');
$loader->replaceArgument(1, $this->getComposerRootDir($container->getParameter('kernel.root_dir')));
$loader->addTag('twig.loader');
$loader->setMethodCalls($container->getDefinition('twig.loader.filesystem')->getMethodCalls());
$container->setDefinition('twig.loader.filesystem', $loader);
}
if ($container->has('assets.packages')) {
$container->getDefinition('twig.extension.assets')->addTag('twig.extension');
}
$container->addResource(new ClassExistenceResource(YamlParser::class));
if (class_exists(YamlParser::class)) {
$container->getDefinition('twig.extension.yaml')->addTag('twig.extension');
}
$container->addResource(new ClassExistenceResource(Stopwatch::class));
if (class_exists(Stopwatch::class)) {
$container->getDefinition('twig.extension.debug.stopwatch')->addTag('twig.extension');
}
$container->addResource(new ClassExistenceResource(ExpressionLanguage::class));
if (class_exists(ExpressionLanguage::class)) {
$container->getDefinition('twig.extension.expression')->addTag('twig.extension');
}
}
示例8: prepend
/**
* Loads DemoBundle configuration.
*
* @param ContainerBuilder $container
*/
public function prepend(ContainerBuilder $container)
{
$configFile = __DIR__ . '/../Resources/config/ezdemo.yml';
$config = Yaml::parse(file_get_contents($configFile));
$container->prependExtensionConfig('ezpublish', $config);
$container->addResource(new FileResource($configFile));
$ezpageConfigFile = __DIR__ . '/../Resources/config/ezpage.yml';
$ezpageConfig = Yaml::parse(file_get_contents($ezpageConfigFile));
$container->prependExtensionConfig('ezpublish', $ezpageConfig);
$container->addResource(new FileResource($ezpageConfigFile));
$ezCommentsConfigFile = __DIR__ . '/../Resources/config/ezcomments.yml';
$ezCommentsConfig = Yaml::parse(file_get_contents($ezCommentsConfigFile));
$container->prependExtensionConfig('ez_comments', $ezCommentsConfig);
$container->addResource(new FileResource($ezCommentsConfigFile));
}
示例9: prepend
/**
* Loads SimpleDesignBundle configuration.
*
* @param ContainerBuilder $container
*/
public function prepend(ContainerBuilder $container)
{
$legacyConfigFile = __DIR__ . '/../Resources/config/legacy_settings.yml';
$config = Yaml::parse(file_get_contents($legacyConfigFile));
$container->prependExtensionConfig('ez_publish_legacy', $config);
$container->addResource(new FileResource($legacyConfigFile));
$designConfigFile = __DIR__ . '/../Resources/config/simpledesign.yml';
$config = Yaml::parse(file_get_contents($designConfigFile));
$container->prependExtensionConfig('ezpublish', $config);
$container->addResource(new FileResource($designConfigFile));
$configFile = __DIR__ . '/../Resources/config/image_variations.yml';
$config = Yaml::parse(file_get_contents($configFile));
$container->prependExtensionConfig('ezpublish', $config);
$container->addResource(new FileResource($configFile));
}
示例10:
function it_loads_configuration_files(ContainerBuilder $container)
{
$container->addResource(Argument::any())->shouldBeCalled();
$container->setParameter(Argument::cetera())->shouldBeCalled();
$container->setDefinition(Argument::cetera())->shouldBeCalled();
$this->load([], $container);
}
示例11: prepend
/**
* Allows an extension to prepend the extension configurations.
*
* @param ContainerBuilder $container ContainerBuilder object
*/
public function prepend(ContainerBuilder $container)
{
$configFile = dirname(__DIR__) . '/Resources/config/aimeos_shop.yml';
$config = Yaml::parse(file_get_contents($configFile));
$container->prependExtensionConfig('aimeos_shop', $config);
$container->addResource(new FileResource($configFile));
}
示例12: prependRest
public function prependRest(ContainerBuilder $container)
{
$restFile = __DIR__ . '/../Resources/config/default_settings.yml';
$config = Yaml::parse(file_get_contents($restFile));
$container->prependExtensionConfig('ez_publish_rest', $config);
$container->addResource(new FileResource($restFile));
}
示例13: getConfiguration
public function getConfiguration(array $config, ContainerBuilder $container)
{
$configuration = new Configuration($this->getAlias());
$r = new \ReflectionObject($configuration);
$container->addResource(new FileResource($r->getFileName()));
return $configuration;
}
示例14: process
/**
* {@inheritDoc}
*/
public function process(ContainerBuilder $container)
{
if (!$container->hasParameter('fos_user.storage')) {
return;
}
$storage = $container->getParameter('fos_user.storage');
if ('custom' === $storage) {
return;
}
$validationFile = __DIR__ . '/../../Resources/config/validation/' . $storage . '.xml';
if ($container->hasDefinition('validator.builder')) {
// Symfony 2.5+
$container->getDefinition('validator.builder')->addMethodCall('addXmlMapping', array($validationFile));
return;
}
// Old method of loading validation
if (!$container->hasParameter('validator.mapping.loader.xml_files_loader.mapping_files')) {
return;
}
$files = $container->getParameter('validator.mapping.loader.xml_files_loader.mapping_files');
if (is_file($validationFile)) {
$files[] = realpath($validationFile);
$container->addResource(new FileResource($validationFile));
}
$container->setParameter('validator.mapping.loader.xml_files_loader.mapping_files', $files);
}
示例15: load
/** {@inheritdoc} */
public function load(array $config, ContainerBuilder $container)
{
// Load configuration
(new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')))->load('webpack.yml');
// Retrieve all configuration entities
$bundles = $container->getParameter('kernel.bundles');
$builder_definition = $container->getDefinition('hostnet_webpack.bridge.config_generator');
$config_extension_ids = array_keys($container->findTaggedServiceIds('hostnet_webpack.config_extension'));
$config_definitions = [];
$config_class_names = [];
foreach ($config_extension_ids as $id) {
$config_definitions[$id] = $container->getDefinition($id);
$config_class_names[$id] = $container->getDefinition($id)->getClass();
}
$configuration = new Configuration(array_keys($bundles), $config_class_names);
$config = $this->processConfiguration($configuration, $config);
$container->addResource(new FileResource((new \ReflectionClass(Configuration::class))->getFileName()));
// Select the correct node binary for the platform we're currently running on.
$config['node']['binary'] = $config['node']['binary'][$this->getPlatformKey()];
$config['node']['node_modules_path'] = !empty($config['node']['node_modules_path']) ? $config['node']['node_modules_path'] : getenv('NODE_PATH');
// Parse application config into the config generator
foreach ($config_definitions as $id => $definition) {
/* @var $definition Definition */
$builder_definition->addMethodCall('addExtension', [new Reference($id)]);
$definition->addArgument($config);
}
// Pass the configuration to a container parameter for the CompilerPass and profiler to read.
$container->setParameter('hostnet_webpack_config', $config);
}