-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Console container class replace call of invalid commands (#304)
* 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
Showing
3 changed files
with
75 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); | ||
} | ||
|
||
} |