Fr3nch13/CakePHP Utilities

ProgressinfoHelper extends ProgressHelper
in package

Progress Info Helper

Console helper to show a progress bar.

Based on CakePHP's Progress Helper. It allows you to add additional information to the end of the progress bar.

Table of Contents

Constants

DEFAULT_TOTAL  = 100
Default value for progress bar total value.
DEFAULT_WIDTH  = 80
Default value for progress bar width

Properties

$_arrowChar  : string
$_closeChar  : string
$_config  : array<string, mixed>
Runtime config
$_configInitialized  : bool
Whether the config property has already been configured with defaults
$_countformat  : string
$_defaultConfig  : array<string, mixed>
Default config for this helper.
$_info  : string
$_io  : ConsoleIo
ConsoleIo instance.
$_location  : bool
$_openChar  : string
$_padChar  : string
$_progress  : float|int
The current progress.
$_progressChar  : string
$_showcount  : bool
$_total  : int
The total number of 'items' to progress through.
$_width  : int
The width of the bar.

Methods

__construct()  : mixed
Constructor.
configShallow()  : $this
Merge provided config with existing config. Unlike `config()` which does a recursive merge for nested keys, this method does a simple merge.
draw()  : self
Used to include extra info when drawing.
getArrowChar()  : string
Gets the arrow character
getCloseChar()  : string
Gets the closing barrier character
getConfig()  : mixed
Returns the config.
getConfigOrFail()  : mixed
Returns the config for this specific key.
getCountformat()  : string
Gets location for the info
getLocation()  : bool
Gets location for the info
getOpenChar()  : string
Gets the opening barrier character
getPadChar()  : string
Gets the padding character
getProgressChar()  : string
Gets the progress character
getShowcount()  : bool
Gets location for the info
increment()  : $this
Increment the progress bar.
info()  : $this
Sets the info to display with the progress bar.
init()  : $this
Initialize the progress bar for use.
makeComposer()  : array<string, mixed>
Makes it look like composer's progress bar.
output()  : void
Output a progress bar.
setArrowChar()  : $this
Sets the arrow character
setCloseChar()  : $this
Sets the closing barrier character
setConfig()  : $this
Sets the config.
setCountformat()  : $this
Sets the count format. Should be compatible with the __() function.
setLocation()  : $this
Sets the location for the info
setOpenChar()  : $this
Sets the opening barrier character
setPadChar()  : $this
Sets the padding character
setProgressChar()  : $this
Sets the progress character
setShowcount()  : $this
Sets if we should show the count or not
_configDelete()  : void
Deletes a single config key.
_configRead()  : mixed
Reads a config key.
_configWrite()  : void
Writes a config key.

Constants

DEFAULT_TOTAL

Default value for progress bar total value.

protected mixed DEFAULT_TOTAL = 100

Percent completion is derived from progress/total

DEFAULT_WIDTH

Default value for progress bar width

protected mixed DEFAULT_WIDTH = 80

Properties

$_arrowChar

protected string $_arrowChar = '>'

The arrow character, must be only 1 character.

$_closeChar

protected string $_closeChar = ''

The closing barrier, must be only 1 character.

$_configInitialized

Whether the config property has already been configured with defaults

protected bool $_configInitialized = false

$_countformat

protected string $_countformat = '{0}/{1}'

The count format that is compatibly with the __() function.

$_defaultConfig

Default config for this helper.

protected array<string, mixed> $_defaultConfig = []

$_location

protected bool $_location = false

The location of the info. True: Left, False: Right.

$_openChar

protected string $_openChar = ''

The opening barrier, must be only 1 character.

$_padChar

protected string $_padChar = ' '

The padding character, must be only 1 character.

$_progress

The current progress.

protected float|int $_progress = 0

$_progressChar

protected string $_progressChar = '='

The progress bar character, must be only 1 character.

$_total

The total number of 'items' to progress through.

protected int $_total = self::DEFAULT_TOTAL

$_width

The width of the bar.

protected int $_width = self::DEFAULT_WIDTH

Methods

__construct()

Constructor.

public __construct(ConsoleIo $io[, array<string, mixed> $config = [] ]) : mixed
Parameters
$io : ConsoleIo

The ConsoleIo instance to use.

$config : array<string, mixed> = []

The settings for this helper.

configShallow()

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

public configShallow(array<string, mixed>|string $key[, mixed|null $value = null ]) : $this

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
$key : array<string, mixed>|string

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

$value : mixed|null = null

The value to set.

Return values
$this

draw()

Used to include extra info when drawing.

public draw([null|string $info = null ]) : self
Parameters
$info : null|string = null

The string to include after the percent.

Return values
self

An Instance of this class

getArrowChar()

Gets the arrow character

public getArrowChar() : string
Return values
string

The arrow character

getCloseChar()

Gets the closing barrier character

public getCloseChar() : string
Return values
string

The closing barrier character

getConfig()

Returns the config.

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

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
$key : string|null = null

The key to get or null for the whole config.

$default : mixed = null

The return value when the key does not exist.

Return values
mixed

Configuration data at the named key or null if the key does not exist.

getConfigOrFail()

Returns the config for this specific key.

public getConfigOrFail(string $key) : mixed

The config value for this key must exist, it can never be null.

Parameters
$key : string

The key to get.

