5 * Contains \Drupal\Console\Command\Debug\RestCommand.
8 namespace Drupal\Console\Command\Debug;
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 Drupal\Console\Core\Command\Command;
15 use Drupal\Console\Annotations\DrupalCommand;
16 use Drupal\Console\Command\Shared\RestTrait;
17 use Drupal\rest\Plugin\Type\ResourcePluginManager;
22 * extensionType = "module"
25 class RestCommand extends Command
30 * @var ResourcePluginManager $pluginManagerRest
32 protected $pluginManagerRest;
35 * RestCommand constructor.
37 * @param ResourcePluginManager $pluginManagerRest
39 public function __construct(ResourcePluginManager $pluginManagerRest)
41 $this->pluginManagerRest = $pluginManagerRest;
42 parent::__construct();
45 protected function configure()
48 ->setName('debug:rest')
49 ->setDescription($this->trans('commands.debug.rest.description'))
52 InputArgument::OPTIONAL,
53 $this->trans('commands.debug.rest.arguments.resource-id')
58 InputOption::VALUE_OPTIONAL,
59 $this->trans('commands.debug.rest.options.status')
61 ->setAliases(['rede']);
64 protected function execute(InputInterface $input, OutputInterface $output)
66 $resource_id = $input->getArgument('resource-id');
67 $status = $input->getOption('authorization');
70 $this->restDetail($resource_id);
72 $this->restList($status);
78 private function restDetail($resource_id)
80 $config = $this->getRestDrupalConfig();
82 $plugin = $this->pluginManagerRest->getInstance(['id' => $resource_id]);
85 $this->getIo()->error(
87 $this->trans('commands.debug.rest.messages.not-found'),
95 $resource = $plugin->getPluginDefinition();
99 $this->trans('commands.debug.rest.messages.id'),
103 $this->trans('commands.debug.rest.messages.label'),
104 (string) $resource['label']
107 $this->trans('commands.debug.rest.messages.canonical-url'),
108 $resource['uri_paths']['canonical']
111 $this->trans('commands.debug.rest.messages.status'),
112 (isset($config[$resource['id']])) ? $this->trans('commands.debug.rest.messages.enabled') : $this->trans('commands.debug.rest.messages.disabled')];
116 'commands.debug.rest.messages.provider',
117 $resource['provider']
122 $this->getIo()->comment($resource_id);
123 $this->getIo()->newLine();
125 $this->getIo()->table([], $configuration, 'compact');
128 $this->trans('commands.debug.rest.messages.rest-state'),
129 $this->trans('commands.debug.rest.messages.supported-formats'),
130 $this->trans('commands.debug.rest.messages.supported-auth'),
134 foreach ($config[$resource['id']] as $method => $settings) {
137 implode(', ', $settings['supported_formats']),
138 implode(', ', $settings['supported-auth']),
142 $this->getIo()->table($tableHeader, $tableRows);
145 protected function restList($status)
147 $rest_resources = $this->getRestResources($status);
150 $this->trans('commands.debug.rest.messages.id'),
151 $this->trans('commands.debug.rest.messages.label'),
152 $this->trans('commands.debug.rest.messages.canonical-url'),
153 $this->trans('commands.debug.rest.messages.status'),
154 $this->trans('commands.debug.rest.messages.provider'),
158 foreach ($rest_resources as $status => $resources) {
159 foreach ($resources as $id => $resource) {
163 $resource['uri_paths']['canonical'],
165 $resource['provider'],
169 $this->getIo()->table($tableHeader, $tableRows, 'compact');