本文整理汇总了PHP中Sensio\Bundle\GeneratorBundle\Command\Validators::validateEntityName方法的典型用法代码示例。如果您正苦于以下问题:PHP Validators::validateEntityName方法的具体用法?PHP Validators::validateEntityName怎么用?PHP Validators::validateEntityName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sensio\Bundle\GeneratorBundle\Command\Validators
的用法示例。
在下文中一共展示了Validators::validateEntityName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$questionHelper = $this->getQuestionHelper();
if ($input->isInteractive()) {
$confirmationQuestion = new ConfirmationQuestion($questionHelper->getQuestion('Do you confirm generation', 'yes', '?'), true);
if (!$questionHelper->ask($input, $output, $confirmationQuestion)) {
$output->writeln('<error>Command aborted</error>');
return 1;
}
}
GeneratorUtils::ensureOptionsProvided($input, array('entity', 'fields', 'prefix'));
$entityInput = Validators::validateEntityName($input->getOption('entity'));
list($bundleName, $entity) = $this->parseShortcutNotation($entityInput);
$format = 'annotation';
$fields = $this->parseFields($input->getOption('fields'));
$prefix = $input->getOption('prefix');
$questionHelper->writeSection($output, 'Entity generation');
$bundle = $this->getContainer()->get('kernel')->getBundle($bundleName);
$generator = $this->getGenerator($this->getApplication()->getKernel()->getBundle("KunstmaanGeneratorBundle"));
$generator->generate($bundle, $entity, $format, array_values($fields), $input->getOption('with-repository'), $prefix);
$output->writeln('Generating the entity code: <info>OK</info>');
$withAdminlist = $input->getOption('with-adminlist');
if ($withAdminlist) {
$command = $this->getApplication()->find('kuma:generate:adminlist');
$arguments = array('command' => 'doctrine:fixtures:load', '--entity' => $entityInput);
$input = new ArrayInput($arguments);
$command->run($input, $output);
}
$questionHelper->writeGeneratorSummary($output, array());
$output->writeln(array('Make sure you update your database first before you test the entity/adminlist:', ' Directly update your database: <comment>app/console doctrine:schema:update --force</comment>', ' Create a Doctrine migration and run it: <comment>app/console doctrine:migrations:diff && app/console doctrine:migrations:migrate</comment>', ''));
}
示例2: execute
/**
* @throws \InvalidArgumentException When the bundle doesn't end with Bundle (Example: "Bundle/MySampleBundle")
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$dialog = $this->getDialogHelper();
if ($input->isInteractive()) {
if (!$dialog->askConfirmation($output, $dialog->getQuestion('Do you confirm generation', 'yes', '?'), true)) {
$output->writeln('<error>Command aborted</error>');
return 1;
}
}
$entity = Validators::validateEntityName($input->getOption('entity'));
$translationEntity = Validators::validateEntityName(sprintf('%sTranslation', $input->getOption('entity')));
list($bundle, $entity) = $this->parseShortcutNotation($entity);
list($translationBundle, $translationEntity) = $this->parseShortcutNotation($translationEntity);
$format = Validators::validateFormat($input->getOption('format'));
$fields = $this->parseFields($input->getOption('fields'));
$translatableFields = $this->parseFields($input->getOption('translatable-fields'));
$dialog->writeSection($output, 'Entities generation');
$kernel = $this->getContainer()->get('kernel');
$bundle = $kernel->getBundle($bundle);
$translationBundle = $kernel->getBundle($translationBundle);
/** @var OrkestroEntityGenerator $generator */
$generator = $this->getGenerator();
$generator->generateTranslatable($bundle, $entity, $translationEntity, $format, array_values($fields), array_values($translatableFields), $input->getOption('with-repository'));
$output->writeln('Generating the entities code: <info>OK</info>');
$dialog->writeGeneratorSummary($output, array());
}
示例3: execute
/**
* @throws \InvalidArgumentException When the bundle doesn't end with Bundle (Example: "Bundle/MySampleBundle")
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$questionHelper = $this->getQuestionHelper();
if ($input->isInteractive()) {
$question = new ConfirmationQuestion($questionHelper->getQuestion('Do you confirm generation', 'yes', '?'), true);
if (!$questionHelper->ask($input, $output, $question)) {
$output->writeln('<error>Command aborted</error>');
return 1;
}
}
$entity = Validators::validateEntityName($input->getOption('entity'));
$fields = $this->parseFields($input->getOption('fields'));
if (!$input->getOption('no-summary')) {
$questionHelper->writeSection($output, 'Entity generation');
}
/** @var TemplateInterface $generator */
$generator = $this->getGenerator();
$generator->setConfiguration('fields', $fields);
if ($input->getOption('no-interface')) {
$generator->setConfiguration('with_interface', false);
}
$errors = array();
$runner = $questionHelper->getRunner($output, $errors);
$runner($generator->generate($entity));
if (!$input->getOption('no-summary')) {
$questionHelper->writeGeneratorSummary($output, $generator->getErrors());
}
}
示例4: execute
/**
* @see Command
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$dialog = $this->getDialogHelper();
if ($input->isInteractive()) {
if (!$dialog->askConfirmation($output, $dialog->getQuestion('Do you confirm generation', 'yes', '?'), true)) {
$output->writeln('<error>Command aborted</error>');
return 1;
}
}
$entity = Validators::validateEntityName($input->getOption('entity'));
list($bundle, $entity) = $this->parseShortcutNotation($entity);
$format = Validators::validateFormat($input->getOption('format'));
$prefix = $this->getRoutePrefix($input, $entity);
$withWrite = $input->getOption('with-write');
$dialog->writeSection($output, 'CRUD generation');
$entityClass = $this->getContainer()->get('doctrine')->getEntityNamespace($bundle) . '\\' . $entity;
$metadata = $this->getEntityMetadata($entityClass);
$bundle = $this->getContainer()->get('kernel')->getBundle($bundle);
$generator = $this->getGenerator();
$generator->generate($bundle, $entity, $metadata[0], $format, $prefix, $withWrite);
$output->writeln('Generating the CRUD code: <info>OK</info>');
$errors = array();
$runner = $dialog->getRunner($output, $errors);
// form
if ($withWrite) {
$this->generateForm($bundle, $entity, $metadata);
$output->writeln('Generating the Form code: <info>OK</info>');
}
// routing
if ('annotation' != $format) {
$runner($this->updateRouting($dialog, $input, $output, $bundle, $format, $entity, $prefix));
}
$dialog->writeGeneratorSummary($output, $errors);
}
示例5: interact
/**
* {@inheritdoc}
*/
protected function interact(InputInterface $input, OutputInterface $output)
{
// Start question helper
$questionHelper = $this->getQuestionHelper();
$questionHelper->writeSection($output, 'Welcome to the united CRUD generator!');
// get entity
$entity = $input->getOption('entity');
$question = new Question($questionHelper->getQuestion('Entity', $entity), $entity);
$question->setValidator(function ($answer) {
return Validators::validateEntityName($answer);
});
$complete = new EntitiesAutoCompleter($this->getContainer()->get('doctrine')->getManager());
$completeEntities = $complete->getSuggestions();
$question->setAutocompleterValues($completeEntities);
$entity = $questionHelper->ask($input, $output, $question);
$input->setOption('entity', $entity);
// get bundle
$destinationBundle = $input->getOption('bundle');
$question = new Question($questionHelper->getQuestion('Destination bundle', $destinationBundle), $destinationBundle);
$question->setValidator(function ($answer) {
return Validators::validateBundleName($answer);
});
$question->setAutocompleterValues($this->getBundleSuggestions());
$destinationBundle = $questionHelper->ask($input, $output, $question);
$input->setOption('bundle', $destinationBundle);
}
示例6: execute
/**
* @see Command
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$questionHelper = $this->getQuestionHelper();
if ($input->isInteractive()) {
$question = new ConfirmationQuestion($questionHelper->getQuestion('Do you confirm generation', 'yes', '?'), true);
if (!$questionHelper->ask($input, $output, $question)) {
$output->writeln('<error>Command aborted</error>');
return 1;
}
}
$entity = Validators::validateEntityName($input->getOption('entity'));
list($bundle, $entity) = $this->parseShortcutNotation($entity);
$prefix = $this->getRoutePrefix($input, $entity);
$forceOverwrite = $input->getOption('overwrite');
$questionHelper->writeSection($output, 'REST api generation');
$entityClass = $this->getContainer()->get('doctrine')->getAliasNamespace($bundle) . '\\' . $entity;
$metadata = $this->getEntityMetadata($entityClass);
$bundle = $this->getContainer()->get('kernel')->getBundle($bundle);
$resource = $input->getOption('resource');
$document = $input->getOption('document');
$generator = $this->getGenerator($bundle);
$generator->generate($bundle, $entity, $metadata[0], $prefix, $forceOverwrite, $resource, $document);
$output->writeln('Generating the REST api code: <info>OK</info>');
$errors = array();
// form
$this->generateForm($bundle, $entity, $metadata);
$output->writeln('Generating the Form code: <info>OK</info>');
$questionHelper->writeGeneratorSummary($output, $errors);
}
示例7: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$dialog = $this->getDialogHelper();
$entity = Validators::validateEntityName($input->getOption('entity'));
list($bundle, $entity) = $this->parseShortcutNotation($entity);
$field = $input->getOption('field');
print $bundle . ":" . $entity . "->" . $field;
$repo = $this->getContainer()->get('doctrine')->getRepository($bundle . ":" . $entity);
$em = $this->getContainer()->get('doctrine')->getManager();
$ids = $em->createQuery("SELECT e.id FROM " . $bundle . ":" . $entity . " e ORDER BY e.id ASC")->setMaxResults(16000)->getArrayResult();
foreach ($ids as $pos => $e) {
$toFlush = false;
$entity = $repo->findOneById($e['id']);
$fileData = $entity->{'get' . ucfirst($field)}();
if (!$fileData) {
continue;
}
$filename = $fileData['dir'] . '/' . $fileData['fileName'];
if (file_exists($filename)) {
//print "\n exists " . $filename;
$byFileNameExists = true;
} else {
//print "\n NO exists " . $filename;
$byFileNameExists = false;
}
$webDir = $this->getContainer()->getParameter('iphp.web_dir');
$filenameByPath = $webDir . $fileData['path'];
if (file_exists($filenameByPath)) {
// print "\n By Path exists " . $filenameByPath;
$byFilePathExists = true;
} else {
// print "\n By Path NO exists " . $filenameByPath;
$byFilePathExists = false;
}
print "\n\n " . $entity->getId() . ' ' . (string) $entity;
if ($byFilePathExists && $byFileNameExists) {
print ": NO PROBLEM";
continue;
}
if (!$byFilePathExists && $byFileNameExists) {
print "\nresave " . $filename;
print file_exists($filename) ? " EXISTS" : " NO EXISTS";
$fileObj = new \Symfony\Component\HttpFoundation\File\File($filename);
print "\n Obj created";
$entity->{'set' . ucfirst($field)}($fileObj);
$em->persist($entity);
$toFlush = true;
print 'saved';
}
if ($pos % 20 == 0 && $toFlush) {
$em->flush();
}
if ($pos % 100 == 0) {
$em->clear();
}
}
}
示例8: execute
/**
* @see Command
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$entity = Validators::validateEntityName($input->getArgument('entity'));
list($bundle, $entity) = $this->parseShortcutNotation($entity);
$entityClass = $this->getContainer()->get('doctrine')->getAliasNamespace($bundle) . '\\' . $entity;
$metadata = $this->getEntityMetadata($entityClass);
$bundle = $this->getApplication()->getKernel()->getBundle($bundle);
$generator = $this->getGenerator($bundle);
$generator->generate($bundle, $entity, $metadata[0]);
$output->writeln(sprintf('The new %s.php class file has been created under %s.', $generator->getClassName(), $generator->getClassPath()));
}
示例9: execute
public function execute(InputInterface $input, OutputInterface $output)
{
$this->input = $input;
$this->output = $output;
Validators::validateEntityName($input->getOption('entity'));
$dialog = $this->getDialogHelper();
if ($input->getOption('trait')) {
if (PHP_MAJOR_VERSION < 5 || PHP_MINOR_VERSION < 4) {
throw new \RuntimeException('You need PHP > 5.4 to use trait feature');
}
}
if (null === $input->getOption('controller')) {
throw new \RuntimeException('The controller option must be provided.');
}
list($bundle, $controller) = $this->parseShortcutNotation($input->getOption('controller'));
/** @var Bundle $bundle */
if (is_string($bundle)) {
$bundle = Validators::validateBundleName($bundle);
try {
$bundle = $this->getContainer()->get('kernel')->getBundle($bundle);
} catch (\Exception $e) {
$output->writeln(sprintf('<bg=red>Bundle "%s" does not exists.</>', $bundle));
}
}
$dialog->writeSection($output, 'Controller generation: ' . $controller . 'Controller (' . $bundle->getName() . ')');
/** @var RestControllerGenerator $generator */
$generator = $this->getGenerator($bundle);
if ($input->getOption('trait')) {
$output->writeln("<info>Generating Controller with Traits</info>");
$generator->setUseTrait(true);
$generator->generate($bundle, $controller, '', '');
$output->writeln("<info>Trait Controller Generated</info>");
$generator->setUseTrait(false);
$generator->setTemplateFile('UseTraitController.php');
try {
$generator->generate($bundle, $controller, '', '');
$output->writeln("<info>Controller Generated</info>");
} catch (\RuntimeException $e) {
$output->writeln("<info>Controller Skipped</info>");
}
} else {
$generator->generate($bundle, $controller, '', '');
$output->writeln("<info>Controller Generated</info>");
}
$output->writeln('Generating the bundle code: <info>OK</info>');
$dialog->writeGeneratorSummary($output, array());
}
示例10: execute
/**
* @see Command
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$questionHelper = $this->getQuestionHelper();
$entity = Validators::validateEntityName($input->getOption('entity'));
/** @var TemplateInterface $generator */
$generator = $this->getGenerator();
if ($input->getOption('path')) {
$generator->setConfiguration('path', $input->getOption('path'));
}
$questionHelper->writeSection($output, 'Form generation');
$errors = array();
$runner = $questionHelper->getRunner($output, $errors);
$runner($generator->generate($entity));
if (!$input->getOption('no-summary')) {
$questionHelper->writeGeneratorSummary($output, $generator->getErrors());
}
}
示例11: execute
/**
* @see Command
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$questionHelper = $this->getQuestionHelper();
if ($input->isInteractive()) {
$question = new ConfirmationQuestion($questionHelper->getQuestion('Do you confirm generation', 'yes', '?'), true);
if (!$questionHelper->ask($input, $output, $question)) {
$output->writeln('<error>Command aborted</error>');
return 1;
}
}
$entity = Validators::validateEntityName($input->getOption('entity'));
list($bundle, $entity) = $this->parseShortcutNotation($entity);
$format = "rest";
$prefix = $this->getRoutePrefix($input, $entity);
$forceOverwrite = $input->getOption('overwrite');
$questionHelper->writeSection($output, 'REST api generation');
$entityClass = $this->getContainer()->get('doctrine')->getAliasNamespace($bundle) . '\\' . $entity;
$metadata = $this->getEntityMetadata($entityClass);
$bundle = $this->getContainer()->get('kernel')->getBundle($bundle);
$resource = $input->getOption('resource');
$document = $input->getOption('document');
$form = $input->getOption('form');
if ($form) {
$entityName = $input->getOption('entity');
$process = new Process("app/console doctrine:generate:form {$entityName}");
$process->run(function ($type, $buffer) {
if ('err' === $type) {
echo 'ERR > ' . $buffer;
} else {
echo 'OUT > ' . $buffer;
}
});
}
/** @var DoctrineRESTGenerator $generator */
$generator = $this->getGenerator($bundle);
$generator->generate($bundle, $entity, $metadata[0], $prefix, $forceOverwrite, $resource, $document);
$output->writeln('Generating the REST api code: <info>OK</info>');
$errors = array();
$runner = $questionHelper->getRunner($output, $errors);
// form
$this->generateForm($bundle, $entity, $metadata);
$output->writeln('Generating the Form code: <info>OK</info>');
// create route
$runner($this->updateRouting($questionHelper, $input, $output, $bundle, $format, $entity, $prefix));
$questionHelper->writeGeneratorSummary($output, $errors);
}
示例12: interact
/**
* Interacts with the user.
*
* @param InputInterface $input An InputInterface instance
* @param OutputInterface $output An OutputInterface instance
*/
protected function interact(InputInterface $input, OutputInterface $output)
{
$dialog = $this->getDialogHelper();
$dialog->writeSection($output, 'Welcome to the Kunstmaan admin list generator');
// entity
$entity = null;
try {
$entity = $input->getOption('entity') ? Validators::validateEntityName($input->getOption('entity')) : null;
} catch (\Exception $error) {
$output->writeln($dialog->getHelperSet()->get('formatter')->formatBlock($error->getMessage(), 'error'));
}
if (is_null($entity)) {
$output->writeln(array('', 'This command helps you to generate an admin list for your entity.', '', 'You must use the shortcut notation like <comment>AcmeBlogBundle:Post</comment>.', ''));
$entity = $dialog->askAndValidate($output, $dialog->getQuestion('The entity shortcut name', $entity), array('Sensio\\Bundle\\GeneratorBundle\\Command\\Validators', 'validateEntityName'), false, $entity);
$input->setOption('entity', $entity);
}
}
示例13: execute
/**
* @see Command
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$questionHelper = $this->getQuestionHelper();
if ($input->isInteractive()) {
$question = new ConfirmationQuestion($questionHelper->getQuestion('Do you confirm generation', 'yes', '?'), true);
if (!$questionHelper->ask($input, $output, $question)) {
$output->writeln('<error>Command aborted</error>');
return 1;
}
}
$entity = Validators::validateEntityName($input->getOption('entity'));
list($bundle, $entity) = $this->parseShortcutNotation($entity);
$format = Validators::validateFormat($input->getOption('format'));
$prefix = $this->getRoutePrefix($input, $entity);
$withWrite = $input->getOption('with-write');
$forceOverwrite = $input->getOption('overwrite');
$questionHelper->writeSection($output, 'CRUD generation');
try {
$entityClass = $this->getContainer()->get('doctrine')->getAliasNamespace($bundle) . '\\' . $entity;
$metadata = $this->getEntityMetadata($entityClass);
} catch (\Exception $e) {
throw new \RuntimeException(sprintf('Entity "%s" does not exist in the "%s" bundle. Create it with the "doctrine:generate:entity" command and then execute this command again.', $entity, $bundle));
}
$bundle = $this->getContainer()->get('kernel')->getBundle($bundle);
$generator = $this->getGenerator($bundle);
$generator->generate($bundle, $entity, $metadata[0], $format, $prefix, $withWrite, $forceOverwrite);
$output->writeln('Generating the CRUD code: <info>OK</info>');
$errors = array();
$runner = $questionHelper->getRunner($output, $errors);
// form
if ($withWrite) {
$output->write('Generating the Form code: ');
if ($this->generateForm($bundle, $entity, $metadata)) {
$output->writeln('<info>OK</info>');
} else {
$output->writeln('<comment>Already exists, skipping</comment>');
}
}
// routing
if ('annotation' != $format) {
$runner($this->updateRouting($questionHelper, $input, $output, $bundle, $format, $entity, $prefix));
}
$questionHelper->writeGeneratorSummary($output, $errors);
}
示例14: execute
/**
* @throws \InvalidArgumentException When the bundle doesn't end with Bundle (Example: "Bundle/MySampleBundle")
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$questionHelper = $this->getQuestionHelper();
$entity = Validators::validateEntityName($input->getOption('entity'));
list($bundle, $entity) = $this->parseShortcutNotation($entity);
$format = Validators::validateFormat($input->getOption('format'));
$fields = $this->parseFields($input->getOption('fields'));
$questionHelper->writeSection($output, 'Entity generation');
$bundle = $this->getContainer()->get('kernel')->getBundle($bundle);
/** @var DoctrineEntityGenerator $generator */
$generator = $this->getGenerator();
$generatorResult = $generator->generate($bundle, $entity, $format, array_values($fields));
$output->writeln(sprintf('> Generating entity class <info>%s</info>: <comment>OK!</comment>', $this->makePathRelative($generatorResult->getEntityPath())));
$output->writeln(sprintf('> Generating repository class <info>%s</info>: <comment>OK!</comment>', $this->makePathRelative($generatorResult->getRepositoryPath())));
if ($generatorResult->getMappingPath()) {
$output->writeln(sprintf('> Generating mapping file <info>%s</info>: <comment>OK!</comment>', $this->makePathRelative($generatorResult->getMappingPath())));
}
$questionHelper->writeGeneratorSummary($output, array());
}
示例15: execute
/**
* @throws \InvalidArgumentException When the bundle doesn't end with Bundle (Example: "Bundle/MySampleBundle")
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$questionHelper = $this->getQuestionHelper();
if ($input->isInteractive()) {
$question = new ConfirmationQuestion($questionHelper->getQuestion('Do you confirm generation', 'yes', '?'), true);
if (!$questionHelper->ask($input, $output, $question)) {
$output->writeln('<error>Command aborted</error>');
return 1;
}
}
$entity = Validators::validateEntityName($input->getOption('entity'));
list($bundle, $entity) = $this->parseShortcutNotation($entity);
$format = Validators::validateFormat($input->getOption('format'));
$fields = $this->parseFields($input->getOption('fields'));
$questionHelper->writeSection($output, 'Entity generation');
$bundle = $this->getContainer()->get('kernel')->getBundle($bundle);
$generator = $this->getGenerator();
$generator->generate($bundle, $entity, $format, array_values($fields), $input->getOption('with-repository'));
$output->writeln('Generating the entity code: <info>OK</info>');
$questionHelper->writeGeneratorSummary($output, array());
}