Commit d6ac6e41 authored by moshe weitzman's avatar moshe weitzman

Add DI to devel's Drush commands.

parent 71a91440
......@@ -8,6 +8,9 @@ use Drush\Commands\DrushCommands;
/**
* For commands that are parts of modules, Drush expects to find commandfiles in
* __MODULE__/src/Commands, and the namespace is Drupal/__MODULE__/Commands.
*
* In addition to a commandfile like this one, you need to add a drush.services.yml
* in root of your module like this module does.
*/
class DevelGenerateCommands extends DrushCommands {
......
services:
devel.command:
class: Drupal\devel\Commands\DevelCommands
arguments: ['@token', '@service_container', '@event_dispatcher']
tags:
- { name: drush.command }
......@@ -2,6 +2,7 @@
namespace Drupal\devel\Commands;
use Consolidation\OutputFormatters\StructuredData\RowsOfFields;
use Drupal\Component\Uuid\Php;
use Drupal\Core\Utility\Token;
use Drush\Commands\DrushCommands;
use Drush\Exceptions\UserAbortException;
......@@ -14,6 +15,40 @@ use Drush\Exceptions\UserAbortException;
*/
class DevelCommands extends DrushCommands {
protected $token;
protected $container;
protected $eventDispatcher;
public function __construct(Token $token, $container, $eventDispatcher) {
parent::__construct();
$this->token = $token;
$this->container = $container;
$this->eventDispatcher = $eventDispatcher;
}
/**
* @return mixed
*/
public function getEventDispatcher() {
return $this->eventDispatcher;
}
/**
* @return mixed
*/
public function getContainer() {
return $this->container;
}
/**
* @return Token
*/
public function getToken() {
return $this->token;
}
/**
* Uninstall, and Install a list of modules.
......@@ -75,7 +110,7 @@ class DevelCommands extends DrushCommands {
* @aliases fne,fn-event,event
*/
function event($event) {
$dispatcher = \Drupal::service('event_dispatcher');
$dispatcher = $this->getEventDispatcher();
if (empty($event)) {
// @todo Expand this list and move to interact().
$events = array('kernel.controller', 'kernel.exception', 'kernel.request', 'kernel.response', 'kernel.terminate', 'kernel.view');
......@@ -115,7 +150,7 @@ class DevelCommands extends DrushCommands {
* @return \Consolidation\OutputFormatters\StructuredData\RowsOfFields
*/
public function token($options = ['format' => 'table']) {
$all = \Drupal::token()->getInfo();
$all = $this->getToken()->getInfo();
foreach ($all['tokens'] as $group => $tokens) {
foreach ($tokens as $key => $token) {
$rows[] = [
......@@ -185,7 +220,7 @@ class DevelCommands extends DrushCommands {
* @return array
*/
public function services($prefix = NULL, $options = ['format' => 'yaml']) {
$container = \Drupal::getContainer();
$container = $this->getContainer();
// Get a list of all available service IDs.
$services = $container->getServiceIds();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment