本文整理汇总了PHP中Doctrine\ORM\Tools\EntityGenerator::setRegenerateEntityIfExists方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityGenerator::setRegenerateEntityIfExists方法的具体用法?PHP EntityGenerator::setRegenerateEntityIfExists怎么用?PHP EntityGenerator::setRegenerateEntityIfExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\Tools\EntityGenerator
的用法示例。
在下文中一共展示了EntityGenerator::setRegenerateEntityIfExists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: exportClassMetadata
/**
* {@inheritdoc}
*/
public function exportClassMetadata(ClassMetadataInfo $metadata)
{
if (!$this->_entityGenerator) {
throw new \RuntimeException('For the AnnotationExporter you must set an EntityGenerator instance with the setEntityGenerator() method.');
}
$this->_entityGenerator->setGenerateAnnotations(true);
$this->_entityGenerator->setGenerateStubMethods(false);
$this->_entityGenerator->setRegenerateEntityIfExists(false);
$this->_entityGenerator->setUpdateEntityIfExists(false);
return $this->_entityGenerator->generateEntityClass($metadata);
}
示例2: setUp
public function setUp()
{
$this->_namespace = uniqid("doctrine_");
$this->_tmpDir = \sys_get_temp_dir();
\mkdir($this->_tmpDir . \DIRECTORY_SEPARATOR . $this->_namespace);
$this->_generator = new EntityGenerator();
$this->_generator->setAnnotationPrefix("");
$this->_generator->setGenerateAnnotations(true);
$this->_generator->setGenerateStubMethods(true);
$this->_generator->setRegenerateEntityIfExists(false);
$this->_generator->setUpdateEntityIfExists(true);
$this->_generator->setFieldVisibility(EntityGenerator::FIELD_VISIBLE_PROTECTED);
}
示例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: run
/**
* @inheritdoc
*/
public function run()
{
$printer = $this->getPrinter();
$arguments = $this->getArguments();
$from = $arguments['from'];
$dest = realpath($arguments['dest']);
$entityGenerator = new EntityGenerator();
$entityGenerator->setGenerateAnnotations(false);
$entityGenerator->setGenerateStubMethods(true);
$entityGenerator->setRegenerateEntityIfExists(false);
$entityGenerator->setUpdateEntityIfExists(true);
if (isset($arguments['extend']) && $arguments['extend']) {
$entityGenerator->setClassToExtend($arguments['extend']);
}
if (isset($arguments['num-spaces']) && $arguments['extend']) {
$entityGenerator->setNumSpaces($arguments['num-spaces']);
}
$reader = new ClassMetadataReader();
$reader->setEntityManager($this->getConfiguration()->getAttribute('em'));
$reader->addMappingSource($from);
$metadatas = $reader->getMetadatas();
foreach ($metadatas as $metadata) {
$printer->writeln(sprintf('Processing entity "%s"', $printer->format($metadata->name, 'KEYWORD')));
}
$entityGenerator->generate($metadatas, $dest);
$printer->write(PHP_EOL);
$printer->writeln(sprintf('Entity classes generated to "%s"', $printer->format($dest, 'KEYWORD')));
}
示例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: getEntityGenerator
protected function getEntityGenerator()
{
$entityGenerator = new EntityGenerator();
$entityGenerator->setGenerateAnnotations(false);
$entityGenerator->setGenerateStubMethods(true);
$entityGenerator->setRegenerateEntityIfExists(false);
$entityGenerator->setUpdateEntityIfExists(true);
$entityGenerator->setNumSpaces(4);
return $entityGenerator;
}
示例8: getEntityGenerator
/**
* Get entity generator.
*
* @return EntityGenerator
*/
protected static function getEntityGenerator()
{
$entityGenerator = new EntityGenerator();
$entityGenerator->setGenerateAnnotations(true);
$entityGenerator->setGenerateStubMethods(true);
$entityGenerator->setRegenerateEntityIfExists(true);
$entityGenerator->setUpdateEntityIfExists(true);
$entityGenerator->setNumSpaces(4);
$entityGenerator->setAnnotationPrefix(self::$annotationPrefix);
return $entityGenerator;
}
示例9: initGenerator
protected function initGenerator()
{
$this->generator->setGenerateAnnotations(true);
$this->generator->setBackupExisting(false);
$this->generator->setGenerateStubMethods(true);
$this->generator->setRegenerateEntityIfExists(true);
$this->generator->setUpdateEntityIfExists(false);
if ($this->parentClassName != null) {
$this->generator->setClassToExtend($this->parentClassName);
}
return $this->generator;
}
示例10: testRegenerateEntityClass
public function testRegenerateEntityClass()
{
$metadata = $this->generateBookEntityFixture();
$this->loadEntityClass($metadata);
$className = basename(str_replace('\\', '/', $metadata->name));
$path = $this->_tmpDir . '/' . $this->_namespace . '/' . $className . '.php';
$classTest = file_get_contents($path);
$this->_generator->setRegenerateEntityIfExists(true);
$this->_generator->setBackupExisting(false);
$this->_generator->writeEntityClass($metadata, $this->_tmpDir);
$classNew = file_get_contents($path);
$this->assertSame($classTest, $classNew);
}
示例11: getEntityGenerator
protected function getEntityGenerator()
{
$entityGenerator = new EntityGenerator();
if (version_compare(DoctrineVersion::VERSION, "2.0.2-DEV") >= 0) {
$entityGenerator->setAnnotationPrefix("orm:");
}
$entityGenerator->setGenerateAnnotations(false);
$entityGenerator->setGenerateStubMethods(true);
$entityGenerator->setRegenerateEntityIfExists(false);
$entityGenerator->setUpdateEntityIfExists(true);
$entityGenerator->setNumSpaces(4);
return $entityGenerator;
}
示例12: 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);
}
}
示例13: 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 (($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);
}
}
示例14: generateEntities
/**
* Generate entity classes
*
* @param array $metadata
*/
protected function generateEntities(array $metadata)
{
$generator = new EntityGenerator();
$generator->setGenerateAnnotations(true);
$generator->setGenerateStubMethods(true);
$generator->setRegenerateEntityIfExists(false);
$generator->setUpdateEntityIfExists(true);
$generator->setBackupExisting(false);
if (null !== ($superclass = $this->getSuperclass())) {
$generator->setClassToExtend($superclass);
}
/* @var $classMetadata \Doctrine\ORM\Mapping\ClassMetadata */
foreach ($metadata as $classMetadata) {
$className = end(explode('\\', $classMetadata->getName()));
$classMetadata->setCustomRepositoryClass($this->getNsRepository() . $className);
if (null !== ($prefix = $this->getSequencePrefix())) {
$classMetadata->setSequenceGeneratorDefinition(array('sequenceName' => strtoupper($prefix . '_' . $className)));
}
}
$generator->generate($metadata, $this->getDirectory());
}
示例15: generador
/**
* Entidades::generador()
*
* Genera el proceso correspondiente
* @param array $metadata
* @return void
*/
private function generador($metadata = false)
{
$generator = new EntityGenerator();
$generator->setAnnotationPrefix('');
// edit: quick fix for No Metadata Classes to process
$generator->setUpdateEntityIfExists(true);
// only update if class already exists
$generator->setRegenerateEntityIfExists(true);
// this will overwrite the existing classes
$generator->setGenerateStubMethods(true);
$generator->setGenerateAnnotations(true);
$generator->generate($metadata, dirname($this->dirEntidades));
}