ArtaCli

A frame for command line applications. May be used to create command line tools for an Artaengine based web application. When you create an CLI application your main class can inherit this class and use the provided methods. This class can be used to access an Artaengine based web application's resources and can use most Artaengine libraries.
Source
ArtaCli.php
Implements
ICli
Extends
Arta

Constants

VERSION = '2.0'

Artaengine version

Static Properties

HtmlDebug = true

ArtaCli::$HtmlDebug = true

I(); and inspect(); output format. True = HTML, False = text.

autoload = array

ArtaCli::$autoload = array()

List of autoload paths which will be used by the autoload handler.

cacheConfigs

ArtaCli::$cacheConfigs

Cache configurations.

configs

ArtaCli::$configs

App configs, from app configs ini files or array.

customAutoload

ArtaCli::$customAutoload

Path to a PHP file containing a custom autoload function.

dateFormat = 'Y/m/d'

ArtaCli::$dateFormat = 'Y/m/d'

The default date format. Set in app cofigs under [arta] to key 'date-format'.

dbConfigs

ArtaCli::$dbConfigs

Database configurations.

exceptionHandler

ArtaCli::$exceptionHandler

Exception handler function(method).

factory

ArtaCli::$factory

Reference to current factory object.

globals = array

ArtaCli::$globals = array()

To be used for storing global values instead of $_GLOBALS.

illegalHandler

ArtaCli::$illegalHandler

Special event handler access.

logConfigs

ArtaCli::$logConfigs

Log configurations.

nofactoryHandler

ArtaCli::$nofactoryHandler

Special event handler access.

notajaxHandler

ArtaCli::$notajaxHandler

Special event handler access.

notfoundHandler

ArtaCli::$notfoundHandler

Special event handler access.

permissionsClass

ArtaCli::$permissionsClass

Class permissions. Used by the permission Principal.

permissionsFactory

ArtaCli::$permissionsFactory

Factory permissions. Used by the permission Principal.

principal

ArtaCli::$principal

Name of the application princName of application principal class (class which checks permissions).

tplConfigs

ArtaCli::$tplConfigs

Factory and template configurations.

unauthorizedHandler

ArtaCli::$unauthorizedHandler

Special event handler access.

Properties

indentStr = "\t"

$obj->indentStr = "\t"

The string used for indents

Static Methods

build

void ArtaCli::build(string | array configs=null)

Builds the application. /build

Arguments

    configs=null (string | array)
    App configs ini file-path or array

Returns

void

errorHandler

void ArtaCli::errorHandler(int code, string description, string file, int line)

Default error handler - converts error to exception and calls the exception handler.

See also
http://artaengine.com/tutorials/url-mapping#handle

Arguments

    code (int)
    Error code
    description (string)
    Error description
    file (string)
    File which raised the error
    line (int)
    Line where the error happened

Returns

void

Throws

  • ErrorException Throws the error as exception

exceptionHandler

void ArtaCli::exceptionHandler(ErrorException exception)

Default exception handler. If an exception handler factory is not defined this method will catch all exceptions, if debug mode or PHP error reporting is off then swallows the exception otherwise shows a message.

See also
http://artaengine.com/tutorials/url-mapping#handle

Arguments

    exception (ErrorException)
    ErrorException Object to be handled

Returns

void

g

mixed ArtaCli::g(string key, mixed default=null)

Get value of a global variable defined in Arta::$globals

Arguments

    key (string)
    Variable name
    default=null (mixed)
    If key did not exist return this value

Returns

mixed
Value of the global key or default

makePath

string ArtaCli::makePath(array | string | [string] paths)

Fixes/sticks a path(s) and replaces "ARTA_DIR", "APP_DIR", "ARTA_TEMP_DIR" and "TEMP_DIR" inside the path with their real directory values.

Since
Artaengine 1.1.0

Arguments

    paths (array | string | [string])
    An array of paths, one paths or parts of a path to be sticked together, be fixed and constants be replaced with real paths.

Returns

string
Fixed path

now

string ArtaCli::now(string format=null, string zone=null)

Get current time. The timezone and format are defined in app config under section 'arta' with keys 'timezone' and 'date_format', if not set the default values will be 'UTC' and 'Y/m/d H:i:s'.

See also
To get dates based on user's selected locale
Since
Artaengine 1.1.0

Arguments

    format=null (string)
    Date/time format, null='date_format H:i:s' or 'Y/m/d H:i:s'
    zone=null (string)
    Time zone, null=default application time zone or 'UTC'

