CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 3.1 Red Velvet API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 3.1
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Global
  • Cake
    • Auth
    • Cache
    • Collection
    • Console
      • Exception
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Filesystem
    • Form
    • I18n
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • Shell
    • TestSuite
    • Utility
    • Validation
    • View

Class ConsoleIo

A wrapper around the various IO operations shell tasks need to do.

Packages up the stdout, stderr, and stdin streams providing a simple consistent interface for shells to use. This class also makes mocking streams easy to do in unit tests.

Namespace: Cake\Console

Constants

  • int
    NORMAL ¶
    1

    Output constant for making normal shells.

  • int
    QUIET ¶
    0

    Output constants for making quiet shells.

  • int
    VERBOSE ¶
    2

    Output constant making verbose shells.

Property Summary

  • $_err protected
    Cake\Console\ConsoleOutput

    The error stream

  • $_helpers protected
    Cake\Console\HelperRegistry

    The helper registry.

  • $_in protected
    Cake\Console\ConsoleInput

    The input stream

  • $_lastWritten protected
    int

    The number of bytes last written to the output stream used when overwriting the previous message.

  • $_level protected
    int

    The current output level.

  • $_out protected
    Cake\Console\ConsoleOutput

    The output stream

Method Summary

  • __construct() public

    Constructor

  • _getInput() protected

    Prompts the user for input, and returns it.

  • ask() public

    Prompts the user for input, and returns it.

  • askChoice() public

    Prompts the user for input based on a list of options, and returns it.

  • err() public

    Outputs a single or multiple error messages to stderr. If no parameters are passed outputs just a newline.

  • helper() public

    Render a Console Helper

  • hr() public

    Outputs a series of minus characters to the standard output, acts as a visual separator.

  • level() public

    Get/set the current output level.

  • nl() public

    Returns a single or multiple linefeeds sequences.

  • out() public

    Outputs a single or multiple messages to stdout. If no parameters are passed outputs just a newline.

  • outputAs() public

    Change the output mode of the stdout stream

  • overwrite() public

    Overwrite some already output text.

  • quiet() public

    Output at all levels.

  • setLoggers() public

    Connects or disconnects the loggers to the console output.

  • styles() public

    Add a new output style or get defined styles.

  • verbose() public

    Output at the verbose level.

Method Detail

__construct() ¶ public

__construct(Cake\Console\ConsoleOutput|null $out = null, Cake\Console\ConsoleOutput|null $err = null, Cake\Console\ConsoleInput|null $in = null, Cake\Console\HelperRegistry|null $helpers = null)

Constructor

Parameters
Cake\Console\ConsoleOutput|null $out optional

A ConsoleOutput object for stdout.

Cake\Console\ConsoleOutput|null $err optional

A ConsoleOutput object for stderr.

Cake\Console\ConsoleInput|null $in optional

A ConsoleInput object for stdin.

Cake\Console\HelperRegistry|null $helpers optional

A HelperRegistry instance

_getInput() ¶ protected

_getInput(string $prompt, string|null $options, string|null $default): string

Prompts the user for input, and returns it.

Parameters
string $prompt

Prompt text.

string|null $options

String of options. Pass null to omit.

string|null $default

Default input value. Pass null to omit.

Returns
string

ask() ¶ public

ask(string $prompt, string|null $default = null): mixed

Prompts the user for input, and returns it.

Parameters
string $prompt

Prompt text.

string|null $default optional

Default input value.

Returns
mixed

askChoice() ¶ public

askChoice(string $prompt, string|array $options, string|null $default = null): mixed

Prompts the user for input based on a list of options, and returns it.

Parameters
string $prompt

Prompt text.

string|array $options

Array or string of options.

string|null $default optional

Default input value.

Returns
mixed

err() ¶ public

err(string|array $message = '', int $newlines = 1): void

Outputs a single or multiple error messages to stderr. If no parameters are passed outputs just a newline.

Parameters
string|array $message optional

A string or an array of strings to output

