More updates to stop using dev or alpha or beta versions.
[yaffs-website] / vendor / drush / drush / includes / output.inc
1 <?php
2
3 use Drupal\Core\Render\Markup;
4 use Drush\Utils\StringUtils;
5
6 /**
7  * @defgroup outputfunctions Process output text.
8  * @{
9  */
10
11 /**
12  * Prints a message with optional indentation. In general,
13  * $this->>logger()->$method($message) is often a better choice than this function.
14  * That gets your confirmation message (for example) into the logs for this
15  * drush request. Consider that Drush requests may be executed remotely and
16  * non interactively.
17  *
18  * @param $message
19  *   The message to print.
20  * @param $indent
21  *    The indentation (space chars)
22  * @param $handle
23  *    File handle to write to.  NULL will write
24  *    to standard output, STDERR will write to the standard
25  *    error.  See http://php.net/manual/en/features.commandline.io-streams.php
26  * @param $newline
27  *    Add a "\n" to the end of the output.  Defaults to TRUE.
28  *
29  * @deprecated
30  *   Use $this->output()->writeln() in a command method.
31  */
32 function drush_print($message = '', $indent = 0, $handle = NULL, $newline = TRUE) {
33   $msg = str_repeat(' ', $indent) . (string)$message;
34   if ($newline) {
35     $msg .= "\n";
36   }
37   if (($charset = drush_get_option('output_charset')) && function_exists('iconv')) {
38     $msg = iconv('UTF-8', $charset, $msg);
39   }
40   if (!$handle) {
41     $handle = STDOUT;
42   }
43   fwrite($handle, $msg);
44 }
45
46 /**
47  * Rudimentary translation system, akin to Drupal's t() function.
48  *
49  * @param string
50  *   String to process, possibly with replacement item.
51  * @param array
52  *  An associative array of replacement items.
53  *
54  * @return
55  *   The processed string.
56  */
57 function dt($string, $args = []) {
58   return StringUtils::interpolate($string, $args);
59 }
60
61 /**
62  * Convert html to readable text.  Compatible API to
63  * drupal_html_to_text, but less functional.  Caller
64  * might prefer to call drupal_html_to_text if there
65  * is a bootstrapped Drupal site available.
66  *
67  * @param string $html
68  *   The html text to convert.
69  *
70  * @return string
71  *   The plain-text representation of the input.
72  */
73 function drush_html_to_text($html, $allowed_tags = NULL) {
74   $replacements = [
75     '<hr>' => '------------------------------------------------------------------------------',
76     '<li>' => '  * ',
77     '<h1>' => '===== ',
78     '</h1>' => ' =====',
79     '<h2>' => '---- ',
80     '</h2>' => ' ----',
81     '<h3>' => '::: ',
82     '</h3>' => ' :::',
83     '<br/>' => "\n",
84   ];
85   $text = str_replace(array_keys($replacements), array_values($replacements), $html);
86   return html_entity_decode(preg_replace('/ *<[^>]*> */', ' ', $text));
87 }
88
89 /**
90  * @} End of "defgroup outputfunctions".
91  */