本文整理汇总了PHP中Sensio\Bundle\GeneratorBundle\Command\Validators类的典型用法代码示例。如果您正苦于以下问题:PHP Validators类的具体用法?PHP Validators怎么用?PHP Validators使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Validators类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
示例2: 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>', ''));
}
示例3: 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);
}
示例4: 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());
}
示例5: execute
/**
* @see Command
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln('');
$output->writeln(sprintf('<info>Generation of Crud Rest Controller for "%s" Document in "%s" bundle.</info>', $input->getOption('document'), $input->getOption('bundle')));
$output->writeln('');
$document = $input->getOption('document');
$bundle = $input->getOption('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 exist.</>', $bundle));
}
// Get document metadata
$dm = $this->getContainer()->get('doctrine_mongodb.odm.document_manager');
$class_metadata = $dm->getClassMetadata($document);
$generator = $this->getGenerator($this->getContainer()->get('kernel')->getBundle('RedkingCoreRestBundle'));
if ($input->getOption('no-controller') === false) {
$generator->generate($bundle, $class_metadata);
$output->writeln('Generating the CRUD code: <info>OK</info>');
}
if ($input->getOption('no-service') === false) {
$generator->generateServices($bundle, $class_metadata);
$output->writeln('Generating the services: <info>OK</info>');
}
if ($input->getOption('no-test') === false) {
$generator->generateTests($bundle, $class_metadata);
$output->writeln('Generating the functional test: <info>OK</info>');
}
if ($input->getOption('no-route') === false) {
$generator->generateRouting($bundle, $class_metadata);
$output->writeln('Add routing: <info>OK</info>');
}
}
示例6: execute
public function execute(InputInterface $input, OutputInterface $output)
{
$questionHelper = $this->getQuestionHelper();
if ($input->isInteractive() && !$input->getOption('no-summary')) {
$question = new Question($questionHelper->getQuestion('Do you confirm generation', 'yes', '?'), true);
if (!$questionHelper->ask($input, $output, $question)) {
$output->writeln('<error>Command aborted</error>');
return 1;
}
}
if (null === $input->getOption('controller')) {
throw new \RuntimeException('The controller option must be provided.');
}
list($bundle) = $this->parseShortcutNotation($input->getOption('controller'));
if (is_string($bundle)) {
$bundle = Validators::validateBundleName($bundle);
try {
$this->getContainer()->get('kernel')->getBundle($bundle);
} catch (\Exception $e) {
$output->writeln(sprintf('<bg=red>Bundle "%s" does not exist.</>', $bundle));
}
}
/** @var TemplateInterface $generator */
$generator = $this->getGenerator();
$questionHelper->writeSection($output, 'Controller generation');
$errors = array();
$runner = $questionHelper->getRunner($output, $errors);
$runner($generator->generate($input->getOption('controller')));
if (!$input->getOption('no-summary')) {
$questionHelper->writeGeneratorSummary($output, $generator->getErrors());
}
}
示例7: execute
/**
* Executes the command.
*
* @param InputInterface $input An InputInterface instance
* @param OutputInterface $output An OutputInterface instance
*
* @throws \RuntimeException
* @return void
*/
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('namespace', 'dir'));
$namespace = Validators::validateBundleNamespace($input->getOption('namespace'));
if (!($bundle = $input->getOption('bundle-name'))) {
$bundle = strtr($namespace, array('\\' => ''));
}
$bundle = Validators::validateBundleName($bundle);
$dir = $this::validateTargetDir($input->getOption('dir'), $bundle, $namespace);
$format = 'yml';
$questionHelper->writeSection($output, 'Bundle generation');
if (!$this->getContainer()->get('filesystem')->isAbsolutePath($dir)) {
$dir = getcwd() . '/' . $dir;
}
$generator = $this->getGenerator($this->getApplication()->getKernel()->getBundle("KunstmaanGeneratorBundle"));
$generator->generate($namespace, $bundle, $dir, $format);
$output->writeln('Generating the bundle code: <info>OK</info>');
$errors = array();
$runner = $questionHelper->getRunner($output, $errors);
// check that the namespace is already autoloaded
$runner($this->checkAutoloader($output, $namespace, $bundle));
// register the bundle in the Kernel class
$runner($this->updateKernel($questionHelper, $input, $output, $this->getContainer()->get('kernel'), $namespace, $bundle));
// routing
$runner($this->updateRouting($questionHelper, $input, $output, $bundle, $format));
$questionHelper->writeGeneratorSummary($output, $errors);
}
示例8: execute
public function execute(InputInterface $input, OutputInterface $output)
{
$questionHelper = $this->getQuestionHelper();
if ($input->isInteractive()) {
$question = new Question($questionHelper->getQuestion('Do you confirm generation', 'yes', '?'), true);
if (!$questionHelper->ask($input, $output, $question)) {
$output->writeln('<error>Command aborted</error>');
return 1;
}
}
if (null === $input->getOption('controller')) {
throw new \RuntimeException('The controller option must be provided.');
}
list($bundle, $controller) = $this->parseShortcutNotation($input->getOption('controller'));
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 exist.</>', $bundle));
}
}
$questionHelper->writeSection($output, 'Controller generation');
$generator = $this->getGenerator($bundle);
$generator->generate($bundle, $controller, $input->getOption('route-format'), $input->getOption('template-format'), $this->parseActions($input->getOption('actions')));
$output->writeln('Generating the bundle code: <info>OK</info>');
$questionHelper->writeGeneratorSummary($output, array());
}
示例9: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$namespace = $input->getOption('namespace');
$bundleName = strtr($namespace, array('\\' => ''));
$bundleName = Validators::validateBundleName($bundleName);
$bundle = new Bundle($namespace, $bundleName, getcwd() . '/src', 'yml', true);
/**
* @var UnitedBundleGenerator $generator
*/
$generator = $this->getGenerator();
$output->writeln(sprintf('> Generating a united admin bundle skeleton into <info>%s</info> <comment>OK!</comment>', $this->makePathRelative($bundle->getTargetDirectory())));
// Write section
$questionHelper = $this->getQuestionHelper();
$questionHelper->writeSection($output, 'Bundle generation');
// generate the bundle
$generator->generateBundle($bundle);
// After generation we need to perform some app updates
$errors = array();
$runner = $questionHelper->getRunner($output, $errors);
// register the bundle in the Kernel class
$runner($this->updateKernel($output, $this->getContainer()->get('kernel'), $bundle));
// routing importing
$runner($this->updateRouting($output, $bundle));
// print summary
$questionHelper->writeGeneratorSummary($output, $errors);
}
示例10: 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());
}
}
示例11: askForNamespace
/**
* Asks for the namespace and sets it on the InputInterface as the 'namespace' option, if this option is not set yet.
*
* @param array $text What you want printed before the namespace is asked.
*
* @return string The namespace. But it's also been set on the InputInterface.
*/
public function askForNamespace(array $text = null)
{
$namespace = $this->input->hasOption('namespace') ? $this->input->getOption('namespace') : null;
// When the Namespace is filled in return it immediately if valid.
try {
if (!is_null($namespace) && !empty($namespace)) {
Validators::validateBundleNamespace($namespace);
return $namespace;
}
} catch (\Exception $error) {
$this->writeError(array("Namespace '{$namespace}' is incorrect. Please provide a correct value.", $error->getMessage()));
exit;
}
$ownBundles = $this->getOwnBundles();
if (count($ownBundles) <= 0) {
$this->writeError("Looks like you don't have created a bundle for your project, create one first.", true);
}
$namespace = '';
// If we only have 1 or more bundles, we can prefill it.
if (count($ownBundles) > 0) {
$namespace = $ownBundles[1]['namespace'] . '/' . $ownBundles[1]['name'];
}
$namespaces = $this->getNamespaceAutoComplete($this->kernel);
if (!is_null($text) && count($text) > 0) {
$this->output->writeln($text);
}
$question = new Question($this->questionHelper->getQuestion('Bundle Namespace', $namespace), $namespace);
$question->setValidator(array('Sensio\\Bundle\\GeneratorBundle\\Command\\Validators', 'validateBundleNamespace'));
$question->setAutocompleterValues($namespaces);
$namespace = $this->questionHelper->ask($this->input, $this->output, $question);
if ($this->input->hasOption('namespace')) {
$this->input->setOption('namespace', $namespace);
}
return $namespace;
}
示例12: 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);
}
示例13: 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();
}
}
}
示例14: 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()));
}
示例15: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$questionHelper = $this->getQuestionHelper();
$questionHelper->writeSection($output, 'Admin Tests Generation');
GeneratorUtils::ensureOptionsProvided($input, array('namespace'));
$namespace = Validators::validateBundleNamespace($input->getOption('namespace'));
$bundle = strtr($namespace, array('\\Bundle\\' => '', '\\' => ''));
$bundle = $this->getApplication()->getKernel()->getBundle($bundle);
$generator = $this->getGenerator($this->getApplication()->getKernel()->getBundle("KunstmaanGeneratorBundle"));
$generator->generate($bundle, $output);
}