php Drupal-Console-Style-DrupalStyle类(方法)实例源码

下面列出了php Drupal-Console-Style-DrupalStyle 类(方法)源码代码实例,从而了解它的用法。

作者:jlbellid    项目:DrupalConsol   
/**
  * {@inheritdoc}
  */
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     // --module option
     $module = $input->getOption('module');
     if (!$module) {
         // @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion
         $module = $this->moduleQuestion($output);
         $input->setOption('module', $module);
     }
     // --name option
     $name = $input->getOption('name');
     if (!$name) {
         $name = $io->ask($this->trans('commands.generate.twig.extension.questions.twig-extension'), $module . '.twig.extension');
         $input->setOption('name', $name);
     }
     // --class option
     $class = $input->getOption('class');
     if (!$class) {
         $class = $io->ask($this->trans('commands.common.options.class'), 'DefaultTwigExtension');
         $input->setOption('class', $class);
     }
     // --services option
     $services = $input->getOption('services');
     if (!$services) {
         // @see Drupal\Console\Command\Shared\ServicesTrait::servicesQuestion
         $services = $this->servicesQuestion($output);
         $input->setOption('services', $services);
     }
 }

作者:durgesh    项目:DrupalConsol   
protected function interact(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     // --module option
     $module = $input->getOption('module');
     if (!$module) {
         // @see Drupal\Console\Command\ModuleTrait::moduleQuestion
         $module = $this->moduleQuestion($output);
         $input->setOption('module', $module);
     }
     // --class option
     $class = $input->getOption('class');
     if (!$class) {
         $class = $io->ask($this->trans('commands.generate.plugin.mail.options.class'), 'HtmlFormatterMail', function ($class) {
             return $this->validateClassName($class);
         });
         $input->setOption('class', $class);
     }
     // --label option
     $label = $input->getOption('label');
     if (!$label) {
         $label = $io->ask($this->trans('commands.generate.plugin.mail.options.label'), $this->getStringHelper()->camelCaseToHuman($class));
         $input->setOption('label', $label);
     }
     // --plugin-id option
     $pluginId = $input->getOption('plugin-id');
     if (!$pluginId) {
         $pluginId = $io->ask($this->trans('commands.generate.plugin.mail.options.plugin-id'), $this->getStringHelper()->camelCaseToUnderscore($class));
         $input->setOption('plugin-id', $pluginId);
     }
     // --services option
     // @see Drupal\Console\Command\ServicesTrait::servicesQuestion
     $services = $this->servicesQuestion($output);
     $input->setOption('services', $services);
 }

作者:mnic    项目:DrupalConsol   
/**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $tableHeader = [$this->trans('commands.queue.debug.messages.queue'), $this->trans('commands.queue.debug.messages.items'), $this->trans('commands.queue.debug.messages.class')];
     $tableBody = $this->listQueues();
     $io->table($tableHeader, $tableBody);
 }

作者:shakti    项目:DrupalConsol   
/**
  * {@inheritdoc}
  */
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $validator_filename = function ($value) use($io) {
         if (!strlen(trim($value)) || !is_file($value)) {
             $io->error($this->trans('commands.common.errors.invalid-file-path'));
             return false;
         }
         return $value;
     };
     // --yaml-left option
     $yaml_left = $input->getArgument('yaml-left');
     if (!$yaml_left) {
         while (true) {
             $yaml_left = $output->ask($this->trans('commands.yaml.diff.questions.yaml-left'), null, $validator_filename);
             if ($yaml_left) {
                 break;
             }
         }
         $input->setArgument('yaml-left', $yaml_left);
     }
     // --yaml-right option
     $yaml_right = $input->getArgument('yaml-right');
     if (!$yaml_right) {
         while (true) {
             $yaml_right = $output->ask($this->trans('commands.yaml.diff.questions.yaml-right'), null, $validator_filename);
             if ($yaml_right) {
                 break;
             }
         }
         $input->setArgument('yaml-right', $yaml_right);
     }
 }

作者:ranqiangju    项目:DrupalConsol   
protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $moduleHandler = $this->moduleHandler;
     $moduleHandler->loadInclude('locale', 'inc', 'locale.translation');
     $moduleHandler->loadInclude('locale', 'module');
     $language = $input->getArgument('language');
     $languagesObjects = locale_translatable_language_list();
     $languages = $this->site->getStandardLanguages();
     if (isset($languagesObjects[$language])) {
         $languageEntity = $languagesObjects[$language];
     } elseif (array_search($language, $languages)) {
         $langcode = array_search($language, $languages);
         $languageEntity = $languagesObjects[$langcode];
     } else {
         $io->error(sprintf($this->trans('commands.locale.language.delete.messages.invalid-language'), $language));
         return 1;
     }
     try {
         $configurable_language_storage = $this->entityTypeManager->getStorage('configurable_language');
         $configurable_language_storage->load($languageEntity->getId())->delete();
         $io->info(sprintf($this->trans('commands.locale.language.delete.messages.language-deleted-successfully'), $languageEntity->getName()));
     } catch (\Exception $e) {
         $io->error($e->getMessage());
         return 1;
     }
     return 0;
 }

作者:blasoliv    项目:DrupalConsol   
protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $language = $input->getArgument('language');
     $tableHeader = [$this->trans('commands.locale.translation.status.messages.project'), $this->trans('commands.locale.translation.status.messages.version'), $this->trans('commands.locale.translation.status.messages.local-age'), $this->trans('commands.locale.translation.status.messages.remote-age'), $this->trans('commands.locale.translation.status.messages.info')];
     $languages = locale_translatable_language_list();
     $status = locale_translation_get_status();
     $this->getModuleHandler()->loadInclude('locale', 'compare.inc');
     if (!$languages) {
         $io->info($this->trans('commands.locale.translation.status.messages.no-languages'));
         return;
     } elseif (empty($status)) {
         $io->info($this->trans('commands.locale.translation.status.messages.no-translations'));
         return;
     }
     if ($languages) {
         $projectsStatus = $this->projectsStatus();
         foreach ($projectsStatus as $langcode => $rows) {
             $tableRows = [];
             if ($language != '' && !($language == $langcode || strtolower($language) == strtolower($languages[$langcode]->getName()))) {
                 continue;
             }
             $io->info($languages[$langcode]->getName());
             foreach ($rows as $row) {
                 if ($row[0] == 'drupal') {
                     $row[0] = $this->trans('commands.common.messages.drupal-core');
                 }
                 $tableRows[] = $row;
             }
             $io->table($tableHeader, $tableRows, 'compact');
         }
     }
 }

作者:eleag    项目:DrupalConsol   
protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $module_handler = $this->getModuleHandler();
     $io->section($this->trans('commands.cron.debug.messages.module-list'));
     $io->table([$this->trans('commands.cron.debug.messages.module')], $module_handler->getImplementations('cron'), 'compact');
 }

作者:durgesh    项目:DrupalConsol   
/**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /**
      * DrupalConsole extends the SymfonyStyle class to provide
      * an standardized Output Formatting Style.
      *
      * Drupal Console provides the DrupalStyle helper class:
      */
     $io = new DrupalStyle($input, $output);
     $io->simple('This text could be translatable by');
     $io->simple('adding a YAML file at "config/translations/LANGUAGE/command.name.yml"');
     /**
      *  By using ContainerAwareCommand as the base class for the command
      *  (instead of the more basic Command), you have access to
      *  the service container.
      *
      *  In other words, you can access to any configured Drupal service
      *  using the provided getService method.
      *
      *  $this->getService('entity_type.manager');
      *
      *  Reading user input argument
      *  $input->getArgument('ARGUMENT_NAME');
      *
      *  Reading user input option
      *  $input->getOption('OPTION_NAME');
      */
 }

作者:GDrupa    项目:DrupalConsol   
protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $resource_id = $input->getArgument('resource-id');
     $rest_resources = $this->getRestResources();
     $rest_resources_ids = array_merge(array_keys($rest_resources['enabled']), array_keys($rest_resources['disabled']));
     if (!$resource_id) {
         $resource_id = $io->choiceNoList($this->trans('commands.rest.enable.arguments.resource-id'), $rest_resources_ids);
     }
     $this->validateRestResource($resource_id, $rest_resources_ids, $this->translator);
     $input->setArgument('resource-id', $resource_id);
     // Calculate states available by resource and generate the question.
     $plugin = $this->pluginManagerRest->getInstance(['id' => $resource_id]);
     $methods = $plugin->availableMethods();
     $method = $io->choice($this->trans('commands.rest.enable.arguments.methods'), $methods);
     $io->writeln($this->trans('commands.rest.enable.messages.selected-method') . ' ' . $method);
     $format = $io->choice($this->trans('commands.rest.enable.arguments.formats'), $this->formats);
     $io->writeln($this->trans('commands.rest.enable.messages.selected-format') . ' ' . $format);
     // Get Authentication Provider and generate the question
     $authenticationProviders = $this->authenticationCollector->getSortedProviders();
     $authenticationProvidersSelected = $io->choice($this->trans('commands.rest.enable.messages.authentication-providers'), array_keys($authenticationProviders), 0, true);
     $io->writeln($this->trans('commands.rest.enable.messages.selected-authentication-providers') . ' ' . implode(', ', $authenticationProvidersSelected));
     $format_resource_id = str_replace(':', '.', $resource_id);
     $config = $this->entityManager->getStorage('rest_resource_config')->load($format_resource_id);
     if (!$config) {
         $config = $this->entityManager->getStorage('rest_resource_config')->create(['id' => $format_resource_id, 'granularity' => RestResourceConfigInterface::METHOD_GRANULARITY, 'configuration' => []]);
     }
     $configuration = $config->get('configuration') ?: [];
     $configuration[$method] = ['supported_formats' => [$format], 'supported_auth' => $authenticationProvidersSelected];
     $config->set('configuration', $configuration);
     $config->save();
     $message = sprintf($this->trans('commands.rest.enable.messages.success'), $resource_id);
     $io->info($message);
     return true;
 }

