PHP Class AbstractObject, atk4

(c) 2008-2011 Romans Malinovskis Distributed under Affero General Public License v3 See http://agiletoolkit.org/about/license =====================================================ATK4=
Show file Open project: atk4/atk4 Class Usage Examples

Public Properties

Property Type Description
$_info Records debug information.
$_initialized boolean To make sure you have called parent::init() properly.
$api
$app App_CLI Always points to current Application
$auto_track_element boolean When this object is added, owner->elements[$this->short_name] will be == $this;.
$controller Controller Reference to the current controller. Read only. Use setController()
$debug boolean Setting this to true will output additional debug info about object
$default_controller string Default controller to initialize when calling setModel()
$default_exception string $default_exception='PathFinder' by default would return 'Exception_PathFinder' from exception(). $default_exceptoin='PathFinder' in combination with ->exception('Blah','_NotFound') will return 'Exception_PathFinder_NotFound' $default_exception='BaseException' in combination with ->exception('Blah', 'PathFinder') will create 'Exception_PathFinder' exception. and finally $default_exception='PathFinder' in combination with ->exception('Blah','NotFound') will return 'Exception_NotFound';
$elements array short_name => object hash of children objects
$hooks {{{ Hooks: http://agiletoolkit.org/doc/hooks
$model Model Reference to the current model. Read only. Use setModel()
$name string Unique object name
$owner AbstractObject Link to object into which we added this object
$short_name string Name of the object in owner's element array

Public Methods

Method Description
__call ( string $method, array $arguments ) : mixed Call method is used to display exception for non-existant methods and provides ability to extend objects with addMethod().
__clone ( ) : AbstractObject Clones associated controller and model. If cloning views, add them to the owner.
__construct ( array $options = [] ) This is default constructor of ATK4. Please do not re-define it and avoid calling it directly. Always use add() and init() methods.
__destruct ( ) Always call parent if you redefine this/.
__sleep ( ) : mixed Do not serialize objects.
__toString ( ) : string Converts into string "Object View(myapp_page_view)".
_removeElement ( string $short_name ) Actually removes the element.
_shorten ( string $desired ) : string Method used internally for shortening object names.
_ticker ( )
_unique ( &$array, string $desired = null ) : string This funcion given the associative $array and desired new key will return the best matching key which is not yet in the array.
_unique_element ( $desired = null )
add ( array | string | object $class, array | string $options = null, string $template_spot = null, array | string $template_branch = null ) : AbstractObject Creates new object and adds it as a child of current object.
addHook ( string $hook_spot, AbstractObject | callable $callable, array $arguments = [], integer $priority = 5 ) If priority is negative, then hooks will be executed in reverse order.
addMethod ( string | array $name, callable $callable ) Add new method for this object.
breakHook ( mixed $return ) When called from inside a hook callable, will stop execution of other callables on same hook. The passed argument will be returned by the hook method.
debug ( boolean | string $msg = true, string $file = null, string $line = null ) Turns on debug mode for this object.
destroy ( $recursive = true ) Removes object from parent and prevents it from rendering \code $view = $this->add('View'); $view -> destroy(); \endcode.
each ( string | callable $callable ) A handy shortcut for foreach(){ .
exception ( string $message = 'Undefined Exception', string $type = null, string $code = null ) : BaseException Returns relevant exception class. Use this method with "throw".
fatal ( string $error, integer $shift ) Reports fatal error. Use ->exception instead.
forget ( string $key = null ) Forget session data for arg $key. If $key is omitted will forget all associated session data.
getElement ( string $short_name ) : AbstractObject Find child element by its short name. Use in chaining.
getModel ( ) : AbstractModel Return current model.
hasElement ( string $short_name ) : AbstractObject | boolean Find child element. Use in condition.
hasMethod ( string $name ) : boolean Return if this object has specified method (either native or dynamic).
hook ( string $hook_spot, array $arg = [] ) : mixed Execute all callables assigned to $hook_spot.
info ( $msg )
init ( ) Initialize object. Always call parent::init(). Do not call directly.
learn ( string $key, mixed $default = null ) : mixed Similar to memorize, but if value for key exist, will return it.
logError ( string $error, string $msg = '' ) Output string into error file.
logInfo ( string $info, string $msg = '' ) Output string into info file.
logVar ( string $var, string $msg = '' ) Output string into log file.
memorize ( string $key, mixed $value ) : mixed Remember data in object-relevant session data.
newInstance ( array $properties = null ) : self Creates one more instance of $this object.
recall ( string $key, mixed $default = null ) : mixed Returns session data for this object. If not previously set, then $default is returned.
removeElement ( string $short_name ) Remove child element if it exists.
removeHook ( string $hook_spot ) Delete all hooks for specified spot.
removeMethod ( string $name ) Remove dynamically registered method.
rename ( string $short_name ) Names object accordingly. May not work on some objects.
runTests ( Tester $tester = null ) This method will find private methods started with test_ in the current class and will execute each method in succession by passing $t argument to it. Before each test execution takes place, $t->prepareForTest($test) will be called. It must return non-false for test to be carried out.
setController ( string | object $controller, string | array $name = null ) : AbstractController Associate controller with the object.
setModel ( string | object $model ) : AbstractModel Associate model with object.
tryCall ( string $method, array $arguments ) : mixed Attempts to call dynamic method. Returns array containing result or false.
upCall ( string $type, array $args = [] ) Call specified method for this class and all parents up to app.
warning ( string $msg, integer $shift ) Records warning.

Method Details

__call() public method

Call method is used to display exception for non-existant methods and provides ability to extend objects with addMethod().
public __call ( string $method, array $arguments ) : mixed
$method string Name of the method
$arguments array Arguments
return mixed

__clone() public method

Clones associated controller and model. If cloning views, add them to the owner.
public __clone ( ) : AbstractObject
return AbstractObject Copy of this object

__construct() public method

This is default constructor of ATK4. Please do not re-define it and avoid calling it directly. Always use add() and init() methods.
public __construct ( array $options = [] )
$options array will initialize class properties

__destruct() public method

Always call parent if you redefine this/.
public __destruct ( )

__sleep() public method

Do not serialize objects.
public __sleep ( ) : mixed
return mixed

__toString() public method

Converts into string "Object View(myapp_page_view)".
public __toString ( ) : string
return string

_removeElement() public method

Actually removes the element.
public _removeElement ( string $short_name )
$short_name string short name

_shorten() public method

Method used internally for shortening object names.
public _shorten ( string $desired ) : string
$desired string Desired name of new object.
return string Shortened name of new object.

_ticker() public method

public _ticker ( )

_unique() public method

For example, if you have array('foo'=>x,'bar'=>x) and $desired is 'foo' function will return 'foo_2'. If 'foo_2' key also exists in that array, then 'foo_3' is returned and so on.
public _unique ( &$array, string $desired = null ) : string
$desired string Desired key for new object
return string unique key for new object

_unique_element() public method

public _unique_element ( $desired = null )

add() public method

Returns new object.
public add ( array | string | object $class, array | string $options = null, string $template_spot = null, array | string $template_branch = null ) : AbstractObject
$class array | string | object Name of the new class. Can also be array with 0=>name and rest of array will be considered as $options or object.
$options array | string Short name or array of properties. 0=>name will be used as a short-name or your object.
$template_spot string Tag where output will appear
$template_branch array | string Redefine template
return AbstractObject

addHook() public method

If priority is negative, then hooks will be executed in reverse order.
public addHook ( string $hook_spot, AbstractObject | callable $callable, array $arguments = [], integer $priority = 5 )
$hook_spot string Hook identifier to bind on
$callable AbstractObject | callable Will be called on hook()
$arguments array Arguments are passed to $callable
$priority integer Lower priority is called sooner

addMethod() public method

Add new method for this object.
public addMethod ( string | array $name, callable $callable )
$name string | array Name of new method of $this object
$callable callable Callback

breakHook() public method

When called from inside a hook callable, will stop execution of other callables on same hook. The passed argument will be returned by the hook method.
public breakHook ( mixed $return )
$return mixed What would hook() return?

debug() public method

Using first argument as string is obsolete.
public debug ( boolean | string $msg = true, string $file = null, string $line = null )
$msg boolean | string "true" to start debugging
$file string obsolete
$line string obsolete

destroy() public method

Removes object from parent and prevents it from rendering \code $view = $this->add('View'); $view -> destroy(); \endcode.
public destroy ( $recursive = true )

each() public method

. } code. Make your callable return "false" if you would like to break the loop.
public each ( string | callable $callable )
$callable string | callable will be executed for each member

exception() public method

Returns relevant exception class. Use this method with "throw".
public exception ( string $message = 'Undefined Exception', string $type = null, string $code = null ) : BaseException
$message string Static text of exception.
$type string Exception class or class postfix
$code string Optional error code
return BaseException

fatal() public method

Reports fatal error. Use ->exception instead.
public fatal ( string $error, integer $shift )
$error string error text
$shift integer relative offset in backtrace

forget() public method

Forget session data for arg $key. If $key is omitted will forget all associated session data.
public forget ( string $key = null )
$key string Optional key of data to forget

getElement() public method

Exception if not found.
public getElement ( string $short_name ) : AbstractObject
$short_name string Short name of the child element
return AbstractObject

getModel() public method

Return current model.
public getModel ( ) : AbstractModel
return AbstractModel Currently associated model object

hasElement() public method

Find child element. Use in condition.
public hasElement ( string $short_name ) : AbstractObject | boolean
$short_name string Short name of the child element
return AbstractObject | boolean

hasMethod() public method

Return if this object has specified method (either native or dynamic).
public hasMethod ( string $name ) : boolean
$name string Name of the method
return boolean

hook() public method

Execute all callables assigned to $hook_spot.
public hook ( string $hook_spot, array $arg = [] ) : mixed
$hook_spot string Hook identifier
$arg array Additional arguments to callables
return mixed Array of responses or value specified to breakHook

info() public method

public info ( $msg )

init() public method

Initialize object. Always call parent::init(). Do not call directly.
public init ( )

learn() public method

Similar to memorize, but if value for key exist, will return it.
public learn ( string $key, mixed $default = null ) : mixed
$key string Data Key
$default mixed Default value
return mixed Previously memorized data or $default

logError() public method

Output string into error file.
public logError ( string $error, string $msg = '' )
$error string error
$msg string msg

logInfo() public method

Output string into info file.
public logInfo ( string $info, string $msg = '' )
$info string info
$msg string msg

logVar() public method

Output string into log file.
public logVar ( string $var, string $msg = '' )
$var string var
$msg string msg

memorize() public method

Remember data in object-relevant session data.
public memorize ( string $key, mixed $value ) : mixed
$key string Key for the data
$value mixed Value
return mixed $value

newInstance() public method

Creates one more instance of $this object.
public newInstance ( array $properties = null ) : self
$properties array Set initial properties for new object
return self

recall() public method

Returns session data for this object. If not previously set, then $default is returned.
public recall ( string $key, mixed $default = null ) : mixed
$key string Data Key
$default mixed Default value
return mixed Previously memorized data or $default

removeElement() public method

Remove child element if it exists.
public removeElement ( string $short_name )
$short_name string short name of the element

removeHook() public method

Delete all hooks for specified spot.
public removeHook ( string $hook_spot )
$hook_spot string Hook identifier to bind on

removeMethod() public method

Remove dynamically registered method.
public removeMethod ( string $name )
$name string Name of the method

rename() public method

Names object accordingly. May not work on some objects.
public rename ( string $short_name )
$short_name string Short name of the child element

runTests() public method

$test will be an array containing keys for 'name', 'object' and 'class'
public runTests ( Tester $tester = null )
$tester Tester

setController() public method

Associate controller with the object.
public setController ( string | object $controller, string | array $name = null ) : AbstractController
$controller string | object Class or instance of controller
$name string | array Name or property for new controller
return AbstractController Newly added controller

setModel() public method

Associate model with object.
public setModel ( string | object $model ) : AbstractModel
$model string | object Class or instance of model
return AbstractModel Newly added Model

tryCall() public method

Attempts to call dynamic method. Returns array containing result or false.
public tryCall ( string $method, array $arguments ) : mixed
$method string Name of the method
$arguments array Arguments
return mixed

upCall() public method

Call specified method for this class and all parents up to app.
public upCall ( string $type, array $args = [] )
$type string information
$args array relative offset in backtrace

warning() public method

Records warning.
public warning ( string $msg, integer $shift )
$msg string information
$shift integer relative offset in backtrace

Property Details

$_info public property

Records debug information.
public $_info

$_initialized public property

To make sure you have called parent::init() properly.
public bool $_initialized
return boolean

$api public property

Deprecation: 4.3.0 Left for compatibility with ATK 4.2 and lower, use ->app instead
public $api

$app public property

Always points to current Application
public App_CLI $app
return App_CLI

$auto_track_element public property

When this object is added, owner->elements[$this->short_name] will be == $this;.
public bool $auto_track_element
return boolean

$controller public property

Reference to the current controller. Read only. Use setController()
public Controller $controller
return Controller

$debug public property

Setting this to true will output additional debug info about object
public bool $debug
return boolean

$default_controller public property

Default controller to initialize when calling setModel()
public string $default_controller
return string

$default_exception public property

$default_exception='PathFinder' by default would return 'Exception_PathFinder' from exception(). $default_exceptoin='PathFinder' in combination with ->exception('Blah','_NotFound') will return 'Exception_PathFinder_NotFound' $default_exception='BaseException' in combination with ->exception('Blah', 'PathFinder') will create 'Exception_PathFinder' exception. and finally $default_exception='PathFinder' in combination with ->exception('Blah','NotFound') will return 'Exception_NotFound';
public string $default_exception
return string

$elements public property

short_name => object hash of children objects
public array $elements
return array

$hooks public property

{{{ Hooks: http://agiletoolkit.org/doc/hooks
public $hooks

$model public property

Reference to the current model. Read only. Use setModel()
public Model $model
return Model

$name public property

Unique object name
public string $name
return string

$owner public property

Link to object into which we added this object
public AbstractObject $owner
return AbstractObject

$short_name public property

Name of the object in owner's element array
public string $short_name
return string