Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5e00d46

Browse files
authored
Update 3 commands to use new StdinAwareInterface. (#3865)
Update 3 commands to use new StdinAwareInterface.
1 parent 5640cf9 commit 5e00d46

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

src/Commands/core/PhpCommands.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
<?php
22
namespace Drush\Commands\core;
33

4+
use Consolidation\AnnotatedCommand\Input\StdinAwareInterface;
5+
use Consolidation\AnnotatedCommand\Input\StdinAwareTrait;
46
use Drush\Commands\DrushCommands;
57
use Symfony\Component\Finder\Finder;
68

7-
class PhpCommands extends DrushCommands
9+
class PhpCommands extends DrushCommands implements StdinAwareInterface
810
{
11+
use StdinAwareTrait;
912

1013
/**
1114
* Evaluate arbitrary php code after bootstrapping Drupal (if available).
@@ -57,7 +60,7 @@ public function script(array $extra, $options = ['format' => 'var_export', 'scri
5760
$script = array_shift($extra);
5861

5962
if ($script == '-') {
60-
return eval(stream_get_contents(STDIN));
63+
return eval($this->stdin()->contents());
6164
} elseif (file_exists($script)) {
6265
$found = $script;
6366
} else {

src/Drupal/Commands/config/ConfigCommands.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
use Consolidation\AnnotatedCommand\CommandError;
55
use Consolidation\AnnotatedCommand\CommandData;
6+
use Consolidation\AnnotatedCommand\Input\StdinAwareInterface;
7+
use Consolidation\AnnotatedCommand\Input\StdinAwareTrait;
68
use Consolidation\OutputFormatters\StructuredData\RowsOfFields;
79
use Consolidation\SiteProcess\Util\Escape;
810
use Drupal\Core\Config\ConfigFactoryInterface;
@@ -20,8 +22,9 @@
2022
use Symfony\Component\Yaml\Parser;
2123
use Webmozart\PathUtil\Path;
2224

23-
class ConfigCommands extends DrushCommands
25+
class ConfigCommands extends DrushCommands implements StdinAwareInterface
2426
{
27+
use StdinAwareTrait;
2528
use ExecTrait;
2629

2730
/**
@@ -84,7 +87,6 @@ public function get($config_name, $key = '', $options = ['format' => 'yaml', 'so
8487
* @param $key The config key, for example "page.front".
8588
* @param $value The value to assign to the config key. Use '-' to read from STDIN.
8689
* @option input-format Format to parse the object. Use "string" for string (default), and "yaml" for YAML.
87-
* // A convenient way to pass a multiline value within a backend request.
8890
* @option value The value to assign to the config key (if any).
8991
* @hidden-options value
9092
* @usage drush config:set system.site page.front node
@@ -106,7 +108,7 @@ public function set($config_name, $key, $value = null, $options = ['input-format
106108

107109
// Special flag indicating that the value has been passed via STDIN.
108110
if ($data === '-') {
109-
$data = stream_get_contents(STDIN);
111+
$data = $this->stdin()->contents();
110112
}
111113

112114
// Now, we parse the value.

src/Drupal/Commands/core/StateCommands.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22

33
namespace Drush\Drupal\Commands\core;
44

5+
use Consolidation\AnnotatedCommand\Input\StdinAwareInterface;
6+
use Consolidation\AnnotatedCommand\Input\StdinAwareTrait;
57
use Consolidation\OutputFormatters\StructuredData\PropertyList;
68
use Drupal\Core\State\StateInterface;
79
use Drush\Commands\DrushCommands;
810
use Symfony\Component\Yaml\Yaml;
911

10-
class StateCommands extends DrushCommands
12+
class StateCommands extends DrushCommands implements StdinAwareInterface
1113
{
14+
use StdinAwareTrait;
1215

1316
protected $state;
1417

@@ -74,7 +77,7 @@ public function set($key, $value, $options = ['input-format' => 'auto', 'value'
7477

7578
// Special flag indicating that the value has been passed via STDIN.
7679
if ($value === '-') {
77-
$value = stream_get_contents(STDIN);
80+
$value = $this->stdin()->contents();
7881
}
7982

8083
// If the value is a string (usual case, unless we are called from code),

0 commit comments

Comments
 (0)