PHP Class App_CLI, atk4

(c) 2008-2013 Agile Toolkit Limited Distributed under Affero General Public License v3 and commercial license. See LICENSE or LICENSE_COM for more information =====================================================ATK4=
Inheritance: extends AbstractView
Mostrar archivo Open project: atk4/atk4 Class Usage Examples

Public Properties

Property Type Description
$atk_version string This is a major version of Agile Toolkit. The APP of Agile Toolkit is very well established and changes rarely. Your application would generally be compatible throughout the same major version of Agile Tooolkit.
$compat_42 boolean | Controller_Compat42 If you want Agile Toolkit to be compatible with 4.2 version, include compatibility controller.
$config array Once configuration file is read, data is saved inside this property.
$config_files array If you are loading additional config later, use readConfig() instead Order of this array is important.
$config_files_loaded array Contains list of loaded config files.
$config_location string ." or inside "config" sub-folder by setting value to 'config' to better reflect your application layout.
$db DB In a typical application, one connection to the database is enough for majority of applications. Calling $app->dbConnect will read Database data from config file and store it in $db property. If you requires a more advanced connectivity or multiple connections, you can manually initialize more database connections.
$locale string This is the default locale for the application. You change this manually inside application APP class or use some controller which will pull this variable out of the URL. This variable will be respected throughout the framework.
$logger Logger Without logger, APP will dump out errors and exceptions in a very brief and straigtforward way. Logger is a controller which enhances error output and in most cases you do need one. Logger can be further configured to either output detailed errors or show brief message instead.
$logger_class If you want to use your own logger class, redefine this property.
$max_name_length integer Agile Toolkit implements a mechanism which will replace common beginning of objects with an abbreviation thus keeping object name length under control. This variable defines the maximum length of the object's $name. Be mindful that some objects will concatinate theri name with fields, so the maximum letgth of GET argument names can exceed this value by the length of your field. We recommend you to increase SUHOSIN get limits if you encounter any problems. Set this value to "false" to turn off name shortening.
$pathfinder PathFinder PathFinder is a controller which is responsible for locating resources, such as PHP includes, JavaScript files, templates, etc. APP Initializes PathFinder as soon as possible, then defines "Locations" which describe type of data found in different folders.
$pm Controller_PageManager PageManager object
$pr object Profiler measures relative time it took in certain parts of your application to help you find a slow-perfoming parts of application. By default $pr points to empty profiler object, which implements empty methods. All the lines referencing $pr myst be prefixed with the 4-symbol sequence "/ ** /" (no spaces). If you want to speed up Agile Toolkit further, you can eliminate all lines started with this sequence from your source code.
$unique_hashes array As more names are shortened, the substituted part is being placed into this hash and the value contains the new key. This helps to avoid creating many sequential prefixes for the same character sequenece.

Protected Properties

Property Type Description
$pagemanager_class string Change a different Page Manager class.
$pagemanager_options array Set to array('debug' => true) to debug Page Manager.
$pathfinder_class string If you would want to use your own PathFinder class, you must change this property and include it.

Public Methods

Method Description
_ ( string $str ) : string Redefine this function to introduce your localization.
__construct ( string $realm = null, array $options = [] ) Regular objects in Agile Toolkit use init() and are added through add().
_beforeInit ( ) Finds out which page is requested. We don't need this method for CLI, but others might need it.
addGlobalMethod ( string $name, callable $callable ) Agile Toolkit objects allow method injection. This is quite similar to technique used in JavaScript:.
addLocation ( array $contents, mixed $obsolete = UNDEFINED ) : PathFinder_Location Add new location with additional resources.
caughtException ( Exception $e ) Is executed if exception is raised during execution.
configExceptionOrDefault ( string $default, string $exceptiontext ) Executed when trying to access config parameter which is not find in the file.
dbConnect ( mixed $dsn = null ) : DB Use database configuration settings from config file to establish default connection.
encodeHtmlChars ( string $s, integer $flags = null, string $encode = null, boolean $double_encode = false ) : string Encodes HTML special chars.
getBaseURL ( ) : string Returns base URL of this Web application installation. If you require link to a page, you can use URL::useAbsoluteURL();.
getConfig ( string $path, mixed $default_value = UNDEFINED ) : string Load config if necessary and look up corresponding setting.
getLogger ( string $class_name = UNDEFINED ) : Logger Initialize logger or return existing one.
getStickyArguments ( ) : array
getVersion ( string $of = 'atk' ) : string Determine version of Agile Toolkit or specified plug-in.
hasGlobalMethod ( string $name ) : boolean Returns if a global method with such name was defined.
locate ( string $type, string $filename = '', string $return = 'relative' ) : string | object | array Find relative path to the resource respective to the current directory.
locatePath ( string $type, string $filename = '' ) : string | object | array Return full system path to specified resource.
locateURL ( string $type, string $filename = '' ) : string | object | array Calculate URL pointing to specified resource.
normalizeClassName ( string | object $name, string $prefix = null ) : string | object First normalize class name, then add specified prefix to class name if it's passed and not already added.
normalizeName ( string $name, string $separator = '_' ) : string Normalize field or identifier name. Can also be used in URL normalization.
outputDebug ( $object, $msg, $shift )
outputWarning ( $msg, $shift )
readAllConfig ( ) Will include all files as they are defined in $this->config_files from folder $config_location.
readConfig ( string $file = 'config.php' ) : boolean Read config file and store it in $this->config. Use getConfig() to access.
removeGlobalMethod ( string $name ) Removes global method.
requires ( string $addon = 'atk', string $v, string $location = null ) : boolean Verifies version. Should be used by addons. For speed improvement, redefine this into empty function.
setConfig ( array $config = [], mixed $val = UNDEFINED ) Manually set configuration option.
url ( mixed $page = null, array $arguments = [] ) : URL Generates URL for specified page. Useful for building links on pages or emails. Returns URL object.
versionRequirement ( $v, $location = null )

Method Details

_() public method

Agile Toolkit will pass all system strings through this method. If some methods are not properly passed through, please fork Agile Toolkit from http://github.com/atk4/atk4/ , modify, commit, push your fix and notify authors of Agile Toolkit using contact form on http://agiletoolkit.org/contact. See file CONTRIBUTING
public _ ( string $str ) : string
$str string String which needs localization
return string Localized string

__construct() public method

Application class is differente, you use "new" keyword because it's the first class to be created. That's why constructor will perform quite a bit of initialization. Do not redefine constructor but instead use init(); $realm defines a top-level name of your application. This impacts all id= prefixes in your HTML code, form field names and many other things, such as session name. If you have two application classes which are part of same web app and may want to use same realm, but in other cases it's preferably that you keep realm unique on your domain in the interests of security.
public __construct ( string $realm = null, array $options = [] )
$realm string Will become $app->name
$options array

_beforeInit() public method

Finds out which page is requested. We don't need this method for CLI, but others might need it.
public _beforeInit ( )

addGlobalMethod() public method

obj.test = function() { .. } All non-existant method calls on all Agile Toolkit objects will be tried against local table of registered methods and then against global registered methods. addGlobalmethod allows you to register a globally-recognized for all agile toolkit object. PHP is not particularly fast about executing methods like that, but this technique can be used for adding backward-compatibility or debugging, etc.
See also: AbstractObject::hasMethod()
See also: AbstractObject::__call()
public addGlobalMethod ( string $name, callable $callable )
$name string Name of the method
$callable callable Calls your function($object, $arg1, $arg2)

addLocation() public method

Add new location with additional resources.
public addLocation ( array $contents, mixed $obsolete = UNDEFINED ) : PathFinder_Location
$contents array
$obsolete mixed
return PathFinder_Location

caughtException() public method

Re-define to have custom handling of exceptions system-wide.
public caughtException ( Exception $e )
$e Exception

configExceptionOrDefault() public method

Executed when trying to access config parameter which is not find in the file.
public configExceptionOrDefault ( string $default, string $exceptiontext )
$default string
$exceptiontext string

dbConnect() public method

Use database configuration settings from config file to establish default connection.
public dbConnect ( mixed $dsn = null ) : DB
$dsn mixed
return DB

encodeHtmlChars() public method

By default does not encode already encoded ones.
public encodeHtmlChars ( string $s, integer $flags = null, string $encode = null, boolean $double_encode = false ) : string
$s string
$flags integer
$encode string
$double_encode boolean
return string

getBaseURL() public method

Returns base URL of this Web application installation. If you require link to a page, you can use URL::useAbsoluteURL();.
See also: URL::useAbsoluteURL()
public getBaseURL ( ) : string
return string

getConfig() public method

Load config if necessary and look up corresponding setting.
public getConfig ( string $path, mixed $default_value = UNDEFINED ) : string
$path string
$default_value mixed
return string

getLogger() public method

Initialize logger or return existing one.
public getLogger ( string $class_name = UNDEFINED ) : Logger
$class_name string
return Logger

getStickyArguments() public method

public getStickyArguments ( ) : array
return array

getVersion() public method

Determine version of Agile Toolkit or specified plug-in.
public getVersion ( string $of = 'atk' ) : string
$of string
return string

hasGlobalMethod() public method

Returns if a global method with such name was defined.
public hasGlobalMethod ( string $name ) : boolean
$name string Name of the method
return boolean if registered

locate() public method

Find relative path to the resource respective to the current directory.
public locate ( string $type, string $filename = '', string $return = 'relative' ) : string | object | array
$type string
$filename string
$return string
return string | object | array

locatePath() public method

Return full system path to specified resource.
public locatePath ( string $type, string $filename = '' ) : string | object | array
$type string
$filename string
return string | object | array

locateURL() public method

Calculate URL pointing to specified resource.
public locateURL ( string $type, string $filename = '' ) : string | object | array
$type string
$filename string
return string | object | array

normalizeClassName() public method

Class name can have namespaces and they are treated prefectly. If object is passed as $name parameter, then same object is returned. Example: normalizeClassName('User','Model') == 'Model_User';
public normalizeClassName ( string | object $name, string $prefix = null ) : string | object
$name string | object Name of class or object
$prefix string Optional prefix for class name
return string | object Full, normalized class name or received object

normalizeName() public method

This will replace all non alpha-numeric characters with separator. Multiple separators in a row is replaced with one. Separators in beginning and at the end of name are removed. Sample input: "Hello, Dear Jon!" Sample output: "Hello_Dear_Jon"
public normalizeName ( string $name, string $separator = '_' ) : string
$name string String to process
$separator string Character acting as separator
return string Normalized string

outputDebug() public method

Deprecation: 4.3.2
public outputDebug ( $object, $msg, $shift )

outputWarning() public method

Deprecation: 4.3.2
public outputWarning ( $msg, $shift )

readAllConfig() public method

Will include all files as they are defined in $this->config_files from folder $config_location.
public readAllConfig ( )

readConfig() public method

Read config file and store it in $this->config. Use getConfig() to access.
public readConfig ( string $file = 'config.php' ) : boolean
$file string Filename
return boolean

removeGlobalMethod() public method

Removes global method.
public removeGlobalMethod ( string $name )
$name string

requires() public method

Verifies version. Should be used by addons. For speed improvement, redefine this into empty function.
public requires ( string $addon = 'atk', string $v, string $location = null ) : boolean
$addon string
$v string
$location string
return boolean

setConfig() public method

Manually set configuration option.
public setConfig ( array $config = [], mixed $val = UNDEFINED )
$config array
$val mixed

url() public method

Generates URL for specified page. Useful for building links on pages or emails. Returns URL object.
public url ( mixed $page = null, array $arguments = [] ) : URL
$page mixed
$arguments array
return URL

versionRequirement() public method

public versionRequirement ( $v, $location = null )

Property Details

$atk_version public_oe property

This is a major version of Agile Toolkit. The APP of Agile Toolkit is very well established and changes rarely. Your application would generally be compatible throughout the same major version of Agile Tooolkit.
public string $atk_version
return string

$compat_42 public_oe property

If you want Agile Toolkit to be compatible with 4.2 version, include compatibility controller.
public bool|Controller_Compat42 $compat_42
return boolean | Controller_Compat42

$config public_oe property

Once configuration file is read, data is saved inside this property.
See also: getConfig()
See also: readConfig()
public array $config
return array

$config_files public_oe property

If you are loading additional config later, use readConfig() instead Order of this array is important.
public array $config_files
return array

$config_files_loaded public_oe property

Contains list of loaded config files.
public array $config_files_loaded
return array

$config_location public_oe property

." or inside "config" sub-folder by setting value to 'config' to better reflect your application layout.
public string $config_location
return string

$db public_oe property

In a typical application, one connection to the database is enough for majority of applications. Calling $app->dbConnect will read Database data from config file and store it in $db property. If you requires a more advanced connectivity or multiple connections, you can manually initialize more database connections.
See also: dbConnect()
public DB $db
return DB

$locale public_oe property

This is the default locale for the application. You change this manually inside application APP class or use some controller which will pull this variable out of the URL. This variable will be respected throughout the framework.
public string $locale
return string

$logger public_oe property

Without logger, APP will dump out errors and exceptions in a very brief and straigtforward way. Logger is a controller which enhances error output and in most cases you do need one. Logger can be further configured to either output detailed errors or show brief message instead.
See also: Logger
public Logger $logger
return Logger

$logger_class public_oe property

If you want to use your own logger class, redefine this property.
public $logger_class

$max_name_length public_oe property

Agile Toolkit implements a mechanism which will replace common beginning of objects with an abbreviation thus keeping object name length under control. This variable defines the maximum length of the object's $name. Be mindful that some objects will concatinate theri name with fields, so the maximum letgth of GET argument names can exceed this value by the length of your field. We recommend you to increase SUHOSIN get limits if you encounter any problems. Set this value to "false" to turn off name shortening.
public int $max_name_length
return integer

$pagemanager_class protected_oe property

Change a different Page Manager class.
protected string $pagemanager_class
return string

$pagemanager_options protected_oe property

Set to array('debug' => true) to debug Page Manager.
protected array $pagemanager_options
return array

$pathfinder public_oe property

PathFinder is a controller which is responsible for locating resources, such as PHP includes, JavaScript files, templates, etc. APP Initializes PathFinder as soon as possible, then defines "Locations" which describe type of data found in different folders.
public PathFinder $pathfinder
return PathFinder

$pathfinder_class protected_oe property

If you would want to use your own PathFinder class, you must change this property and include it.
protected string $pathfinder_class
return string

$pm public_oe property

PageManager object
See also: Controller_PageManager::init()
public Controller_PageManager $pm
return Controller_PageManager

$pr public_oe property

Profiler measures relative time it took in certain parts of your application to help you find a slow-perfoming parts of application. By default $pr points to empty profiler object, which implements empty methods. All the lines referencing $pr myst be prefixed with the 4-symbol sequence "/ ** /" (no spaces). If you want to speed up Agile Toolkit further, you can eliminate all lines started with this sequence from your source code.
public object $pr
return object

$unique_hashes public_oe property

As more names are shortened, the substituted part is being placed into this hash and the value contains the new key. This helps to avoid creating many sequential prefixes for the same character sequenece.
public array $unique_hashes
return array