Repository navigation
Closed
Description
This issue only applies to non-generator commands
Problem/Motivation
Register DC core commands as services on the DC container.
Why
- Improve command discover by using code like this:
$tags = $this->container->findTaggedServiceIds('console.command');
foreach ($tags as $name => $tags) {
$this->add($this->getContainerHelper()->get($name));
}
- Instead of the current FileSystem discovery CommandDiscoveryHelper
Solution
Remove use keyword
use Drupal\Console\Command\Command;
# or
use Drupal\Console\Command\ContainerAwareCommand;
Add new use keyword:
use Symfony\Component\Console\Command\Command;
Update class to extend from Command
NOTE: Instead of
CommandorContainerAwareCommand
Before:
class AwesomeCommand extends Command
# or
class AwesomeCommand extends ContainerAwareCommand
After
class AwesomeCommand extends Command
Add use keyword for trait
For commands previously extending Command
Add use keyword
use Drupal\Console\Command\Shared\CommandTrait;
Add use trait:
use CommandTrait;
For commands previously extending ContainerAwareCommand
Add use keyword
use Drupal\Console\Command\Shared\ContainerAwareCommandTrait;
Add use trait:
use ContainerAwareCommandTrait;
Register command class as a service at config/services/NAMESPACE.yml
awesome:
class: Drupal\Console\Command\AwesomeCommand
tags:
- { name: console.command }
NOTE: Make sure you get latest changes from Drupal Console repository for instructions Keeping your fork up to date
Replace calls to any of the helpers on the Command class
| Before | After |
|---|---|
| $this->getSite(); | $this->getApplication()->getSite(); |
| $this->getChain(); | $this->get('chain_queue'); |
| $this->getStringHelper(); | $this->getApplication()->getStringHelper(); |
| $this->getValidator(); | $this->getApplication()->getValidator(); |
| $this->getDrupalHelper(); | $this->get('site'); |
| $this->getKernelHelper(); | $this->getApplication()->getKernelHelper(); |
| $this->getShowFileHelper(); | $this->get('showfile'); |
| $this->getRenderHelper() | $this->getApplication()->getRenderHelper() |
| $this->getNestedArrayHelper() | $this->getApplication()->getNestedArrayHelper() |
| $this->getCommandDiscoveryHelper() | $this->getApplication()->getCommandDiscoveryHelper() |
| $this->getRemoteHelper() | $this->getApplication()->getRemoteHelper() |
| $this->getHttpClientHelper() | $this->getApplication()->getHttpClientHelper() |
| $this->getDrupalApi() | $this->getApplication()->getDrupalApi() |
| $this->getContainerHelper() | $this->getApplication()->getContainerHelper() |
Replace any calls:
| Before | After |
|---|---|
| $this->getService('SERVIDE_NAME'); | $this->getDrupalService('SERVIDE_NAME'); |
| $this->hasService('SERVIDE_NAME'); | $this->hasDrupalService('SERVIDE_NAME'); |
Completed Namespace
- Miscellaneous without Namespace.
- Breakpoints Namespace
- Chain Namespace
- Config Namespace
- Create Namespace
- Cron Namespace
- Database Namespace
- Develop Namespace
- Exclude Namespace
-
Generate Namespace (This will be done in another issue) - Image Namespace
- Libraries Namespace
- Migrate Namespace (WIP)
- Module Namespace
- Multisite Namespace
- Node Namespace
- Rest Namespace
- Router Namespace
- Self Namespace
- Settings Namespace
- Site Namespace
- State Namespace
- Test Namespace
- Theme Namespace
- Update Namespace
- User Namespace
- Views Namespace
- Yaml Namespace
Activity
[-]Register commands as services[/-][+][meta] Register commands as services[/+]jmolivas commentedon May 9, 2016
[plugin:debug] Register Command as a Service. #2227 by @omero
Merge pull request #2231 from darol100/view-plugin-debug-service
[chain] Register Command as a Service. hechoendrupal#2225
[chain:debug] Register Command as a Service. hechoendrupal#2225
[config:debug] Register Command as a Service. hechoendrupal#2225
Merge pull request #2240 from omero/config-debug-register-command-ser…
[config:delete] Register Command as a Service. hechoendrupal#2225
[config:diff] Register Command as a Service. hechoendrupal#2225
[config:edit] Register Command as a Service. hechoendrupal#2225
[config:export] Register Command as a Service. hechoendrupal#2225
[config:export:content:type] Register Command as a Service. hechoendr…
[config:export:view] Register Command as a Service. hechoendrupal#2225
14 remaining items
[database:restore] Register Command as a Service. hechoendrupal#2225
[database:table:debug] Register Command as a Service. hechoendrupal#2225
[image:styles:debug] Register Command as a Service. hechoendrupal#2225
[image:styles:flush] Register Command as a Service. hechoendrupal#2225
[libraries:debug] Register Command as a Service. hechoendrupal#2225
[module:debug] Register Command as a Service. hechoendrupal#2225
[module:install] Register Command as a Service. hechoendrupal#2225
[module:uninstall] Register Command as a Service. hechoendrupal#2225
[state:*] Register command as service #2225 (#2381)
[multisite:new] Registers command as a service @see hechoendrupal#2225
[multisite:new] Sets up files for a new multisite installation #23 (#…
Saphyel commentedon Jun 12, 2016
Themeis already merge in, andYamlon the way..? #2417[yaml] as a service (#2417)
jmolivas commentedon Dec 2, 2016
Yay completed thank you all the participants on this issue