Development

Changeset 31486

You must first sign up to be able to contribute.

Changeset 31486

Show
Ignore:
Timestamp:
11/23/10 23:00:34 (2 years ago)
Author:
fabien
Message:

Merge branch 'master' of git://github.com/symfony/symfony

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/2.0/src/Symfony/Bundle/DoctrineBundle/Command/ConvertDoctrine1SchemaDoctrineCommand.php

    r31229 r31486  
    5757    { 
    5858        $bundleClass = null; 
    59         $bundleDirs = $this->container->getKernelService()->getBundleDirs(); 
    60         foreach ($this->container->getKernelService()->getBundles() as $bundle) { 
     59        $bundleDirs = $this->container->get('kernel')->getBundleDirs(); 
     60        foreach ($this->container->get('kernel')->getBundles() as $bundle) { 
    6161            if (strpos(get_class($bundle), $input->getArgument('bundle')) !== false) { 
    6262                $tmp = dirname(str_replace('\\', '/', get_class($bundle))); 
  • branches/2.0/src/Symfony/Bundle/DoctrineBundle/Command/DoctrineCommand.php

    r31463 r31486  
    8989    protected function runCommand($name, array $input = array()) 
    9090    { 
    91         $application = new Application($this->container->getKernelService()); 
     91        $application = new Application($this->container->get('kernel')); 
    9292        $arguments = array(); 
    9393        $arguments = array_merge(array($name), $input); 
  • branches/2.0/src/Symfony/Bundle/DoctrineBundle/Command/GenerateEntitiesDoctrineCommand.php

    r31463 r31486  
    6363 
    6464        $entityGenerator = $this->getEntityGenerator(); 
    65         foreach ($this->container->getKernelService()->getBundles() as $bundle) { 
     65        foreach ($this->container->get('kernel')->getBundles() as $bundle) { 
    6666 
    6767            // retrieve the full bundle classname 
  • branches/2.0/src/Symfony/Bundle/DoctrineBundle/Command/GenerateEntityDoctrineCommand.php

    r31229 r31486  
    6161        } 
    6262 
    63         $dirs = $this->container->getKernelService()->getBundleDirs(); 
     63        $dirs = $this->container->get('kernel')->getBundleDirs(); 
    6464 
    6565        $tmp = str_replace('\\', '/', $bundle); 
  • branches/2.0/src/Symfony/Bundle/DoctrineBundle/Command/ImportMappingDoctrineCommand.php

    r31229 r31486  
    5555    { 
    5656        $bundleClass = null; 
    57         $bundleDirs = $this->container->getKernelService()->getBundleDirs(); 
    58         foreach ($this->container->getKernelService()->getBundles() as $bundle) { 
     57        $bundleDirs = $this->container->get('kernel')->getBundleDirs(); 
     58        foreach ($this->container->get('kernel')->getBundles() as $bundle) { 
    5959            if (strpos(get_class($bundle), $input->getArgument('bundle')) !== false) { 
    6060                $tmp = dirname(str_replace('\\', '/', get_class($bundle))); 
  • branches/2.0/src/Symfony/Bundle/DoctrineBundle/Command/LoadDataFixturesDoctrineCommand.php

    r31229 r31486  
    6868        } else { 
    6969            $paths = array(); 
    70             $bundleDirs = $this->container->getKernelService()->getBundleDirs(); 
    71             foreach ($this->container->getKernelService()->getBundles() as $bundle) { 
     70            $bundleDirs = $this->container->get('kernel')->getBundleDirs(); 
     71            foreach ($this->container->get('kernel')->getBundles() as $bundle) { 
    7272                $tmp = dirname(str_replace('\\', '/', get_class($bundle))); 
    7373                $namespace = str_replace('/', '\\', dirname($tmp)); 
  • branches/2.0/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/LoadDataFixturesDoctrineODMCommand.php

    r31229 r31486  
    6868        } else { 
    6969            $paths = array(); 
    70             $bundleDirs = $this->container->getKernelService()->getBundleDirs(); 
    71             foreach ($this->container->getKernelService()->getBundles() as $bundle) { 
     70            $bundleDirs = $this->container->get('kernel')->getBundleDirs(); 
     71            foreach ($this->container->get('kernel')->getBundles() as $bundle) { 
    7272                $tmp = dirname(str_replace('\\', '/', get_class($bundle))); 
    7373                $namespace = str_replace('/', '\\', dirname($tmp)); 
  • branches/2.0/src/Symfony/Bundle/FrameworkBundle/Client.php

    r31229 r31486  
    7676        } 
    7777 
    78         return $this->container->getProfilerService()->loadFromResponse($this->response); 
     78        return $this->container->get('profiler')->loadFromResponse($this->response); 
    7979    } 
    8080 
  • branches/2.0/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php

    r31229 r31486  
    5353        $filesystem = new Filesystem(); 
    5454 
    55         foreach ($this->container->getKernelService()->getBundles() as $bundle) { 
     55        foreach ($this->container->get('kernel')->getBundles() as $bundle) { 
    5656            if (is_dir($originDir = $bundle->getPath().'/Resources/public')) { 
    5757                $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  
    5252        } 
    5353 
    54         $dirs = $this->container->getKernelService()->getBundleDirs(); 
     54        $dirs = $this->container->get('kernel')->getBundleDirs(); 
    5555 
    5656        $tmp = str_replace('\\', '/', $namespace); 
  • branches/2.0/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerResolver.php

    r31371 r31486  
    9797    { 
    9898        $attributes['_controller'] = $controller; 
    99         $subRequest = $this->container->getRequestService()->duplicate($query, null, $attributes); 
     99        $subRequest = $this->container->get('request')->duplicate($query, null, $attributes); 
    100100 
    101101        return $this->container->get('kernel')->handle($subRequest, HttpKernelInterface::SUB_REQUEST); 
     
    138138 
    139139        if (null === $this->esiSupport) { 
    140             $this->esiSupport = $this->container->has('esi') && $this->container->getEsiService()->hasSurrogateEsiCapability($this->container->getRequestService()); 
     140            $this->esiSupport = $this->container->has('esi') && $this->container->get('esi')->hasSurrogateEsiCapability($this->container->get('request')); 
    141141        } 
    142142 
     
    149149            } 
    150150 
    151             return $this->container->getEsiService()->renderIncludeTag($uri, $alt, $options['ignore_errors'], $options['comment']); 
    152         } 
    153  
    154         $request = $this->container->getRequestService(); 
     151            return $this->container->get('esi')->renderIncludeTag($uri, $alt, $options['ignore_errors'], $options['comment']); 
     152        } 
     153 
     154        $request = $this->container->get('request'); 
    155155 
    156156        // controller or URI? 
     
    165165 
    166166        try { 
    167             $response = $this->container->getKernelService()->handle($subRequest, HttpKernelInterface::SUB_REQUEST, true); 
     167            $response = $this->container->get('kernel')->handle($subRequest, HttpKernelInterface::SUB_REQUEST, true); 
    168168 
    169169            if (200 != $response->getStatusCode()) { 
     
    205205        } 
    206206 
    207         $uri = $this->container->getRouterService()->generate('_internal', array( 
     207        $uri = $this->container->get('router')->generate('_internal', array( 
    208208            'controller' => $controller, 
    209209            'path'       => $attributes ? http_build_query($attributes) : 'none', 
    210             '_format'    => $this->container->getRequestService()->getRequestFormat(), 
     210            '_format'    => $this->container->get('request')->getRequestFormat(), 
    211211        ), true); 
    212212 
  • branches/2.0/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

    r31482 r31486  
    105105        } 
    106106 
    107         if (isset($config['templating'])) { 
     107        if (array_key_exists('templating', $config)) { 
    108108            $this->registerTemplatingConfiguration($config, $container); 
    109109        } 
  • branches/2.0/src/Symfony/Bundle/FrameworkBundle/Templating/Engine.php

    r31482 r31486  
    3131     * @param ContainerInterface $container A ContainerInterface instance 
    3232     * @param LoaderInterface    $loader    A loader instance 
    33      * @param array              $renderers An array of renderer instances 
    3433     */ 
    35     public function __construct(ContainerInterface $container, LoaderInterface $loader, array $renderers = array()
     34    public function __construct(ContainerInterface $container, LoaderInterface $loader
    3635    { 
    3736        $this->container = $container; 
    3837 
    39         parent::__construct($loader, $renderers); 
     38        parent::__construct($loader); 
    4039 
    4140        foreach ($this->container->findTaggedServiceIds('templating.renderer') as $id => $attributes) { 
    4241            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); 
    4444            } 
    4545        } 
     
    5151            } 
    5252        } 
    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); 
    6753    } 
    6854 
  • branches/2.0/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php

    r31463 r31486  
    4040        $this->kernel->boot(); 
    4141 
    42         $client = $this->kernel->getContainer()->getTest_ClientService(); 
     42        $client = $this->kernel->getContainer()->get('test.client'); 
    4343        $client->setServerParameters($server); 
    4444 
  • branches/2.0/src/Symfony/Bundle/TwigBundle/Extension/TemplatingExtension.php

    r31463 r31486  
    2626{ 
    2727    protected $container; 
    28     protected $templating; 
    2928 
    3029    public function __construct(ContainerInterface $container) 
    3130    { 
    3231        $this->container = $container; 
    33         $this->templating = $container->get('templating.engine'); 
    3432    } 
    3533 
     
    4139    public function getTemplating() 
    4240    { 
    43         return $this->templating
     41        return $this->container->get('templating.engine')
    4442    } 
    4543 
     
    115113    public function abbrClass($class) 
    116114    { 
    117         return $this->templating->get('code')->abbrClass($class); 
     115        return $this->getTemplating()->get('code')->abbrClass($class); 
    118116    } 
    119117 
    120118    public function abbrMethod($method) 
    121119    { 
    122         return $this->templating->get('code')->abbrMethod($method); 
     120        return $this->getTemplating()->get('code')->abbrMethod($method); 
    123121    } 
    124122 
    125123    public function formatArgs($args) 
    126124    { 
    127         return $this->templating->get('code')->formatArgs($args); 
     125        return $this->getTemplating()->get('code')->formatArgs($args); 
    128126    } 
    129127 
    130128    public function formatArgsAsText($args) 
    131129    { 
    132         return $this->templating->get('code')->formatArgsAsText($args); 
     130        return $this->getTemplating()->get('code')->formatArgsAsText($args); 
    133131    } 
    134132 
    135133    public function fileExcerpt($file, $line) 
    136134    { 
    137         return $this->templating->get('code')->fileExcerpt($file, $line); 
     135        return $this->getTemplating()->get('code')->fileExcerpt($file, $line); 
    138136    } 
    139137 
    140138    public function formatFile($file, $line) 
    141139    { 
    142         return $this->templating->get('code')->formatFile($file, $line); 
     140        return $this->getTemplating()->get('code')->formatFile($file, $line); 
    143141    } 
    144142 
    145143    public function formatFileFromText($text) 
    146144    { 
    147         return $this->templating->get('code')->formatFileFromText($text); 
     145        return $this->getTemplating()->get('code')->formatFileFromText($text); 
    148146    } 
    149147 
  • branches/2.0/src/Symfony/Component/DependencyInjection/Container.php

    r31403 r31486  
    182182    public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE) 
    183183    { 
    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; 
    187185 
    188186        if (isset($this->services[$id])) { 
     
    217215    } 
    218216 
    219     /** 
    220      * Catches unknown methods. 
    221      * 
    222      * @param string $method    The called method name 
    223      * @param array  $arguments The method arguments 
    224      * 
    225      * @return mixed 
    226      * 
    227      * @throws \BadMethodCallException When calling to an undefined method 
    228      */ 
    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  
    238217    static public function camelize($id) 
    239218    { 
  • branches/2.0/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

    r31371 r31486  
    6161    } 
    6262 
    63     protected function addServiceShared($id, $definition) 
    64     { 
    65         if ($definition->isShared()) { 
    66             return <<<EOF 
    67         if (isset(\$this->shared['$id'])) return \$this->shared['$id']; 
    68  
    69  
    70 EOF; 
    71         } 
    72     } 
    73  
    7463    protected function addServiceReturn($id, $definition) 
    7564    { 
     
    9584        } 
    9685 
     86        if ($definition->isShared()) { 
     87            $instantiation = sprintf("        \$this->services['$id'] = \$instance"); 
     88        } else { 
     89            $instantiation = sprintf("        \$instance"); 
     90        } 
     91 
    9792        if (null !== $definition->getFactoryMethod()) { 
    9893            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)); 
    10095            } 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)); 
    105100        } 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)); 
    111102        } 
    112103 
     
    181172        $code .= 
    182173            $this->addServiceInclude($id, $definition). 
    183             $this->addServiceShared($id, $definition). 
    184174            $this->addServiceInstance($id, $definition). 
    185175            $this->addServiceMethodCalls($id, $definition). 
     
    285275class $class extends $baseClass implements TaggedContainerInterface 
    286276{ 
    287     protected \$shared = array(); 
    288  
    289277EOF; 
    290278    } 
  • branches/2.0/src/Symfony/Component/HttpKernel/Kernel.php

    r31371 r31486  
    179179        } 
    180180 
    181         return $this->container->getHttpKernelService()->handle($request, $type, $catch); 
     181        return $this->container->get('http_kernel')->handle($request, $type, $catch); 
    182182    } 
    183183 
  • branches/2.0/tests/Symfony/Tests/Component/DependencyInjection/ContainerTest.php

    r31463 r31486  
    101101 
    102102    /** 
    103      * @covers Symfony\Component\DependencyInjection\Container::__call 
    104      */ 
    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     /** 
    121103     * @covers Symfony\Component\DependencyInjection\Container::set 
    122104     */ 
     
    142124        $sc->set('bar', $bar = new \stdClass()); 
    143125        $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         } 
    151126 
    152127        try { 
  • branches/2.0/tests/Symfony/Tests/Component/DependencyInjection/Dumper/PhpDumperTest.php

    r31371 r31486  
    7878        $container->setParameter('foo_bar', 'foo_bar'); 
    7979 
    80         $this->assertEquals($bar, $container->getBarService(), '->set() overrides an already defined service'); 
    8180        $this->assertEquals($bar, $container->get('bar'), '->set() overrides an already defined service'); 
    8281    } 
     
    9190        $container->set('bar', $bar = new \stdClass()); 
    9291 
    93         $this->assertSame($bar, $container->getFooService()->bar, '->set() overrides an already defined service'); 
     92        $this->assertSame($bar, $container->get('foo')->bar, '->set() overrides an already defined service'); 
    9493    } 
    9594} 
  • branches/2.0/tests/Symfony/Tests/Component/DependencyInjection/Fixtures/php/services1-1.php

    r31229 r31486  
    1616class Container extends AbstractContainer implements TaggedContainerInterface 
    1717{ 
    18     protected $shared = array(); 
    19  
    2018    /** 
    2119     * Constructor. 
  • branches/2.0/tests/Symfony/Tests/Component/DependencyInjection/Fixtures/php/services1.php

    r31229 r31486  
    1616class ProjectServiceContainer extends Container implements TaggedContainerInterface 
    1717{ 
    18     protected $shared = array(); 
    19  
    2018    /** 
    2119     * Constructor. 
  • branches/2.0/tests/Symfony/Tests/Component/DependencyInjection/Fixtures/php/services8.php

    r31229 r31486  
    1616class ProjectServiceContainer extends Container implements TaggedContainerInterface 
    1717{ 
    18     protected $shared = array(); 
    19  
    2018    /** 
    2119     * Constructor. 
  • branches/2.0/tests/Symfony/Tests/Component/DependencyInjection/Fixtures/php/services9.php

    r31371 r31486  
    1616class ProjectServiceContainer extends Container implements TaggedContainerInterface 
    1717{ 
    18     protected $shared = array(); 
    19  
    2018    /** 
    2119     * Constructor. 
     
    5149    protected function getBarService() 
    5250    { 
    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')); 
    5752        $this->get('foo.baz')->configure($instance); 
    5853 
     
    7065    protected function getFoo_BazService() 
    7166    { 
    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')); 
    7668        call_user_func(array($this->getParameter('baz_class'), 'configureStatic1'), $instance); 
    7769 
     
    8981    protected function getFooBarService() 
    9082    { 
    91         if (isset($this->shared['foo_bar'])) return $this->shared['foo_bar']; 
    92  
    9383        $class = $this->getParameter('foo_class'); 
    94         $instance = new $class(); 
    95         $this->shared['foo_bar'] = $instance; 
     84        $this->services['foo_bar'] = $instance = new $class(); 
    9685 
    9786        return $instance; 
     
    11099        require_once '%path%foo.php'; 
    111100 
    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(); 
    116102        $instance->setBar($this->get('foo')); 
    117103        $instance->setBar($this->get('foo', ContainerInterface::NULL_ON_INVALID_REFERENCE)); 
     
    136122    protected function getFactoryServiceService() 
    137123    { 
    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(); 
    142125 
    143126        return $instance;