Development

Changeset 28330

You must first sign up to be able to contribute.

Changeset 28330

Show
Ignore:
Timestamp:
03/01/10 12:00:04 (3 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/Components/Console/Input/Input.php

    r26615 r28330  
    131131 
    132132  /** 
     133   * Returns true if an InputArgument object exists by name or position. 
     134   * 
     135   * @param string|integer $name The InputArgument name or position 
     136   * 
     137   * @return Boolean true if the InputArgument object exists, false otherwise 
     138   */ 
     139  public function hasArgument($name) 
     140  { 
     141    return $this->definition->hasArgument($name); 
     142  } 
     143 
     144  /** 
    133145   * Returns the options values. 
    134146   * 
     
    172184    $this->options[$name] = $value; 
    173185  } 
     186 
     187  /** 
     188   * Returns true if an InputOption object exists by name. 
     189   * 
     190   * @param string $name The InputOption name 
     191   * 
     192   * @return Boolean true if the InputOption object exists, false otherwise 
     193   */ 
     194  public function hasOption($name) 
     195  { 
     196    return $this->definition->hasOption($name); 
     197  } 
    174198} 
  • branches/2.0/src/Symfony/Components/DependencyInjection/SimpleXMLElement.php

    r26560 r28330  
    6666  { 
    6767    $value = (string) $value; 
     68    $lowercaseValue = strtolower($value); 
    6869 
    6970    switch (true) 
    7071    { 
    71       case 'null' == strtolower($value)
     72      case 'null' === $lowercaseValue
    7273        return null; 
    7374      case ctype_digit($value): 
    7475        return '0' == $value[0] ? octdec($value) : intval($value); 
    75       case 'true' === strtolower($value)
     76      case 'true' === $lowercaseValue
    7677        return true; 
    77       case 'false' === strtolower($value)
     78      case 'false' === $lowercaseValue
    7879        return false; 
    7980      case is_numeric($value): 
     
    8283        return floatval(str_replace(',', '', $value)); 
    8384      default: 
    84         return (string) $value; 
     85        return $value; 
    8586    } 
    8687  } 
  • branches/2.0/src/Symfony/Foundation/Bundle/KernelBundle.php

    r28142 r28330  
    77use Symfony\Components\DependencyInjection\ContainerInterface; 
    88use Symfony\Components\DependencyInjection\Loader\Loader; 
     9use Symfony\Components\DependencyInjection\Loader\XmlFileLoader; 
     10use Symfony\Components\DependencyInjection\BuilderConfiguration; 
    911 
    1012/* 
     
    2830  { 
    2931    Loader::registerExtension(new KernelExtension()); 
     32 
     33    $configuration = new BuilderConfiguration(); 
     34 
     35    $loader = new XmlFileLoader(array(__DIR__.'/../Resources/config', __DIR__.'/Resources/config')); 
     36    $configuration->merge($loader->load('services.xml')); 
     37 
     38    if ($container->getParameter('kernel.debug')) 
     39    { 
     40      $configuration->merge($loader->load('debug.xml')); 
     41      $configuration->setDefinition('event_dispatcher', $configuration->findDefinition('debug.event_dispatcher')); 
     42    } 
     43 
     44    return $configuration; 
    3045  } 
    3146 
  • branches/2.0/src/Symfony/Foundation/Bundle/KernelExtension.php

    r28096 r28330  
    2626  { 
    2727    $configuration = new BuilderConfiguration(); 
    28  
    29     $loader = new XmlFileLoader(array(__DIR__.'/../Resources/config', __DIR__.'/Resources/config')); 
    30     $configuration->merge($loader->load('services.xml')); 
    3128 
    3229    if (isset($config['charset'])) 
  • branches/2.0/src/Symfony/Foundation/Kernel.php

    r28179 r28330  
    8585 
    8686  /** 
     87   * Checks whether the current kernel has been booted or not. 
     88   * 
     89   * @return boolean $booted 
     90   */ 
     91  public function isBooted() 
     92  { 
     93    return $this->booted; 
     94  } 
     95 
     96  /** 
    8797   * Boots the current kernel. 
    8898   * 
     
    226236    foreach ($_SERVER as $key => $value) 
    227237    { 
    228       if ('SYMFONY__' === $key = substr($key, 0, 9)) 
    229       { 
    230         $parameters[strtolower(str_replace('__', '.', $key))] = $value; 
     238      if ('SYMFONY__' === substr($key, 0, 9)) 
     239      { 
     240        $parameters[strtolower(str_replace('__', '.', substr($key, 9)))] = $value; 
    231241      } 
    232242    } 
     
    270280    $this->optimizeContainer($container); 
    271281 
    272     // cache dir 
    273     if (!is_dir($parameters['kernel.cache_dir'])) 
    274     { 
    275       if (false === @mkdir($parameters['kernel.cache_dir'], 0777, true)) 
    276       { 
    277         die(sprintf('Unable to create the cache directory (%s)', $parameters['kernel.cache_dir'])); 
    278       } 
    279     } 
    280     elseif (!is_writable($parameters['kernel.cache_dir'])) 
    281     { 
    282       die(sprintf('Unable to write in the cache directory (%s)', $parameters['kernel.cache_dir'])); 
    283     } 
    284  
    285     // logs dir 
    286     if (!is_dir($parameters['kernel.logs_dir'])) 
    287     { 
    288       if (false === @mkdir($parameters['kernel.logs_dir'], 0777, true)) 
    289       { 
    290         die(sprintf('Unable to create the logs directory (%s)', $parameters['kernel.logs_dir'])); 
    291       } 
    292     } 
    293     elseif (!is_writable($parameters['kernel.logs_dir'])) 
    294     { 
    295       die(sprintf('Unable to write in the logs directory (%s)', $parameters['kernel.logs_dir'])); 
     282    foreach (array('cache', 'logs') as $name) 
     283    { 
     284      $key = sprintf('kernel.%s_dir', $name); 
     285      if (!is_dir($parameters[$key])) 
     286      { 
     287        if (false === @mkdir($parameters[$key], 0777, true)) 
     288        { 
     289          die(sprintf('Unable to create the %s directory (%s)', $name, dirname($parameters['kernel.cache_dir']))); 
     290        } 
     291      } 
     292      elseif (!is_writable($parameters[$key])) 
     293      { 
     294        die(sprintf('Unable to write in the %s directory (%s)', $name, $parameters['kernel.cache_dir'])); 
     295      } 
    296296    } 
    297297 
  • branches/2.0/src/Symfony/Foundation/Resources/config/debug.xml

    r28096 r28330  
    66 
    77  <parameters> 
    8     <parameter key="symfony.templating.debugger.class">Symfony\Framework\WebBundle\Templating\Debugger</parameter> 
     8    <parameter key="debug.event_dispatcher.class">Symfony\Foundation\Debug\EventDispatcher</parameter> 
    99  </parameters> 
    1010 
    1111  <services> 
    12     <service id="symfony.templating.debugger" class="%symfony.templating.debugger.class%"> 
     12    <service id="debug.event_dispatcher" class="%debug.event_dispatcher.class%"> 
     13      <argument type="service" id="service_container" /> 
    1314      <argument type="service" id="logger" on-invalid="null" /> 
    1415    </service> 
  • branches/2.0/src/Symfony/Foundation/Resources/config/services.xml

    r28096 r28330  
    77  <parameters> 
    88    <parameter key="event_dispatcher.class">Symfony\Foundation\EventDispatcher</parameter> 
    9     <parameter key="debug.event_dispatcher.class">Symfony\Foundation\Debug\EventDispatcher</parameter> 
    109    <parameter key="request_handler.class">Symfony\Components\RequestHandler\RequestHandler</parameter> 
    1110    <parameter key="request.class">Symfony\Components\RequestHandler\Request</parameter> 
     
    1817    <service id="event_dispatcher" class="%event_dispatcher.class%"> 
    1918      <argument type="service" id="service_container" /> 
    20     </service> 
    21  
    22     <service id="debug.event_dispatcher" class="%debug.event_dispatcher.class%"> 
    23       <argument type="service" id="service_container" /> 
    24       <argument type="service" id="logger" on-invalid="null" /> 
    2519    </service> 
    2620 
  • branches/2.0/src/Symfony/Foundation/UniversalClassLoader.php

    r28071 r28330  
    1313 
    1414/** 
    15  * UniversalClassLoader implements a "universal" autoloder for PHP 5.3. 
     15 * UniversalClassLoader implements a "universal" autoloader for PHP 5.3. 
    1616 * 
    1717 * It is able to load classes that use either: 
  • branches/2.0/src/Symfony/Foundation/bootstrap.php

    r28179 r28330  
    4141use Symfony\Components\DependencyInjection\ContainerInterface; 
    4242use Symfony\Components\DependencyInjection\Loader\Loader; 
     43use Symfony\Components\DependencyInjection\Loader\XmlFileLoader; 
     44use Symfony\Components\DependencyInjection\BuilderConfiguration; 
    4345 
    4446 
     
    5052  { 
    5153    Loader::registerExtension(new KernelExtension()); 
     54 
     55    $configuration = new BuilderConfiguration(); 
     56 
     57    $loader = new XmlFileLoader(array(__DIR__.'/../Resources/config', __DIR__.'/Resources/config')); 
     58    $configuration->merge($loader->load('services.xml')); 
     59 
     60    if ($container->getParameter('kernel.debug')) 
     61    { 
     62      $configuration->merge($loader->load('debug.xml')); 
     63      $configuration->setDefinition('event_dispatcher', $configuration->findDefinition('debug.event_dispatcher')); 
     64    } 
     65 
     66    return $configuration; 
    5267  } 
    5368 
     
    7590  { 
    7691    $configuration = new BuilderConfiguration(); 
    77  
    78     $loader = new XmlFileLoader(array(__DIR__.'/../Resources/config', __DIR__.'/Resources/config')); 
    79     $configuration->merge($loader->load('services.xml')); 
    8092 
    8193    if (isset($config['charset'])) 
     
    362374 
    363375   
     376  public function isBooted() 
     377  { 
     378    return $this->booted; 
     379  } 
     380 
     381   
    364382  public function boot() 
    365383  { 
     
    494512    foreach ($_SERVER as $key => $value) 
    495513    { 
    496       if ('SYMFONY__' === $key = substr($key, 0, 9)) 
    497       { 
    498         $parameters[strtolower(str_replace('__', '.', $key))] = $value; 
     514      if ('SYMFONY__' === substr($key, 0, 9)) 
     515      { 
     516        $parameters[strtolower(str_replace('__', '.', substr($key, 9)))] = $value; 
    499517      } 
    500518    } 
     
    538556    $this->optimizeContainer($container); 
    539557 
    540         if (!is_dir($parameters['kernel.cache_dir'])) 
    541     { 
    542       if (false === @mkdir($parameters['kernel.cache_dir'], 0777, true)) 
    543       { 
    544         die(sprintf('Unable to create the cache directory (%s)', $parameters['kernel.cache_dir'])); 
    545       } 
    546     } 
    547     elseif (!is_writable($parameters['kernel.cache_dir'])) 
    548     { 
    549       die(sprintf('Unable to write in the cache directory (%s)', $parameters['kernel.cache_dir'])); 
    550     } 
    551  
    552         if (!is_dir($parameters['kernel.logs_dir'])) 
    553     { 
    554       if (false === @mkdir($parameters['kernel.logs_dir'], 0777, true)) 
    555       { 
    556         die(sprintf('Unable to create the logs directory (%s)', $parameters['kernel.logs_dir'])); 
    557       } 
    558     } 
    559     elseif (!is_writable($parameters['kernel.logs_dir'])) 
    560     { 
    561       die(sprintf('Unable to write in the logs directory (%s)', $parameters['kernel.logs_dir'])); 
     558    foreach (array('cache', 'logs') as $name) 
     559    { 
     560      $key = sprintf('kernel.%s_dir', $name); 
     561      if (!is_dir($parameters[$key])) 
     562      { 
     563        if (false === @mkdir($parameters[$key], 0777, true)) 
     564        { 
     565          die(sprintf('Unable to create the %s directory (%s)', $name, dirname($parameters['kernel.cache_dir']))); 
     566        } 
     567      } 
     568      elseif (!is_writable($parameters[$key])) 
     569      { 
     570        die(sprintf('Unable to write in the %s directory (%s)', $name, $parameters['kernel.cache_dir'])); 
     571      } 
    562572    } 
    563573 
  • branches/2.0/src/Symfony/Framework/DoctrineBundle/Bundle.php

    r28207 r28330  
    2929  public function buildContainer(ContainerInterface $container) 
    3030  { 
    31     Loader::registerExtension(new DoctrineExtension()); 
     31    Loader::registerExtension(new DoctrineExtension($container)); 
    3232 
    3333    $metadataDirs = array(); 
     
    5252      } 
    5353    } 
    54     $container->setParameter('doctrine.orm.metadata_driver_impl.dirs', $metadataDirs); 
    55     $container->setParameter('doctrine.entity_dirs', $entityDirs); 
     54    $container->setParameter('doctrine.orm.metadata_driver.mapping_dirs', $metadataDirs); 
     55    $container->setParameter('doctrine.orm.entity_dirs', $entityDirs); 
    5656  } 
    5757} 
  • branches/2.0/src/Symfony/Framework/DoctrineBundle/Command/DoctrineCommand.php

    r28179 r28330  
    44 
    55use Symfony\Framework\WebBundle\Command\Command; 
     6use Symfony\Components\Console\Input\ArrayInput; 
    67use Symfony\Components\Console\Input\InputArgument; 
    78use Symfony\Components\Console\Input\InputOption; 
     
    910use Symfony\Components\Console\Output\OutputInterface; 
    1011use Symfony\Components\Console\Output\Output; 
     12use Symfony\Framework\WebBundle\Console\Application; 
    1113use Symfony\Framework\WebBundle\Util\Filesystem; 
    1214use Doctrine\Common\Cli\Configuration; 
     
    3133abstract class DoctrineCommand extends Command 
    3234{ 
    33   protected $cli; 
     35  protected 
     36    $application, 
     37    $cli, 
     38    $em; 
    3439 
    3540  protected function getDoctrineCli() 
     
    3843    { 
    3944      $configuration = new Configuration(); 
    40       $configuration->setAttribute('em', $this->container->getDoctrine_Orm_EntityManagerService()); 
    4145      $this->cli = new DoctrineCliController($configuration); 
    4246    } 
     47    $em = $this->em ? $this->em : $this->container->getDoctrine_Orm_EntityManagerService(); 
     48    $this->cli->getConfiguration()->setAttribute('em', $em); 
    4349    return $this->cli; 
    4450  } 
     
    6167  } 
    6268 
    63   public function buildDoctrineCliTaskOptions(InputInterface $input, array $options) 
     69  protected function buildDoctrineCliTaskOptions(InputInterface $input, array $options) 
    6470  { 
    6571    $taskOptions = array(); 
     
    7379    return $options; 
    7480  } 
     81 
     82  protected function runCommand($name, array $input = array()) 
     83  { 
     84    if ($this->application === null) 
     85    { 
     86      $this->application = new Application($this->container->getKernelService()); 
     87    } 
     88 
     89    $arguments = array(); 
     90    $arguments = array_merge(array($name), $input); 
     91    $input = new ArrayInput($arguments); 
     92    $this->application->setAutoExit(false); 
     93    $this->application->run($input); 
     94  } 
     95 
     96  /** 
     97   * TODO: Better way to do these functions? 
     98   */ 
     99  protected function getDoctrineConnections() 
     100  { 
     101    $connections = array(); 
     102    $ids = $this->container->getServiceIds(); 
     103    foreach ($ids as $id) 
     104    { 
     105      preg_match('/doctrine.dbal.(.*)_connection/', $id, $matches); 
     106      if ($matches) 
     107      { 
     108        $name = $matches[1]; 
     109        $connections[$name] = $this->container->getService($id); 
     110      } 
     111    } 
     112    return $connections; 
     113  } 
     114 
     115  protected function getDoctrineEntityManagers() 
     116  { 
     117    $entityManagers = array(); 
     118    $ids = $this->container->getServiceIds(); 
     119    foreach ($ids as $id) 
     120    { 
     121      preg_match('/doctrine.orm.(.*)_entity_manager/', $id, $matches); 
     122      if ($matches) 
     123      { 
     124        $name = $matches[1]; 
     125        $entityManagers[$name] = $this->container->getService($id); 
     126      } 
     127    } 
     128    return $entityManagers; 
     129  } 
    75130} 
  • branches/2.0/src/Symfony/Framework/DoctrineBundle/Command/LoadDataFixturesDoctrineCommand.php

    r28207 r28330  
    4242      ->setName('doctrine:load-data-fixtures') 
    4343      ->setDescription('Load data fixtures to your database.') 
    44       ->addOption('dir_or_file', null, null, 'The directory or file to load data fixtures from.') 
     44      ->addOption('dir_or_file', null, InputOption::PARAMETER_OPTIONAL | InputOption::PARAMETER_IS_ARRAY, 'The directory or file to load data fixtures from.') 
    4545      ->addOption('append', null, InputOption::PARAMETER_OPTIONAL, 'Whether or not to append the data fixtures.', false) 
    4646    ; 
     
    5252  protected function execute(InputInterface $input, OutputInterface $output) 
    5353  { 
    54     $em = $this->container->getDoctrine_ORM_EntityManagerService(); 
    55     if (!$input->getOption('append')) 
    56     { 
    57       $classes = array(); 
    58       $metadatas = $em->getMetadataFactory()->getAllMetadata(); 
    59  
    60       foreach ($metadatas as $metadata) 
    61       { 
    62         if (!$metadata->isMappedSuperclass) 
    63         { 
    64           $classes[] = $metadata; 
    65         } 
    66       } 
    67       $cmf = $em->getMetadataFactory(); 
    68       $classes = $this->getCommitOrder($em, $classes); 
    69       for ($i = count($classes) - 1; $i >= 0; --$i) 
    70       { 
    71         $class = $classes[$i]; 
    72         if ($cmf->hasMetadataFor($class->name)) 
    73         { 
    74           try { 
    75             $em->createQuery('DELETE FROM '.$class->name.' a')->execute(); 
    76           } catch (Exception $e) {} 
    77         } 
    78       } 
    79     } 
    80  
     54    $defaultEm = $this->container->getDoctrine_ORM_EntityManagerService(); 
    8155    $dirOrFile = $input->getOption('dir_or_file'); 
    8256    if ($dirOrFile) 
    8357    { 
    84       $paths = $dirOrFile
     58      $paths = is_array($dirOrFile) ? $dirOrFile : array($dirOrFile)
    8559    } else { 
    8660      $paths = array(); 
     
    11387    } 
    11488 
     89    $ems = array(); 
     90    $emEntities = array(); 
    11591    $files = array_unique($files); 
    116  
    11792    foreach ($files as $file) 
    11893    { 
     94      $em = $defaultEm; 
     95      $output->writeln(sprintf('<info>Loading data fixtures from <comment>"%s"</comment></info>', $file)); 
     96 
    11997      $before = array_keys(get_defined_vars()); 
    12098      include($file); 
    12199      $after = array_keys(get_defined_vars()); 
    122100      $new = array_diff($after, $before); 
    123       $entities = array_values($new); 
    124       unset($entities[array_search('before', $entities)]); 
    125       foreach ($entities as $entity) { 
    126         $em->persist($$entity); 
     101      $params = $em->getConnection()->getParams(); 
     102      $emName = isset($params['path']) ? $params['path']:$params['dbname']; 
     103 
     104      $ems[$emName] = $em; 
     105      $emEntities[$emName] = array(); 
     106      $variables = array_values($new); 
     107 
     108      foreach ($variables as $variable) 
     109      { 
     110        $value = $$variable; 
     111        if (!is_object($value) || $value instanceof \Doctrine\ORM\EntityManager) 
     112        { 
     113          continue; 
     114        } 
     115        $emEntities[$emName][] = $value; 
    127116      } 
    128       $em->flush(); 
     117      foreach ($ems as $emName => $em) 
     118      { 
     119        if (!$input->getOption('append')) 
     120        { 
     121          $output->writeln(sprintf('<info>Purging data from entity manager named <comment>"%s"</comment></info>', $emName)); 
     122          $this->purgeEntityManager($em); 
     123        } 
     124 
     125        $entities = $emEntities[$emName]; 
     126        $numEntities = count($entities); 
     127        $output->writeln(sprintf('<info>Persisting "%s" '.($numEntities > 1 ? 'entities' : 'entity').'</info>', count($entities))); 
     128 
     129        foreach ($entities as $entity) 
     130        { 
     131          $output->writeln(sprintf('<info>Persisting "%s" entity:</info>', get_class($entity))); 
     132          $output->writeln(''); 
     133          $output->writeln(var_dump($entity)); 
     134 
     135          $em->persist($entity); 
     136        } 
     137        $output->writeln('<info>Flushing entity manager</info>'); 
     138        $em->flush(); 
     139      } 
    129140    } 
    130141  } 
    131142   
     143  protected function purgeEntityManager(EntityManager $em) 
     144  { 
     145    $classes = array(); 
     146    $metadatas = $em->getMetadataFactory()->getAllMetadata(); 
     147 
     148    foreach ($metadatas as $metadata) 
     149    { 
     150      if (!$metadata->isMappedSuperclass) 
     151      { 
     152        $classes[] = $metadata; 
     153      } 
     154    } 
     155    $cmf = $em->getMetadataFactory(); 
     156    $classes = $this->getCommitOrder($em, $classes); 
     157    for ($i = count($classes) - 1; $i >= 0; --$i) 
     158    { 
     159      $class = $classes[$i]; 
     160      if ($cmf->hasMetadataFor($class->name)) 
     161      { 
     162        try { 
     163          $em->createQuery('DELETE FROM '.$class->name.' a')->execute(); 
     164        } catch (Exception $e) {} 
     165      } 
     166    } 
     167  } 
     168 
    132169  protected function getCommitOrder(EntityManager $em, array $classes) 
    133170  { 
  • branches/2.0/src/Symfony/Framework/DoctrineBundle/Command/RunDqlDoctrineCommand.php

    r28179 r28330  
    4141      ->addOption('dql', null, null, 'The DQL query to run.') 
    4242      ->addOption('depth', null, null, 'The depth to output the data to.') 
     43      ->addOption('connection', null, null, 'The connection to use.') 
    4344    ; 
    4445  } 
  • branches/2.0/src/Symfony/Framework/DoctrineBundle/Command/RunSqlDoctrineCommand.php

    r28179 r28330  
    4242      ->addOption('file', null, null, 'Path to a SQL file to run.') 
    4343      ->addOption('depth', null, null, 'The depth to output the data to.') 
     44      ->addOption('connection', null, null, 'The connection to use.') 
    4445    ; 
    4546  } 
  • branches/2.0/src/Symfony/Framework/DoctrineBundle/Command/SchemaToolDoctrineCommand.php

    r28179 r28330  
    4545      ->addOption('re-create', null, null, 'Drop and re-create your database schema.') 
    4646      ->addOption('dump-sql', null, null, 'Dump the SQL instead of executing it.') 
     47      ->addOption('connection', null, null, 'The connection to use.') 
    4748    ; 
    4849  } 
     
    5657      'create', 'drop', 'update', 'complete-update', 're-create', 'dump-sql' 
    5758    )); 
    58     $entityDirs = $this->container->getParameter('doctrine.entity_dirs'); 
     59 
     60    $entityDirs = $this->container->getParameter('doctrine.orm.entity_dirs'); 
    5961    $options['class-dir'] = implode(', ', $entityDirs); 
    60     $this->runDoctrineCliTask('orm:schema-tool', $options); 
     62 
     63    $found = false; 
     64    $ems = $this->getDoctrineEntityManagers(); 
     65    foreach  ($ems as $name => $em) 
     66    { 
     67      if ($input->getOption('connection') && $name !== $input->getOption('connection')) 
     68      { 
     69        continue; 
     70      } 
     71      $this->em = $em; 
     72      $this->runDoctrineCliTask('orm:schema-tool', $options); 
     73      $found = true; 
     74    } 
     75 
     76    if ($found === false) 
     77    { 
     78      if ($input->getOption('connection')) 
     79      { 
     80        $output->writeln(sprintf('<error>Could not find a connection named <comment>%s</comment></error>', $input->getOption('connection'))); 
     81      } 
     82      else 
     83      { 
     84        $output->writeln(sprintf('<error>Could not find any configured connections</error>', $input->getOption('connection')));         
     85      } 
     86    } 
    6187  } 
    6288} 
  • branches/2.0/src/Symfony/Framework/DoctrineBundle/Controller/DoctrineController.php

    r28179 r28330  
    1717 
    1818/** 
    19  *  
     19 * Doctrine ORM controller gives you access to entity managers and DQL queries. 
    2020 * 
    2121 * @package    symfony 
    2222 * @author     Fabien Potencier <fabien.potencier@symfony-project.com> 
     23 * @author     Jonathan H. Wage <jonwage@gmail.com> 
    2324 */ 
    2425class DoctrineController extends Controller 
    2526{ 
    26   protected function getEntityManager(
     27  public function getDatabaseConnection($name = null
    2728  { 
    28     return $this->container->getDoctrine_ORM_EntityManagerService(); 
     29    if ($name) 
     30    { 
     31      return $this->container->getService(sprintf('doctrine.dbal.%s_connection', $name)); 
     32    } 
     33    else 
     34    { 
     35      return $this->container->getDatabaseConnectionService(); 
     36    } 
    2937  } 
    3038 
    31   public function createQueryBuilder() 
     39  /** 
     40   * Get the default entity manager service or the entity manager  
     41   * with the given name. 
     42   * 
     43   * @param string $name Optional entity manager service name  
     44   * @return object $em 
     45   */ 
     46  protected function getEntityManager($name = null) 
    3247  { 
    33     return $this->getEntityManager()->createQueryBuilder(); 
     48    if ($name) 
     49    { 
     50      return $this->container->getService(sprintf('doctrine.orm.%s_entity_manager', $name)); 
     51    } 
     52    else 
     53    { 
     54      return $this->container->getDoctrine_ORM_EntityManagerService(); 
     55    } 
    3456  } 
    3557 
    36   public function createQuery($dql = '') 
     58  /** 
     59   * Create a new QueryBuilder instance. 
     60   * 
     61   * @param string $name Optional entity manager service name  
     62   * @return object QueryBuilder 
     63   */ 
     64  public function createQueryBuilder($name = null) 
    3765  { 
    38     return $this->getEntityManager()->createQuery($dql); 
     66    return $this->getEntityManager($name)->createQueryBuilder(); 
     67  } 
     68 
     69  /** 
     70   * Create a new Query instance. 
     71   * 
     72   * @param string $dql Optional Dql string to create the query from 
     73   * @param string $name Optional entity manager service name  
     74   * @return object QueryBuilder 
     75   */ 
     76  public function createQuery($dql = '', $name = null) 
     77  { 
     78    return $this->getEntityManager($name)->createQuery($dql); 
    3979  } 
    4080} 
  • branches/2.0/src/Symfony/Framework/DoctrineBundle/DependencyInjection/DoctrineExtension.php

    r28179 r28330  
    66use Symfony\Components\DependencyInjection\Loader\XmlFileLoader; 
    77use Symfony\Components\DependencyInjection\BuilderConfiguration; 
     8use Symfony\Components\DependencyInjection\Definition; 
     9use Symfony\Components\DependencyInjection\Reference; 
     10use Symfony\Components\DependencyInjection\Container; 
    811 
    912/* 
     
    3235  protected $alias; 
    3336 
     37  public function __construct(Container $container) 
     38  { 
     39    $this->container = $container; 
     40  } 
     41 
    3442  public function setAlias($alias) 
    3543  { 
     
    5563    $configuration->merge($loader->load($this->resources['dbal'])); 
    5664 
    57     foreach (array('dbname', 'host', 'user', 'password', 'path', 'port') as $key) 
    58     { 
    59       if (isset($config[$key])) 
    60       { 
    61         $configuration->setParameter('doctrine.dbal.'.$key, $config[$key]); 
    62       } 
    63     } 
    64  
    65     if (isset($config['options'])) 
    66     { 
    67       $configuration->setParameter('doctrine.dbal.driver.options', $config['options']); 
    68     } 
    69  
    70     if (isset($config['driver'])) 
    71     { 
    72       $class = $config['driver']; 
    73       if (in_array($class, array('OCI8', 'PDOMsSql', 'PDOMySql', 'PDOOracle', 'PDOPgSql', 'PDOSqlite'))) 
    74       { 
    75         $class = 'Doctrine\\DBAL\\Driver\\'.$class.'\\Driver'; 
    76       } 
    77  
    78       $configuration->setParameter('doctrine.dbal.driver.class', $class); 
    79     } 
    80  
    81     $configuration->setAlias('database_connection', null !== $this->alias ? $this->alias : 'doctrine.dbal.connection'); 
     65    $defaultConnection = array( 
     66      'driver'              => 'PDOMySQL', 
     67      'user'                => 'root', 
     68      'password'            => null, 
     69      'host'                => 'localhost', 
     70      'port'                => null, 
     71      'event_manager_class' => 'Doctrine\Common\EventManager', 
     72      'configuration_class' => 'Doctrine\DBAL\Configuration', 
     73      'wrapper_class'       => null, 
     74      'options'             => array() 
     75    ); 
     76 
     77    $config['default_connection'] = isset($config['default_connection']) ? $config['default_connection'] : 'default'; 
     78 
     79    $connections = array(); 
     80    if (isset($config['connections'])) 
     81    { 
     82      foreach ($config['connections'] as $name => $connection) 
     83      { 
     84        $connections[isset($connection['id']) ? $connection['id'] : $name] = $connection; 
     85      } 
     86    } 
     87    else 
     88    { 
     89      $connections = array($config['default_connection'] => $config); 
     90    } 
     91 
     92    foreach ($connections as $name => $connection) 
     93    { 
     94      $connection = array_merge($defaultConnection, $connection); 
     95      $configurationClass = isset($connection['configuration_class']) ? 
     96        $connection['configuration_class'] : 'Doctrine\DBAL\Configuration'; 
     97 
     98      $configurationDef = new Definition($configurationClass); 
     99      $configurationDef->addMethodCall('setSqlLogger', array( 
     100        new Reference('doctrine.dbal.logger') 
     101      )); 
     102      $configuration->setDefinition( 
     103        sprintf('doctrine.dbal.%s_connection.configuration', $name), 
     104        $configurationDef 
     105      ); 
     106 
     107      $eventManagerDef = new Definition($connection['event_manager_class']); 
     108      $configuration->setDefinition( 
     109        sprintf('doctrine.dbal.%s_connection.event_manager', $name), 
     110        $eventManagerDef 
     111      ); 
     112 
     113      $driverOptions = array(); 
     114      if (isset($connection['driver'])) 
     115      { 
     116        $driverOptions['driverClass'] = sprintf( 
     117          'Doctrine\\DBAL\\Driver\\%s\\Driver', 
     118          $connection['driver'] 
     119        ); 
     120      } 
     121      if (isset($connection['wrapper_class'])) 
     122      { 
     123        $driverOptions['wrapperClass'] = $connection['wrapper_class']; 
     124      } 
     125      if (isset($connection['options'])) 
     126      { 
     127        $driverOptions['driverOptions'] = $connection['options']; 
     128      } 
     129      foreach (array('dbname', 'host', 'user', 'password', 'path', 'port') as $key) 
     130      { 
     131        if (isset($connection[$key])) 
     132        { 
     133          $driverOptions[$key] = $connection[$key]; 
     134        } 
     135      } 
     136      $driverArgs = array( 
     137        $driverOptions, 
     138        new Reference(sprintf('doctrine.dbal.%s_connection.configuration', $name)), 
     139        new Reference(sprintf('doctrine.dbal.%s_connection.event_manager', $name)) 
     140      ); 
     141      $driverDef = new Definition('Doctrine\DBAL\DriverManager', $driverArgs); 
     142      $driverDef->setConstructor('getConnection'); 
     143      $configuration->setDefinition(sprintf('doctrine.dbal.%s_connection', $name), $driverDef); 
     144    } 
     145 
     146    $configuration->setAlias('database_connection',  
     147      null !== $this->alias ? $this->alias : sprintf( 
     148        'doctrine.dbal.%s_connection', $config['default_connection'] 
     149      ) 
     150    ); 
    82151 
    83152    return $configuration; 
     
    98167    $configuration->merge($loader->load($this->resources['orm'])); 
    99168 
    100     foreach (array('entity_manager.class', 'metadata_driver_impl.class', 'cache.class') as $key) 
     169    $config['default_entity_manager'] = isset($config['default_entity_manager']) ? $config['default_entity_manager'] : 'default'; 
     170    foreach (array('metadata_driver', 'cache_driver') as $key) 
    101171    { 
    102172      if (isset($config[$key])) 
     
    106176    } 
    107177 
     178    $config['entity_managers'] = isset($config['entity_managers']) ? 
     179      $config['entity_managers'] : array($config['default_entity_manager'] => array()) 
     180    ; 
     181    foreach ($config['entity_managers'] as $name => $connection) 
     182    { 
     183      $ormConfigDef = new Definition('Doctrine\ORM\Configuration'); 
     184      $configuration->setDefinition( 
     185        sprintf('doctrine.orm.%s_configuration', $name), $ormConfigDef 
     186      ); 
     187 
     188      $drivers = array('metadata', 'query', 'result'); 
     189      foreach ($drivers as $driver) 
     190      { 
     191        $definition = $configuration->getDefinition(sprintf('doctrine.orm.cache.%s', $configuration->getParameter('doctrine.orm.cache_driver'))); 
     192        $clone = clone $definition; 
     193        $clone->addMethodCall('setNamespace', array(sprintf('doctrine_%s_', $driver))); 
     194        $configuration->setDefinition(sprintf('doctrine.orm.%s_cache', $driver), $clone); 
     195      } 
     196 
     197      // configure metadata driver for each bundle based on the type of mapping files found 
     198      $mappingDriverDef = new Definition('Doctrine\ORM\Mapping\Driver\DriverChain'); 
     199      $bundleEntityMappings = array(); 
     200      $bundleDirs = $this->container->getParameter('kernel.bundle_dirs'); 
     201      foreach ($this->container->getParameter('kernel.bundles') as $className) 
     202      { 
     203        $tmp = dirname(str_replace('\\', '/', $className)); 
     204        $namespace = str_replace('/', '\\', dirname($tmp)); 
     205        $class = basename($tmp); 
     206 
     207        if (isset($bundleDirs[$namespace])) 
     208        { 
     209          if (is_dir($dir = $bundleDirs[$namespace].'/'.$class.'/Resources/config/doctrine/metadata')) 
     210          { 
     211            $type = $this->detectMappingType($dir); 
     212          } 
     213          elseif (is_dir($dir = $bundleDirs[$namespace].'/'.$class.'/Entities')) 
     214          { 
     215            $type = 'annotation'; 
     216 
     217            $reader = new \Doctrine\Common\Annotations\AnnotationReader(); 
     218            $reader->setDefaultAnnotationNamespace('Doctrine\\ORM\\Mapping\\'); 
     219            $annotationDriver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader, $dir); 
     220            $classNames = $annotationDriver->getAllClassNames(); 
     221            foreach ($classNames as $className) 
     222            { 
     223              $alias = substr_replace($className, '', 0, strpos($className, '\\') + 1); 
     224              $alias = str_replace('\Entities\\', '\\', $alias); 
     225              $ormConfigDef->addMethodCall('addEntityAlias', array($className, $alias)); 
     226            } 
     227          } 
     228          else 
     229          { 
     230            $type = false; 
     231          } 
     232 
     233          if (false !== $type) 
     234          { 
     235            $mappingDriverDef->addMethodCall('addDriver', array( 
     236                new Reference(sprintf('doctrine.orm.metadata_driver.%s', $type)), 
     237                $namespace.'\\'.$class.'\\Entities' 
     238              ) 
     239            ); 
     240          } 
     241        } 
     242      } 
     243 
     244      $configuration->setDefinition('doctrine.orm.metadata_driver', $mappingDriverDef); 
     245 
     246      $methods = array( 
     247        'setMetadataCacheImpl' => new Reference('doctrine.orm.metadata_cache'), 
     248        'setQueryCacheImpl' => new Reference('doctrine.orm.query_cache'), 
     249        'setResultCacheImpl' => new Reference('doctrine.orm.result_cache'), 
     250        'setMetadataDriverImpl' => new Reference('doctrine.orm.metadata_driver'), 
     251        'setProxyDir' => '%kernel.cache_dir%/doctrine/Proxies', 
     252        'setProxyNamespace' => 'Proxies', 
     253        'setAutoGenerateProxyClasses' => true 
     254      ); 
     255 
     256      foreach ($methods as $method => $arg) 
     257      { 
     258        $ormConfigDef->addMethodCall($method, array($arg)); 
     259      } 
     260 
     261      $ormEmArgs = array( 
     262        new Reference( 
     263          sprintf('doctrine.dbal.%s_connection', 
     264          isset($connection['connection']) ? $connection['connection'] : $name) 
     265        ), 
     266        new Reference(sprintf('doctrine.orm.%s_configuration', $name)) 
     267      ); 
     268      $ormEmDef = new Definition('Doctrine\ORM\EntityManager', $ormEmArgs); 
     269      $ormEmDef->setConstructor('create'); 
     270 
     271      $configuration->setDefinition( 
     272        sprintf('doctrine.orm.%s_entity_manager', $name), 
     273        $ormEmDef 
     274      ); 
     275 
     276      if ($name == $config['default_entity_manager']) 
     277      { 
     278        $configuration->setAlias( 
     279          'doctrine.orm.entity_manager', 
     280          sprintf('doctrine.orm.%s_entity_manager', $name) 
     281        ); 
     282      } 
     283    } 
     284 
     285    $configuration->setAlias( 
     286      'doctrine.orm.cache', 
     287      sprintf( 
     288        'doctrine.orm.cache.%s', 
     289        $configuration->getParameter('doctrine.orm.cache_driver') 
     290      ) 
     291    ); 
     292 
    108293    return $configuration; 
    109294  } 
    110295 
    111296  /** 
     297   * Detect the type of Doctrine 2 mapping files located in a given directory. 
     298   * Simply finds the first file in a directory and returns the extension. If no 
     299   * mapping files are found then the annotation type is returned. 
     300   * 
     301   * @param string $dir 
     302   * @return string $type 
     303   */ 
     304  protected function detectMappingType($dir) 
     305  { 
     306    $files = glob($dir.'/*.*'); 
     307    if (!$files) 
     308    { 
     309      return 'annotation'; 
     310    } 
     311    $info = pathinfo($files[0]); 
     312 
     313    return $info['extension']; 
     314  } 
     315 
     316  /** 
    112317   * Returns the base path for the XSD files. 
    113318   * 
  • branches/2.0/src/Symfony/Framework/DoctrineBundle/Resources/config/dbal.xml

    r28096 r28330  
    66 
    77  <parameters> 
    8     <parameter key="doctrine.dbal.dbname">null</parameter> 
    9     <parameter key="doctrine.dbal.user">root</parameter> 
    10     <parameter key="doctrine.dbal.password"></parameter> 
    11     <parameter key="doctrine.dbal.host">localhost</parameter> 
    12     <parameter key="doctrine.dbal.port">null</parameter> 
    13     <parameter key="doctrine.dbal.path">null</parameter> 
    14     <parameter key="doctrine.dbal.driver.class">Doctrine\DBAL\Driver\PDOMySql\Driver</parameter> 
    15     <parameter key="doctrine.dbal.driver.options" type="collection" /> 
    16     <parameter key="doctrine.dbal.wrapper.class">Doctrine\DBAL\Connection</parameter> 
    17     <parameter key="doctrine.dbal.configuration.class">Doctrine\DBAL\Configuration</parameter> 
    18     <parameter key="doctrine.dbal.event_manager.class">Doctrine\Common\EventManager</parameter> 
    19     <parameter key="doctrine.debug.collector.class">Symfony\Framework\DoctrineBundle\Debug\DoctrineDataCollector</parameter> 
     8    <parameter key="doctrine.debug.collector.class"> 
     9      Symfony\Framework\DoctrineBundle\Debug\DoctrineDataCollector 
     10    </parameter> 
    2011  </parameters> 
    2112 
    2213  <services> 
    23     <service id="doctrine.dbal.connection" class="Doctrine\DBAL\DriverManager" constructor="getConnection"> 
    24       <argument type="collection"> 
    25         <argument key="dbname">%doctrine.dbal.dbname%</argument> 
    26         <argument key="user">%doctrine.dbal.user%</argument> 
    27         <argument key="password">%doctrine.dbal.password%</argument> 
    28         <argument key="host">%doctrine.dbal.host%</argument> 
    29         <argument key="port">%doctrine.dbal.port%</argument> 
    30         <argument key="path">%doctrine.dbal.path%</argument> 
    31         <argument key="driverClass">%doctrine.dbal.driver.class%</argument> 
    32         <argument key="driverOptions">%doctrine.dbal.driver.options%</argument> 
    33         <!-- 
    34         <argument key="wrapperClass">%doctrine.dbal.wrapper.class%</argument> 
    35         //--> 
    36       </argument> 
    37       <argument type="service" id="doctrine.dbal.configuration" /> 
    38       <argument type="service" id="doctrine.dbal.event_manager" /> 
    39     </service> 
    40  
    41     <service id="doctrine.dbal.configuration" class="%doctrine.dbal.configuration.class%"> 
    42       <call method="setSqlLogger"><argument type="service" id="doctrine.dbal.logger" on-invalid="ignore" /></call> 
    43     </service> 
    44  
    4514    <service id="doctrine.dbal.logger.debug" class="Doctrine\DBAL\Logging\DebugStack" /> 
    46  
    47     <service id="doctrine.dbal.event_manager" class="%doctrine.dbal.event_manager.class%" /> 
    4815 
    4916    <service id="doctrine.dbal.logger" class="Symfony\Framework\DoctrineBundle\Logger\DbalLogger"> 
  • branches/2.0/src/Symfony/Framework/DoctrineBundle/Resources/config/orm.xml

    r28179 r28330  
    66 
    77  <parameters> 
    8     <parameter key="doctrine.orm.entity_manager.class">Doctrine\ORM\EntityManager</parameter> 
    9     <parameter key="doctrine.orm.metadata_driver_impl.class">Doctrine\ORM\Mapping\Driver\XmlDriver</parameter> 
    10     <parameter key="doctrine.orm.cache.class">Doctrine\Common\Cache\ArrayCache</parameter> 
     8    <parameter key="doctrine.orm.cache_driver">array</parameter> 
     9    <parameter key="doctrine.orm.cache.memcache.host">localhost</parameter> 
     10    <parameter key="doctrine.orm.cache.memcache.port">11211</parameter> 
    1111  </parameters> 
    1212 
    1313  <services> 
    14     <service id="doctrine.orm.entity_manager" class="%doctrine.orm.entity_manager.class%" constructor="create"> 
    15       <argument type="service" id="doctrine.dbal.connection" /> 
    16       <argument type="service" id="doctrine.orm.configuration" /> 
     14    <!--- Should we just move all this to php code? is it best to go one way or the other? --> 
     15 
     16    <!--- Annotation Metadata Driver Service --> 
     17    <service id="doctrine.orm.metadata_driver.annotation" class="Doctrine\ORM\Mapping\Driver\AnnotationDriver"> 
     18      <argument type="service" id="doctrine.orm.metadata_driver.annotation.reader" /> 
     19      <argument>%doctrine.orm.entity_dirs%</argument> 
    1720    </service> 
    1821 
    19     <service id="doctrine.orm.metadata_driver_impl" class="%doctrine.orm.metadata_driver_impl.class%"> 
    20       <argument>%doctrine.orm.metadata_driver_impl.dirs%</argument> 
     22    <service id="doctrine.orm.metadata_driver.annotation.reader" class="Doctrine\Common\Annotations\AnnotationReader"> 
     23      <argument type="service" id="doctrine.orm.cache" /> 
     24      <call method="setDefaultAnnotationNamespace"><argument>Doctrine\ORM\Mapping\</argument></call> 
    2125    </service> 
    2226 
    23     <service id="doctrine.orm.cache" class="%doctrine.orm.cache.class%" /> 
     27    <!--- XML Metadata Driver Service --> 
     28    <service id="doctrine.orm.metadata_driver.xml" class="Doctrine\ORM\Mapping\Driver\XmlDriver"> 
     29      <argument>%doctrine.orm.metadata_driver.mapping_dirs%</argument> 
     30    </service> 
    2431 
    25     <service id="doctrine.orm.configuration" class="Doctrine\ORM\Configuration"> 
    26       <call method="setMetadataCacheImpl"><argument type="service" id="doctrine.orm.cache" /></call> 
    27       <call method="setQueryCacheImpl"><argument type="service" id="doctrine.orm.cache" /></call> 
    28       <call method="setResultCacheImpl"><argument type="service" id="doctrine.orm.cache" /></call> 
    29       <call method="setMetadataDriverImpl"><argument type="service" id="doctrine.orm.metadata_driver_impl" /></call> 
    30       <call method="setProxyDir"><argument>%kernel.cache_dir%/doctrine/Proxies</argument></call> 
    31       <call method="setProxyNamespace"><argument>Proxies</argument></call> 
    32       <call method="setAutoGenerateProxyClasses"><argument>true</argument></call> 
     32    <!--- YAML Metadata Driver Service --> 
     33    <service id="doctrine.orm.metadata_driver.yml" class="Doctrine\ORM\Mapping\Driver\YamlDriver"> 
     34      <argument>%doctrine.orm.metadata_driver.mapping_dirs%</argument> 
    3335    </service> 
     36 
     37    <!--- ORM Array Cache Driver Service --> 
     38    <service id="doctrine.orm.cache.array" class="Doctrine\Common\Cache\ArrayCache" /> 
     39 
     40    <!--- ORM APC Cache Driver Service --> 
     41    <service id="doctrine.orm.cache.apc" class="Doctrine\Common\Cache\ApcCache" /> 
     42 
     43    <!--- ORM Memcache Cache Driver Service --> 
     44    <service id="doctrine.orm.cache.memcache" class="Doctrine\Common\Cache\MemcacheCache"> 
     45      <call method="setMemcache"><argument type="service" id="doctrine.orm.cache.memcache.instance" /></call> 
     46    </service> 
     47 
     48    <!--- ORM Memcache Cache Driver Memcache instance. See doctrine.orm.cache.memcache --> 
     49    <service id="doctrine.orm.cache.memcache.instance" class="Memcache"> 
     50      <call method="connect"> 
     51        <argument>%doctrine.orm.cache.memcache.host%</argument> 
     52        <argument>%doctrine.orm.cache.memcache.port%</argument> 
     53      </call> 
     54    </service> 
     55 
     56    <!--- ORM Xcache Cache Driver Service --> 
     57    <service id="doctrine.orm.cache.xcache" class="Doctrine\Common\Cache\XcacheCache" /> 
    3458  </services> 
    3559</container> 
  • branches/2.0/src/Symfony/Framework/DoctrineBundle/Resources/config/schema/dic/doctrine/doctrine-1.0.xsd

    r28142 r28330  
    99 
    1010  <xsd:complexType name="dbal"> 
     11    <xsd:sequence> 
     12      <xsd:element name="connections" type="connections" minOccurs="0" maxOccurs="1" /> 
     13    </xsd:sequence> 
     14 
     15    <xsd:attribute name="default_connection" type="xsd:string" /> 
    1116    <xsd:attribute name="dbname" type="xsd:string" /> 
    1217    <xsd:attribute name="host" type="xsd:string" /> 
     
    1823    <xsd:attribute name="path" type="xsd:string" /> 
    1924  </xsd:complexType> 
     25 
     26  <xsd:complexType name="connections"> 
     27    <xsd:sequence> 
     28      <xsd:element name="connection" type="connection" minOccurs="1" maxOccurs="unbounded" /> 
     29    </xsd:sequence> 
     30  </xsd:complexType> 
     31 
     32  <xsd:complexType name="connection"> 
     33    <xsd:attribute name="id" type="xsd:string" use="required" /> 
     34    <xsd:attribute name="dbname" type="xsd:string" use="required" /> 
     35    <xsd:attribute name="host" type="xsd:string" /> 
     36    <xsd:attribute name="port" type="xsd:integer" /> 
     37    <xsd:attribute name="user" type="xsd:string" /> 
     38    <xsd:attribute name="password" type="xsd:string" /> 
     39    <xsd:attribute name="driver" type="xsd:string" /> 
     40    <xsd:attribute name="options" type="xsd:string" /> 
     41    <xsd:attribute name="path" type="xsd:string" /> 
     42  </xsd:complexType> 
    2043</xsd:schema> 
  • branches/2.0/src/Symfony/Framework/WebBundle/Bundle.php

    r28142 r28330  
    66use Symfony\Components\DependencyInjection\ContainerInterface; 
    77use Symfony\Components\DependencyInjection\Loader\Loader; 
     8use Symfony\Components\DependencyInjection\Loader\XmlFileLoader; 
     9use Symfony\Components\DependencyInjection\BuilderConfiguration; 
    810use Symfony\Framework\WebBundle\DependencyInjection\WebExtension; 
    911 
     
    3537    } 
    3638    $container->setParameter('templating.loader.filesystem.path', $dirs); 
     39 
     40    $configuration = new BuilderConfiguration(); 
     41    if ($container->getParameter('kernel.debug')) 
     42    { 
     43      $loader = new XmlFileLoader(__DIR__.'/Resources/config'); 
     44      $configuration->merge($loader->load('debug.xml')); 
     45    } 
     46 
     47    return $configuration; 
    3748  } 
    3849} 
  • branches/2.0/src/Symfony/Framework/WebBundle/Console/Application.php

    r28096 r28330  
    3939    $this->definition->addOption(new InputOption('--shell', '-s', InputOption::PARAMETER_NONE, 'Launch the shell.')); 
    4040 
    41     $this->kernel->boot(); 
     41    if (!$this->kernel->isBooted()) 
     42    { 
     43      $this->kernel->boot(); 
     44    } 
    4245 
    4346    $this->registerCommands(); 
     
    9396        foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($commandDir), \RecursiveIteratorIterator::LEAVES_ONLY) as $file) 
    9497        { 
    95           if ($file->isDir()
     98          if ($file->isDir() || strpos($file, -4) !== '.php'
    9699          { 
    97100            continue; 
  • branches/2.0/src/Symfony/Framework/WebBundle/Controller.php

    r28096 r28330  
    1515 
    1616/** 
    17  *  
     17 * WebBundle Controller gives you convenient access to all commonly needed services. 
    1818 * 
    1919 * @package    symfony 
     
    3737  { 
    3838    return $this->container->getUserService(); 
    39   } 
    40  
    41   public function getDatabaseConnection() 
    42   { 
    43     return $this->container->getDatabaseConnectionService(); 
    4439  } 
    4540 
  • branches/2.0/src/Symfony/Framework/WebBundle/Debug/ExceptionFormatter.php

    r28096 r28330  
    169169    } 
    170170 
    171     $linkFormat = $this->container->hasParameter('web_debug.file_link_format') ? $this->container->getParameter('web_debug.file_link_format') : ini_get('xdebug.file_link_format'); 
     171    $linkFormat = $this->container->hasParameter('debug.file_link_format') ? $this->container->getParameter('debug.file_link_format') : ini_get('xdebug.file_link_format'); 
    172172    if ('html' === $format && $file && $line && $linkFormat) 
    173173    { 
  • branches/2.0/src/Symfony/Framework/WebBundle/DependencyInjection/WebExtension.php

    r28096 r28330  
    55use Symfony\Components\DependencyInjection\Loader\LoaderExtension; 
    66use Symfony\Components\DependencyInjection\Loader\XmlFileLoader; 
    7 use Symfony\Components\DependencyInjection\Builder; 
    87use Symfony\Components\DependencyInjection\BuilderConfiguration; 
    98use Symfony\Components\DependencyInjection\Reference; 
     
    3938    $loader = new XmlFileLoader(__DIR__.'/../Resources/config'); 
    4039    $configuration->merge($loader->load($this->resources['web'])); 
     40 
     41    if (isset($config['ide']) && 'textmate' === $config['ide']) 
     42    { 
     43      $configuration->setParameter('debug.file_link_format', 'txmt://open?url=file://%%f&line=%%l'); 
     44    } 
    4145 
    4246    return $configuration; 
     
    148152    $configuration = new BuilderConfiguration(); 
    149153 
    150     $loader = new XmlFileLoader(__DIR__.'/../Resources/config'); 
    151     $configuration->merge($loader->load($this->resources['debug'])); 
    152  
    153     if (isset($config['exception']) && $config['exception']) 
    154     { 
    155       $configuration->merge($loader->load('debug_exception_handler.xml')); 
    156     } 
    157  
    158154    if (isset($config['toolbar']) && $config['toolbar']) 
    159155    { 
     156      $loader = new XmlFileLoader(__DIR__.'/../Resources/config'); 
    160157      $configuration->merge($loader->load('debug_data_collector.xml')); 
    161158      $configuration->merge($loader->load('debug_web_debug_toolbar.xml')); 
    162159    } 
    163  
    164     if (isset($config['ide']) && 'textmate' === $config['ide']) 
    165     { 
    166       $configuration->setParameter('web_debug.file_link_format', 'txmt://open?url=file://%%f&line=%%l'); 
    167     } 
    168  
    169     $configuration->setAlias('event_dispatcher', 'debug.event_dispatcher'); 
    170160 
    171161    return $configuration; 
  • branches/2.0/src/Symfony/Framework/WebBundle/Resources/config/debug.xml

    r28096 r28330  
    66 
    77  <parameters> 
    8     <parameter key="symfony.templating.debugger.class">Symfony\Framework\WebBundle\Templating\Debugger</parameter> 
     8    <parameter key="templating.debugger.class">Symfony\Framework\WebBundle\Templating\Debugger</parameter> 
    99  </parameters> 
    1010 
    1111  <services> 
    12     <service id="symfony.templating.debugger" class="%symfony.templating.debugger.class%"> 
     12    <service id="templating.debugger" class="%templating.debugger.class%"> 
    1313      <argument type="service" id="logger" on-invalid="null" /> 
    1414    </service> 
  • branches/2.0/src/Symfony/Framework/WebBundle/Resources/config/schema/dic/symfony/symfony-1.0.xsd

    r28096 r28330  
    3333 
    3434  <xsd:complexType name="web"> 
     35    <xsd:attribute name="ide" type="xsd:string" /> 
    3536  </xsd:complexType> 
    3637 
     
    4748 
    4849  <xsd:complexType name="debug"> 
    49     <xsd:attribute name="exception" type="xsd:string" /> 
    5050    <xsd:attribute name="toolbar" type="xsd:string" /> 
    51     <xsd:attribute name="ide" type="xsd:string" /> 
    5251  </xsd:complexType> 
    5352</xsd:schema> 
  • branches/2.0/src/Symfony/Framework/WebBundle/Resources/config/web.xml

    r28096 r28330  
    1010    <parameter key="router.class">Symfony\Components\Routing\Router</parameter> 
    1111    <parameter key="response_filter.class">Symfony\Framework\WebBundle\Listener\ResponseFilter</parameter> 
     12 
     13    <parameter key="exception_handler.class">Symfony\Framework\WebBundle\Listener\ExceptionHandler</parameter> 
     14    <parameter key="exception_handler.bundle">WebBundle</parameter> 
     15    <parameter key="exception_handler.controller">Exception</parameter> 
     16    <parameter key="exception_handler.action">exception</parameter> 
    1217  </parameters> 
    1318 
     
    4449      <argument type="service" id="request" /> 
    4550    </service> 
     51 
     52    <service id="exception_handler" class="%exception_handler.class%"> 
     53      <annotation name="kernel.listener" event="core.exception" method="handle" /> 
     54      <argument type="service" id="service_container" /> 
     55      <argument type="service" id="logger" on-invalid="null" /> 
     56      <argument>%exception_handler.bundle%</argument> 
     57      <argument>%exception_handler.controller%</argument> 
     58      <argument>%exception_handler.action%</argument> 
     59    </service> 
    4660  </services> 
    4761</container> 
  • branches/2.0/src/Symfony/Framework/WebBundle/Templating/Engine.php

    r28096 r28330  
    117117  protected function splitTemplateName($name) 
    118118  { 
    119     $parts = explode(':', $name, 3); 
     119    $parts = explode(':', $name, 4); 
    120120 
    121121    $options = array(