Doctrine2 CLI for CodeIgniter2


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2. chdir(dirname(__FILE__) . '/libraries');
  3.  
  4. require_once 'Doctrine/Common/ClassLoader.php';
  5.  
  6. $classLoader = new \Doctrine\Common\ClassLoader('Doctrine');
  7. $classLoader->register();
  8.  
  9. $classLoader = new \Doctrine\Common\ClassLoader('Symfony', 'Doctrine');
  10. $classLoader->register();
  11.  
  12. $configFile = '../cli-config.php';
  13. $helperSet = null;
  14. if (file_exists($configFile)) {
  15. if ( ! is_readable($configFile)) {
  16. 'Configuration file [' . $configFile . '] does not have read permission.', E_ERROR
  17. );
  18. }
  19.  
  20. require $configFile;
  21.  
  22. foreach ($GLOBALS as $helperSetCandidate) {
  23. if ($helperSetCandidate instanceof \Symfony\Component\Console\Helper\HelperSet) {
  24. $helperSet = $helperSetCandidate;
  25. break;
  26. }
  27. }
  28. }
  29.  
  30. $helperSet = ($helperSet) ?: new \Symfony\Component\Console\Helper\HelperSet();
  31.  
  32. $cli = new \Symfony\Component\Console\Application('Doctrine Command Line Interface', Doctrine\ORM\Version::VERSION);
  33. $cli->setCatchExceptions(true);
  34. $cli->setHelperSet($helperSet);
  35. $cli->addCommands(array(
  36. // DBAL Commands
  37. new \Doctrine\DBAL\Tools\Console\Command\RunSqlCommand(),
  38. new \Doctrine\DBAL\Tools\Console\Command\ImportCommand(),
  39.  
  40. // ORM Commands
  41. new \Doctrine\ORM\Tools\Console\Command\ClearCache\MetadataCommand(),
  42. new \Doctrine\ORM\Tools\Console\Command\ClearCache\ResultCommand(),
  43. new \Doctrine\ORM\Tools\Console\Command\ClearCache\QueryCommand(),
  44. new \Doctrine\ORM\Tools\Console\Command\SchemaTool\CreateCommand(),
  45. new \Doctrine\ORM\Tools\Console\Command\SchemaTool\UpdateCommand(),
  46. new \Doctrine\ORM\Tools\Console\Command\SchemaTool\DropCommand(),
  47. new \Doctrine\ORM\Tools\Console\Command\EnsureProductionSettingsCommand(),
  48. new \Doctrine\ORM\Tools\Console\Command\ConvertDoctrine1SchemaCommand(),
  49. new \Doctrine\ORM\Tools\Console\Command\GenerateRepositoriesCommand(),
  50. new \Doctrine\ORM\Tools\Console\Command\GenerateEntitiesCommand(),
  51. new \Doctrine\ORM\Tools\Console\Command\GenerateProxiesCommand(),
  52. new \Doctrine\ORM\Tools\Console\Command\ConvertMappingCommand(),
  53. new \Doctrine\ORM\Tools\Console\Command\RunDqlCommand(),
  54. new \Doctrine\ORM\Tools\Console\Command\ValidateSchemaCommand(),
  55.  
  56. ));
  57. $cli->run();

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.