当前位置: 首页>>代码示例>>PHP>>正文


PHP ContainerBuilder::freeze方法代码示例

本文整理汇总了PHP中Symfony\Component\DependencyInjection\ContainerBuilder::freeze方法的典型用法代码示例。如果您正苦于以下问题:PHP ContainerBuilder::freeze方法的具体用法?PHP ContainerBuilder::freeze怎么用?PHP ContainerBuilder::freeze使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\DependencyInjection\ContainerBuilder的用法示例。


在下文中一共展示了ContainerBuilder::freeze方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testExtensions

 public function testExtensions()
 {
     $container = new ContainerBuilder();
     $container->registerExtension(new \ProjectExtension());
     $container->registerExtension(new \ProjectWithXsdExtension());
     $loader = new ProjectLoader2($container, self::$fixturesPath . '/xml');
     // extension without an XSD
     $loader->load('extensions/services1.xml');
     $container->freeze();
     $services = $container->getDefinitions();
     $parameters = $container->getParameterBag()->all();
     $this->assertTrue(isset($services['project.service.bar']), '->load() parses extension elements');
     $this->assertTrue(isset($parameters['project.parameter.bar']), '->load() parses extension elements');
     $this->assertEquals('BAR', $services['project.service.foo']->getClass(), '->load() parses extension elements');
     $this->assertEquals('BAR', $parameters['project.parameter.foo'], '->load() parses extension elements');
     // extension with an XSD
     $container = new ContainerBuilder();
     $container->registerExtension(new \ProjectExtension());
     $container->registerExtension(new \ProjectWithXsdExtension());
     $loader = new ProjectLoader2($container, self::$fixturesPath . '/xml');
     $loader->load('extensions/services2.xml');
     $container->freeze();
     $services = $container->getDefinitions();
     $parameters = $container->getParameterBag()->all();
     $this->assertTrue(isset($services['project.service.bar']), '->load() parses extension elements');
     $this->assertTrue(isset($parameters['project.parameter.bar']), '->load() parses extension elements');
     $this->assertEquals('BAR', $services['project.service.foo']->getClass(), '->load() parses extension elements');
     $this->assertEquals('BAR', $parameters['project.parameter.foo'], '->load() parses extension elements');
     $loader = new ProjectLoader2(new ContainerBuilder(), self::$fixturesPath . '/xml');
     // extension with an XSD (does not validate)
     try {
         $loader->load('extensions/services3.xml');
         $this->fail('->load() throws an InvalidArgumentException if the configuration does not validate the XSD');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the configuration does not validate the XSD');
         $this->assertRegexp('/The attribute \'bar\' is not allowed/', $e->getMessage(), '->load() throws an InvalidArgumentException if the configuration does not validate the XSD');
     }
     // non-registered extension
     try {
         $loader->load('extensions/services4.xml');
         $this->fail('->load() throws an InvalidArgumentException if the tag is not valid');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the tag is not valid');
         $this->assertStringStartsWith('There is no extension able to load the configuration for "project:bar" (in', $e->getMessage(), '->load() throws an InvalidArgumentException if the tag is not valid');
     }
 }
开发者ID:rsky,项目名称:symfony,代码行数:46,代码来源:XmlFileLoaderTest.php

