out() public method

### Output levels There are 3 built-in output level. Shell::QUIET, Shell::NORMAL, Shell::VERBOSE. The verbose and quiet output levels, map to the verbose and quiet output switches present in most shells. Using Shell::QUIET for a message means it will always display. While using Shell::VERBOSE means it will only display when verbose output is toggled.
public out ( string | array $message = '', integer $newlines = 1, integer $level = ConsoleIo::NORMAL ) : integer | boolean
$message string | array A string or an array of strings to output
$newlines integer Number of newlines to append
$level integer The message's output level, see above.
return integer | boolean The number of bytes returned from writing to stdout.
 /**
  * @returns \React\Promise\Promise
  */
 public function show()
 {
     $deferred = new Deferred();
     $this->io->out('hello');
     $deferred->reject(false);
     return $deferred->promise();
 }
Example #2
0
 /**
  * Creates a file at given path
  *
  * @param string $path Where to put the file.
  * @param string $contents Content to put in the file.
  * @return bool Success
  * @link http://book.cakephp.org/3.0/en/console-and-shells.html#creating-files
  */
 public function createFile($path, $contents)
 {
     $path = str_replace(DS . DS, DS, $path);
     $this->_io->out();
     if (is_file($path) && empty($this->params['force']) && $this->interactive) {
         $this->_io->out(sprintf('<warning>File `%s` exists</warning>', $path));
         $key = $this->_io->askChoice('Do you want to overwrite?', ['y', 'n', 'a', 'q'], 'n');
         if (strtolower($key) === 'q') {
             $this->_io->out('<error>Quitting</error>.', 2);
             return $this->_stop();
         }
         if (strtolower($key) === 'a') {
             $this->params['force'] = true;
             $key = 'y';
         }
         if (strtolower($key) !== 'y') {
             $this->_io->out(sprintf('Skip `%s`', $path), 2);
             return false;
         }
     } else {
         $this->out(sprintf('Creating file %s', $path));
     }
     $File = new File($path, true);
     if ($File->exists() && $File->writable()) {
         $data = $File->prepare($contents);
         $File->write($data);
         $this->_io->out(sprintf('<success>Wrote</success> `%s`', $path));
         return true;
     }
     $this->_io->err(sprintf('<error>Could not write to `%s`</error>.', $path), 2);
     return false;
 }