Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / drush / drush / src / Commands / DrushCommands.php
1 <?php
2 namespace Drush\Commands;
3
4 use Drush\Style\DrushStyle;
5 use Psr\Log\LoggerAwareInterface;
6 use Psr\Log\LoggerAwareTrait;
7 use Psr\Log\LoggerInterface;
8 use Robo\Common\ConfigAwareTrait;
9 use Robo\Contract\ConfigAwareInterface;
10 use Robo\Contract\IOAwareInterface;
11 use Robo\Common\IO;
12 use Symfony\Component\Console\Input\InputOption;
13
14 abstract class DrushCommands implements IOAwareInterface, LoggerAwareInterface, ConfigAwareInterface
15 {
16     // This is more readable.
17     const REQ=InputOption::VALUE_REQUIRED;
18     const OPT=InputOption::VALUE_OPTIONAL;
19
20     use LoggerAwareTrait;
21     use ConfigAwareTrait {
22         // Move aside this method so we can replace. See https://stackoverflow.com/a/37687295.
23         getConfig as ConfigAwareGetConfig;
24     }
25     use IO {
26         io as roboIo;
27     }
28
29     public function __construct()
30     {
31     }
32
33     /**
34      * Returns a logger object.
35      *
36      * @return LoggerInterface
37      */
38     protected function logger()
39     {
40         return $this->logger;
41     }
42
43     /**
44      * Override Robo's IO function with our custom style.
45      */
46     protected function io()
47     {
48         if (!$this->io) {
49             // Specify our own Style class when needed.
50             $this->io = new DrushStyle($this->input(), $this->output());
51         }
52         return $this->io;
53     }
54
55     /**
56      * Replaces same method in ConfigAwareTrait in order to provide a
57      * DrushConfig as return type. Helps with IDE completion.
58      *
59      * @see https://stackoverflow.com/a/37687295.
60      *
61      * @return \Drush\Config\DrushConfig
62      */
63     public function getConfig()
64     {
65         return $this->ConfigAwareGetConfig();
66     }
67
68     /**
69      * Print the contents of a file.
70      *
71      * @param string $file
72      *   Full path to a file.
73      */
74     protected function printFile($file)
75     {
76         if ((substr($file, -4) == ".htm") || (substr($file, -5) == ".html")) {
77             $tmp_file = drush_tempnam(basename($file));
78             file_put_contents($tmp_file, drush_html_to_text(file_get_contents($file)));
79             $file = $tmp_file;
80         }
81
82         if (self::input()->isInteractive()) {
83             if (drush_shell_exec_interactive("less %s", $file)) {
84                 return;
85             } elseif (drush_shell_exec_interactive("more %s", $file)) {
86                 return;
87             } else {
88                 $this->output()->writeln(file_get_contents($file));
89             }
90         }
91     }
92 }