int $newlines optional

Number of newlines to append

Returns
void

helper() ¶ public

helper(string $name, array $settings = []): Cake\Console\Helper

Render a Console Helper

Create and render the output for a helper object. If the helper object has not already been loaded, it will be loaded and constructed.

Parameters
string $name

The name of the helper to render

array $settings optional

Configuration data for the helper.

Returns
Cake\Console\Helper

hr() ¶ public

hr(int $newlines = 0, int $width = 79): void

Outputs a series of minus characters to the standard output, acts as a visual separator.

Parameters
int $newlines optional

Number of newlines to pre- and append

int $width optional

Width of the line, defaults to 79

Returns
void

level() ¶ public

level(null|int $level = null): int

Get/set the current output level.

Parameters
null|int $level optional

The current output level.

Returns
int

nl() ¶ public

nl(int $multiplier = 1): string

Returns a single or multiple linefeeds sequences.

Parameters
int $multiplier optional

Number of times the linefeed sequence should be repeated

Returns
string

out() ¶ public

out(string|array $message = '', int $newlines = 1, int $level = ConsoleIo::NORMAL): int|bool

Outputs a single or multiple messages to stdout. If no parameters are passed outputs just a newline.

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.

Parameters
string|array $message optional

A string or an array of strings to output

int $newlines optional

Number of newlines to append

int $level optional

The message's output level, see above.

Returns
int|bool

outputAs() ¶ public

outputAs(int $mode): void

Change the output mode of the stdout stream

Parameters
int $mode

The output mode.

Returns
void
See Also
\Cake\Console\ConsoleOutput::outputAs()

overwrite() ¶ public

overwrite(array|string $message, int $newlines = 1, int $size = null): void

Overwrite some already output text.

Useful for building progress bars, or when you want to replace text already output to the screen with new text.

Warning You cannot overwrite text that contains newlines.

Parameters
array|string $message

The message to output.

int $newlines optional

Number of newlines to append.

int $size optional

The number of bytes to overwrite. Defaults to the length of the last message output.

Returns
void

quiet() ¶ public

quiet(string|array $message, int $newlines = 1): int|bool

Output at all levels.

Parameters
string|array $message

A string or an array of strings to output

int $newlines optional

Number of newlines to append

Returns
int|bool

setLoggers() ¶ public

setLoggers(int|bool $enable): void

Connects or disconnects the loggers to the console output.

Used to enable or disable logging stream output to stdout and stderr If you don't wish all log output in stdout or stderr through Cake's Log class, call this function with $enable=false.

Parameters
int|bool $enable

Use a boolean to enable/toggle all logging. Use one of the verbosity constants (self::VERBOSE, self::QUIET, self::NORMAL) to control logging levels. VERBOSE enables debug logs, NORMAL does not include debug logs, QUIET disables notice, info and debug logs.

Returns
void

styles() ¶ public

styles(string $style = null, array|bool|null $definition = null): mixed

Add a new output style or get defined styles.

Parameters
string $style optional

The style to get or create.

array|bool|null $definition optional

The array definition of the style to change or create a style or false to remove a style.

Returns
mixed
See Also
\Cake\Console\ConsoleOutput::styles()

verbose() ¶ public

verbose(string|array $message, int $newlines = 1): int|bool

Output at the verbose level.

Parameters
string|array $message

A string or an array of strings to output

int $newlines optional

Number of newlines to append

Returns
int|bool

Property Detail

$_err ¶ protected

The error stream

Type
Cake\Console\ConsoleOutput

$_helpers ¶ protected

The helper registry.

Type
Cake\Console\HelperRegistry

$_in ¶ protected

The input stream

Type
Cake\Console\ConsoleInput

$_lastWritten ¶ protected

The number of bytes last written to the output stream used when overwriting the previous message.

Type
int

$_level ¶ protected

The current output level.

Type
int

$_out ¶ protected

The output stream

Type
Cake\Console\ConsoleOutput
OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs