<?php /** vendor/bin/doctrine looks for a config/cli-config.php file in the project - so that's why this is here **/ /** If the bootstrap (Aurex.php) sees this variable, don't 'run' the HTTP front-controller **/ $cli = true; require_once __DIR__ . '/vendor/autoload.php'; require_once __DIR__ . '/web/index.php'; use Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain, Symfony\Component\Console\Application as CliApplication, Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper, Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper, UseAllFive\Command\LoadDataFixturesDoctrineCommand, Doctrine\Common\Annotations\AnnotationRegistry, Doctrine\ORM\Mapping\Driver\AnnotationDriver, Doctrine\Common\Annotations\AnnotationReader, Symfony\Component\Console\Helper\HelperSet, Doctrine\ORM\Mapping\Driver\DatabaseDriver, Doctrine\ORM\Tools\Console\Command, Doctrine\DBAL\Connection, Doctrine\DBAL\Version; /** @var Connection $db The above bootstrap creates the app object for us */ $db = $aurex['db']; /** @var Doctrine\ORM\EntityManager $em The entity manager */ $em = $aurex['orm.em']; $driver = new DatabaseDriver($db->getSchemaManager()); $driver->setNamespace('Aurex\\Application\\Entity\\'); $annotationsFile = __DIR__ . '/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php'; AnnotationRegistry::registerFile($annotationsFile); $driverChain = new MappingDriverChain(); $driverChain->addDriver(new AnnotationDriver(new AnnotationReader(), [__DIR__ . '/lib/Application/Model/Entity']), 'Aurex\\Application\\Model\\Entity\\'); $em->getConfiguration()->setMetadataDriverImpl($driverChain); /** @var Symfony\Component\Console\Application $cli */ $cli = new CliApplication('Doctrine Command Line Interface', Version::VERSION); $cli->setCatchExceptions(true); $cli->setHelperSet(new HelperSet(['db' => new ConnectionHelper($em->getConnection()), 'em' => new EntityManagerHelper($em)])); $cli->addCommands([new Command\GenerateRepositoriesCommand(), new Command\GenerateEntitiesCommand(), new Command\ConvertMappingCommand(), new Command\ValidateSchemaCommand(), new Command\SchemaTool\CreateCommand(), new Command\SchemaTool\UpdateCommand(), new Command\GenerateProxiesCommand(), new LoadDataFixturesDoctrineCommand()]); $cli->run();
<?php define('DIR_BASE', realpath(dirname(__FILE__) . '/..')); define('DIR_CORE', DIR_BASE . '/core'); define('DIR_CACHE', DIR_BASE . '/cache'); define('DIR_PACKAGES', DIR_BASE . '/packages'); define('DIR_URI', ''); require '../core/autoload.php'; require '../vendor/autoload.php'; use Doctrine\ORM\Tools\Setup; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Mapping\Driver\DatabaseDriver; use Doctrine\ORM\Tools\DisconnectedClassMetadataFactory; use Doctrine\ORM\Tools\Export\ClassMetadataExporter; new AutoLoad(); $dbConfig = Config::getInstance()->getValues('db'); $db = array('driver' => 'pdo_mysql', 'host' => $dbConfig->DB_HOST . ':' . $dbConfig->DB_PORT, 'user' => $dbConfig->DB_USER, 'password' => $dbConfig->DB_PASS, 'dbname' => $dbConfig->DB_NAME); $doctrineConfig = Setup::createAnnotationMetadataConfiguration(array(DIR_CACHE . '/doctrine'), $dbConfig->DB_DEV); $entityManager = EntityManager::create($db, $doctrineConfig); $entityManager->getConnection()->connect(); $databaseDriver = new DatabaseDriver($entityManager->getConnection()->getSchemaManager()); $databaseDriver->setNamespace('Models\\'); $entityManager->getConfiguration()->setMetadataDriverImpl($databaseDriver); $metadataFactory = new DisconnectedClassMetadataFactory(); $metadataFactory->setEntityManager($entityManager); $metadata = $metadataFactory->getAllMetadata(); $metadataExporter = new ClassMetadataExporter(); $exporter = $metadataExporter->getExporter('xml', DIR_CACHE . '/doctrine'); $exporter->setMetadata($metadata); $exporter->export(); echo 'Doctrine models successfully generated!';
/** * Entidades::entityManager() * * Prepara el proceso de la creacion de las entidades * @param object $configuracion * @return object */ private function entityManager($configuracion = false) { $entidad = EntityManager::create($this->confg, $configuracion); $entidad->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('set', 'string'); $entidad->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string'); // fetch metadata $driver = new DatabaseDriver($entidad->getConnection()->getSchemaManager()); $driver->setNamespace('Entidades\\' . $this->conexion . '\\'); //Agrega el namespace Entidad\Nombre de la tabla $entidad->getConfiguration()->setMetadataDriverImpl($driver); $cmf = new DisconnectedClassMetadataFactory(); $cmf->setEntityManager($entidad); // we must set the EntityManager $classes = $driver->getAllClassNames(); $metadata = array(); foreach ($classes as $class) { //any unsupported table/schema could be handled here to exclude some classes if (true) { $metadata[] = $cmf->getMetadataFor($class); } } $this->generador($metadata); }
<?php require_once dirname(__DIR__) . '/vendor/autoload.php'; /** @var boolean $cli If the bootstrap (/web/index.php) sees this variable, don't 'run' the HTTP front-controller */ $cli = true; require_once dirname(__DIR__) . '/web/index.php'; use Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain, Symfony\Component\Console\Application as CliApplication, Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper, Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper, Doctrine\Common\Annotations\AnnotationRegistry, Doctrine\ORM\Mapping\Driver\AnnotationDriver, Doctrine\Common\Annotations\AnnotationReader, Symfony\Component\Console\Helper\HelperSet, Doctrine\ORM\Mapping\Driver\DatabaseDriver, Doctrine\ORM\Tools\Console\Command, Doctrine\DBAL\Connection, Doctrine\DBAL\Version; /** @var Connection $db The above bootstrap creates the app object for us */ $db = $app['db']; /** @var Doctrine\ORM\EntityManager $em The entity manager */ $em = $app['orm.em']; $driver = new DatabaseDriver($db->getSchemaManager()); $driver->setNamespace('App\\Entity\\'); $annotationsFile = dirname(__DIR__) . '/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php'; AnnotationRegistry::registerFile($annotationsFile); $driverChain = new MappingDriverChain(); $driverChain->addDriver(new AnnotationDriver(new AnnotationReader(), [dirname(__DIR__) . '/src/App/Model/Entity']), 'App\\Model\\Entity\\'); $em->getConfiguration()->setMetadataDriverImpl($driverChain); /** @var Symfony\Component\Console\Application $cli */ $cli = new CliApplication('Doctrine Command Line Interface', Version::VERSION); $cli->setCatchExceptions(true); $cli->setHelperSet(new HelperSet(['db' => new ConnectionHelper($em->getConnection()), 'em' => new EntityManagerHelper($em)])); $cli->addCommands([new Command\GenerateRepositoriesCommand(), new Command\GenerateEntitiesCommand(), new Command\ConvertMappingCommand(), new Command\ValidateSchemaCommand(), new Command\SchemaTool\CreateCommand(), new Command\SchemaTool\UpdateCommand(), new Command\GenerateProxiesCommand()]); $cli->run();
/** * Get metadata * * @return array */ protected function getMetadata() { $sm = $this->em->getConnection()->getSchemaManager(); $driver = new DatabaseDriver($sm); $driver->setNamespace($this->getNsEntity()); $this->em->getConfiguration()->setMetadataDriverImpl($driver); $cmf = new DisconnectedClassMetadataFactory(); $cmf->setEntityManager($this->em); $metadata = $cmf->getAllMetadata(); if (count($this->getFilter()) > 0) { $metadata = MetadataFilter::filter($metadata, $this->getFilter()); } return $metadata; }