本文整理汇总了PHP中Doctrine\ORM\Tools\DisconnectedClassMetadataFactory::getAllMetadata方法的典型用法代码示例。如果您正苦于以下问题:PHP DisconnectedClassMetadataFactory::getAllMetadata方法的具体用法?PHP DisconnectedClassMetadataFactory::getAllMetadata怎么用?PHP DisconnectedClassMetadataFactory::getAllMetadata使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\Tools\DisconnectedClassMetadataFactory
的用法示例。
在下文中一共展示了DisconnectedClassMetadataFactory::getAllMetadata方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testTest
public function testTest()
{
if (!class_exists('Symfony\\Component\\Yaml\\Yaml', true)) {
$this->markTestSkipped('Please install Symfony YAML Component into the include path of your PHP installation.');
}
$cme = new ClassMetadataExporter();
$converter = new ConvertDoctrine1Schema(__DIR__ . '/doctrine1schema');
$exporter = $cme->getExporter('yml', __DIR__ . '/convert');
$exporter->setOverwriteExistingFiles(true);
$exporter->setMetadata($converter->getMetadata());
$exporter->export();
$this->assertTrue(file_exists(__DIR__ . '/convert/User.dcm.yml'));
$this->assertTrue(file_exists(__DIR__ . '/convert/Profile.dcm.yml'));
$metadataDriver = new \Doctrine\ORM\Mapping\Driver\YamlDriver(__DIR__ . '/convert');
$em = $this->_createEntityManager($metadataDriver);
$cmf = new DisconnectedClassMetadataFactory();
$cmf->setEntityManager($em);
$metadata = $cmf->getAllMetadata();
$profileClass = $cmf->getMetadataFor('Profile');
$userClass = $cmf->getMetadataFor('User');
$this->assertEquals(2, count($metadata));
$this->assertEquals('Profile', $profileClass->name);
$this->assertEquals('User', $userClass->name);
$this->assertEquals(4, count($profileClass->fieldMappings));
$this->assertEquals(5, count($userClass->fieldMappings));
$this->assertEquals('text', $userClass->fieldMappings['clob']['type']);
$this->assertEquals('test_alias', $userClass->fieldMappings['theAlias']['columnName']);
$this->assertEquals('theAlias', $userClass->fieldMappings['theAlias']['fieldName']);
$this->assertEquals('Profile', $profileClass->associationMappings['User']['sourceEntity']);
$this->assertEquals('User', $profileClass->associationMappings['User']['targetEntity']);
$this->assertEquals('username', $userClass->table['uniqueConstraints']['username']['columns'][0]);
}
示例2: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$bundleClass = null;
$bundleDirs = $this->container->get('kernel')->getBundleDirs();
foreach ($this->container->get('kernel')->getBundles() as $bundle) {
if (strpos(get_class($bundle), $input->getArgument('bundle')) !== false) {
$tmp = dirname(str_replace('\\', '/', get_class($bundle)));
$namespace = str_replace('/', '\\', dirname($tmp));
$class = basename($tmp);
if (isset($bundleDirs[$namespace])) {
$destPath = realpath($bundleDirs[$namespace]) . '/' . $class;
$bundleClass = $class;
break;
}
}
}
$type = $input->getArgument('mapping-type') ? $input->getArgument('mapping-type') : 'xml';
if ('annotation' === $type) {
$destPath .= '/Entity';
} else {
$destPath .= '/Resources/config/doctrine/metadata/orm';
}
if ('yaml' === $type) {
$type = 'yml';
}
$cme = new ClassMetadataExporter();
$exporter = $cme->getExporter($type);
if ('annotation' === $type) {
$entityGenerator = $this->getEntityGenerator();
$exporter->setEntityGenerator($entityGenerator);
}
$emName = $input->getOption('em') ? $input->getOption('em') : 'default';
$emServiceName = sprintf('doctrine.orm.%s_entity_manager', $emName);
$em = $this->container->get($emServiceName);
$databaseDriver = new DatabaseDriver($em->getConnection()->getSchemaManager());
$em->getConfiguration()->setMetadataDriverImpl($databaseDriver);
$cmf = new DisconnectedClassMetadataFactory();
$cmf->setEntityManager($em);
$metadata = $cmf->getAllMetadata();
if ($metadata) {
$output->writeln(sprintf('Importing mapping information from "<info>%s</info>" entity manager', $emName));
foreach ($metadata as $class) {
$className = $class->name;
$class->name = $namespace . '\\' . $bundleClass . '\\Entity\\' . $className;
if ('annotation' === $type) {
$path = $destPath . '/' . $className . '.php';
} else {
$path = $destPath . '/' . str_replace('\\', '.', $class->name) . '.dcm.' . $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.' . PHP_EOL, 'ERROR');
}
}
示例3: testCreateSchema
function testCreateSchema()
{
/* @var $em \Doctrine\ORM\EntityManager */
$em = $this->app["orm.em"];
$tool = new SchemaTool($em);
//@note @doctrine générer les fichiers de classe à partir de métadonnées
/* generate entity classes */
$dmf = new DisconnectedClassMetadataFactory();
$dmf->setEntityManager($em);
$metadatas = $dmf->getAllMetadata();
//print_r($metadatas);
$generator = new EntityGenerator();
$generator->setGenerateAnnotations(TRUE);
$generator->setGenerateStubMethods(TRUE);
$generator->setRegenerateEntityIfExists(TRUE);
$generator->setUpdateEntityIfExists(TRUE);
$generator->generate($metadatas, ROOT_TEST_DIR);
$generator->setNumSpaces(4);
$this->assertFileExists(ROOT_TEST_DIR . "/Entity/Post.php");
/* @note @doctrine générer la base de donnée à partir des métadonnées */
/* @see Doctrine\ORM\Tools\Console\Command\SchemaTool\CreateCommand */
/* generate database */
$tool->dropSchema($metadatas);
$tool->createSchema($metadatas);
$post = new \Entity\Post();
$post->setTitle("the title");
$em->persist($post);
$em->flush();
$this->assertInternalType("int", $post->getId());
}
示例4: __construct
public function __construct()
{
try {
$conn = array("driver" => "pdo_mysql", "host" => "localhost", "port" => "3306", "user" => "root", "password" => "", "dbname" => "controle_gastos");
/*
var_dump(__DIR__);
var_dump(PP);
exit;
*/
$loader = new \Doctrine\Common\ClassLoader("Entities", __DIR__);
$loader->register();
$config = Setup::createAnnotationMetadataConfiguration(array("../../" . __DIR__ . "/app/models"), false);
$em = EntityManager::create($conn, $config);
$cmf = new DisconnectedClassMetadataFactory();
$cmf->setEntityManager($em);
$em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('set', 'string');
$em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');
$driver = new DatabaseDriver($em->getConnection()->getSchemaManager());
$em->getConfiguration()->setMetadataDriverImpl($driver);
$metadata = $cmf->getAllMetadata();
$generator = new EntityGenerator();
$generator->setGenerateAnnotations(true);
$generator->setGenerateStubMethods(true);
$generator->setRegenerateEntityIfExists(true);
$generator->setUpdateEntityIfExists(true);
$generator->generate($metadata, "../../" . __DIR__ . "/app/models");
} catch (\Exception $e) {
throw $e;
}
}
示例5: execute
/**
* Read declared business entities and BusinessEntityPatternPages to generate their urls
* @param InputInterface $input
* @param OutputInterface $output
*
* @return void
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$progress = $this->getHelperSet()->get('progress');
$progress->setProgressCharacter('V');
$progress->setEmptyBarCharacter('-');
$entityManager = $this->getContainer()->get('doctrine.orm.entity_manager');
$cmf = new DisconnectedClassMetadataFactory();
$cmf->setEntityManager($entityManager);
$metadatas = $cmf->getAllMetadata();
$classes = [];
$output->writeln('<info>Parse every classes to know which ones are related to Link</info>');
$progress->start($output, count($metadatas));
foreach ($metadatas as $key => $metadata) {
$progress->advance();
if ($metadata->hasAssociation('link')) {
$association = $metadata->getAssociationMapping('link');
if ('Victoire\\Bundle\\CoreBundle\\Entity\\Link' === $association['targetEntity']) {
$classes[] = $metadata;
}
}
}
$progress->finish();
$counter = 0;
if (count($classes)) {
$output->writeln('<info>Let\'s migrate</info>');
$progress->start($output, count($classes));
foreach ($classes as $class) {
$progress->advance();
//get the full universe of entities thanks to the entity repository
$objects = $entityManager->getRepository($class->name)->findAll();
foreach ($objects as $object) {
if (!$object->hasLink()) {
//Create a Link according to the legacy link trait properties
$link = new Link();
$object->setLink($link);
//fill the values
$link->setUrl($object->url);
$link->setTarget($object->target);
$link->setRoute($object->route);
$link->setRouteParameters($object->routeParameters);
$link->setPage($object->page);
$link->setLinkType($object->linkType);
$link->setAttachedWidget($object->attachedWidget);
$link->setAnalyticsTrackCode($object->analyticsTrackCode);
//persist the new link and the relation
$entityManager->persist($object);
$entityManager->persist($link);
$entityManager->flush();
$counter++;
}
}
}
$progress->finish();
$output->writeln(sprintf('<comment>Ok, %s records migrated !</comment>', $counter));
}
if (0 == $counter) {
$output->writeln('<comment>Nothing to do...</comment>');
}
}
示例6: execute
/**
* @see Console\Command\Command
*/
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
{
$em = $this->getHelper('em')->getEntityManager();
if (\Zend_Registry::isRegistered(\LoSo_Zend_Application_Bootstrap_SymfonyContainerBootstrap::getRegistryIndex()) && ($container = \Zend_Registry::get(\LoSo_Zend_Application_Bootstrap_SymfonyContainerBootstrap::getRegistryIndex())) instanceof \Symfony\Component\DependencyInjection\ContainerInterface) {
$mappingPaths = $container->getParameter('doctrine.orm.mapping_paths');
$entitiesPaths = $container->getParameter('doctrine.orm.entities_paths');
} else {
$doctrineConfig = \Zend_Registry::get('doctrine.config');
$mappingPaths = $doctrineConfig['doctrine.orm.mapping_paths'];
$entitiesPaths = $doctrineConfig['doctrine.orm.entities_paths'];
}
$cmf = new DisconnectedClassMetadataFactory($em);
$metadatas = $cmf->getAllMetadata();
foreach ($mappingPaths as $namespace => $mappingPath) {
// Process destination directory
$destPath = realpath($entitiesPaths[$namespace]);
if (!file_exists($destPath)) {
throw new \InvalidArgumentException(sprintf("Entities destination directory '<info>%s</info>' does not exist.", $destPath));
} else {
if (!is_writable($destPath)) {
throw new \InvalidArgumentException(sprintf("Entities destination directory '<info>%s</info>' does not have write permissions.", $destPath));
}
}
$moduleMetadatas = MetadataFilter::filter($metadatas, $namespace);
if (count($moduleMetadatas)) {
// Create EntityGenerator
$entityGenerator = new EntityGenerator();
$entityGenerator->setGenerateAnnotations($input->getOption('generate-annotations'));
$entityGenerator->setGenerateStubMethods($input->getOption('generate-methods'));
$entityGenerator->setRegenerateEntityIfExists($input->getOption('regenerate-entities'));
$entityGenerator->setUpdateEntityIfExists($input->getOption('update-entities'));
$entityGenerator->setNumSpaces($input->getOption('num-spaces'));
if (($extend = $input->getOption('extend')) !== null) {
$entityGenerator->setClassToExtend($extend);
}
foreach ($moduleMetadatas as $metadata) {
$output->write(sprintf('Processing entity "<info>%s</info>"', $metadata->name) . PHP_EOL);
}
// Generating Entities
$entityGenerator->generate($moduleMetadatas, $destPath);
$this->_processNamespaces($destPath, $namespace);
// Outputting information message
$output->write(sprintf('Entity classes generated to "<info>%s</INFO>"', $destPath) . PHP_EOL);
} else {
$output->write('No Metadata Classes to process.' . PHP_EOL);
}
}
/*$output->write(PHP_EOL . 'Reset database.' . PHP_EOL);
$metadatas = $em->getMetadataFactory()->getAllMetadata();
$schemaTool = new \Doctrine\ORM\Tools\SchemaTool($em);
$output->write('Dropping database schema...' . PHP_EOL);
$schemaTool->dropSchema($metadatas);
$output->write('Database schema dropped successfully!' . PHP_EOL);
$output->write('Creating database schema...' . PHP_EOL);
$schemaTool->createSchema($metadatas);
$output->write('Database schema created successfully!' . PHP_EOL);*/
}
示例7: execute
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/Base';
} 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\\Base\\' . $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);
}
$code = str_replace('private $', 'protected $', $code);
file_put_contents($path, $code);
$mainFilePath = $destPath . '/../' . $className . '.php';
$output->writeln(sprintf(' > writing <comment>%s</comment>', $mainFilePath));
file_put_contents($mainFilePath, '<?php' . "\n\n" . 'namespace ' . $bundle->getNamespace() . '\\Entity;' . "\n\n" . 'use ' . $bundle->getNamespace() . '\\Entity\\Base\\' . $className . ' as Base' . $className . ';' . "\n\n" . 'class ' . $className . ' extends Base' . $className . "\n" . '{' . "\n" . '}');
}
} else {
$output->writeln('Database does not have any mapping information.', 'ERROR');
$output->writeln('', 'ERROR');
}
}
示例8: findAllMetadatas
protected function findAllMetadatas()
{
$metadatas = array();
foreach ($this->container->get('doctrine')->getEntityManagerNames() as $id) {
$cmf = new DisconnectedClassMetadataFactory();
$cmf->setEntityManager($this->container->get($id));
foreach ($cmf->getAllMetadata() as $metadata) {
$metadatas[$metadata->name] = $metadata;
}
}
return $metadatas;
}
示例9: DatabaseDriver
/**
* generate entity objects automatically from mysql db tables
* @return none
*/
function generate_classes()
{
$this->em->getConfiguration()->setMetadataDriverImpl(new DatabaseDriver($this->em->getConnection()->getSchemaManager()));
$cmf = new DisconnectedClassMetadataFactory();
$cmf->setEntityManager($this->em);
$metadata = $cmf->getAllMetadata();
$generator = new EntityGenerator();
$generator->setUpdateEntityIfExists(true);
$generator->setGenerateStubMethods(true);
$generator->setGenerateAnnotations(true);
$generator->generate($metadata, APPPATH . "models/Entities");
}
示例10: prepare
protected function prepare()
{
$this->metadata = $this->cmf->getAllMetadata();
$this->metadata = MetadataFilter::filter($this->metadata, $this->filter);
$this->filename = $this->path . '/' . self::PROJECT_FILE;
if (!is_dir($dir = dirname($this->filename))) {
mkdir($dir, 0777, true);
}
$configFile = $this->path . '/' . self::CONFIG_FILE;
if (is_readable($configFile)) {
$this->configuration = Yaml::parse(file_get_contents($configFile));
}
}
示例11: execute
/**
* @see Console\Command\Command
*/
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
{
$em = $this->getHelper('em')->getEntityManager();
if ($input->getOption('from-database') === true) {
$databaseDriver = new \Doctrine\ORM\Mapping\Driver\DatabaseDriver($em->getConnection()->getSchemaManager());
$em->getConfiguration()->setMetadataDriverImpl($databaseDriver);
if (($namespace = $input->getOption('namespace')) !== null) {
$databaseDriver->setNamespace($namespace);
}
}
$cmf = new DisconnectedClassMetadataFactory();
$cmf->setEntityManager($em);
$metadata = $cmf->getAllMetadata();
$metadata = MetadataFilter::filter($metadata, $input->getOption('filter'));
// Process destination directory
if (!is_dir($destPath = $input->getArgument('dest-path'))) {
mkdir($destPath, 0777, true);
}
$destPath = realpath($destPath);
if (!file_exists($destPath)) {
throw new \InvalidArgumentException(sprintf("Mapping destination directory '<info>%s</info>' does not exist.", $destPath));
} else {
if (!is_writable($destPath)) {
throw new \InvalidArgumentException(sprintf("Mapping destination directory '<info>%s</info>' does not have write permissions.", $destPath));
}
}
$toType = strtolower($input->getArgument('to-type'));
$exporter = $this->getExporter($toType, $destPath);
$exporter->setOverwriteExistingFiles($input->getOption('force') !== false);
if ($toType == 'annotation') {
$entityGenerator = new \Internshala\Doctrine_Extension\Entity_Generator();
//$entityGenerator = new EntityGenerator();
$exporter->setEntityGenerator($entityGenerator);
$entityGenerator->setNumSpaces($input->getOption('num-spaces'));
if (($extend = $input->getOption('extend')) !== null) {
$entityGenerator->setClassToExtend($extend);
}
}
if (count($metadata)) {
foreach ($metadata as $class) {
$output->write(sprintf('Processing entity "<info>%s</info>"', $class->name) . PHP_EOL);
}
$exporter->setMetadata($metadata);
$exporter->export();
$output->write(PHP_EOL . sprintf('Exporting "<info>%s</info>" mapping information to "<info>%s</info>"' . PHP_EOL, $toType, $destPath));
} else {
$output->write('No Metadata Classes to process.' . PHP_EOL);
}
}
示例12: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$bundle = $this->application->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/metadata/orm';
}
if ('yaml' === $type) {
$type = 'yml';
}
$cme = new ClassMetadataExporter();
$exporter = $cme->getExporter($type);
if ('annotation' === $type) {
$entityGenerator = $this->getEntityGenerator();
$exporter->setEntityGenerator($entityGenerator);
}
$em = $this->getEntityManager($this->container, $input->getOption('em'));
$databaseDriver = new DatabaseDriver($em->getConnection()->getSchemaManager());
$em->getConfiguration()->setMetadataDriverImpl($databaseDriver);
$cmf = new DisconnectedClassMetadataFactory();
$cmf->setEntityManager($em);
$metadata = $cmf->getAllMetadata();
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 . '/' . str_replace('\\', '.', $class->name) . '.dcm.' . $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.' . PHP_EOL, 'ERROR');
}
}
示例13: fire
public function fire()
{
$this->info('Starting entities generation....');
// flush all generated and cached entities, etc
\D2Cache::flushAll();
$cmf = new DisconnectedClassMetadataFactory();
$cmf->setEntityManager($this->d2em);
$metadata = $cmf->getAllMetadata();
if (empty($metadata)) {
$this->error('No metadata found to generate entities.');
return -1;
}
$directory = Config::get('d2doctrine.paths.entities');
if (!$directory) {
$this->error('The entity directory has not been set.');
return -1;
}
$entityGenerator = new EntityGenerator();
$entityGenerator->setGenerateAnnotations($this->option('generate-annotations'));
$entityGenerator->setGenerateStubMethods($this->option('generate-methods'));
$entityGenerator->setRegenerateEntityIfExists($this->option('regenerate-entities'));
$entityGenerator->setUpdateEntityIfExists($this->option('update-entities'));
$entityGenerator->setNumSpaces($this->option('num-spaces'));
$entityGenerator->setBackupExisting(!$this->option('no-backup'));
$this->info('Processing entities:');
foreach ($metadata as $item) {
$this->line($item->name);
}
try {
$entityGenerator->generate($metadata, $directory);
$this->info('Entities have been created.');
} catch (\ErrorException $e) {
if ($this->option('verbose') == 3) {
throw $e;
}
$this->error("Caught ErrorException: " . $e->getMessage());
$this->info("Re-optimizing:");
$this->call('optimize');
$this->comment("*** You must now rerun this artisan command ***");
exit(-1);
}
}
示例14: execute
/**
* @see Console\Command\Command
*/
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
{
$em = $this->getHelper('em')->getEntityManager();
$cmf = new DisconnectedClassMetadataFactory();
$cmf->setEntityManager($em);
$metadatas = $cmf->getAllMetadata();
$metadatas = MetadataFilter::filter($metadatas, $input->getOption('filter'));
// Process destination directory
$destPath = realpath($input->getArgument('dest-path'));
if (!file_exists($destPath)) {
throw new \InvalidArgumentException(sprintf("Entities destination directory '<info>%s</info>' does not exist.", $destPath));
} else {
if (!is_writable($destPath)) {
throw new \InvalidArgumentException(sprintf("Entities destination directory '<info>%s</info>' does not have write permissions.", $destPath));
}
}
if (count($metadatas)) {
// Create EntityGenerator
$entityGenerator = new EntityGenerator();
$entityGenerator->setGenerateAnnotations($input->getOption('generate-annotations'));
$entityGenerator->setGenerateStubMethods($input->getOption('generate-methods'));
$entityGenerator->setRegenerateEntityIfExists($input->getOption('regenerate-entities'));
$entityGenerator->setUpdateEntityIfExists($input->getOption('update-entities'));
$entityGenerator->setNumSpaces($input->getOption('num-spaces'));
if (($attributeVisibility = $input->getOption('attribute-visibility')) !== null) {
$entityGenerator->setAttributeVisibility($attributeVisibility);
}
if (($extend = $input->getOption('extend')) !== null) {
$entityGenerator->setClassToExtend($extend);
}
foreach ($metadatas as $metadata) {
$output->write(sprintf('Processing entity "<info>%s</info>"', $metadata->name) . PHP_EOL);
}
// Generating Entities
$entityGenerator->generate($metadatas, $destPath);
// Outputting information message
$output->write(PHP_EOL . sprintf('Entity classes generated to "<info>%s</INFO>"', $destPath) . PHP_EOL);
} else {
$output->write('No Metadata Classes to process.' . PHP_EOL);
}
}
示例15: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
global $container;
/** @var string $cacheDir */
$cacheDir = $container['doctrine.orm.repositoriesCacheDir'];
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($cacheDir, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST);
/** @var \SplFileInfo $file */
foreach ($iterator as $file) {
if ($file->isDir()) {
rmdir($file);
} else {
unlink($file);
}
}
/** @var EntityManager $entityManager */
$entityManager = $container['doctrine.orm.entityManager'];
$classMetadataFactory = new DisconnectedClassMetadataFactory();
$classMetadataFactory->setEntityManager($entityManager);
$metadatas = $classMetadataFactory->getAllMetadata();
if (count($metadatas)) {
$numRepositories = 0;
$generator = new EntityRepositoryGenerator();
foreach ($metadatas as $metadata) {
if ($metadata->customRepositoryClassName) {
$output->write(sprintf('Processing repository "<info>%s</info>"', $metadata->customRepositoryClassName) . PHP_EOL);
$generator->writeEntityRepositoryClass($metadata->customRepositoryClassName, $cacheDir);
$numRepositories++;
}
}
if ($numRepositories) {
// Outputting information message
$output->write(PHP_EOL . sprintf('Repository classes generated to "<info>%s</INFO>"', $cacheDir) . PHP_EOL);
} else {
$output->write('No Repository classes were found to be processed.' . PHP_EOL);
}
} else {
$output->write('No Metadata Classes to process.' . PHP_EOL);
}
}