本文整理汇总了PHP中Doctrine\ORM\Tools\DisconnectedClassMetadataFactory类的典型用法代码示例。如果您正苦于以下问题:PHP DisconnectedClassMetadataFactory类的具体用法?PHP DisconnectedClassMetadataFactory怎么用?PHP DisconnectedClassMetadataFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DisconnectedClassMetadataFactory类的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
protected function execute(InputInterface $input, OutputInterface $output)
{
$dbName = $input->getArgument('dbname');
$path = $input->getOption('path');
$extensionKey = $input->getOption('extension-key');
$connectionParams = array('dbname' => $dbName, 'user' => $input->getOption('user'), 'password' => $input->getOption('password'), 'host' => $input->getOption('host'), 'driver' => $input->getOption('driver'), 'port' => $input->getOption('port'));
$config = Setup::createAnnotationMetadataConfiguration(array('.'), false);
$em = EntityManager::create($connectionParams, $config);
$em->getConfiguration()->setMetadataDriverImpl(new \Doctrine\ORM\Mapping\Driver\DatabaseDriver($em->getConnection()->getSchemaManager()));
$cmf = new DisconnectedClassMetadataFactory();
$cmf->setEntityManager($em);
if (is_null($extensionKey)) {
$extensionKey = $dbName;
if (self::DEFAULT_PATH != $path) {
$extensionKey = array_pop(explode(DIRECTORY_SEPARATOR, $path));
}
}
$exporter = new ExtbaseExporter($cmf);
$exporter->setExtensionKey($extensionKey);
$exporter->setPath($input->getOption('path'));
self::mapDefaultInputOptions($exporter, $input);
$output->writeln(sprintf('Exporting database schema "<info>%s</info>".', $dbName));
$result = $exporter->exportJson();
foreach ($exporter->getLogs() as $log) {
$output->writeln($log);
}
return $result ? 0 : 1;
}
示例6: 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>');
}
}
示例7: __construct
/**
*
*/
public function __construct(App $app, EntityManager $em, DisconnectedClassMetadataFactory $cmf)
{
$cmf->setEntityManager($em);
$this->app = $app;
$this->metaData = $cmf->getAllMetaData();
$this->entityManager = $em;
parent::__construct('orm:generate:classes');
}
示例8: 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);*/
}
示例9: getAllMetadata
protected function getAllMetadata(array $entity)
{
$metadata = array();
$cmf = new DisconnectedClassMetadataFactory();
$cmf->setEntityManager($this->_em);
foreach ($entity as $e) {
$metadata[] = $cmf->getMetadataFor($e);
}
return $metadata;
}
示例10: _createClassMetadataFactory
protected function _createClassMetadataFactory($em, $type)
{
if ($type === 'annotation') {
$factory = new ClassMetadataFactory();
} else {
$factory = new DisconnectedClassMetadataFactory();
}
$factory->setEntityManager($em);
return $factory;
}
示例11: 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');
}
}
示例12: 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");
}
示例13: 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;
}
示例14: 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);
}
}
示例15: 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');
}
}