本文整理汇总了PHP中Doctrine\ORM\Tools\Console\MetadataFilter类的典型用法代码示例。如果您正苦于以下问题:PHP MetadataFilter类的具体用法?PHP MetadataFilter怎么用?PHP MetadataFilter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MetadataFilter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$em = $this->getHelper('em')->getEntityManager();
$metadatas = $em->getMetadataFactory()->getAllMetadata();
$metadatas = MetadataFilter::filter($metadatas, $input->getOption('filter'));
$repositoryName = $em->getConfiguration()->getDefaultRepositoryClassName();
// 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.", $input->getArgument('dest-path')));
}
if (!is_writable($destPath)) {
throw new \InvalidArgumentException(sprintf("Entities destination directory '<info>%s</info>' does not have write permissions.", $destPath));
}
if (count($metadatas)) {
$numRepositories = 0;
$generator = new EntityRepositoryGenerator();
$generator->setDefaultRepositoryName($repositoryName);
foreach ($metadatas as $metadata) {
if ($metadata->customRepositoryClassName) {
$output->writeln(sprintf('Processing repository "<info>%s</info>"', $metadata->customRepositoryClassName));
$generator->writeEntityRepositoryClass($metadata->customRepositoryClassName, $destPath);
$numRepositories++;
}
}
if ($numRepositories) {
// Outputting information message
$output->writeln(PHP_EOL . sprintf('Repository classes generated to "<info>%s</INFO>"', $destPath));
} else {
$output->writeln('No Repository classes were found to be processed.');
}
} else {
$output->writeln('No Metadata Classes to process.');
}
}
示例2: execute
/**
* @see Console\Command\Command
*/
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
{
$em = $this->getHelper('em')->getEntityManager();
$metadatas = $em->getMetadataFactory()->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 AS3EntityGenerator($em);
$entityGenerator->setGenerateAssociationHelperMethods($input->getOption('generate-helper-methods'));
$entityGenerator->setRegenerateEntityIfExists($input->getOption('regenerate-entities'));
$entityGenerator->setUpdateEntityIfExists($input->getOption('update-entities'));
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('AS3 entity classes generated to "<info>%s</INFO>"', $destPath) . PHP_EOL);
} else {
$output->write('No Metadata Classes to process.' . PHP_EOL);
}
}
示例3: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$em = $this->getHelper('em')->getEntityManager();
$metadatas = $em->getMetadataFactory()->getAllMetadata();
$metadatas = MetadataFilter::filter($metadatas, $input->getOption('filter'));
// Process destination directory
if (($destPath = $input->getArgument('dest-path')) === null) {
$destPath = $em->getConfiguration()->getProxyDir();
}
if (!is_dir($destPath)) {
mkdir($destPath, 0777, true);
}
$destPath = realpath($destPath);
if (!file_exists($destPath)) {
throw new \InvalidArgumentException(sprintf("Proxies destination directory '<info>%s</info>' does not exist.", $em->getConfiguration()->getProxyDir()));
}
if (!is_writable($destPath)) {
throw new \InvalidArgumentException(sprintf("Proxies destination directory '<info>%s</info>' does not have write permissions.", $destPath));
}
if (count($metadatas)) {
foreach ($metadatas as $metadata) {
$output->writeln(sprintf('Processing entity "<info>%s</info>"', $metadata->name));
}
// Generating Proxies
$em->getProxyFactory()->generateProxyClasses($metadatas, $destPath);
// Outputting information message
$output->writeln(PHP_EOL . sprintf('Proxy classes generated to "<info>%s</INFO>"', $destPath));
} else {
$output->writeln('No Metadata Classes to process.');
}
}
示例4: 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);*/
}
示例5: 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');
}
}
示例6: _getMetadata
protected function _getMetadata()
{
if (null === $this->metadata) {
$this->bootstrap->bootstrap('Doctrine2');
$em = $this->bootstrap->getResource('Doctrine2');
$cmf = new \Doctrine\ORM\Tools\DisconnectedClassMetadataFactory($em);
$metadatas = $cmf->getAllMetadata();
$entityName = $this->_getEntityName();
$entityClass = $this->_getModuleNamespace() . '_Model_' . $entityName;
$metadata = current(\Doctrine\ORM\Tools\Console\MetadataFilter::filter($metadatas, $entityClass));
$this->metadata = $metadata;
}
return $this->metadata;
}
示例7: 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);
}
}
示例8: 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);
}
}
示例9: fire
/**
* Execute the console command.
*
* @param ManagerRegistry $registry
*/
public function fire(ManagerRegistry $registry)
{
$names = $this->option('em') ? [$this->option('em')] : $registry->getManagerNames();
foreach ($names as $name) {
$em = $registry->getManager($name);
$this->comment('');
$this->message('Generating proxies for <info>' . $name . '</info> entity manager...', 'blue');
$metadatas = $em->getMetadataFactory()->getAllMetadata();
$metadatas = MetadataFilter::filter($metadatas, $this->option('filter'));
// Process destination directory
if (($destPath = $this->argument('dest-path')) === null) {
$destPath = $em->getConfiguration()->getProxyDir();
}
if (!is_dir($destPath)) {
mkdir($destPath, 0777, true);
}
$destPath = realpath($destPath);
if (!file_exists($destPath)) {
throw new InvalidArgumentException(sprintf("Proxies destination directory '<info>%s</info>' does not exist.", $em->getConfiguration()->getProxyDir()));
}
if (!is_writable($destPath)) {
throw new InvalidArgumentException(sprintf("Proxies destination directory '<info>%s</info>' does not have write permissions.", $destPath));
}
if (count($metadatas)) {
foreach ($metadatas as $metadata) {
$this->comment(sprintf('Processing entity "<info>%s</info>"', $metadata->name));
}
// Generating Proxies
$em->getProxyFactory()->generateProxyClasses($metadatas, $destPath);
// Outputting information message
$this->comment(sprintf('Proxy classes generated to "<info>%s</INFO>"', $destPath));
} else {
$this->error('No Metadata Classes to process.');
}
}
}
示例10: exportJson
public function exportJson()
{
$metadata = $this->cmf->getAllMetadata();
$metadata = MetadataFilter::filter($metadata, $this->filter);
if ($metadata) {
$filename = $this->path . '/' . $this->extensionKey . '/' . self::PROJECT_FILE_NAME;
if (!is_dir($dir = dirname($filename))) {
mkdir($dir, 0777, true);
}
$configuration = new ExtensionBuilderConfiguration();
if (is_readable($filename)) {
if ($this->overwriteExistingFiles && $this->roundTripExistingFiles) {
$this->logs[] = sprintf('File "<info>%s</info>" already exists, you selected both override (force) and round-trip - please choose one.', $filename);
return 1;
}
if (!$this->overwriteExistingFiles && !$this->roundTripExistingFiles) {
$this->logs[] = sprintf('File "<info>%s</info>" already exists, use --force to override or --round-trip it.', $filename);
return 1;
}
if ($this->roundTripExistingFiles) {
$roundtripContents = json_decode(file_get_contents($filename), true);
$configuration->setProperties($this->mapArrayToClass($roundtripContents['properties'], new Properties()));
$configuration->setLog($this->mapArrayToClass($roundtripContents['log'], new Log()));
}
}
$configuration->getProperties()->setExtensionKey($this->extensionKey);
$configuration->getLog()->setLastModified(date('Y-m-d H:i'));
//in this array we store the target entites for all relations to create wires later on
$relationTargetsByModuleByRelation = array();
$moduleIndex = 0;
$posX = 50;
$posY = 50;
foreach ($metadata as $metadata) {
if ($moduleIndex) {
if (0 == $moduleIndex % 5) {
$posX = 50;
$posY += 200;
} else {
$posX += 300;
}
}
$className = $metadata->name;
//remove namespaces, e.g. when importing entities
if (class_exists($className)) {
$reflection = new \ReflectionClass($className);
$className = $reflection->getShortName();
}
$this->logs[] = sprintf('Processing table "<info>%s</info>"', $className);
$module = new Module();
$module->getValue()->setName($className);
$module->getConfig()->setPosition(array($posX, $posY));
$module->getValue()->getObjectsettings()->setUid($this->getRandomUid());
$module->getValue()->getObjectsettings()->setType(ObjectSettings::OBJECT_TYPE_ENTITY);
//export properties
foreach ($metadata->fieldMappings as $fieldMapping) {
$property = new Property();
$property->setPropertyName($fieldMapping['fieldName']);
$property->setPropertyType($this->getPropertyType($fieldMapping['type']));
$property->setUid($this->getRandomUid());
$module->getValue()->getPropertyGroup()->addProperty($property);
}
//export relations
$relationIndex = 0;
foreach ($metadata->associationMappings as $associationMapping) {
$relationNameSingular = $associationMapping['fieldName'];
$relationNamePlural = Inflector::pluralize(Inflector::singularize($associationMapping['fieldName']));
$relation = new Relation();
$relationType = null;
$relationName = '';
switch ($associationMapping['type']) {
case ClassMetadataInfo::ONE_TO_MANY:
$relationType = Relation::ONE_TO_MANY;
$relationName = $relationNamePlural;
break;
case ClassMetadataInfo::MANY_TO_ONE:
$relationType = Relation::MANY_TO_ONE;
$relationName = $relationNameSingular;
break;
case ClassMetadataInfo::ONE_TO_ONE:
$relationType = Relation::ONE_TO_ONE;
$relationName = $relationNameSingular;
break;
case ClassMetadataInfo::MANY_TO_MANY:
$relationType = Relation::MANY_TO_MANY;
$relationName = $relationNamePlural;
break;
}
$relation->setRelationName($relationName);
$relation->setRelationType($relationType);
$relationName = $relationNameSingular;
$module->getValue()->getRelationGroup()->addRelation($relation);
$targetClassName = $associationMapping['targetEntity'];
//remove namespaces, e.g. when importing entities
if (class_exists($targetClassName)) {
$reflection = new \ReflectionClass($targetClassName);
$targetClassName = $reflection->getShortName();
}
$relationTargetsByModuleByRelation[$moduleIndex][$relationIndex] = $targetClassName;
$relationIndex++;
$this->logs[] = sprintf('Added relation "<comment>%s</comment>": "<info>%s</info>" -> "<info>%s</info>"', $relationName, $className, $targetClassName);
//.........这里部分代码省略.........
示例11: execute
/**
* {@inheritDoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$app = $this->getHelper("app")->getApplication();
$registry = $app['orm.manager_registry'];
/* @var $registry ManagerRegistry */
$emName = $input->getOption("em") ? $input->getOption("em") : "default";
$em = $registry->getManager($emName);
//$bundle = $this->getApplication()->getKernel()->getBundle($input->getArgument('bundle'));
// $destPath = $bundle->getPath();
$destPath = $input->getArgument("path");
$type = $input->getArgument('mapping-type') ? $input->getArgument('mapping-type') : 'xml';
if ('annotation' === $type) {
$destPath .= "/" . preg_replace("#\\\\#", "/", $input->getOption("namespace"));
} else {
$destPath .= '/Resources/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 = $input->getOption("namespace") . "\\" . $className;
//$classPath = $class-> /* todo fix it */
if ('annotation' === $type) {
$path = $destPath . '/' . $className . '.php';
} else {
$path = $destPath . '/' . preg_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.', 'ERROR');
$output->writeln('', 'ERROR');
}
}
示例12: 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));
}
}
示例13: main
/**
* main method
*
* @return void
*/
public function main()
{
static $em;
if ($em === null) {
$wd = getcwd();
$zf = $this->project->getProperty('zf');
$application = (require $zf);
if (!$application instanceof Application) {
throw new BuildException(sprintf('zf bootstrap file "%s" should return an instance of Zend\\Mvc\\Application', $zf));
}
chdir($wd);
$em = $application->getServiceManager()->get($this->em);
}
$metadatas = $em->getMetadataFactory()->getAllMetadata();
if (!empty($this->filter)) {
$metadatas = MetadataFilter::filter($metadatas, $this->filter);
}
if (count($metadatas)) {
foreach ($metadatas as $metadata) {
$this->log(sprintf('Processing entity %s', $metadata->name));
}
$em->getProxyFactory()->generateProxyClasses($metadatas, $this->output);
// Outputting information message
$this->log(sprintf('Proxy classes generated to %s', $this->output));
} else {
$this->log('No metadata classes to process');
}
}
示例14: main
/**
* main method
*
* @return void
*/
public function main()
{
static $em;
if ($em === null) {
$wd = getcwd();
$zf = $this->project->getProperty('zf');
$application = (require $zf);
if (!$application instanceof Application) {
throw new BuildException(sprintf('zf bootstrap file "%s" should return an instance of Zend\\Mvc\\Application', $zf));
}
chdir($wd);
$em = $application->getServiceManager()->get($this->em);
}
$cmf = new DisconnectedClassMetadataFactory();
$cmf->setEntityManager($em);
$metadatas = $cmf->getAllMetadata();
if (!empty($this->filter)) {
$metadatas = MetadataFilter::filter($metadatas, $this->filter);
}
if (count($metadatas)) {
// Create EntityGenerator
$entityGenerator = new EntityGenerator();
$entityGenerator->setGenerateAnnotations(true);
$entityGenerator->setGenerateStubMethods(true);
$entityGenerator->setRegenerateEntityIfExists(true);
$entityGenerator->setUpdateEntityIfExists(true);
$entityGenerator->setNumSpaces(4);
foreach ($metadatas as $metadata) {
$this->log(sprintf('Processing entity %s', $metadata->name));
}
// Generating Entities
$entityGenerator->generate($metadatas, $this->output);
// Outputting information message
$this->log(sprintf('Entity classes generated to %s', $this->output));
} else {
$this->log('No metadata classes to process');
}
}
示例15: execute
/**
* {@inheritDoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$em = $this->getEntityManager();
$destPath = APP_PATH . DIRECTORY_SEPARATOR . preg_replace("#\\\\#", DIRECTORY_SEPARATOR, $this->getNamespace());
$type = 'annotation';
$cme = new ClassMetadataExporter();
$exporter = $cme->getExporter($type);
$exporter->setOverwriteExistingFiles($input->getOption('force'));
$exporter->setEntityGenerator($this->getEntityGenerator());
$databaseDriver = new DatabaseDriver($em->getConnection()->getSchemaManager());
$em->getConfiguration()->setMetadataDriverImpl($databaseDriver);
$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', 'default'));
foreach ($metadata as $class) {
$className = $class->name;
$class->name = sprintf('%s\\%s', $this->getNamespace(), $className);
$path = $destPath . DIRECTORY_SEPARATOR . str_replace('\\', '.', $className) . '.php';
$output->writeln(sprintf(' > writing <comment>%s</comment>', $path));
$code = $exporter->exportClassMetadata($class);
if (!is_dir($dir = dirname($path))) {
mkdir($dir, 0775, true);
}
file_put_contents($path, $code);
chmod($path, 0664);
}
return 0;
} else {
$output->writeln('Database does not have any mapping information.', 'ERROR');
$output->writeln('', 'ERROR');
return 1;
}
}