Changeset 31486
- Timestamp:
- 11/23/10 23:00:34 (2 years ago)
- Files:
-
- branches/2.0/src/Symfony/Bundle/DoctrineBundle/Command/ConvertDoctrine1SchemaDoctrineCommand.php (modified) (1 diff)
- branches/2.0/src/Symfony/Bundle/DoctrineBundle/Command/DoctrineCommand.php (modified) (1 diff)
- branches/2.0/src/Symfony/Bundle/DoctrineBundle/Command/GenerateEntitiesDoctrineCommand.php (modified) (1 diff)
- branches/2.0/src/Symfony/Bundle/DoctrineBundle/Command/GenerateEntityDoctrineCommand.php (modified) (1 diff)
- branches/2.0/src/Symfony/Bundle/DoctrineBundle/Command/ImportMappingDoctrineCommand.php (modified) (1 diff)
- branches/2.0/src/Symfony/Bundle/DoctrineBundle/Command/LoadDataFixturesDoctrineCommand.php (modified) (1 diff)
- branches/2.0/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/LoadDataFixturesDoctrineODMCommand.php (modified) (1 diff)
- branches/2.0/src/Symfony/Bundle/FrameworkBundle/Client.php (modified) (1 diff)
- branches/2.0/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php (modified) (1 diff)
- branches/2.0/src/Symfony/Bundle/FrameworkBundle/Command/InitBundleCommand.php (modified) (1 diff)
- branches/2.0/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerResolver.php (modified) (5 diffs)
- branches/2.0/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php (modified) (1 diff)
- branches/2.0/src/Symfony/Bundle/FrameworkBundle/Templating/Engine.php (modified) (2 diffs)
- branches/2.0/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php (modified) (1 diff)
- branches/2.0/src/Symfony/Bundle/TwigBundle/Extension/TemplatingExtension.php (modified) (3 diffs)
- branches/2.0/src/Symfony/Component/DependencyInjection/Container.php (modified) (2 diffs)
- branches/2.0/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php (modified) (4 diffs)
- branches/2.0/src/Symfony/Component/HttpKernel/Kernel.php (modified) (1 diff)
- branches/2.0/tests/Symfony/Tests/Component/DependencyInjection/ContainerTest.php (modified) (2 diffs)
- branches/2.0/tests/Symfony/Tests/Component/DependencyInjection/Dumper/PhpDumperTest.php (modified) (2 diffs)
- branches/2.0/tests/Symfony/Tests/Component/DependencyInjection/Fixtures/php/services1-1.php (modified) (1 diff)
- branches/2.0/tests/Symfony/Tests/Component/DependencyInjection/Fixtures/php/services1.php (modified) (1 diff)
- branches/2.0/tests/Symfony/Tests/Component/DependencyInjection/Fixtures/php/services8.php (modified) (1 diff)
- branches/2.0/tests/Symfony/Tests/Component/DependencyInjection/Fixtures/php/services9.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/2.0/src/Symfony/Bundle/DoctrineBundle/Command/ConvertDoctrine1SchemaDoctrineCommand.php
r31229 r31486 57 57 { 58 58 $bundleClass = null; 59 $bundleDirs = $this->container->get KernelService()->getBundleDirs();60 foreach ($this->container->get KernelService()->getBundles() as $bundle) {59 $bundleDirs = $this->container->get('kernel')->getBundleDirs(); 60 foreach ($this->container->get('kernel')->getBundles() as $bundle) { 61 61 if (strpos(get_class($bundle), $input->getArgument('bundle')) !== false) { 62 62 $tmp = dirname(str_replace('\\', '/', get_class($bundle))); branches/2.0/src/Symfony/Bundle/DoctrineBundle/Command/DoctrineCommand.php
r31463 r31486 89 89 protected function runCommand($name, array $input = array()) 90 90 { 91 $application = new Application($this->container->get KernelService());91 $application = new Application($this->container->get('kernel')); 92 92 $arguments = array(); 93 93 $arguments = array_merge(array($name), $input); branches/2.0/src/Symfony/Bundle/DoctrineBundle/Command/GenerateEntitiesDoctrineCommand.php
r31463 r31486 63 63 64 64 $entityGenerator = $this->getEntityGenerator(); 65 foreach ($this->container->get KernelService()->getBundles() as $bundle) {65 foreach ($this->container->get('kernel')->getBundles() as $bundle) { 66 66 67 67 // retrieve the full bundle classname branches/2.0/src/Symfony/Bundle/DoctrineBundle/Command/GenerateEntityDoctrineCommand.php
r31229 r31486 61 61 } 62 62 63 $dirs = $this->container->get KernelService()->getBundleDirs();63 $dirs = $this->container->get('kernel')->getBundleDirs(); 64 64 65 65 $tmp = str_replace('\\', '/', $bundle); branches/2.0/src/Symfony/Bundle/DoctrineBundle/Command/ImportMappingDoctrineCommand.php
r31229 r31486 55 55 { 56 56 $bundleClass = null; 57 $bundleDirs = $this->container->get KernelService()->getBundleDirs();58 foreach ($this->container->get KernelService()->getBundles() as $bundle) {57 $bundleDirs = $this->container->get('kernel')->getBundleDirs(); 58 foreach ($this->container->get('kernel')->getBundles() as $bundle) { 59 59 if (strpos(get_class($bundle), $input->getArgument('bundle')) !== false) { 60 60 $tmp = dirname(str_replace('\\', '/', get_class($bundle))); branches/2.0/src/Symfony/Bundle/DoctrineBundle/Command/LoadDataFixturesDoctrineCommand.php
r31229 r31486 68 68 } else { 69 69 $paths = array(); 70 $bundleDirs = $this->container->get KernelService()->getBundleDirs();71 foreach ($this->container->get KernelService()->getBundles() as $bundle) {70 $bundleDirs = $this->container->get('kernel')->getBundleDirs(); 71 foreach ($this->container->get('kernel')->getBundles() as $bundle) { 72 72 $tmp = dirname(str_replace('\\', '/', get_class($bundle))); 73 73 $namespace = str_replace('/', '\\', dirname($tmp)); branches/2.0/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/LoadDataFixturesDoctrineODMCommand.php
r31229 r31486 68 68 } else { 69 69 $paths = array(); 70 $bundleDirs = $this->container->get KernelService()->getBundleDirs();71 foreach ($this->container->get KernelService()->getBundles() as $bundle) {70 $bundleDirs = $this->container->get('kernel')->getBundleDirs(); 71 foreach ($this->container->get('kernel')->getBundles() as $bundle) { 72 72 $tmp = dirname(str_replace('\\', '/', get_class($bundle))); 73 73 $namespace = str_replace('/', '\\', dirname($tmp)); branches/2.0/src/Symfony/Bundle/FrameworkBundle/Client.php
r31229 r31486 76 76 } 77 77 78 return $this->container->get ProfilerService()->loadFromResponse($this->response);78 return $this->container->get('profiler')->loadFromResponse($this->response); 79 79 } 80 80 branches/2.0/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php
r31229 r31486 53 53 $filesystem = new Filesystem(); 54 54 55 foreach ($this->container->get KernelService()->getBundles() as $bundle) {55 foreach ($this->container->get('kernel')->getBundles() as $bundle) { 56 56 if (is_dir($originDir = $bundle->getPath().'/Resources/public')) { 57 57 $output->writeln(sprintf('Installing assets for <comment>%s\\%s</comment>', $bundle->getNamespacePrefix(), $bundle->getName())); branches/2.0/src/Symfony/Bundle/FrameworkBundle/Command/InitBundleCommand.php
r31229 r31486 52 52 } 53 53 54 $dirs = $this->container->get KernelService()->getBundleDirs();54 $dirs = $this->container->get('kernel')->getBundleDirs(); 55 55 56 56 $tmp = str_replace('\\', '/', $namespace); branches/2.0/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerResolver.php
r31371 r31486 97 97 { 98 98 $attributes['_controller'] = $controller; 99 $subRequest = $this->container->get RequestService()->duplicate($query, null, $attributes);99 $subRequest = $this->container->get('request')->duplicate($query, null, $attributes); 100 100 101 101 return $this->container->get('kernel')->handle($subRequest, HttpKernelInterface::SUB_REQUEST); … … 138 138 139 139 if (null === $this->esiSupport) { 140 $this->esiSupport = $this->container->has('esi') && $this->container->get EsiService()->hasSurrogateEsiCapability($this->container->getRequestService());140 $this->esiSupport = $this->container->has('esi') && $this->container->get('esi')->hasSurrogateEsiCapability($this->container->get('request')); 141 141 } 142 142 … … 149 149 } 150 150 151 return $this->container->get EsiService()->renderIncludeTag($uri, $alt, $options['ignore_errors'], $options['comment']);152 } 153 154 $request = $this->container->get RequestService();151 return $this->container->get('esi')->renderIncludeTag($uri, $alt, $options['ignore_errors'], $options['comment']); 152 } 153 154 $request = $this->container->get('request'); 155 155 156 156 // controller or URI? … … 165 165 166 166 try { 167 $response = $this->container->get KernelService()->handle($subRequest, HttpKernelInterface::SUB_REQUEST, true);167 $response = $this->container->get('kernel')->handle($subRequest, HttpKernelInterface::SUB_REQUEST, true); 168 168 169 169 if (200 != $response->getStatusCode()) { … … 205 205 } 206 206 207 $uri = $this->container->get RouterService()->generate('_internal', array(207 $uri = $this->container->get('router')->generate('_internal', array( 208 208 'controller' => $controller, 209 209 'path' => $attributes ? http_build_query($attributes) : 'none', 210 '_format' => $this->container->get RequestService()->getRequestFormat(),210 '_format' => $this->container->get('request')->getRequestFormat(), 211 211 ), true); 212 212 branches/2.0/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
r31482 r31486 105 105 } 106 106 107 if ( isset($config['templating'])) {107 if (array_key_exists('templating', $config)) { 108 108 $this->registerTemplatingConfiguration($config, $container); 109 109 } branches/2.0/src/Symfony/Bundle/FrameworkBundle/Templating/Engine.php
r31482 r31486 31 31 * @param ContainerInterface $container A ContainerInterface instance 32 32 * @param LoaderInterface $loader A loader instance 33 * @param array $renderers An array of renderer instances34 33 */ 35 public function __construct(ContainerInterface $container, LoaderInterface $loader , array $renderers = array())34 public function __construct(ContainerInterface $container, LoaderInterface $loader) 36 35 { 37 36 $this->container = $container; 38 37 39 parent::__construct($loader , $renderers);38 parent::__construct($loader); 40 39 41 40 foreach ($this->container->findTaggedServiceIds('templating.renderer') as $id => $attributes) { 42 41 if (isset($attributes[0]['alias'])) { 43 $this->renderers[$attributes[0]['alias']] = $id; 42 $this->renderers[$attributes[0]['alias']] = $this->container->get($id); 43 $this->renderers[$attributes[0]['alias']]->setEngine($this); 44 44 } 45 45 } … … 51 51 } 52 52 } 53 }54 55 public function render($name, array $parameters = array())56 {57 list(, $options) = $this->splitTemplateName($name);58 59 $renderer = $options['renderer'];60 61 if (isset($this->renderers[$renderer]) && is_string($this->renderers[$renderer])) {62 $this->renderers[$renderer] = $this->container->get($this->renderers[$renderer]);63 $this->renderers[$renderer]->setEngine($this);64 }65 66 return parent::render($name, $parameters);67 53 } 68 54 branches/2.0/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php
r31463 r31486 40 40 $this->kernel->boot(); 41 41 42 $client = $this->kernel->getContainer()->get Test_ClientService();42 $client = $this->kernel->getContainer()->get('test.client'); 43 43 $client->setServerParameters($server); 44 44 branches/2.0/src/Symfony/Bundle/TwigBundle/Extension/TemplatingExtension.php
r31463 r31486 26 26 { 27 27 protected $container; 28 protected $templating;29 28 30 29 public function __construct(ContainerInterface $container) 31 30 { 32 31 $this->container = $container; 33 $this->templating = $container->get('templating.engine');34 32 } 35 33 … … 41 39 public function getTemplating() 42 40 { 43 return $this-> templating;41 return $this->container->get('templating.engine'); 44 42 } 45 43 … … 115 113 public function abbrClass($class) 116 114 { 117 return $this-> templating->get('code')->abbrClass($class);115 return $this->getTemplating()->get('code')->abbrClass($class); 118 116 } 119 117 120 118 public function abbrMethod($method) 121 119 { 122 return $this-> templating->get('code')->abbrMethod($method);120 return $this->getTemplating()->get('code')->abbrMethod($method); 123 121 } 124 122 125 123 public function formatArgs($args) 126 124 { 127 return $this-> templating->get('code')->formatArgs($args);125 return $this->getTemplating()->get('code')->formatArgs($args); 128 126 } 129 127 130 128 public function formatArgsAsText($args) 131 129 { 132 return $this-> templating->get('code')->formatArgsAsText($args);130 return $this->getTemplating()->get('code')->formatArgsAsText($args); 133 131 } 134 132 135 133 public function fileExcerpt($file, $line) 136 134 { 137 return $this-> templating->get('code')->fileExcerpt($file, $line);135 return $this->getTemplating()->get('code')->fileExcerpt($file, $line); 138 136 } 139 137 140 138 public function formatFile($file, $line) 141 139 { 142 return $this-> templating->get('code')->formatFile($file, $line);140 return $this->getTemplating()->get('code')->formatFile($file, $line); 143 141 } 144 142 145 143 public function formatFileFromText($text) 146 144 { 147 return $this-> templating->get('code')->formatFileFromText($text);145 return $this->getTemplating()->get('code')->formatFileFromText($text); 148 146 } 149 147 branches/2.0/src/Symfony/Component/DependencyInjection/Container.php
r31403 r31486 182 182 public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE) 183 183 { 184 if (!is_string($id)) { 185 throw new \InvalidArgumentException(sprintf('A service id should be a string (%s given).', str_replace("\n", '', var_export($id, true)))); 186 } 184 $id = (string) $id; 187 185 188 186 if (isset($this->services[$id])) { … … 217 215 } 218 216 219 /**220 * Catches unknown methods.221 *222 * @param string $method The called method name223 * @param array $arguments The method arguments224 *225 * @return mixed226 *227 * @throws \BadMethodCallException When calling to an undefined method228 */229 public function __call($method, $arguments)230 {231 if (!preg_match('/^get(.+)Service$/', $method, $match)) {232 throw new \BadMethodCallException(sprintf('Call to undefined method %s::%s.', get_class($this), $method));233 }234 235 return $this->get(self::underscore($match[1]));236 }237 238 217 static public function camelize($id) 239 218 { branches/2.0/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php
r31371 r31486 61 61 } 62 62 63 protected function addServiceShared($id, $definition)64 {65 if ($definition->isShared()) {66 return <<<EOF67 if (isset(\$this->shared['$id'])) return \$this->shared['$id'];68 69 70 EOF;71 }72 }73 74 63 protected function addServiceReturn($id, $definition) 75 64 { … … 95 84 } 96 85 86 if ($definition->isShared()) { 87 $instantiation = sprintf(" \$this->services['$id'] = \$instance"); 88 } else { 89 $instantiation = sprintf(" \$instance"); 90 } 91 97 92 if (null !== $definition->getFactoryMethod()) { 98 93 if (null !== $definition->getFactoryService()) { 99 $code = sprintf(" \$instance= %s->%s(%s);\n", $this->getServiceCall($definition->getFactoryService()), $definition->getFactoryMethod(), implode(', ', $arguments));94 $code = sprintf("$instantiation = %s->%s(%s);\n", $this->getServiceCall($definition->getFactoryService()), $definition->getFactoryMethod(), implode(', ', $arguments)); 100 95 } else { 101 $code = sprintf(" \$instance= call_user_func(array(%s, '%s')%s);\n", $class, $definition->getFactoryMethod(), $arguments ? ', '.implode(', ', $arguments) : '');102 } 103 } elseif ( $class != "'".str_replace('\\', '\\\\', $definition->getClass())."'") {104 $code = sprintf(" \$class = %s;\n \$instance= new \$class(%s);\n", $class, implode(', ', $arguments));96 $code = sprintf("$instantiation = call_user_func(array(%s, '%s')%s);\n", $class, $definition->getFactoryMethod(), $arguments ? ', '.implode(', ', $arguments) : ''); 97 } 98 } elseif (false !== strpos($class, '$')) { 99 $code = sprintf(" \$class = %s;\n$instantiation = new \$class(%s);\n", $class, implode(', ', $arguments)); 105 100 } else { 106 $code = sprintf(" \$instance = new %s(%s);\n", $definition->getClass(), implode(', ', $arguments)); 107 } 108 109 if ($definition->isShared()) { 110 $code .= sprintf(" \$this->shared['$id'] = \$instance;\n"); 101 $code = sprintf("$instantiation = new \\%s(%s);\n", substr(str_replace('\\\\', '\\', $class), 1, -1), implode(', ', $arguments)); 111 102 } 112 103 … … 181 172 $code .= 182 173 $this->addServiceInclude($id, $definition). 183 $this->addServiceShared($id, $definition).184 174 $this->addServiceInstance($id, $definition). 185 175 $this->addServiceMethodCalls($id, $definition). … … 285 275 class $class extends $baseClass implements TaggedContainerInterface 286 276 { 287 protected \$shared = array();288 289 277 EOF; 290 278 } branches/2.0/src/Symfony/Component/HttpKernel/Kernel.php
r31371 r31486 179 179 } 180 180 181 return $this->container->get HttpKernelService()->handle($request, $type, $catch);181 return $this->container->get('http_kernel')->handle($request, $type, $catch); 182 182 } 183 183 branches/2.0/tests/Symfony/Tests/Component/DependencyInjection/ContainerTest.php
r31463 r31486 101 101 102 102 /** 103 * @covers Symfony\Component\DependencyInjection\Container::__call104 */105 public function testGetCall()106 {107 $sc = new Container();108 $sc->set('foo_bar.foo', $foo = new \stdClass());109 $this->assertEquals($foo, $sc->getFooBar_FooService(), '__call() finds services is the method is getXXXService()');110 111 try {112 $sc->getFooBar_Foo();113 $this->fail('__call() throws a \BadMethodCallException exception if the method is not a service method');114 } catch (\Exception $e) {115 $this->assertInstanceOf('\BadMethodCallException', $e, '__call() throws a \BadMethodCallException exception if the method is not a service method');116 $this->assertEquals('Call to undefined method Symfony\Component\DependencyInjection\Container::getFooBar_Foo.', $e->getMessage(), '__call() throws a \BadMethodCallException exception if the method is not a service method');117 }118 }119 120 /**121 103 * @covers Symfony\Component\DependencyInjection\Container::set 122 104 */ … … 142 124 $sc->set('bar', $bar = new \stdClass()); 143 125 $this->assertSame($sc->get('bar'), $bar, '->getServiceIds() prefers to return a service defined with a getXXXService() method than one defined with set()'); 144 145 try {146 $sc->get(new \stdClass());147 $this->fail('->get() throws a \InvalidArgumentException exception if the service id is not a string');148 } catch (\Exception $e) {149 $this->assertInstanceOf('\InvalidArgumentException', $e, '->get() throws a \InvalidArgumentException exception if the service id is not a string');150 }151 126 152 127 try { branches/2.0/tests/Symfony/Tests/Component/DependencyInjection/Dumper/PhpDumperTest.php
r31371 r31486 78 78 $container->setParameter('foo_bar', 'foo_bar'); 79 79 80 $this->assertEquals($bar, $container->getBarService(), '->set() overrides an already defined service');81 80 $this->assertEquals($bar, $container->get('bar'), '->set() overrides an already defined service'); 82 81 } … … 91 90 $container->set('bar', $bar = new \stdClass()); 92 91 93 $this->assertSame($bar, $container->get FooService()->bar, '->set() overrides an already defined service');92 $this->assertSame($bar, $container->get('foo')->bar, '->set() overrides an already defined service'); 94 93 } 95 94 } branches/2.0/tests/Symfony/Tests/Component/DependencyInjection/Fixtures/php/services1-1.php
r31229 r31486 16 16 class Container extends AbstractContainer implements TaggedContainerInterface 17 17 { 18 protected $shared = array();19 20 18 /** 21 19 * Constructor. branches/2.0/tests/Symfony/Tests/Component/DependencyInjection/Fixtures/php/services1.php
r31229 r31486 16 16 class ProjectServiceContainer extends Container implements TaggedContainerInterface 17 17 { 18 protected $shared = array();19 20 18 /** 21 19 * Constructor. branches/2.0/tests/Symfony/Tests/Component/DependencyInjection/Fixtures/php/services8.php
r31229 r31486 16 16 class ProjectServiceContainer extends Container implements TaggedContainerInterface 17 17 { 18 protected $shared = array();19 20 18 /** 21 19 * Constructor. branches/2.0/tests/Symfony/Tests/Component/DependencyInjection/Fixtures/php/services9.php
r31371 r31486 16 16 class ProjectServiceContainer extends Container implements TaggedContainerInterface 17 17 { 18 protected $shared = array();19 20 18 /** 21 19 * Constructor. … … 51 49 protected function getBarService() 52 50 { 53 if (isset($this->shared['bar'])) return $this->shared['bar']; 54 55 $instance = new FooClass('foo', $this->get('foo.baz'), $this->getParameter('foo_bar')); 56 $this->shared['bar'] = $instance; 51 $this->services['bar'] = $instance = new \FooClass('foo', $this->get('foo.baz'), $this->getParameter('foo_bar')); 57 52 $this->get('foo.baz')->configure($instance); 58 53 … … 70 65 protected function getFoo_BazService() 71 66 { 72 if (isset($this->shared['foo.baz'])) return $this->shared['foo.baz']; 73 74 $instance = call_user_func(array($this->getParameter('baz_class'), 'getInstance')); 75 $this->shared['foo.baz'] = $instance; 67 $this->services['foo.baz'] = $instance = call_user_func(array($this->getParameter('baz_class'), 'getInstance')); 76 68 call_user_func(array($this->getParameter('baz_class'), 'configureStatic1'), $instance); 77 69 … … 89 81 protected function getFooBarService() 90 82 { 91 if (isset($this->shared['foo_bar'])) return $this->shared['foo_bar'];92 93 83 $class = $this->getParameter('foo_class'); 94 $instance = new $class(); 95 $this->shared['foo_bar'] = $instance; 84 $this->services['foo_bar'] = $instance = new $class(); 96 85 97 86 return $instance; … … 110 99 require_once '%path%foo.php'; 111 100 112 if (isset($this->shared['method_call1'])) return $this->shared['method_call1']; 113 114 $instance = new FooClass(); 115 $this->shared['method_call1'] = $instance; 101 $this->services['method_call1'] = $instance = new \FooClass(); 116 102 $instance->setBar($this->get('foo')); 117 103 $instance->setBar($this->get('foo', ContainerInterface::NULL_ON_INVALID_REFERENCE)); … … 136 122 protected function getFactoryServiceService() 137 123 { 138 if (isset($this->shared['factory_service'])) return $this->shared['factory_service']; 139 140 $instance = $this->get('foo.baz')->getInstance(); 141 $this->shared['factory_service'] = $instance; 124 $this->services['factory_service'] = $instance = $this->get('foo.baz')->getInstance(); 142 125 143 126 return $instance;