\Cake\Shell\HelperTableHelper

Create a visually pleasing ASCII art table from 2 dimensional array data.

Console Helpers allow you to package up reusable blocks of Console output logic. For example creating tables, progress bars or ascii art.

Summary

Methods
Properties
Constants
__construct()
output()
setConfig()
getConfig()
config()
configShallow()
No public properties found
No constants found
_configRead()
_configWrite()
_configDelete()
_calculateWidths()
_rowSeparator()
_render()
_addStyle()
$_defaultConfig
$_io
$_config
$_configInitialized
N/A
No private methods found
No private properties found
N/A

Properties

$_defaultConfig

$_defaultConfig : array

Default config for this helper.

Type

array

$_config

$_config : array

Runtime config

Type

array

$_configInitialized

$_configInitialized : boolean

Whether the config property has already been configured with defaults

Type

boolean

Methods

__construct()

__construct(\Cake\Console\ConsoleIo  $io, array  $config = array()) 

Constructor.

Parameters

\Cake\Console\ConsoleIo $io

The ConsoleIo instance to use.

array $config

The settings for this helper.

output()

output(array  $rows) : void

Output a table.

Data will be output based on the order of the values in the array. The keys will not be used to align data.

Parameters

array $rows

The data to render out.

setConfig()

setConfig(string|array  $key, mixed|null  $value = null, boolean  $merge = true) : $this

Sets the config.

Usage

Setting a specific value:

$this->setConfig('key', $value);

Setting a nested value:

$this->setConfig('some.nested.key', $value);

Updating multiple config settings at the same time:

$this->setConfig(['one' => 'value', 'another' => 'value']);

Parameters

string|array $key

The key to set, or a complete array of configs.

mixed|null $value

The value to set.

boolean $merge

Whether to recursively merge or overwrite existing config, defaults to true.

Throws

\Cake\Core\Exception\Exception

When trying to set a key that is invalid.

Returns

$this

getConfig()

getConfig(string|null  $key = null, mixed  $default = null) : mixed

Returns the config.

Usage

Reading the whole config:

$this->getConfig();

Reading a specific value:

$this->getConfig('key');

Reading a nested value:

$this->getConfig('some.nested.key');

Reading with default value:

$this->getConfig('some-key', 'default-value');

Parameters

string|null $key

The key to get or null for the whole config.

mixed $default

The return value when the key does not exist.

Returns

mixed —

Config value being read.

config()

config(string|array|null  $key = null, mixed|null  $value = null, boolean  $merge = true) : mixed

Gets/Sets the config.

Usage

Reading the whole config:

$this->config();

Reading a specific value:

$this->config('key');

Reading a nested value:

$this->config('some.nested.key');

Setting a specific value:

$this->config('key', $value);

Setting a nested value:

$this->config('some.nested.key', $value);

Updating multiple config settings at the same time:

$this->config(['one' => 'value', 'another' => 'value']);

Parameters

string|array|null $key

The key to get/set, or a complete array of configs.

mixed|null $value

The value to set.

boolean $merge

Whether to recursively merge or overwrite existing config, defaults to true.

Throws

\Cake\Core\Exception\Exception

When trying to set a key that is invalid.

Returns

mixed —

Config value being read, or the object itself on write operations.

configShallow()

configShallow(string|array  $key, mixed|null  $value = null) : $this

Merge provided config with existing config. Unlike `config()` which does a recursive merge for nested keys, this method does a simple merge.

Setting a specific value:

$this->configShallow('key', $value);

Setting a nested value:

$this->configShallow('some.nested.key', $value);

Updating multiple config settings at the same time:

$this->configShallow(['one' => 'value', 'another' => 'value']);

Parameters

string|array $key

The key to set, or a complete array of configs.

mixed|null $value

The value to set.

Returns

$this

_configRead()

_configRead(string|null  $key) : mixed

Reads a config key.

Parameters

string|null $key

Key to read.

Returns

mixed

_configWrite()

_configWrite(string|array  $key, mixed  $value, boolean|string  $merge = false) : void

Writes a config key.

Parameters

string|array $key

Key to write to.

mixed $value

Value to write.

boolean|string $merge

True to merge recursively, 'shallow' for simple merge, false to overwrite, defaults to false.

Throws

\Cake\Core\Exception\Exception

if attempting to clobber existing config

_configDelete()

_configDelete(string  $key) : void

Deletes a single config key.

Parameters

string $key

Key to delete.

Throws

\Cake\Core\Exception\Exception

if attempting to clobber existing config

_calculateWidths()

_calculateWidths(array  $rows) : array

Calculate the column widths

Parameters

array $rows

The rows on which the columns width will be calculated on.

Returns

array

_rowSeparator()

_rowSeparator(array  $widths) : void

Output a row separator.

Parameters

array $widths

The widths of each column to output.

_render()

_render(array  $row, array  $widths, array  $options = array()) : void

Output a row.

Parameters

array $row

The row to output.

array $widths

The widths of each column to output.

array $options

Options to be passed.

_addStyle()

_addStyle(string  $text, string  $style) : string

Add style tags

Parameters

string $text

The text to be surrounded

string $style

The style to be applied

Returns

string