5 * Contains \Drupal\Console\Command\Rest\DebugCommand.
8 namespace Drupal\Console\Command\Rest;
10 use Symfony\Component\Console\Input\InputArgument;
11 use Symfony\Component\Console\Input\InputOption;
12 use Symfony\Component\Console\Input\InputInterface;
13 use Symfony\Component\Console\Output\OutputInterface;
14 use Symfony\Component\Console\Command\Command;
15 use Drupal\Console\Core\Command\Shared\CommandTrait;
16 use Drupal\Console\Annotations\DrupalCommand;
17 use Drupal\Console\Core\Style\DrupalStyle;
18 use Drupal\Console\Command\Shared\RestTrait;
19 use Drupal\rest\Plugin\Type\ResourcePluginManager;
24 * extensionType = "module"
27 class DebugCommand extends Command
34 * @var ResourcePluginManager $pluginManagerRest
36 protected $pluginManagerRest;
39 * DebugCommand constructor.
41 * @param ResourcePluginManager $pluginManagerRest
43 public function __construct(ResourcePluginManager $pluginManagerRest)
45 $this->pluginManagerRest = $pluginManagerRest;
46 parent::__construct();
49 protected function configure()
52 ->setName('rest:debug')
53 ->setDescription($this->trans('commands.rest.debug.description'))
56 InputArgument::OPTIONAL,
57 $this->trans('commands.rest.debug.arguments.resource-id')
62 InputOption::VALUE_OPTIONAL,
63 $this->trans('commands.rest.debug.options.status')
67 protected function execute(InputInterface $input, OutputInterface $output)
69 $io = new DrupalStyle($input, $output);
71 $resource_id = $input->getArgument('resource-id');
72 $status = $input->getOption('authorization');
75 $this->restDetail($io, $resource_id);
77 $this->restList($io, $status);
83 private function restDetail(DrupalStyle $io, $resource_id)
85 $config = $this->getRestDrupalConfig();
87 $plugin = $this->pluginManagerRest->getInstance(['id' => $resource_id]);
92 $this->trans('commands.rest.debug.messages.not-found'),
100 $resource = $plugin->getPluginDefinition();
104 $this->trans('commands.rest.debug.messages.id'),
108 $this->trans('commands.rest.debug.messages.label'),
109 (string) $resource['label']
112 $this->trans('commands.rest.debug.messages.canonical_url'),
113 $resource['uri_paths']['canonical']
116 $this->trans('commands.rest.debug.messages.status'),
117 (isset($config[$resource['id']])) ? $this->trans('commands.rest.debug.messages.enabled') : $this->trans('commands.rest.debug.messages.disabled')];
121 'commands.rest.debug.messages.provider',
122 $resource['provider']
127 $io->comment($resource_id);
130 $io->table([], $configuration, 'compact');
133 $this->trans('commands.rest.debug.messages.rest-state'),
134 $this->trans('commands.rest.debug.messages.supported-formats'),
135 $this->trans('commands.rest.debug.messages.supported_auth'),
139 foreach ($config[$resource['id']] as $method => $settings) {
142 implode(', ', $settings['supported_formats']),
143 implode(', ', $settings['supported_auth']),
147 $io->table($tableHeader, $tableRows);
150 protected function restList(DrupalStyle $io, $status)
152 $rest_resources = $this->getRestResources($status);
155 $this->trans('commands.rest.debug.messages.id'),
156 $this->trans('commands.rest.debug.messages.label'),
157 $this->trans('commands.rest.debug.messages.canonical_url'),
158 $this->trans('commands.rest.debug.messages.status'),
159 $this->trans('commands.rest.debug.messages.provider'),
163 foreach ($rest_resources as $status => $resources) {
164 foreach ($resources as $id => $resource) {
168 $resource['uri_paths']['canonical'],
170 $resource['provider'],
174 $io->table($tableHeader, $tableRows, 'compact');