Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[DoctrineBundle] removed the bundle (migrated to the Doctrine organiz…

…ation)
  • Loading branch information...
commit dcf209a4aaf27147848437bc5a505b5506116d44 1 parent d3ab39d
Fabien Potencier fabpot authored
Showing with 0 additions and 5,086 deletions.
  1. +0 −68 src/Symfony/Bundle/DoctrineBundle/Command/CreateDatabaseDoctrineCommand.php
  2. +0 −52 src/Symfony/Bundle/DoctrineBundle/Command/DoctrineCommand.php
  3. +0 −80 src/Symfony/Bundle/DoctrineBundle/Command/DropDatabaseDoctrineCommand.php
  4. +0 −131 src/Symfony/Bundle/DoctrineBundle/Command/GenerateEntitiesDoctrineCommand.php
  5. +0 −123 src/Symfony/Bundle/DoctrineBundle/Command/ImportMappingDoctrineCommand.php
  6. +0 −86 src/Symfony/Bundle/DoctrineBundle/Command/InfoDoctrineCommand.php
  7. +0 −55 src/Symfony/Bundle/DoctrineBundle/Command/Proxy/ClearMetadataCacheDoctrineCommand.php
  8. +0 −55 src/Symfony/Bundle/DoctrineBundle/Command/Proxy/ClearQueryCacheDoctrineCommand.php
  9. +0 −70 src/Symfony/Bundle/DoctrineBundle/Command/Proxy/ClearResultCacheDoctrineCommand.php
  10. +0 −65 src/Symfony/Bundle/DoctrineBundle/Command/Proxy/ConvertMappingDoctrineCommand.php
  11. +0 −60 src/Symfony/Bundle/DoctrineBundle/Command/Proxy/CreateSchemaDoctrineCommand.php
  12. +0 −46 src/Symfony/Bundle/DoctrineBundle/Command/Proxy/DoctrineCommandHelper.php
  13. +0 −60 src/Symfony/Bundle/DoctrineBundle/Command/Proxy/DropSchemaDoctrineCommand.php
  14. +0 −55 src/Symfony/Bundle/DoctrineBundle/Command/Proxy/EnsureProductionSettingsDoctrineCommand.php
  15. +0 −60 src/Symfony/Bundle/DoctrineBundle/Command/Proxy/RunDqlDoctrineCommand.php
  16. +0 −50 src/Symfony/Bundle/DoctrineBundle/Command/Proxy/RunSqlDoctrineCommand.php
  17. +0 −64 src/Symfony/Bundle/DoctrineBundle/Command/Proxy/UpdateSchemaDoctrineCommand.php
  18. +0 −56 src/Symfony/Bundle/DoctrineBundle/Command/Proxy/ValidateSchemaCommand.php
  19. +0 −75 src/Symfony/Bundle/DoctrineBundle/ConnectionFactory.php
  20. +0 −105 src/Symfony/Bundle/DoctrineBundle/DependencyInjection/Compiler/RegisterEventListenersAndSubscribersPass.php
  21. +0 −289 src/Symfony/Bundle/DoctrineBundle/DependencyInjection/Configuration.php
  22. +0 −430 src/Symfony/Bundle/DoctrineBundle/DependencyInjection/DoctrineExtension.php
  23. +0 −92 src/Symfony/Bundle/DoctrineBundle/DoctrineBundle.php
  24. +0 −52 src/Symfony/Bundle/DoctrineBundle/Mapping/ClassMetadataCollection.php
  25. +0 −23 src/Symfony/Bundle/DoctrineBundle/Mapping/DisconnectedMetadataFactory.php
  26. +0 −174 src/Symfony/Bundle/DoctrineBundle/Mapping/MetadataFactory.php
  27. +0 −152 src/Symfony/Bundle/DoctrineBundle/Registry.php
  28. +0 −64 src/Symfony/Bundle/DoctrineBundle/Resources/config/dbal.xml
  29. +0 −81 src/Symfony/Bundle/DoctrineBundle/Resources/config/orm.xml
  30. +0 −149 src/Symfony/Bundle/DoctrineBundle/Resources/config/schema/doctrine-1.0.xsd
  31. +0 −88 src/Symfony/Bundle/DoctrineBundle/Resources/views/Collector/db.html.twig
  32. +0 −45 src/Symfony/Bundle/DoctrineBundle/Tests/Command/InfoDoctrineCommandTest.php
  33. +0 −48 src/Symfony/Bundle/DoctrineBundle/Tests/ContainerTest.php
  34. +0 −788 src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php
  35. +0 −18 ...ny/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/Bundles/AnnotationsBundle/AnnotationsBundle.php
  36. +0 −16 src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/Bundles/AnnotationsBundle/Entity/Test.php
  37. +0 −18 ...le/DoctrineBundle/Tests/DependencyInjection/Fixtures/Bundles/Vendor/AnnotationsBundle/AnnotationsBundle.php
  38. +0 −16 ...y/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/Bundles/Vendor/AnnotationsBundle/Entity/Test.php
  39. +0 −16 src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/Bundles/XmlBundle/Entity/Test.php
  40. 0  .../DoctrineBundle/Tests/DependencyInjection/Fixtures/Bundles/XmlBundle/Resources/config/doctrine/Test.orm.xml
  41. +0 −18 src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/Bundles/XmlBundle/XmlBundle.php
  42. +0 −17 src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/Bundles/YamlBundle/Entity/Test.php
  43. +0 −5 ...DoctrineBundle/Tests/DependencyInjection/Fixtures/Bundles/YamlBundle/Resources/config/doctrine/Test.orm.yml
  44. +0 −18 src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/Bundles/YamlBundle/YamlBundle.php
  45. +0 −29 src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/dbal_logging.xml
  46. +0 −33 ...y/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/dbal_service_multiple_connections.xml
  47. +0 −12 ...fony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/dbal_service_single_connection.xml
  48. +0 −15 src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/dbal_types.xml
  49. +0 −25 src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_functions.xml
  50. +0 −21 src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_hydration_mode.xml
  51. +0 −16 src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_imports.xml
  52. +0 −23 src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_imports_import.xml
  53. +0 −27 ...ony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_multiple_em_bundle_mappings.xml
  54. +0 −40 ...undle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_service_multiple_entity_managers.xml
  55. +0 −26 ...e/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_service_simple_single_entity_manager.xml
  56. +0 −39 ...y/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_service_single_entity_manager.xml
  57. +0 −23 ...mfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_single_em_bundle_mappings.xml
  58. +0 −20 ...Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_single_em_dql_functions.xml
  59. +0 −13 src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/yml/dbal_logging.yml
  60. +0 −18 ...y/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/yml/dbal_service_multiple_connections.yml
  61. +0 −6 ...fony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/yml/dbal_service_single_connection.yml
  62. +0 −7 src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/yml/dbal_types.yml
  63. +0 −19 src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/yml/orm_functions.yml
  64. +0 −14 src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/yml/orm_hydration_mode.yml
  65. +0 −6 src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/yml/orm_imports.yml
  66. +0 −15 src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/yml/orm_imports_import.yml
  67. +0 −23 ...ony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/yml/orm_multiple_em_bundle_mappings.yml
  68. +0 −34 ...undle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/yml/orm_service_multiple_entity_managers.yml
  69. +0 −19 ...e/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/yml/orm_service_simple_single_entity_manager.yml
  70. +0 −26 ...y/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/yml/orm_service_single_entity_manager.yml
  71. +0 −18 ...mfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/yml/orm_single_em_bundle_mappings.yml
  72. +0 −11 ...Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/yml/orm_single_em_dql_functions.yml
  73. +0 −29 src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/TestDatetimeFunction.php
  74. +0 −29 src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/TestNumericFunction.php
  75. +0 −29 src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/TestStringFunction.php
  76. +0 −27 src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/TestType.php
  77. +0 −63 src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/XMLSchemaTest.php
  78. +0 −25 src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/XmlDoctrineExtensionTest.php
  79. +0 −25 src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/YamlDoctrineExtensionTest.php
  80. +0 −146 src/Symfony/Bundle/DoctrineBundle/Tests/RegistryTest.php
  81. +0 −75 src/Symfony/Bundle/DoctrineBundle/Tests/TestCase.php
  82. +0 −27 src/Symfony/Bundle/DoctrineBundle/composer.json