作者:blasoliv    项目:DrupalConsol   
/**
  * @param \Drupal\Console\Style\DrupalStyle $io
  * @param $eventType
  * @param $eventSeverity
  * @param $userId
  * @return bool
  */
 protected function clearEvents(DrupalStyle $io, $eventType, $eventSeverity, $userId)
 {
     $connection = $this->getDatabase();
     $severity = RfcLogLevel::getLevels();
     $query = $connection->delete('watchdog');
     if ($eventType) {
         $query->condition('type', $eventType);
     }
     if ($eventSeverity) {
         if (!in_array($eventSeverity, $severity)) {
             $io->error(sprintf($this->trans('commands.database.log.clear.messages.invalid-severity'), $eventSeverity));
             return false;
         }
         $query->condition('severity', array_search($eventSeverity, $severity));
     }
     if ($userId) {
         $query->condition('uid', $userId);
     }
     $result = $query->execute();
     if (!$result) {
         $io->error($this->trans('commands.database.log.clear.messages.clear-error'));
         return false;
     }
     $io->success($this->trans('commands.database.log.clear.messages.clear-sucess'));
     return true;
 }

作者:mnic    项目:DrupalConsol   
/**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $learning = $input->hasOption('learning') ? $input->getOption('learning') : false;
     $address = $input->getArgument('address');
     if (false === strpos($address, ':')) {
         $address = sprintf('%s:8088', $address);
     }
     $finder = new PhpExecutableFinder();
     if (false === ($binary = $finder->find())) {
         $io->error($this->trans('commands.server.errors.binary'));
         return;
     }
     $router = $this->getRouterPath();
     $cli = sprintf('%s %s %s %s', $binary, '-S', $address, $router);
     if ($learning) {
         $io->commentBlock($cli);
     }
     $io->success(sprintf($this->trans('commands.server.messages.executing'), $binary));
     $processBuilder = new ProcessBuilder(explode(' ', $cli));
     $process = $processBuilder->getProcess();
     $process->setWorkingDirectory($this->get('site')->getRoot());
     $process->setTty('true');
     $process->run();
     if (!$process->isSuccessful()) {
         $io->error($process->getErrorOutput());
     }
 }

作者:vielsof    项目:DrupalConsol   
/**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $vocabularies = $this->getDrupalApi()->getVocabularies();
     // Validate provided vocabularies
     $vids = $input->getArgument('vocabularies');
     $invalidVids = array_filter(array_map(function ($vid) use($vocabularies) {
         if (!isset($vocabularies[$vid])) {
             return $vid;
         } else {
             return null;
         }
     }, $vids));
     if (!empty($invalidVids)) {
         $io->error(sprintf($this->trans('commands.create.terms.messages.invalid-vocabularies'), implode(',', $invalidVids)));
         return;
     }
     $limit = $input->getOption('limit') ?: 10;
     $nameWords = $input->getOption('name-words') ?: 5;
     $createTerms = $this->getDrupalApi()->getCreateTerms();
     $terms = $createTerms->createTerm($vids, $limit, $nameWords);
     $tableHeader = [$this->trans('commands.create.terms.messages.term-id'), $this->trans('commands.create.terms.messages.vocabulary'), $this->trans('commands.create.terms.messages.name')];
     $io->table($tableHeader, $terms['success']);
     $io->success(sprintf($this->trans('commands.create.terms.messages.created-terms'), $limit));
     return;
 }

作者:ibonell    项目:DrupalConsol   
/**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $styles = $input->getArgument('styles');
     $result = 0;
     $imageStyle = $this->entityTypeManager->getStorage('image_style');
     $stylesNames = [];
     if (in_array('all', $styles)) {
         $styles = $imageStyle->loadMultiple();
         foreach ($styles as $style) {
             $stylesNames[] = $style->get('name');
         }
         $styles = $stylesNames;
     }
     foreach ($styles as $style) {
         try {
             $io->info(sprintf($this->trans('commands.image.styles.flush.messages.executing-flush'), $style));
             $imageStyle->load($style)->flush();
         } catch (\Exception $e) {
             watchdog_exception('image', $e);
             $io->error($e->getMessage());
             $result = 1;
         }
     }
     $io->success($this->trans('commands.image.styles.flush.messages.success'));
     return $result;
 }

作者:ibonell    项目:DrupalConsol   
protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $moduleHandler = $this->moduleHandler;
     $moduleHandler->loadInclude('locale', 'inc', 'locale.translation');
     $moduleHandler->loadInclude('locale', 'module');
     $language = $input->getArgument('language');
     $languages = $this->site->getStandardLanguages();
     if (isset($languages[$language])) {
         $langcode = $language;
     } elseif (array_search($language, $languages)) {
         $langcode = array_search($language, $languages);
     } else {
         $io->error(sprintf($this->trans('commands.locale.language.add.messages.invalid-language'), $language));
         return 1;
     }
     try {
         $language = ConfigurableLanguage::createFromLangcode($langcode);
         $language->type = LOCALE_TRANSLATION_REMOTE;
         $language->save();
         $io->info(sprintf($this->trans('commands.locale.language.add.messages.language-add-successfully'), $language->getName()));
     } catch (\Exception $e) {
         $io->error($e->getMessage());
         return 1;
     }
     return 0;
 }

作者:mnic    项目:DrupalConsol   
/**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $uid = $input->getArgument('uid');
     $account = User::load($uid);
     if (!$account) {
         // Error loading User entity.
         $io->error(sprintf($this->trans('commands.user.login.clear.attempts.errors.invalid-user'), $uid));
         return 1;
     }
     // Define event name and identifier.
     $event = 'user.failed_login_user';
     // Identifier is created by uid and IP address,
     // Then we defined a generic identifier.
     $identifier = "{$account->id()}-";
     // Retrieve current database connection.
     $database = $this->getDrupalService('database');
     $schema = $database->schema();
     $flood = $schema->findTables('flood');
     if (!$flood) {
         $io->error($this->trans('commands.user.login.clear.attempts.errors.no-flood'));
         return 1;
     }
     // Clear login attempts.
     $database->delete('flood')->condition('event', $event)->condition('identifier', $database->escapeLike($identifier) . '%', 'LIKE')->execute();
     // Command executed successful.
     $io->success(sprintf($this->trans('commands.user.login.clear.attempts.messages.successful'), $uid));
 }

作者:blasoliv    项目:DrupalConsol   
protected function interact(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     // --module option
     $module = $input->getOption('module');
     if (!$module) {
         // @see Drupal\Console\Command\ModuleTrait::moduleQuestion
         $module = $this->moduleQuestion($output);
         $input->setOption('module', $module);
     }
     // --class option
     $class_name = $input->getOption('class');
     if (!$class_name) {
         $class_name = $io->ask($this->trans('commands.generate.plugin.type.annotation.options.class'), 'ExamplePlugin');
         $input->setOption('class', $class_name);
     }
     // --machine-name option
     $machine_name = $input->getOption('machine-name');
     if (!$machine_name) {
         $machine_name = $io->ask($this->trans('commands.generate.plugin.type.annotation.options.machine-name'), $this->getStringHelper()->camelCaseToUnderscore($class_name));
         $input->setOption('machine-name', $machine_name);
     }
     // --label option
     $label = $input->getOption('label');
     if (!$label) {
         $label = $output->ask($this->trans('commands.generate.plugin.type.annotation.options.label'), $this->getStringHelper()->camelCaseToHuman($class_name));
         $input->setOption('label', $label);
     }
 }

作者:blasoliv    项目:DrupalConsol   
/**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $roles = $input->getOption('roles');
     $limit = $input->getOption('limit');
     $entityManager = $this->getEntityManager();
     $userStorage = $entityManager->getStorage('user');
     $systemRoles = $this->getDrupalApi()->getRoles();
     $entityQuery = $this->getEntityQuery();
     $query = $entityQuery->get('user');
     $query->condition('uid', 0, '>');
     $query->sort('uid');
     if ($roles) {
         $query->condition('roles', is_array($roles) ? $roles : [$roles], 'IN');
     }
     if ($limit) {
         $query->range(0, $limit);
     }
     $results = $query->execute();
     $users = $userStorage->loadMultiple($results);
     $tableHeader = [$this->trans('commands.user.debug.messages.user-id'), $this->trans('commands.user.debug.messages.username'), $this->trans('commands.user.debug.messages.roles'), $this->trans('commands.user.debug.messages.status')];
     $tableRows = [];
     foreach ($users as $userId => $user) {
         $userRoles = [];
         foreach ($user->getRoles() as $userRole) {
             $userRoles[] = $systemRoles[$userRole];
         }
         $status = $user->isActive() ? $this->trans('commands.common.status.enabled') : $this->trans('commands.common.status.disabled');
         $tableRows[] = [$userId, $user->getUsername(), implode(', ', $userRoles), $status];
     }
     $io->table($tableHeader, $tableRows);
 }

作者:mnic    项目:DrupalConsol   
protected function interact(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     // --module option
     $module = $input->getOption('module');
     if (!$module) {
         // @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion
         $module = $this->moduleQuestion($output);
         $input->setOption('module', $module);
     }
     // --class option
     $class_name = $input->getOption('class');
     if (!$class_name) {
         $class_name = $io->ask($this->trans('commands.generate.plugin.imageeffect.questions.class'), 'DefaultImageEffect');
         $input->setOption('class', $class_name);
     }
     // --label option
     $label = $input->getOption('label');
     if (!$label) {
         $label = $io->ask($this->trans('commands.generate.plugin.imageeffect.questions.label'), $this->getStringHelper()->camelCaseToHuman($class_name));
         $input->setOption('label', $label);
     }
     // --plugin-id option
     $plugin_id = $input->getOption('plugin-id');
     if (!$plugin_id) {
         $plugin_id = $io->ask($this->trans('commands.generate.plugin.imageeffect.questions.plugin-id'), $this->getStringHelper()->camelCaseToUnderscore($class_name));
         $input->setOption('plugin-id', $plugin_id);
     }
     // --description option
     $description = $input->getOption('description');
     if (!$description) {
         $description = $io->ask($this->trans('commands.generate.plugin.imageeffect.questions.description'), 'My Image Effect');
         $input->setOption('description', $description);
     }
 }

作者:mnic    项目:DrupalConsol   
protected function interact(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     // --module option
     $module = $input->getOption('module');
     if (!$module) {
         // @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion
         $module = $this->moduleQuestion($output);
         $input->setOption('module', $module);
     }
     // --class option
     $class_name = $input->getOption('class');
     if (!$class_name) {
         $class_name = $io->ask($this->trans('commands.generate.plugin.type.yaml.options.class'), 'ExamplePlugin');
         $input->setOption('class', $class_name);
     }
     // --plugin-name option
     $plugin_name = $input->getOption('plugin-name');
     if (!$plugin_name) {
         $plugin_name = $io->ask($this->trans('commands.generate.plugin.type.yaml.options.plugin-name'), $this->getStringHelper()->camelCaseToUnderscore($class_name));
         $input->setOption('plugin-name', $plugin_name);
     }
     // --plugin-file-name option
     $plugin_file_name = $input->getOption('plugin-file-name');
     if (!$plugin_file_name) {
         $plugin_file_name = $io->ask($this->trans('commands.generate.plugin.type.yaml.options.plugin-file-name'), strtr($plugin_name, '_-', '..'));
         $input->setOption('plugin-file-name', $plugin_file_name);
     }
 }

作者:ibonell    项目:DrupalConsol   
/**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $language = $input->getArgument('language');
     $format = $input->getOption('format');
     $application = $this->getApplication();
     $appRoot = $application->getDirectoryRoot();
     $languages = $application->getConfig()->get('application.languages');
     unset($languages['en']);
     if ($language && !isset($languages[$language])) {
         $io->error(sprintf($this->trans('commands.translation.stats.messages.invalid-language'), $language));
         return 1;
     }
     if ($language) {
         $languages = [$language => $languages[$language]];
     }
     $stats = $this->calculateStats($io, $language, $languages, $appRoot);
     if ($format == 'table') {
         $tableHeaders = [$this->trans('commands.translation.stats.messages.language'), $this->trans('commands.translation.stats.messages.percentage'), $this->trans('commands.translation.stats.messages.iso')];
         $io->table($tableHeaders, $stats);
         return 0;
     }
     if ($format == 'markdown') {
         $arguments['language'] = $this->trans('commands.translation.stats.messages.language');
         $arguments['percentage'] = $this->trans('commands.translation.stats.messages.percentage');
         $arguments['languages'] = $stats;
         $io->writeln($this->getRenderHelper()->render('core/translation/stats.md.twig', $arguments));
     }
 }


问题


面经


文章

微信
公众号

扫码关注公众号