示例2: testMerge

 /**
  * @covers Symfony\Component\DependencyInjection\ContainerBuilder::merge
  */
 public function testMerge()
 {
     $container = new ContainerBuilder(new ParameterBag(array('bar' => 'foo')));
     $config = new ContainerBuilder(new ParameterBag(array('foo' => 'bar')));
     $container->merge($config);
     $this->assertEquals(array('bar' => 'foo', 'foo' => 'bar'), $container->getParameterBag()->all(), '->merge() merges current parameters with the loaded ones');
     $container = new ContainerBuilder(new ParameterBag(array('bar' => 'foo')));
     $config = new ContainerBuilder(new ParameterBag(array('foo' => '%bar%')));
     $container->merge($config);
     ////// FIXME
     $container->freeze();
     $this->assertEquals(array('bar' => 'foo', 'foo' => 'foo'), $container->getParameterBag()->all(), '->merge() evaluates the values of the parameters towards already defined ones');
     $container = new ContainerBuilder(new ParameterBag(array('bar' => 'foo')));
     $config = new ContainerBuilder(new ParameterBag(array('foo' => '%bar%', 'baz' => '%foo%')));
     $container->merge($config);
     ////// FIXME
     $container->freeze();
     $this->assertEquals(array('bar' => 'foo', 'foo' => 'foo', 'baz' => 'foo'), $container->getParameterBag()->all(), '->merge() evaluates the values of the parameters towards already defined ones');
     $container = new ContainerBuilder();
     $container->register('foo', 'FooClass');
     $container->register('bar', 'BarClass');
     $config = new ContainerBuilder();
     $config->setDefinition('baz', new Definition('BazClass'));
     $config->setAlias('alias_for_foo', 'foo');
     $container->merge($config);
     $this->assertEquals(array('foo', 'bar', 'baz'), array_keys($container->getDefinitions()), '->merge() merges definitions already defined ones');
     $this->assertEquals(array('alias_for_foo' => 'foo'), $container->getAliases(), '->merge() registers defined aliases');
     $container = new ContainerBuilder();
     $container->register('foo', 'FooClass');
     $config->setDefinition('foo', new Definition('BazClass'));
     $container->merge($config);
     $this->assertEquals('BazClass', $container->getDefinition('foo')->getClass(), '->merge() overrides already defined services');
 }
开发者ID:netixpro,项目名称:symfony,代码行数:36,代码来源:ContainerBuilderTest.php

示例3: testMergeLogicException

 /**
  * @covers Symfony\Component\DependencyInjection\ContainerBuilder::merge
  * @expectedException LogicException
  */
 public function testMergeLogicException()
 {
     $container = new ContainerBuilder();
     $container->freeze();
     $container->merge(new ContainerBuilder());
 }
开发者ID:rsky,项目名称:symfony,代码行数:10,代码来源:ContainerBuilderTest.php

示例4: testExtensions

 public function testExtensions()
 {
     $container = new ContainerBuilder();
     $container->registerExtension(new \ProjectExtension());
     $loader = new ProjectLoader3($container, self::$fixturesPath . '/yaml');
     $loader->load('services10.yml');
     $container->freeze();
     $services = $container->getDefinitions();
     $parameters = $container->getParameterBag()->all();
     $this->assertTrue(isset($services['project.service.bar']), '->load() parses extension elements');
     $this->assertTrue(isset($parameters['project.parameter.bar']), '->load() parses extension elements');
     $this->assertEquals('BAR', $services['project.service.foo']->getClass(), '->load() parses extension elements');
     $this->assertEquals('BAR', $parameters['project.parameter.foo'], '->load() parses extension elements');
     try {
         $loader->load('services11.yml');
         $this->fail('->load() throws an InvalidArgumentException if the tag is not valid');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the tag is not valid');
         $this->assertStringStartsWith('There is no extension able to load the configuration for "foobar.foobar" (in', $e->getMessage(), '->load() throws an InvalidArgumentException if the tag is not valid');
     }
     try {
         $loader->load('services12.yml');
         $this->fail('->load() throws an InvalidArgumentException if an extension is not loaded');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if an extension is not loaded');
         $this->assertStringStartsWith('The "foobar" tag is not valid (in', $e->getMessage(), '->load() throws an InvalidArgumentException if an extension is not loaded');
     }
 }
开发者ID:netixpro,项目名称:symfony,代码行数:28,代码来源:YamlFileLoaderTest.php

示例5: testThrowsExceptionWhenSetDefinitionOnAFrozenContainer

 /**
  * @expectedException BadMethodCallException
  */
 public function testThrowsExceptionWhenSetDefinitionOnAFrozenContainer()
 {
     $container = new ContainerBuilder();
     $container->freeze();
     $container->setDefinition('a', new Definition());
 }
开发者ID:spf13,项目名称:symfony,代码行数:9,代码来源:ContainerBuilderTest.php


注:本文中的Symfony\Component\DependencyInjection\ContainerBuilder::freeze方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。