68 src/Symfony/Bundle/DoctrineBundle/Command/CreateDatabaseDoctrineCommand.php
View
@@ -1,68 +0,0 @@
-<?php
-
-/*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Bundle\DoctrineBundle\Command;
-
-use Symfony\Component\Console\Input\InputOption;
-use Symfony\Component\Console\Input\InputInterface;
-use Symfony\Component\Console\Output\OutputInterface;
-use Doctrine\DBAL\DriverManager;
-
-/**
- * Database tool allows you to easily drop and create your configured databases.
- *
- * @author Fabien Potencier <fabien@symfony.com>
- * @author Jonathan H. Wage <jonwage@gmail.com>
- */
-class CreateDatabaseDoctrineCommand extends DoctrineCommand
-{
- protected function configure()
- {
- $this
- ->setName('doctrine:database:create')
- ->setDescription('Create the configured databases')
- ->addOption('connection', null, InputOption::VALUE_OPTIONAL, 'The connection to use for this command')
- ->setHelp(<<<EOT
-The <info>doctrine:database:create</info> command creates the default
-connections database:
-
-<info>php app/console doctrine:database:create</info>
-
-You can also optionally specify the name of a connection to create the
-database for:
-
-<info>php app/console doctrine:database:create --connection=default</info>
-EOT
- );
- }
-
- protected function execute(InputInterface $input, OutputInterface $output)
- {
- $connection = $this->getDoctrineConnection($input->getOption('connection'));
-
- $params = $connection->getParams();
- $name = isset($params['path']) ? $params['path'] : $params['dbname'];
-
- unset($params['dbname']);
-
- $tmpConnection = DriverManager::getConnection($params);
-
- try {
- $tmpConnection->getSchemaManager()->createDatabase($name);
- $output->writeln(sprintf('<info>Created database for connection named <comment>%s</comment></info>', $name));
- } catch (\Exception $e) {
- $output->writeln(sprintf('<error>Could not create database for connection named <comment>%s</comment></error>', $name));
- $output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
- }
-
- $tmpConnection->close();
- }
-}
52 src/Symfony/Bundle/DoctrineBundle/Command/DoctrineCommand.php
View
@@ -1,52 +0,0 @@
-<?php
-
-/*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Bundle\DoctrineBundle\Command;
-
-use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
-use Doctrine\ORM\Tools\EntityGenerator;
-
-/**
- * Base class for Doctrine console commands to extend from.
- *
- * @author Fabien Potencier <fabien@symfony.com>
- */
-abstract class DoctrineCommand extends ContainerAwareCommand
-{
- protected function getEntityGenerator()
- {
- $entityGenerator = new EntityGenerator();
- $entityGenerator->setGenerateAnnotations(false);
- $entityGenerator->setGenerateStubMethods(true);
- $entityGenerator->setRegenerateEntityIfExists(false);
- $entityGenerator->setUpdateEntityIfExists(true);
- $entityGenerator->setNumSpaces(4);
- $entityGenerator->setAnnotationPrefix('ORM\\');
-
- return $entityGenerator;
- }
-
- protected function getEntityManager($name)
- {
- return $this->getContainer()->get('doctrine')->getManager($name);
- }
-
- /**
- * Get a doctrine dbal connection by symfony name.
- *
- * @param string $name
- * @return Doctrine\DBAL\Connection
- */
- protected function getDoctrineConnection($name)
- {
- return $this->getContainer()->get('doctrine')->getConnection($name);
- }
-}
80 src/Symfony/Bundle/DoctrineBundle/Command/DropDatabaseDoctrineCommand.php
View
@@ -1,80 +0,0 @@
-<?php
-
-/*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Bundle\DoctrineBundle\Command;
-
-use Symfony\Component\Console\Input\InputOption;
-use Symfony\Component\Console\Input\InputInterface;
-use Symfony\Component\Console\Output\OutputInterface;
-
-/**
- * Database tool allows you to easily drop and create your configured databases.
- *
- * @author Fabien Potencier <fabien@symfony.com>
- * @author Jonathan H. Wage <jonwage@gmail.com>
- */
-class DropDatabaseDoctrineCommand extends DoctrineCommand
-{
- protected function configure()
- {
- $this
- ->setName('doctrine:database:drop')
- ->setDescription('Drop the configured databases')
- ->addOption('connection', null, InputOption::VALUE_OPTIONAL, 'The connection to use for this command')
- ->addOption('force', null, InputOption::VALUE_NONE, 'Set this parameter to execute this action')
- ->setHelp(<<<EOT
-The <info>doctrine:database:drop</info> command drops the default connections
-database:
-
-<info>php app/console doctrine:database:drop</info>
-
-The --force parameter has to be used to actually drop the database.
-
-You can also optionally specify the name of a connection to drop the database
-for:
-
-<info>php app/console doctrine:database:drop --connection=default</info>
-
-<error>Be careful: All data in a given database will be lost when executing
-this command.</error>
-EOT
- );
- }
-
- protected function execute(InputInterface $input, OutputInterface $output)
- {
- $connection = $this->getDoctrineConnection($input->getOption('connection'));
-
- $params = $connection->getParams();
-
- $name = isset($params['path']) ? $params['path'] : (isset($params['dbname']) ? $params['dbname'] : false);
-
- if (!$name) {
- throw new \InvalidArgumentException("Connection does not contain a 'path' or 'dbname' parameter and cannot be dropped.");
- }
-
- if ($input->getOption('force')) {
- try {
- $connection->getSchemaManager()->dropDatabase($name);
- $output->writeln(sprintf('<info>Dropped database for connection named <comment>%s</comment></info>', $name));
- } catch (\Exception $e) {
- $output->writeln(sprintf('<error>Could not drop database for connection named <comment>%s</comment></error>', $name));
- $output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
- }
- } else {
- $output->writeln('<error>ATTENTION:</error> This operation should not be executed in a production environment.');
- $output->writeln('');
- $output->writeln(sprintf('<info>Would drop the database named <comment>%s</comment>.</info>', $name));
- $output->writeln('Please run the operation with --force to execute');
- $output->writeln('<error>All data will be lost!</error>');
- }
- }
-}
131 src/Symfony/Bundle/DoctrineBundle/Command/GenerateEntitiesDoctrineCommand.php
View
@@ -1,131 +0,0 @@
-<?php
-
-/*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Bundle\DoctrineBundle\Command;
-
-use Symfony\Component\Console\Input\InputArgument;
-use Symfony\Component\Console\Input\InputOption;
-use Symfony\Component\Console\Input\InputInterface;
-use Symfony\Component\Console\Output\OutputInterface;
-use Doctrine\ORM\Tools\EntityRepositoryGenerator;
-use Symfony\Bundle\DoctrineBundle\Mapping\DisconnectedMetadataFactory;
-
-/**
- * Generate entity classes from mapping information
- *
- * @author Fabien Potencier <fabien@symfony.com>
- * @author Jonathan H. Wage <jonwage@gmail.com>
- */
-class GenerateEntitiesDoctrineCommand extends DoctrineCommand
-{
- protected function configure()
- {
- $this
- ->setName('doctrine:generate:entities')
- ->setAliases(array('generate:doctrine:entities'))
- ->setDescription('Generate entity classes and method stubs from your mapping information')
- ->addArgument('name', InputArgument::REQUIRED, 'A bundle name, a namespace, or a class name')
- ->addOption('path', null, InputOption::VALUE_REQUIRED, 'The path where to generate entities when it cannot be guessed')
- ->addOption('no-backup', null, InputOption::VALUE_NONE, 'Do not backup existing entities files.')
- ->setHelp(<<<EOT
-The <info>doctrine:generate:entities</info> command generates entity classes
-and method stubs from your mapping information:
-
-You have to limit generation of entities:
-
-* To a bundle:
-
- <info>php app/console doctrine:generate:entities MyCustomBundle</info>
-
-* To a single entity:
-
- <info>php app/console doctrine:generate:entities MyCustomBundle:User</info>
- <info>php app/console doctrine:generate:entities MyCustomBundle/Entity/User</info>
-
-* To a namespace
-
- <info>php app/console doctrine:generate:entities MyCustomBundle/Entity</info>
-
-If the entities are not stored in a bundle, and if the classes do not exist,
-the command has no way to guess where they should be generated. In this case,
-you must provide the <comment>--path</comment> option:
-
- <info>php app/console doctrine:generate:entities Blog/Entity --path=src/</info>
-
-By default, the unmodified version of each entity is backed up and saved
-(e.g. Product.php~). To prevent this task from creating the backup file,
-pass the <comment>--no-backup</comment> option:
-
- <info>php app/console doctrine:generate:entities Blog/Entity --no-backup</info>
-
-<error>Important:</error> Even if you specified Inheritance options in your
-XML or YAML Mapping files the generator cannot generate the base and
-child classes for you correctly, because it doesn't know which
-class is supposed to extend which. You have to adjust the entity
-code manually for inheritance to work!
-
-EOT
- );
- }
-
- protected function execute(InputInterface $input, OutputInterface $output)
- {
- $manager = new DisconnectedMetadataFactory($this->getContainer()->get('doctrine'));
-
- try {
- $bundle = $this->getApplication()->getKernel()->getBundle($input->getArgument('name'));
-
- $output->writeln(sprintf('Generating entities for bundle "<info>%s</info>"', $bundle->getName()));
- $metadata = $manager->getBundleMetadata($bundle);
- } catch (\InvalidArgumentException $e) {
- $name = strtr($input->getArgument('name'), '/', '\\');
-
- if (false !== $pos = strpos($name, ':')) {
- $name = $this->getContainer()->get('doctrine')->getEntityNamespace(substr($name, 0, $pos)).'\\'.substr($name, $pos + 1);
- }
-
- if (class_exists($name)) {
- $output->writeln(sprintf('Generating entity "<info>%s</info>"', $name));
- $metadata = $manager->getClassMetadata($name, $input->getOption('path'));
- } else {
- $output->writeln(sprintf('Generating entities for namespace "<info>%s</info>"', $name));
- $metadata = $manager->getNamespaceMetadata($name, $input->getOption('path'));
- }
- }
-
- $generator = $this->getEntityGenerator();
-
- $backupExisting = !$input->getOption('no-backup');
- $generator->setBackupExisting($backupExisting);
-
- $repoGenerator = new EntityRepositoryGenerator();
- foreach ($metadata->getMetadata() as $m) {
- if ($backupExisting) {
- $basename = substr($m->name, strrpos($m->name, '\\') + 1);
- $output->writeln(sprintf(' > backing up <comment>%s.php</comment> to <comment>%s.php~</comment>', $basename, $basename));
- }
- // Getting the metadata for the entity class once more to get the correct path if the namespace has multiple occurrences
- try {
- $entityMetadata = $manager->getClassMetadata($m->getName(), $input->getOption('path'));
- } catch (\RuntimeException $e) {
- // fall back to the bundle metadata when no entity class could be found
- $entityMetadata = $metadata;
- }
-
- $output->writeln(sprintf(' > generating <comment>%s</comment>', $m->name));
- $generator->generate(array($m), $entityMetadata->getPath());
-
- if ($m->customRepositoryClassName && false !== strpos($m->customRepositoryClassName, $metadata->getNamespace())) {
- $repoGenerator->writeEntityRepositoryClass($m->customRepositoryClassName, $metadata->getPath());
- }
- }
- }
-}
123 src/Symfony/Bundle/DoctrineBundle/Command/ImportMappingDoctrineCommand.php
View
@@ -1,123 +0,0 @@
-<?php
-
-/*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Bundle\DoctrineBundle\Command;
-
-use Symfony\Component\Console\Input\InputArgument;
-use Symfony\Component\Console\Input\InputOption;
-use Symfony\Component\Console\Input\InputInterface;
-use Symfony\Component\Console\Output\OutputInterface;
-use Doctrine\ORM\Mapping\Driver\DatabaseDriver;
-use Doctrine\ORM\Tools\DisconnectedClassMetadataFactory;
-use Doctrine\ORM\Tools\Export\ClassMetadataExporter;
-use Doctrine\ORM\Tools\Console\MetadataFilter;
-
-/**
- * Import Doctrine ORM metadata mapping information from an existing database.
- *
- * @author Fabien Potencier <fabien@symfony.com>
- * @author Jonathan H. Wage <jonwage@gmail.com>
- */
-class ImportMappingDoctrineCommand extends DoctrineCommand
-{
- protected function configure()
- {
- $this
- ->setName('doctrine:mapping:import')
- ->addArgument('bundle', InputArgument::REQUIRED, 'The bundle to import the mapping information to')
- ->addArgument('mapping-type', InputArgument::OPTIONAL, 'The mapping type to export the imported mapping information to')
- ->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command')
- ->addOption('filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'A string pattern used to match entities that should be mapped.')
- ->addOption('force', null, InputOption::VALUE_NONE, 'Force to overwrite existing mapping files.')
- ->setDescription('Import mapping information from an existing database')
- ->setHelp(<<<EOT
-The <info>doctrine:mapping:import</info> command imports mapping information
-from an existing database:
-
-<info>php app/console doctrine:mapping:import "MyCustomBundle" xml</info>
-
-You can also optionally specify which entity manager to import from with the
-<info>--em</info> option:
-
-<info>php app/console doctrine:mapping:import "MyCustomBundle" xml --em=default</info>
-
-If you don't want to map every entity that can be found in the database, use the
-<info>--filter</info> option. It will try to match the targeted mapped entity with the
-provided pattern string.
-
-<info>php app/console doctrine:mapping:import "MyCustomBundle" xml --filter=MyMatchedEntity</info>
-
-Use the <info>--force</info> option, if you want to override existing mapping files:
-
-<info>php app/console doctrine:mapping:import "MyCustomBundle" xml --force</info>
-EOT
- );
- }
-
- protected function execute(InputInterface $input, OutputInterface $output)
- {
- $bundle = $this->getApplication()->getKernel()->getBundle($input->getArgument('bundle'));
-
- $destPath = $bundle->getPath();
- $type = $input->getArgument('mapping-type') ? $input->getArgument('mapping-type') : 'xml';
- if ('annotation' === $type) {
- $destPath .= '/Entity';
- } else {
- $destPath .= '/Resources/config/doctrine';
- }
- if ('yaml' === $type) {
- $type = 'yml';
- }
-
- $cme = new ClassMetadataExporter();
- $exporter = $cme->getExporter($type);
- $exporter->setOverwriteExistingFiles($input->getOption('force'));
-
- if ('annotation' === $type) {
- $entityGenerator = $this->getEntityGenerator();
- $exporter->setEntityGenerator($entityGenerator);
- }
-
- $em = $this->getEntityManager($input->getOption('em'));
-
- $databaseDriver = new DatabaseDriver($em->getConnection()->getSchemaManager());
- $em->getConfiguration()->setMetadataDriverImpl($databaseDriver);
-
- $emName = $input->getOption('em');
- $emName = $emName ? $emName : 'default';
-
- $cmf = new DisconnectedClassMetadataFactory();
- $cmf->setEntityManager($em);
- $metadata = $cmf->getAllMetadata();
- $metadata = MetadataFilter::filter($metadata, $input->getOption('filter'));
- if ($metadata) {
- $output->writeln(sprintf('Importing mapping information from "<info>%s</info>" entity manager', $emName));
- foreach ($metadata as $class) {
- $className = $class->name;
- $class->name = $bundle->getNamespace().'\\Entity\\'.$className;
- if ('annotation' === $type) {
- $path = $destPath.'/'.$className.'.php';
- } else {
- $path = $destPath.'/'.$className.'.orm.'.$type;
- }
- $output->writeln(sprintf(' > writing <comment>%s</comment>', $path));
- $code = $exporter->exportClassMetadata($class);
- if (!is_dir($dir = dirname($path))) {
- mkdir($dir, 0777, true);
- }
- file_put_contents($path, $code);
- }
- } else {
- $output->writeln('Database does not have any mapping information.', 'ERROR');
- $output->writeln('', 'ERROR');
- }
- }
-}
86 src/Symfony/Bundle/DoctrineBundle/Command/InfoDoctrineCommand.php
View
@@ -1,86 +0,0 @@
-<?php
-
-/*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Bundle\DoctrineBundle\Command;
-
-use Doctrine\ORM\Mapping\MappingException;
-use Symfony\Component\Console\Input\InputOption;
-use Symfony\Component\Console\Input\InputInterface;
-use Symfony\Component\Console\Output\OutputInterface;
-
-/**
- * Show information about mapped entities
- *
- * @author Benjamin Eberlei <kontakt@beberlei.de>
- */
-class InfoDoctrineCommand extends DoctrineCommand
-{
- protected function configure()
- {
- $this
- ->setName('doctrine:mapping:info')
- ->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command')
- ->setDescription('Show basic information about all mapped entities')
- ->setHelp(<<<EOT
-The <info>doctrine:mapping:info</info> shows basic information about which
-entities exist and possibly if their mapping information contains errors or
-not.
-
-<info>php app/console doctrine:mapping:info</info>
-
-If you are using multiple entity managers you can pick your choice with the
-<info>--em</info> option:
-
-<info>php app/console doctrine:mapping:info --em=default</info>
-EOT
- );
- }
-
- protected function execute(InputInterface $input, OutputInterface $output)
- {
- $entityManagerName = $input->getOption('em') ? $input->getOption('em') : $this->getContainer()->get('doctrine')->getDefaultManagerName();
-
- /* @var $entityManager Doctrine\ORM\EntityManager */
- $entityManager = $this->getEntityManager($input->getOption('em'));
-
- $entityClassNames = $entityManager->getConfiguration()
- ->getMetadataDriverImpl()
- ->getAllClassNames();
-
- if (!$entityClassNames) {
- throw new \LogicException(
- 'You do not have any mapped Doctrine ORM entities for any of your bundles. '.
- 'Create a class inside the Entity namespace of any of your bundles and provide '.
- 'mapping information for it with Annotations directly in the classes doc blocks '.
- 'or with XML/YAML in your bundles Resources/config/doctrine/ directory.'
- );
- }
-
- $output->writeln(sprintf("Found <info>%d</info> entities mapped in entity manager <info>%s</info>:", count($entityClassNames), $entityManagerName));
-
- foreach ($entityClassNames as $entityClassName) {
- try {
- $cm = $entityManager->getClassMetadata($entityClassName);
- $output->writeln(sprintf("<info>[OK]</info> %s", $entityClassName));
- } catch (MappingException $e) {
- $message = $e->getMessage();
- while ($e->getPrevious()) {
- $e = $e->getPrevious();
- $message .= "\n" . $e->getMessage();
- }
-
- $output->writeln("<error>[FAIL]</error> ".$entityClassName);
- $output->writeln(sprintf("<comment>%s</comment>", $message));
- $output->writeln('');
- }
- }
- }
-}
55 src/Symfony/Bundle/DoctrineBundle/Command/Proxy/ClearMetadataCacheDoctrineCommand.php
View
@@ -1,55 +0,0 @@
-<?php
-
-/*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Bundle\DoctrineBundle\Command\Proxy;
-
-use Symfony\Component\Console\Input\InputOption;
-use Symfony\Component\Console\Input\InputInterface;
-use Symfony\Component\Console\Output\OutputInterface;
-use Doctrine\ORM\Tools\Console\Command\ClearCache\MetadataCommand;
-
-/**
- * Command to clear the metadata cache of the various cache drivers.
- *
- * @author Fabien Potencier <fabien@symfony.com>
- * @author Jonathan H. Wage <jonwage@gmail.com>
- */
-class ClearMetadataCacheDoctrineCommand extends MetadataCommand
-{
- protected function configure()
- {
- parent::configure();
-
- $this
- ->setName('doctrine:cache:clear-metadata')
- ->setDescription('Clear all metadata cache for a entity manager')
- ->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command')
- ->setHelp(<<<EOT
-The <info>doctrine:cache:clear-metadata</info> command clears all metadata
-cache for the default entity manager:
-
-<info>php app/console doctrine:cache:clear-metadata</info>
-
-You can also optionally specify the <comment>--em</comment> option to specify
-which entity manager to clear the cache for:
-
-<info>php app/console doctrine:cache:clear-metadata --em=default</info>
-EOT
- );
- }
-
- protected function execute(InputInterface $input, OutputInterface $output)
- {
- DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));
-
- return parent::execute($input, $output);
- }
-}
55 src/Symfony/Bundle/DoctrineBundle/Command/Proxy/ClearQueryCacheDoctrineCommand.php
View
@@ -1,55 +0,0 @@
-<?php
-
-/*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Bundle\DoctrineBundle\Command\Proxy;
-
-use Symfony\Component\Console\Input\InputOption;
-use Symfony\Component\Console\Input\InputInterface;
-use Symfony\Component\Console\Output\OutputInterface;
-use Doctrine\ORM\Tools\Console\Command\ClearCache\QueryCommand;
-
-/**
- * Command to clear the query cache of the various cache drivers.
- *
- * @author Fabien Potencier <fabien@symfony.com>
- * @author Jonathan H. Wage <jonwage@gmail.com>
- */
-class ClearQueryCacheDoctrineCommand extends QueryCommand
-{
- protected function configure()
- {
- parent::configure();
-
- $this
- ->setName('doctrine:cache:clear-query')
- ->setDescription('Clear all query cache for a entity manager')
- ->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command')
- ->setHelp(<<<EOT
-The <info>doctrine:cache:clear-query</info> command clears all query cache for
-the default entity manager:
-
-<info>php app/console doctrine:cache:clear-query</info>
-
-You can also optionally specify the <comment>--em</comment> option to specify
-which entity manager to clear the cache for:
-
-<info>php app/console doctrine:cache:clear-query --em=default</info>
-EOT
- );
- }
-
- protected function execute(InputInterface $input, OutputInterface $output)
- {
- DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));
-
- return parent::execute($input, $output);
- }
-}
70 src/Symfony/Bundle/DoctrineBundle/Command/Proxy/ClearResultCacheDoctrineCommand.php
View
@@ -1,70 +0,0 @@
-<?php
-
-/*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Bundle\DoctrineBundle\Command\Proxy;
-
-use Symfony\Component\Console\Input\InputOption;
-use Symfony\Component\Console\Input\InputInterface;
-use Symfony\Component\Console\Output\OutputInterface;
-use Doctrine\ORM\Tools\Console\Command\ClearCache\ResultCommand;
-
-/**
- * Command to clear the result cache of the various cache drivers.
- *
- * @author Fabien Potencier <fabien@symfony.com>
- * @author Jonathan H. Wage <jonwage@gmail.com>
- */
-class ClearResultCacheDoctrineCommand extends ResultCommand
-{
- protected function configure()
- {
- parent::configure();
-
- $this
- ->setName('doctrine:cache:clear-result')
- ->setDescription('Clear result cache for a entity manager')
- ->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command')
- ->setHelp(<<<EOT
-The <info>doctrine:cache:clear-result</info> command clears all result cache
-for the default entity manager:
-
-<info>php app/console doctrine:cache:clear-result</info>
-
-You can also optionally specify the <comment>--em</comment> option to specify
-which entity manager to clear the cache for:
-
-<info>php app/console doctrine:cache:clear-result --em=default</info>
-
-If you don't want to clear all result cache you can specify some additional
-options to control what cache is deleted:
-
-<info>php app/console doctrine:cache:clear-result --id=cache_key</info>
-
-Or you can specify a <comment>--regex</comment> to delete cache entries that
-match it:
-
-<info>php app/console doctrine:cache:clear-result --regex="user_(.*)"</info>
-
-You can also specify a <comment>--prefix</comment> or
-<comment>--suffix</comment> to delete cache entries for:
-
-<info>php app/console doctrine:cache:clear-result --prefix="user_" --suffix="_frontend"</info>
-EOT
- );
- }
-
- protected function execute(InputInterface $input, OutputInterface $output)
- {
- DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));
-
- return parent::execute($input, $output);
- }
-}
65 src/Symfony/Bundle/DoctrineBundle/Command/Proxy/ConvertMappingDoctrineCommand.php
View
@@ -1,65 +0,0 @@
-<?php
-
-/*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Bundle\DoctrineBundle\Command\Proxy;
-
-use Symfony\Component\Console\Input\InputOption;
-use Symfony\Component\Console\Input\InputInterface;
-use Symfony\Component\Console\Output\OutputInterface;
-use Symfony\Component\Console\Output\Output;
-use Doctrine\ORM\Tools\Console\Command\ConvertMappingCommand;
-use Doctrine\ORM\Tools\Export\Driver\XmlExporter;
-use Doctrine\ORM\Tools\Export\Driver\YamlExporter;
-
-/**
- * Convert Doctrine ORM metadata mapping information between the various supported
- * formats.
- *
- * @author Fabien Potencier <fabien@symfony.com>
- * @author Jonathan H. Wage <jonwage@gmail.com>
- */
-class ConvertMappingDoctrineCommand extends ConvertMappingCommand
-{
- protected function configure()
- {
- parent::configure();
- $this
- ->setName('doctrine:mapping:convert')
- ->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command')
- ->setHelp(<<<EOT
-The <info>doctrine:mapping:convert</info> command converts mapping information
-between supported formats:
-
-<info>php app/console doctrine:mapping:convert xml /path/to/output</info>
-EOT
- );
- }
-
- protected function execute(InputInterface $input, OutputInterface $output)
- {
- DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));
-
- return parent::execute($input, $output);
- }
-
-
- protected function getExporter($toType, $destPath)
- {
- $exporter = parent::getExporter($toType, $destPath);
- if ($exporter instanceof XmlExporter) {
- $exporter->setExtension('.orm.xml');
- } elseif ($exporter instanceof YamlExporter) {
- $exporter->setExtension('.orm.yml');
- }
-
- return $exporter;
- }
-}
60 src/Symfony/Bundle/DoctrineBundle/Command/Proxy/CreateSchemaDoctrineCommand.php
View
@@ -1,60 +0,0 @@
-<?php
-
-/*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Bundle\DoctrineBundle\Command\Proxy;
-
-use Symfony\Component\Console\Input\InputOption;
-use Symfony\Component\Console\Input\InputInterface;
-use Symfony\Component\Console\Output\OutputInterface;
-use Symfony\Component\Console\Output\Output;
-use Doctrine\ORM\Tools\Console\Command\SchemaTool\CreateCommand;
-
-/**
- * Command to execute the SQL needed to generate the database schema for
- * a given entity manager.
- *
- * @author Fabien Potencier <fabien@symfony.com>
- * @author Jonathan H. Wage <jonwage@gmail.com>
- */
-class CreateSchemaDoctrineCommand extends CreateCommand
-{
- protected function configure()
- {
- parent::configure();
-
- $this
- ->setName('doctrine:schema:create')
- ->setDescription('Executes (or dumps) the SQL needed to generate the database schema')
- ->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command')
- ->setHelp(<<<EOT
-The <info>doctrine:schema:create</info> command executes the SQL needed to
-generate the database schema for the default entity manager:
-
-<info>php app/console doctrine:schema:create</info>
-
-You can also generate the database schema for a specific entity manager:
-
-<info>php app/console doctrine:schema:create --em=default</info>
-
-Finally, instead of executing the SQL, you can output the SQL:
-
-<info>php app/console doctrine:schema:create --dump-sql</info>
-EOT
- );
- }
-
- protected function execute(InputInterface $input, OutputInterface $output)
- {
- DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));
-
- parent::execute($input, $output);
- }
-}
46 src/Symfony/Bundle/DoctrineBundle/Command/Proxy/DoctrineCommandHelper.php
View
@@ -1,46 +0,0 @@
-<?php
-
-/*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Bundle\DoctrineBundle\Command\Proxy;
-
-use Symfony\Component\Console\Application;
-use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper;
-use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper;
-
-/**
- * Provides some helper and convenience methods to configure doctrine commands in the context of bundles
- * and multiple connections/entity managers.
- *
- * @author Fabien Potencier <fabien@symfony.com>
- */
-abstract class DoctrineCommandHelper
-{
- /**
- * Convenience method to push the helper sets of a given entity manager into the application.
- *
- * @param Application $application
- * @param string $emName
- */
- static public function setApplicationEntityManager(Application $application, $emName)
- {
- $em = $application->getKernel()->getContainer()->get('doctrine')->getManager($emName);
- $helperSet = $application->getHelperSet();
- $helperSet->set(new ConnectionHelper($em->getConnection()), 'db');
- $helperSet->set(new EntityManagerHelper($em), 'em');
- }
-
- static public function setApplicationConnection(Application $application, $connName)
- {
- $connection = $application->getKernel()->getContainer()->get('doctrine')->getConnection($connName);
- $helperSet = $application->getHelperSet();
- $helperSet->set(new ConnectionHelper($connection), 'db');
- }
-}
60 src/Symfony/Bundle/DoctrineBundle/Command/Proxy/DropSchemaDoctrineCommand.php
View
@@ -1,60 +0,0 @@
-<?php
-
-/*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Bundle\DoctrineBundle\Command\Proxy;
-
-use Symfony\Component\Console\Input\InputOption;
-use Symfony\Component\Console\Input\InputInterface;
-use Symfony\Component\Console\Output\OutputInterface;
-use Symfony\Component\Console\Output\Output;
-use Doctrine\ORM\Tools\Console\Command\SchemaTool\DropCommand;
-
-/**
- * Command to drop the database schema for a set of classes based on their mappings.
- *
- * @author Fabien Potencier <fabien@symfony.com>
- * @author Jonathan H. Wage <jonwage@gmail.com>
- */
-class DropSchemaDoctrineCommand extends DropCommand
-{
- protected function configure()
- {
- parent::configure();
-
- $this
- ->setName('doctrine:schema:drop')
- ->setDescription('Executes (or dumps) the SQL needed to drop the current database schema')
- ->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command')
- ->setHelp(<<<EOT
-The <info>doctrine:schema:drop</info> command generates the SQL needed to
-drop the database schema of the default entity manager:
-
-<info>php app/console doctrine:schema:drop --dump-sql</info>
-
-Alternatively, you can execute the generated queries:
-
-<info>php app/console doctrine:schema:drop --force</info>
-
-You can also optionally specify the name of a entity manager to drop the
-schema for:
-
-<info>php app/console doctrine:schema:drop --em=default</info>
-EOT
- );
- }
-
- protected function execute(InputInterface $input, OutputInterface $output)
- {
- DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));
-
- parent::execute($input, $output);
- }
-}
55 src/Symfony/Bundle/DoctrineBundle/Command/Proxy/EnsureProductionSettingsDoctrineCommand.php
View
@@ -1,55 +0,0 @@
-<?php
-
-/*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Bundle\DoctrineBundle\Command\Proxy;
-
-use Symfony\Component\Console\Input\InputOption;
-use Symfony\Component\Console\Input\InputInterface;
-use Symfony\Component\Console\Output\OutputInterface;
-use Symfony\Component\Console\Output\Output;
-use Doctrine\ORM\Tools\Console\Command\EnsureProductionSettingsCommand;
-
-/**
- * Ensure the Doctrine ORM is configured properly for a production environment.
- *
- * @author Fabien Potencier <fabien@symfony.com>
- * @author Jonathan H. Wage <jonwage@gmail.com>
- */
-class EnsureProductionSettingsDoctrineCommand extends EnsureProductionSettingsCommand
-{
- protected function configure()
- {
- parent::configure();
-
- $this
- ->setName('doctrine:ensure-production-settings')
- ->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command')
- ->setHelp(<<<EOT
-The <info>doctrine:ensure-production-settings</info> command ensures that
-Doctrine is properly configured for a production environment.:
-
-<info>php app/console doctrine:ensure-production-settings</info>
-
-You can also optionally specify the <comment>--em</comment> option to specify
-which entity manager to use:
-
-<info>php app/console doctrine:ensure-production-settings --em=default</info>
-EOT
- );
- }
-
- protected function execute(InputInterface $input, OutputInterface $output)
- {
- DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));
-
- parent::execute($input, $output);
- }
-}
60 src/Symfony/Bundle/DoctrineBundle/Command/Proxy/RunDqlDoctrineCommand.php
View
@@ -1,60 +0,0 @@
-<?php
-
-/*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Bundle\DoctrineBundle\Command\Proxy;
-
-use Symfony\Component\Console\Input\InputOption;
-use Symfony\Component\Console\Input\InputInterface;
-use Symfony\Component\Console\Output\OutputInterface;
-use Symfony\Component\Console\Output\Output;
-use Doctrine\ORM\Tools\Console\Command\RunDqlCommand;
-
-/**
- * Execute a Doctrine DQL query and output the results.
- *
- * @author Fabien Potencier <fabien@symfony.com>
- * @author Jonathan H. Wage <jonwage@gmail.com>
- */
-class RunDqlDoctrineCommand extends RunDqlCommand
-{
- protected function configure()
- {
- parent::configure();
-
- $this
- ->setName('doctrine:query:dql')
- ->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command')
- ->setHelp(<<<EOT
-The <info>doctrine:query:dql</info> command executes the given DQL query and
-outputs the results:
-
-<info>php app/console doctrine:query:dql "SELECT u FROM UserBundle:User u"</info>
-
-You can also optional specify some additional options like what type of
-hydration to use when executing the query:
-
-<info>php app/console doctrine:query:dql "SELECT u FROM UserBundle:User u" --hydrate=array</info>
-
-Additionally you can specify the first result and maximum amount of results to
-show:
-
-<info>php app/console doctrine:query:dql "SELECT u FROM UserBundle:User u" --first-result=0 --max-result=30</info>
-EOT
- );
- }
-
- protected function execute(InputInterface $input, OutputInterface $output)
- {
- DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));
-
- return parent::execute($input, $output);
- }
-}
50 src/Symfony/Bundle/DoctrineBundle/Command/Proxy/RunSqlDoctrineCommand.php
View
@@ -1,50 +0,0 @@
-<?php
-
-/*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Bundle\DoctrineBundle\Command\Proxy;
-
-use Symfony\Component\Console\Input\InputOption;
-use Symfony\Component\Console\Input\InputInterface;
-use Symfony\Component\Console\Output\OutputInterface;
-use Symfony\Component\Console\Output\Output;
-use Doctrine\DBAL\Tools\Console\Command\RunSqlCommand;
-
-/**
- * Execute a SQL query and output the results.
- *
- * @author Fabien Potencier <fabien@symfony.com>
- * @author Jonathan H. Wage <jonwage@gmail.com>
- */
-class RunSqlDoctrineCommand extends RunSqlCommand
-{
- protected function configure()
- {
- parent::configure();
-
- $this
- ->setName('doctrine:query:sql')
- ->addOption('connection', null, InputOption::VALUE_OPTIONAL, 'The connection to use for this command')
- ->setHelp(<<<EOT
-The <info>doctrine:query:sql</info> command executes the given DQL query and
-outputs the results:
-
-<info>php app/console doctrine:query:sql "SELECT * from user"</info>
-EOT
- );
- }
-
- protected function execute(InputInterface $input, OutputInterface $output)
- {
- DoctrineCommandHelper::setApplicationConnection($this->getApplication(), $input->getOption('connection'));
-
- return parent::execute($input, $output);
- }
-}
64 src/Symfony/Bundle/DoctrineBundle/Command/Proxy/UpdateSchemaDoctrineCommand.php
View
@@ -1,64 +0,0 @@
-<?php
-
-/*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Bundle\DoctrineBundle\Command\Proxy;
-
-use Symfony\Component\Console\Input\InputOption;
-use Symfony\Component\Console\Input\InputInterface;
-use Symfony\Component\Console\Output\OutputInterface;
-use Symfony\Component\Console\Output\Output;
-use Doctrine\ORM\Tools\Console\Command\SchemaTool\UpdateCommand;
-
-/**
- * Command to generate the SQL needed to update the database schema to match
- * the current mapping information.
- *
- * @author Fabien Potencier <fabien@symfony.com>
- * @author Jonathan H. Wage <jonwage@gmail.com>
- */
-class UpdateSchemaDoctrineCommand extends UpdateCommand
-{
- protected function configure()
- {
- parent::configure();
-
- $this
- ->setName('doctrine:schema:update')
- ->setDescription('Executes (or dumps) the SQL needed to update the database schema to match the current mapping metadata')
- ->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command')
- ->setHelp(<<<EOT
-The <info>doctrine:schema:update</info> command generates the SQL needed to
-synchronize the database schema with the current mapping metadata of the
-default entity manager.
-
-For example, if you add metadata for a new column to an entity, this command
-would generate and output the SQL needed to add the new column to the database:
-
-<info>php app/console doctrine:schema:update --dump-sql</info>
-
-Alternatively, you can execute the generated queries:
-
-<info>php app/console doctrine:schema:update --force</info>
-
-You can also update the database schema for a specific entity manager:
-
-<info>php app/console doctrine:schema:update --em=default</info>
-EOT
- );
- }
-
- protected function execute(InputInterface $input, OutputInterface $output)
- {
- DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));
-
- parent::execute($input, $output);
- }
-}
56 src/Symfony/Bundle/DoctrineBundle/Command/Proxy/ValidateSchemaCommand.php
View
@@ -1,56 +0,0 @@
-<?php
-
-/*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Bundle\DoctrineBundle\Command\Proxy;
-
-use Symfony\Component\Console\Input\InputOption;
-use Symfony\Component\Console\Input\InputInterface;
-use Symfony\Component\Console\Output\OutputInterface;
-use Doctrine\ORM\Tools\Console\Command\ValidateSchemaCommand as DoctrineValidateSchemaCommand;
-
-/**
- * Command to run Doctrine ValidateSchema() on the current mappings.
- *
- * @author Fabien Potencier <fabien@symfony.com>
- * @author Jonathan H. Wage <jonwage@gmail.com>
- * @author Neil Katin <symfony@askneil.com>
- */
-class ValidateSchemaCommand extends DoctrineValidateSchemaCommand
-{
- protected function configure()
- {
- parent::configure();
-
- $this
- ->setName('doctrine:schema:validate')
- ->setDescription('Validate the doctrine mapping files')
- ->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command')
- ->setHelp(<<<EOT
-The <info>doctrine:schema:validate</info> checks the current mappings
-for valid forward and reverse mappings.
-
-<info>php app/console doctrine:schema:validate</info>
-
-You can also optionally specify the <comment>--em</comment> option to specify
-which entity manager use for the validation.
-
-<info>php app/console doctrine:schema:validate --em=default</info>
-EOT
- );
- }
-
- protected function execute(InputInterface $input, OutputInterface $output)
- {
- DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));
-
- return parent::execute($input, $output);
- }
-}
75 src/Symfony/Bundle/DoctrineBundle/ConnectionFactory.php
View
@@ -1,75 +0,0 @@
-<?php
-
-/*
- * This file is part of the Symfony framework.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * This source file is subject to the MIT license that is bundled
- * with this source code in the file LICENSE.
- */
-
-namespace Symfony\Bundle\DoctrineBundle;
-
-use Doctrine\Common\EventManager;
-use Doctrine\DBAL\Configuration;
-use Doctrine\DBAL\DriverManager;
-use Doctrine\DBAL\Types\Type;
-
-/**
- * Connection
- */
-class ConnectionFactory
-{
- private $typesConfig = array();
- private $initialized = false;
-
- /**
- * Construct.
- *
- * @param array $typesConfig
- */
- public function __construct(array $typesConfig)
- {
- $this->typesConfig = $typesConfig;
- }
-
- /**
- * Create a connection by name.
- *
- * @param array $params
- * @param Configuration $config
- * @param EventManager $eventManager
- *
- * @return Doctrine\DBAL\Connection
- */
- public function createConnection(array $params, Configuration $config = null, EventManager $eventManager = null, array $mappingTypes = array())
- {
- if (!$this->initialized) {
- $this->initializeTypes();
- $this->initialized = true;
- }
-
- $connection = DriverManager::getConnection($params, $config, $eventManager);
-
- if (!empty($mappingTypes)) {
- $platform = $connection->getDatabasePlatform();
- foreach ($mappingTypes as $dbType => $doctrineType) {
- $platform->registerDoctrineTypeMapping($dbType, $doctrineType);
- }
- }
-
- return $connection;
- }
-
- private function initializeTypes()
- {
- foreach ($this->typesConfig as $type => $className) {
- if (Type::hasType($type)) {
- Type::overrideType($type, $className);
- } else {
- Type::addType($type, $className);
- }
- }
- }
-}
105 src/Symfony/Bundle/DoctrineBundle/DependencyInjection/Compiler/RegisterEventListenersAndSubscribersPass.php
View
@@ -1,105 +0,0 @@
-<?php
-
-/*
- * This file is part of the Symfony framework.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * This source file is subject to the MIT license that is bundled
- * with this source code in the file LICENSE.
- */
-
-namespace Symfony\Bundle\DoctrineBundle\DependencyInjection\Compiler;
-
-use Symfony\Component\DependencyInjection\Reference;
-use Symfony\Component\DependencyInjection\ContainerBuilder;
-use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
-
-class RegisterEventListenersAndSubscribersPass implements CompilerPassInterface
-{
- private $container;
- private $connections;
- private $eventManagers;
-
- public function process(ContainerBuilder $container)
- {
- if (!$container->hasDefinition('doctrine')) {
- return;
- }
-
- $this->container = $container;
- $this->connections = $container->getParameter('doctrine.connections');
-
- foreach ($container->findTaggedServiceIds('doctrine.event_subscriber') as $subscriberId => $instances) {
- $this->registerSubscriber($subscriberId, $instances);
- }
-
- foreach ($container->findTaggedServiceIds('doctrine.event_listener') as $listenerId => $instances) {
- $this->registerListener($listenerId, $instances);
- }
- }
-
- protected function registerSubscriber($subscriberId, $instances)
- {
- $connections = array();
- foreach ($instances as $attributes) {
- if (isset($attributes['connection'])) {
- $connections[] = $attributes['connection'];
- } else {
- $connections = array_keys($this->connections);
- break;
- }
- }
-
- foreach ($connections as $name) {
- $this->getEventManager($name, $subscriberId)->addMethodCall('addEventSubscriber', array(new Reference($subscriberId)));
- }
- }
-
- protected function registerListener($listenerId, $instances)
- {
- $connections = array();
- foreach ($instances as $attributes) {
- if (!isset($attributes['event'])) {
- throw new \InvalidArgumentException(sprintf('Doctrine event listener "%s" must specify the "event" attribute.', $listenerId));
- }
-
- if (isset($attributes['connection'])) {
- $cs = array($attributes['connection']);
- } else {
- $cs = array_keys($this->connections);
- }
-
- foreach ($cs as $connection) {
- if (!isset($connections[$connection]) || !is_array($connections[$connection])) {
- $connections[$connection] = array();
- }
- $connections[$connection][] = $attributes['event'];
- }
- }
-
- foreach ($connections as $name => $events) {
- $this->getEventManager($name, $listenerId)->addMethodCall('addEventListener', array(
- array_unique($events),
- new Reference($listenerId),
- ));
- }
- }
-
- private function getEventManager($name, $listenerId = null)
- {
- if (null === $this->eventManagers) {
- $this->eventManagers = array();
- foreach ($this->connections as $n => $id) {
- $arguments = $this->container->getDefinition($id)->getArguments();
- $this->eventManagers[$n] = $this->container->getDefinition((string) $arguments[2]);
- }
- }
-
- if (!isset($this->eventManagers[$name])) {
- throw new \InvalidArgumentException(sprintf('Doctrine connection "%s" does not exist but is referenced in the "%s" event listener.', $name, $listenerId));
- }
-
- return $this->eventManagers[$name];
- }
-}
289 src/Symfony/Bundle/DoctrineBundle/DependencyInjection/Configuration.php
View
@@ -1,289 +0,0 @@
-<?php
-
-/*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Bundle\DoctrineBundle\DependencyInjection;
-
-use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
-use Symfony\Component\Config\Definition\Builder\TreeBuilder;
-use Symfony\Component\Config\Definition\ConfigurationInterface;
-
-/**
- * This class contains the configuration information for the bundle
- *
- * This information is solely responsible for how the different configuration
- * sections are normalized, and merged.
- *
- * @author Christophe Coevoet <stof@notk.org>
- */
-class Configuration implements ConfigurationInterface
-{
- private $debug;
-
- /**
- * Constructor
- *
- * @param Boolean $debug Whether to use the debug mode
- */
- public function __construct($debug)
- {
- $this->debug = (Boolean) $debug;
- }
-
- /**
- * Generates the configuration tree builder.
- *
- * @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder
- */
- public function getConfigTreeBuilder()
- {
- $treeBuilder = new TreeBuilder();
- $rootNode = $treeBuilder->root('doctrine');
-
- $this->addDbalSection($rootNode);
- $this->addOrmSection($rootNode);
-
- return $treeBuilder;
- }
-
- private function addDbalSection(ArrayNodeDefinition $node)
- {
- $node
- ->children()
- ->arrayNode('dbal')
- ->beforeNormalization()
- ->ifTrue(function ($v) { return is_array($v) && !array_key_exists('connections', $v) && !array_key_exists('connection', $v); })
- ->then(function ($v) {
- $connection = array();
- foreach (array(
- 'dbname',
- 'host',
- 'port',
- 'user',
- 'password',
- 'driver',
- 'driver_class',
- 'options',
- 'path',
- 'memory',
- 'unix_socket',
- 'wrapper_class',
- 'platform_service',
- 'charset',
- 'logging',
- 'profiling',
- 'mapping_types',
- ) as $key) {
- if (array_key_exists($key, $v)) {
- $connection[$key] = $v[$key];
- unset($v[$key]);
- }
- }
- $v['default_connection'] = isset($v['default_connection']) ? (string) $v['default_connection'] : 'default';
- $v['connections'] = array($v['default_connection'] => $connection);
-
- return $v;
- })
- ->end()
- ->children()
- ->scalarNode('default_connection')->end()
- ->end()
- ->fixXmlConfig('type')
- ->children()
- ->arrayNode('types')
- ->useAttributeAsKey('name')
- ->prototype('scalar')->end()
- ->end()
- ->end()
- ->fixXmlConfig('connection')
- ->append($this->getDbalConnectionsNode())
- ->end()
- ;
- }
-
- private function getDbalConnectionsNode()
- {
- $treeBuilder = new TreeBuilder();
- $node = $treeBuilder->root('connections');
-
- $node
- ->requiresAtLeastOneElement()
- ->useAttributeAsKey('name')
- ->prototype('array')
- ->fixXmlConfig('mapping_type')
- ->children()
- ->scalarNode('dbname')->end()
- ->scalarNode('host')->defaultValue('localhost')->end()
- ->scalarNode('port')->defaultNull()->end()
- ->scalarNode('user')->defaultValue('root')->end()
- ->scalarNode('password')->defaultNull()->end()
- ->scalarNode('driver')->defaultValue('pdo_mysql')->end()
- ->scalarNode('path')->end()
- ->booleanNode('memory')->end()
- ->scalarNode('unix_socket')->end()
- ->scalarNode('platform_service')->end()
- ->scalarNode('charset')->end()
- ->booleanNode('logging')->defaultValue($this->debug)->end()
- ->booleanNode('profiling')->defaultValue($this->debug)->end()
- ->scalarNode('driver_class')->end()
- ->scalarNode('wrapper_class')->end()
- ->arrayNode('options')
- ->useAttributeAsKey('key')
- ->prototype('scalar')->end()
- ->end()
- ->arrayNode('mapping_types')
- ->useAttributeAsKey('name')
- ->prototype('scalar')->end()
- ->end()
- ->end()
- ->end()
- ;
-
- return $node;
- }
-
- private function addOrmSection(ArrayNodeDefinition $node)
- {
- $node
- ->children()
- ->arrayNode('orm')
- ->beforeNormalization()
- ->ifTrue(function ($v) { return null === $v || (is_array($v) && !array_key_exists('entity_managers', $v) && !array_key_exists('entity_manager', $v)); })
- ->then(function ($v) {
- $v = (array) $v;
- $entityManager = array();
- foreach (array(
- 'result_cache_driver', 'result-cache-driver',
- 'metadata_cache_driver', 'metadata-cache-driver',
- 'query_cache_driver', 'query-cache-driver',
- 'auto_mapping', 'auto-mapping',
- 'mappings', 'mapping',
- 'connection', 'dql'
- ) as $key) {
- if (array_key_exists($key, $v)) {
- $entityManager[$key] = $v[$key];
- unset($v[$key]);
- }
- }
- $v['default_entity_manager'] = isset($v['default_entity_manager']) ? (string) $v['default_entity_manager'] : 'default';
- $v['entity_managers'] = array($v['default_entity_manager'] => $entityManager);
-
- return $v;
- })
- ->end()
- ->children()
- ->scalarNode('default_entity_manager')->end()
- ->booleanNode('auto_generate_proxy_classes')->defaultFalse()->end()
- ->scalarNode('proxy_dir')->defaultValue('%kernel.cache_dir%/doctrine/orm/Proxies')->end()
- ->scalarNode('proxy_namespace')->defaultValue('Proxies')->end()
- ->end()
- ->fixXmlConfig('entity_manager')
- ->append($this->getOrmEntityManagersNode())
- ->end()
- ->end()
- ;
- }
-
- private function getOrmEntityManagersNode()
- {
- $treeBuilder = new TreeBuilder();
- $node = $treeBuilder->root('entity_managers');
-
- $node
- ->requiresAtLeastOneElement()
- ->useAttributeAsKey('name')
- ->prototype('array')
- ->addDefaultsIfNotSet()
- ->append($this->getOrmCacheDriverNode('query_cache_driver'))
- ->append($this->getOrmCacheDriverNode('metadata_cache_driver'))
- ->append($this->getOrmCacheDriverNode('result_cache_driver'))
- ->children()
- ->scalarNode('connection')->end()
- ->scalarNode('class_metadata_factory_name')->defaultValue('Doctrine\ORM\Mapping\ClassMetadataFactory')->end()
- ->scalarNode('auto_mapping')->defaultFalse()->end()
- ->end()
- ->fixXmlConfig('hydrator')
- ->children()
- ->arrayNode('hydrators')
- ->useAttributeAsKey('name')
- ->prototype('scalar')->end()
- ->end()
- ->end()
- ->fixXmlConfig('mapping')
- ->children()
- ->arrayNode('mappings')
- ->useAttributeAsKey('name')
- ->prototype('array')
- ->beforeNormalization()
- ->ifString()
- ->then(function($v) { return array('type' => $v); })
- ->end()
- ->treatNullLike(array())
- ->treatFalseLike(array('mapping' => false))
- ->performNoDeepMerging()
- ->children()
- ->scalarNode('mapping')->defaultValue(true)->end()
- ->scalarNode('type')->end()
- ->scalarNode('dir')->end()
- ->scalarNode('alias')->end()
- ->scalarNode('prefix')->end()
- ->booleanNode('is_bundle')->end()
- ->end()
- ->end()
- ->end()
- ->arrayNode('dql')
- ->fixXmlConfig('string_function')
- ->fixXmlConfig('numeric_function')
- ->fixXmlConfig('datetime_function')
- ->children()
- ->arrayNode('string_functions')
- ->useAttributeAsKey('name')
- ->prototype('scalar')->end()
- ->end()
- ->arrayNode('numeric_functions')
- ->useAttributeAsKey('name')
- ->prototype('scalar')->end()
- ->end()
- ->arrayNode('datetime_functions')
- ->useAttributeAsKey('name')
- ->prototype('scalar')->end()
- ->end()
- ->end()
- ->end()
- ->end()
- ->end()
- ;
-
- return $node;
- }
-
- private function getOrmCacheDriverNode($name)
- {
- $treeBuilder = new TreeBuilder();
- $node = $treeBuilder->root($name);
-
- $node
- ->addDefaultsIfNotSet()
- ->beforeNormalization()
- ->ifString()
- ->then(function($v) { return array('type' => $v); })
- ->end()
- ->children()
- ->scalarNode('type')->defaultValue('array')->isRequired()->end()
- ->scalarNode('host')->end()
- ->scalarNode('port')->end()
- ->scalarNode('instance_class')->end()
- ->scalarNode('class')->end()
- ->end()
- ;
-
- return $node;
- }
-}
430 src/Symfony/Bundle/DoctrineBundle/DependencyInjection/DoctrineExtension.php
View
@@ -1,430 +0,0 @@
-<?php
-
-/*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Bundle\DoctrineBundle\DependencyInjection;
-
-use Symfony\Component\DependencyInjection\Alias;
-use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
-use Symfony\Component\DependencyInjection\ContainerBuilder;
-use Symfony\Component\DependencyInjection\Definition;
-use Symfony\Component\DependencyInjection\DefinitionDecorator;
-use Symfony\Component\DependencyInjection\Reference;
-use Symfony\Bridge\Doctrine\DependencyInjection\AbstractDoctrineExtension;
-use Symfony\Component\Config\FileLocator;
-
-/**
- * DoctrineExtension is an extension for the Doctrine DBAL and ORM library.
- *
- * @author Jonathan H. Wage <jonwage@gmail.com>
- * @author Fabien Potencier <fabien@symfony.com>
- * @author Benjamin Eberlei <kontakt@beberlei.de>
- */
-class DoctrineExtension extends AbstractDoctrineExtension
-{
- public function load(array $configs, ContainerBuilder $container)
- {
- $configuration = $this->getConfiguration($configs, $container);
- $config = $this->processConfiguration($configuration, $configs);
-
- if (!empty($config['dbal'])) {
- $this->dbalLoad($config['dbal'], $container);
- }
-
- if (!empty($config['orm'])) {
- $this->ormLoad($config['orm'], $container);
- }
- }
-
- /**
- * Loads the DBAL configuration.
- *
- * Usage example:
- *
- * <doctrine:dbal id="myconn" dbname="sfweb" user="root" />
- *
- * @param array $config An array of configuration settings
- * @param ContainerBuilder $container A ContainerBuilder instance
- */
- protected function dbalLoad(array $config, ContainerBuilder $container)
- {
- $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
- $loader->load('dbal.xml');
-
- if (empty($config['default_connection'])) {
- $keys = array_keys($config['connections']);
- $config['default_connection'] = reset($keys);
- }
- $this->defaultConnection = $config['default_connection'];
-
- $container->setAlias('database_connection', sprintf('doctrine.dbal.%s_connection', $this->defaultConnection));
- $container->setAlias('doctrine.dbal.event_manager', new Alias(sprintf('doctrine.dbal.%s_connection.event_manager', $this->defaultConnection), false));
-
- $container->setParameter('doctrine.dbal.connection_factory.types', $config['types']);
-
- $connections = array();
- foreach (array_keys($config['connections']) as $name) {
- $connections[$name] = sprintf('doctrine.dbal.%s_connection', $name);
- }
- $container->setParameter('doctrine.connections', $connections);
- $container->setParameter('doctrine.default_connection', $this->defaultConnection);
-
- foreach ($config['connections'] as $name => $connection) {
- $this->loadDbalConnection($name, $connection, $container);
- }
- }
-
- /**
- * Loads a configured DBAL connection.
- *
- * @param string $name The name of the connection
- * @param array $connection A dbal connection configuration.
- * @param ContainerBuilder $container A ContainerBuilder instance
- */
- protected function loadDbalConnection($name, array $connection, ContainerBuilder $container)
- {
- // configuration
- $configuration = $container->setDefinition(sprintf('doctrine.dbal.%s_connection.configuration', $name), new DefinitionDecorator('doctrine.dbal.connection.configuration'));
- $logger = null;
- if ($connection['logging']) {
- $logger = new Reference('doctrine.dbal.logger');
- }
- unset ($connection['logging']);
- if ($connection['profiling']) {
- $logger = $logger ? new Reference('doctrine.dbal.logger.chain') : new Reference('doctrine.dbal.logger.profiling');
- }
- unset($connection['profiling']);
-
- if ($logger) {
- $configuration->addMethodCall('setSQLLogger', array($logger));
- }
-
- // event manager
- $def = $container->setDefinition(sprintf('doctrine.dbal.%s_connection.event_manager', $name), new DefinitionDecorator('doctrine.dbal.connection.event_manager'));
-
- // connection
- if (isset($connection['charset'])) {
- if ((isset($connection['driver']) && stripos($connection['driver'], 'mysql') !== false) ||
- (isset($connection['driver_class']) && stripos($connection['driver_class'], 'mysql') !== false)) {
- $mysqlSessionInit = new Definition('%doctrine.dbal.events.mysql_session_init.class%');
- $mysqlSessionInit->setArguments(array($connection['charset']));
- $mysqlSessionInit->setPublic(false);
- $mysqlSessionInit->addTag('doctrine.event_subscriber', array('connection' => $name));
-
- $container->setDefinition(
- sprintf('doctrine.dbal.%s_connection.events.mysqlsessioninit', $name),
- $mysqlSessionInit
- );
- unset($connection['charset']);
- }
- }
-
- $options = $this->getConnectionOptions($connection);
-
- $container
- ->setDefinition(sprintf('doctrine.dbal.%s_connection', $name), new DefinitionDecorator('doctrine.dbal.connection'))
- ->setArguments(array(
- $options,
- new Reference(sprintf('doctrine.dbal.%s_connection.configuration', $name)),
- new Reference(sprintf('doctrine.dbal.%s_connection.event_manager', $name)),
- $connection['mapping_types'],
- ))
- ;
- }
-
- protected function getConnectionOptions($connection)
- {
- $options = $connection;
-
- if (isset($options['platform_service'])) {
- $options['platform'] = new Reference($options['platform_service']);
- unset($options['platform_service']);
- }
- unset($options['mapping_types']);
-
- foreach (array(
- 'options' => 'driverOptions',
- 'driver_class' => 'driverClass',
- 'wrapper_class' => 'wrapperClass',
- ) as $old => $new) {
- if (isset($options[$old])) {
- $options[$new] = $options[$old];
- unset($options[$old]);
- }
- }
-
- return $options;
- }
-
- /**
- * Loads the Doctrine ORM configuration.
- *
- * Usage example:
- *
- * <doctrine:orm id="mydm" connection="myconn" />
- *
- * @param array $config An array of configuration settings
- * @param ContainerBuilder $container A ContainerBuilder instance
- */
- protected function ormLoad(array $config, ContainerBuilder $container)
- {
- $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
- $loader->load('orm.xml');
-
- $this->entityManagers = array();
- foreach (array_keys($config['entity_managers']) as $name) {
- $this->entityManagers[$name] = sprintf('doctrine.orm.%s_entity_manager', $name);
- }
- $container->setParameter('doctrine.entity_managers', $this->entityManagers);
-
- if (empty($config['default_entity_manager'])) {
- $tmp = array_keys($this->entityManagers);
- $config['default_entity_manager'] = reset($tmp);
- }
- $container->setParameter('doctrine.default_entity_manager', $config['default_entity_manager']);
-
- $options = array('auto_generate_proxy_classes', 'proxy_dir', 'proxy_namespace');
- foreach ($options as $key) {
- $container->setParameter('doctrine.orm.'.$key, $config[$key]);
- }
-
- $container->setAlias('doctrine.orm.entity_manager', sprintf('doctrine.orm.%s_entity_manager', $config['default_entity_manager']));
-
- foreach ($config['entity_managers'] as $name => $entityManager) {
- $entityManager['name'] = $name;
- $this->loadOrmEntityManager($entityManager, $container);
- }
- }
-
- /**
- * Loads a configured ORM entity manager.
- *
- * @param array $entityManager A configured ORM entity manager.
- * @param ContainerBuilder $container A ContainerBuilder instance
- */
- protected function loadOrmEntityManager(array $entityManager, ContainerBuilder $container)
- {
- if ($entityManager['auto_mapping'] && count($this->entityManagers) > 1) {
- throw new \LogicException('You cannot enable "auto_mapping" when several entity managers are defined.');
- }
-
- $ormConfigDef = $container->setDefinition(sprintf('doctrine.orm.%s_configuration', $entityManager['name']), new DefinitionDecorator('doctrine.orm.configuration'));
-
- $this->loadOrmEntityManagerMappingInformation($entityManager, $ormConfigDef, $container);
- $this->loadOrmCacheDrivers($entityManager, $container);
-
- $methods = array(
- 'setMetadataCacheImpl' => new Reference(sprintf('doctrine.orm.%s_metadata_cache', $entityManager['name'])),
- 'setQueryCacheImpl' => new Reference(sprintf('doctrine.orm.%s_query_cache', $entityManager['name'])),
- 'setResultCacheImpl' => new Reference(sprintf('doctrine.orm.%s_result_cache', $entityManager['name'])),
- 'setMetadataDriverImpl' => new Reference('doctrine.orm.'.$entityManager['name'].'_metadata_driver'),
- 'setProxyDir' => '%doctrine.orm.proxy_dir%',
- 'setProxyNamespace' => '%doctrine.orm.proxy_namespace%',
- 'setAutoGenerateProxyClasses' => '%doctrine.orm.auto_generate_proxy_classes%',
- 'setClassMetadataFactoryName' => $entityManager['class_metadata_factory_name'],
- );
- foreach ($methods as $method => $arg) {
- $ormConfigDef->addMethodCall($method, array($arg));
- }
-
- foreach ($entityManager['hydrators'] as $name => $class) {
- $ormConfigDef->addMethodCall('addCustomHydrationMode', array($name, $class));
- }
-
- if (!empty($entityManager['dql'])) {
- foreach ($entityManager['dql']['string_functions'] as $name => $function) {
- $ormConfigDef->addMethodCall('addCustomStringFunction', array($name, $function));
- }
- foreach ($entityManager['dql']['numeric_functions'] as $name => $function) {
- $ormConfigDef->addMethodCall('addCustomNumericFunction', array($name, $function));
- }
- foreach ($entityManager['dql']['datetime_functions'] as $name => $function) {
- $ormConfigDef->addMethodCall('addCustomDatetimeFunction', array($name, $function));
- }
- }
-
- if (!isset($entityManager['connection'])) {
- $entityManager['connection'] = $this->defaultConnection;
- }
-
- $container
- ->setDefinition(sprintf('doctrine.orm.%s_entity_manager', $entityManager['name']), new DefinitionDecorator('doctrine.orm.entity_manager.abstract'))
- ->setArguments(array(
- new Reference(sprintf('doctrine.dbal.%s_connection', $entityManager['connection'])),
- new Reference(sprintf('doctrine.orm.%s_configuration', $entityManager['name']))
- ))
- ;
-
- $container->setAlias(
- sprintf('doctrine.orm.%s_entity_manager.event_manager', $entityManager['name']),
- new Alias(sprintf('doctrine.dbal.%s_connection.event_manager', $entityManager['connection']), false)
- );
- }
-
- /**
- * Loads an ORM entity managers bundle mapping information.
- *
- * There are two distinct configuration possibilities for mapping information:
- *
- * 1. Specify a bundle and optionally details where the entity and mapping information reside.
- * 2. Specify an arbitrary mapping location.
- *
- * @example
- *
- * doctrine.orm:
- * mappings:
- * MyBundle1: ~
- * MyBundle2: yml
- * MyBundle3: { type: annotation, dir: Entities/ }
- * MyBundle4: { type: xml, dir: Resources/config/doctrine/mapping }
- * MyBundle5:
- * type: yml
- * dir: [bundle-mappings1/, bundle-mappings2/]
- * alias: BundleAlias
- * arbitrary_key:
- * type: xml
- * dir: %kernel.dir%/../src/vendor/DoctrineExtensions/lib/DoctrineExtensions/Entities
- * prefix: DoctrineExtensions\Entities\
- * alias: DExt
- *
- * In the case of bundles everything is really optional (which leads to autodetection for this bundle) but
- * in the mappings key everything except alias is a required argument.
- *
- * @param array $entityManager A configured ORM entity manager
- * @param Definition $ormConfigDef A Definition instance
- * @param ContainerBuilder $container A ContainerBuilder instance
- */
- protected function loadOrmEntityManagerMappingInformation(array $entityManager, Definition $ormConfigDef, ContainerBuilder $container)
- {
- // reset state of drivers and alias map. They are only used by this methods and children.
- $this->drivers = array();
- $this->aliasMap = array();
-
- $this->loadMappingInformation($entityManager, $container);
- $this->registerMappingDrivers($entityManager, $container);
-
- $ormConfigDef->addMethodCall('setEntityNamespaces', array($this->aliasMap));
- }
-
- protected function getObjectManagerElementName($name)
- {
- return 'doctrine.orm.'.$name;
- }
-
- protected function getMappingObjectDefaultName()
- {
- return 'Entity';
- }
-
- protected function getMappingResourceConfigDirectory()
- {
- return 'Resources/config/doctrine';
- }
-
- protected function getMappingResourceExtension()
- {
- return 'orm';
- }
-
- /**
- * Loads a configured entity managers cache drivers.
- *
- * @param array $entityManager A configured ORM entity manager.
- * @param ContainerBuilder $container A ContainerBuilder instance
- */
- protected function loadOrmCacheDrivers(array $entityManager, ContainerBuilder $container)
- {
- $this->loadOrmEntityManagerCacheDriver($entityManager, $container, 'metadata_cache');
- $this->loadOrmEntityManagerCacheDriver($entityManager, $container, 'result_cache');
- $this->loadOrmEntityManagerCacheDriver($entityManager, $container, 'query_cache');
- }
-
- /**
- * Loads a configured entity managers metadata, query or result cache driver.
- *
- * @param array $entityManager A configured ORM entity manager.
- * @param ContainerBuilder $container A ContainerBuilder instance
- * @param string $cacheName
- */
- protected function loadOrmEntityManagerCacheDriver(array $entityManager, ContainerBuilder $container, $cacheName)
- {
- $cacheDriverService = sprintf('doctrine.orm.%s_%s', $entityManager['name'], $cacheName);
-
- $driver = $cacheName."_driver";
- $cacheDef = $this->getEntityManagerCacheDefinition($entityManager, $entityManager[$driver], $container);
- $container->setDefinition($cacheDriverService, $cacheDef);
- }
-
- /**
- * Gets an entity manager cache driver definition for metadata, query and result caches.
- *
- * @param array $entityManager The array configuring an entity manager.
- * @param array $cacheDriver The cache driver configuration.
- * @param ContainerBuilder $container
- * @return Definition $cacheDef
- */
- protected function getEntityManagerCacheDefinition(array $entityManager, $cacheDriver, ContainerBuilder $container)
- {
- switch ($cacheDriver['type']) {
- case 'memcache':
- $memcacheClass = !empty($cacheDriver['class']) ? $cacheDriver['class'] : '%doctrine.orm.cache.memcache.class%';
- $memcacheInstanceClass = !empty($cacheDriver['instance_class']) ? $cacheDriver['instance_class'] : '%doctrine.orm.cache.memcache_instance.class%';
- $memcacheHost = !empty($cacheDriver['host']) ? $cacheDriver['host'] : '%doctrine.orm.cache.memcache_host%';
- $memcachePort = !empty($cacheDriver['port']) ? $cacheDriver['port'] : '%doctrine.orm.cache.memcache_port%';
- $cacheDef = new Definition($memcacheClass);
- $memcacheInstance = new Definition($memcacheInstanceClass);
- $memcacheInstance->addMethodCall('connect', array(
- $memcacheHost, $memcachePort
- ));
- $container->setDefinition(sprintf('doctrine.orm.%s_memcache_instance', $entityManager['name']), $memcacheInstance);
- $cacheDef->addMethodCall('setMemcache', array(new Reference(sprintf('doctrine.orm.%s_memcache_instance', $entityManager['name']))));
- break;
- case 'apc':
- case 'array':
- case 'xcache':
- $cacheDef = new Definition('%'.sprintf('doctrine.orm.cache.%s.class', $cacheDriver['type']).'%');
- break;
- default:
- throw new \InvalidArgumentException(sprintf('"%s" is an unrecognized Doctrine cache driver.', $cacheDriver['type']));
- }
-
- $cacheDef->setPublic(false);
- // generate a unique namespace for the given application
- $namespace = 'sf2orm_'.$entityManager['name'].'_'.md5($container->getParameter('kernel.root_dir').$container->getParameter('kernel.environment'));
- $cacheDef->addMethodCall('setNamespace', array($namespace));