Tags
throws
InvalidArgumentException
Return values
mixed

Configuration data at the named key

getCountformat()

Gets location for the info

public getCountformat() : string
Return values
string

The count format string.

getLocation()

Gets location for the info

public getLocation() : bool
Return values
bool

If true, left, if false, right

getOpenChar()

Gets the opening barrier character

public getOpenChar() : string
Return values
string

The opening barrier character

getPadChar()

Gets the padding character

public getPadChar() : string
Return values
string

The padding character

getProgressChar()

Gets the progress character

public getProgressChar() : string
Return values
string

The progress character

getShowcount()

Gets location for the info

public getShowcount() : bool
Return values
bool

If true, left, if false, right

increment()

Increment the progress bar.

public increment([float|int $num = 1 ]) : $this
Parameters
$num : float|int = 1

The amount of progress to advance by.

Return values
$this

info()

Sets the info to display with the progress bar.

public info([null|string $info = null ]) : $this

Done using a method instead of an option so it can be used in the closure.

Parameters
$info : null|string = null

The info to display.

Return values
$this

init()

Initialize the progress bar for use.

public init([array<int|string, mixed> $args = [] ]) : $this
  • total The total number of items in the progress bar. Defaults to 100.
  • width The width of the progress bar. Defaults to 80.
  • progress The progress character. Defaults to '='
  • arrow The arrow character. Defaults to '>'.
  • pad The padding character. Defaults to ' '.
  • open The opening barrier character. Defaults to ''.
  • close The closing barrier character. Defaults to ''.
  • location Location of the info. True: Left, False: Right. Defaults tp False.
  • composer If set and true, mimmicks the Composer progress bar.
Parameters
$args : array<int|string, mixed> = []

The initialization data.

Return values
$this

makeComposer()

Makes it look like composer's progress bar.

public makeComposer() : array<string, mixed>

Example: " 7/8 [========================>---] 87%"

Return values
array<string, mixed>

Settings to use in init to make a composer progress bar.

output()

Output a progress bar.

public output(array<int|string, mixed> $args) : void

Takes a number of options to customize the behavior:

  • total The total number of items in the progress bar. Defaults to 100.
  • width The width of the progress bar. Defaults to 80.
  • progress The progress character. Defaults to '='
  • arrow The arrow character. Defaults to '>'.
  • pad The padding character. Defaults to ' '.
  • callback The callback that will be called in a loop to advance the progress bar.
  • showcount Boolean, whether or not to show the count.
  • countformat The format to show the count, sould be in the format of the __() function.
  • composer If set and true, mimmicks the Composer progress bar.
Parameters
$args : array<int|string, mixed>

The arguments/options to use when outputing the progress bar.

setArrowChar()

Sets the arrow character

public setArrowChar(string $char) : $this
Parameters
$char : string

The arrow character to use

Tags
throws
InvalidCharException

if the character isn't a string or isn't 1 character in length.

Return values
$this

setCloseChar()

Sets the closing barrier character

public setCloseChar(string $char) : $this
Parameters
$char : string

The closing barrier character to use

Tags
throws
InvalidCharException

if the character isn't a string or isn't 1 character in length.

Return values
$this

setConfig()

Sets the config.

public setConfig(array<string, mixed>|string $key[, mixed|null $value = null ][, bool $merge = true ]) : $this

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
$key : array<string, mixed>|string

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

$value : mixed|null = null

The value to set.

$merge : bool = true

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

Tags
throws
CakeException

When trying to set a key that is invalid.

Return values
$this

setCountformat()

Sets the count format. Should be compatible with the __() function.

public setCountformat(string $countformat) : $this
Parameters
$countformat : string

The count format string.

Return values
$this

setLocation()

Sets the location for the info

public setLocation(bool $location) : $this
Parameters
$location : bool

If true, left, if false, right

Return values
$this

setOpenChar()

Sets the opening barrier character

public setOpenChar(string $char) : $this
Parameters
$char : string

The opening barrier character to use

Tags
throws
InvalidCharException

if the character isn't a string or isn't 1 character in length.

Return values
$this

setPadChar()

Sets the padding character

public setPadChar(string $char) : $this
Parameters
$char : string

The padding character to use

Tags
throws
InvalidCharException

if the character isn't a string or isn't 1 character in length.

Return values
$this

setProgressChar()

Sets the progress character

public setProgressChar(string $char) : $this
Parameters
$char : string

The progress character to use

Tags
throws
InvalidCharException

if the character isn't a string or isn't 1 character in length.

Return values
$this

setShowcount()

Sets if we should show the count or not

public setShowcount(bool $showcount) : $this
Parameters
$showcount : bool

If true, show the count

Return values
$this

_configDelete()

Deletes a single config key.

protected _configDelete(string $key) : void
Parameters
$key : string

Key to delete.

Tags
throws
CakeException

if attempting to clobber existing config

_configRead()

Reads a config key.

protected _configRead(string|null $key) : mixed
Parameters
$key : string|null

Key to read.

_configWrite()

Writes a config key.

protected _configWrite(array<string, mixed>|string $key, mixed $value[, string|bool $merge = false ]) : void
Parameters
$key : array<string, mixed>|string

Key to write to.

$value : mixed

Value to write.

$merge : string|bool = false

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

Tags
throws
CakeException

if attempting to clobber existing config


        
On this page

Search results