Returns

string
Current date-time

start

void ArtaCli::start(string | array configs=null)

Start an Artaengine application.

Arguments

    configs=null (string | array)
    App configs ini file-path or array

Returns

void

Throws

getParam

string ArtaCli::getParam(int index)

Get a command param value by index.

Arguments

    index (int)
    The index of the param value to be returned

Returns

string
Value of the param index or null if param not exists

getParam

string ArtaCli::getParam(string index)

Get a command param value by param name.

Arguments

    index (string)
    return the value of the param e.g: "myapp.php -f foo" passinf "-f" will return "foo"

Returns

string
Value of the param or null if param not found

getParam

array ArtaCli::getParam()

Get all the command params.

Returns

array
An array of all params

hasParam

bool ArtaCli::hasParam(string param)

Check if a CLI param value exists inside the proviced params.

Arguments

    param (string)
    Param value

Returns

bool
If param exists

isCli

bool ArtaCli::isCli()

Check if the application is running from the command line.

Returns

bool
true=the application is running from the command line

simulate

void ArtaCli::simulate(string | array configs=null)

Start an Artaengine application. Simulate the Artaengine framework for a CLI application.
Note: This is experimental, Not all Artaengine libs and functions are not tested to work in CLI.

Arguments

    configs=null (string | array)
    App setting file-path or array

Returns

void

Methods

__construct

ArtaCli $obj = new ArtaCli(string | array configs=null)

Start an Artaengine application. An application can also be started by calling the static method "Arta::Start(configs)" without the need to create an Arta object.

Arguments

    configs=null (string | array)
    App configs ini file-path or array

Returns

void

fixCursor

ArtaCli $obj->fixCursor(int column=0, int line=null)

Fix cursor at a point. After the cursor is fixed all next writes will start from this point.

Arguments

    column=0 (int)
    Move cursor to this column number, null=do nothing
    line=null (int)
    Move cursor to this line number, null=do nothing

Returns

ArtaCli
For method chaining

indent

ArtaCli $obj->indent(int indent=1, string str=tab)

Add one or more indents.

Arguments

    indent=1 (int)
    Number of indents to be added
    str=tab (string)
    Indent string

Returns

ArtaCli
For method chaining

moveCursor

ArtaCli $obj->moveCursor(int column=0, int line=null)

Move cursor.

Arguments

    column=0 (int)
    move cursor to this column, null=do nothing
    line=null (int)
    move cursor to this line, null=do nothing

Returns

ArtaCli
For method chaining

nl

ArtaCli $obj->nl(int i)

Print a new line.

Arguments

    i (int)
    Number of new lines

Returns

ArtaCli
For method chaining

releaseCursor

object $obj->releaseCursor()

Release the fixed cursor.

Returns

object
this

removeIndent

ArtaCli $obj->removeIndent(int indent=1)

Remove one or more indents.

Arguments

    indent=1 (int)
    Number of indents to be removed

Returns

ArtaCli
For method chaining

setBackColor

ArtaCli $obj->setBackColor(string color)

Set text back-ground color.

Arguments

    color (string)
    Color name

Returns

ArtaCli
For method chaining

setColor

ArtaCli $obj->setColor(string fore=null, string back=null)

Set fore and back color. To reset to default fore and back colors call this method without params.

Arguments

    fore=null (string)
    Color name
    back=null (string)
    Color name

Returns

ArtaCli
For method chaining

setForeColor

ArtaCli $obj->setForeColor(string color)

Set text color and style.

Arguments

    color (string)
    Color name

Returns

ArtaCli
For method chaining

write

ArtaCli $obj->write(
    string | array data,
    string | array color=null,
    string | array cursor=null
)

Write text.

Arguments

    data (string | array)
    Data to be written
    color=null (string | array)
    "fore-color,back-color" or [fore-color, back-color]
    cursor=null (string | array)
    "column,line" or [column, line]

Returns

ArtaCli
For method chaining

writeLn

ArtaCli $obj->writeLn(
    string | array data,
    string | array color=null,
    string | array cursor=null
)

Write text and goto new line.

Arguments

    data (string | array)
    Data to be written. Array items will be separated by new lines
    color=null (string | array)
    "fore-color,back-color" or [fore-color, back-color]
    cursor=null (string | array)
    "column,line" or [column, line]

Returns

ArtaCli
For method chaining