Skip to content

Commit

Permalink
Add Console container class replace call of invalid commands (#304)
Browse files Browse the repository at this point in the history
* Add Console container class replace call of invalid commands

* Rename ConsoleContainer class to KeyValueStorage

* Remove var_dump

* Add empty string in the end of the file
  • Loading branch information
LOBsTerr authored and jmolivas committed Feb 9, 2018
1 parent 7bbdebd commit 4d59986
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 5 deletions.
4 changes: 3 additions & 1 deletion services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ services:
class: Drupal\Console\Core\Utils\ShellProcess
arguments: ['@app.root', '@console.translator_manager']
console.string_converter:
class: Drupal\Console\Core\Utils\StringConverter
class: Drupal\Console\Core\Utils\StringConverter
console.chain_discovery:
class: Drupal\Console\Core\Utils\ChainDiscovery
arguments: ['@console.root', '@console.configuration_manager', '@console.message_manager', '@console.translator_manager']
Expand All @@ -33,6 +33,8 @@ services:
class: Drupal\Console\Core\Utils\MessageManager
console.drupal_finder:
class: Drupal\Console\Core\Utils\DrupalFinder
console.key_value_storage:
class: Drupal\Console\Core\Utils\KeyValueStorage
# DrupalConsoleCore Commands
console.about:
class: Drupal\Console\Core\Command\AboutCommand
Expand Down
7 changes: 3 additions & 4 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Application extends BaseApplication
* @param string $version
*/
public function __construct(
ContainerInterface$container,
ContainerInterface $container,
$name,
$version
) {
Expand Down Expand Up @@ -419,9 +419,8 @@ private function registerCommands()
->get('application.commands.aliases')?:[];

$invalidCommands = [];
if ($this->container->has('console.invalid_commands')) {
$invalidCommands = (array)$this->container
->get('console.invalid_commands');
if ($this->container->has('console.key_value_storage')) {
$invalidCommands = $this->container->get('console.key_value_storage')->get('invalid_commands');
}

foreach ($consoleCommands as $name => $tags) {
Expand Down
69 changes: 69 additions & 0 deletions src/Utils/KeyValueStorage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php


namespace Drupal\Console\Core\Utils;


class KeyValueStorage
{

/**
* @var array
*/
protected $data = [];

/**
* Checks if the container has the given key.
*
* @param string $key
* The key to check.
*
* @return boolean
*/
public function has($key)
{
return array_key_exists($key, $this->data);
}

/**
* Gets the given key from the container, or returns the default if it does
* not exist.
*
* @param string $key
* The key to get.
* @param mixed $default
* Default value to return.
*
* @return mixed
*/
public function get($key, $default = null)
{
return $this->has($key) ? $this->data[$key] : $default;
}

/**
* Sets the given key in the container.
*
* @param mixed $key
* The key to set
* @param mixed $value
* The value.
*/
public function set($key, $value = null)
{
$this->data[$key] = $value;
}

/**
* Removes the given key from the container.
*
* @param string $key The key to forget.
*
* @return void
*/
public function remove($key)
{
unset($this->data[$key]);
}

}

0 comments on commit 4d59986

Please sign in to comment.