contenido\classes\class.cec_hook.php

Show: PublicProtectedPrivateinherited
Table of Contents
Project: Contenido Content Management System

Description: Includes CEC hook class

Requirements:

Author
Murat Purc  
Con_php_req
5.0  
Copyright
four for business AG  
License
http://www.contenido.org/license/LIZENZ.txt  
Link
http://www.4fb.de  
Link
http://www.contenido.org  
Package
Contenido Backend classes  
Since
file available since contenido release >= 4.8.8 {@internal created 2008-08-28, Murat Purc, initial implementation, port from Advanced Mod Rewrite Plugin modified 2008-09-10, Murat Purc, bugfix: add further condition handling to prevent overwriting of arguments modified 2008-11-11, Andreas Lindner, when overwriting of arguments is prevented and break condition is set added anoption to return break condition value directly, otherwise the args would be returned, which is not desirable under all circumstances modified 2008-12-26, Murat Purc, bugfix: Not each registered chain function will get the same parameter modified 2009-12-26, Murat Purc, bugfix/redesign of CEC_Hook, see [#CON-256] }}  
Subpackage
CEC  
Version
0.5  

\CEC_Hook

Package: Contenido Backend classes\CEC
Static CEC Hook class, provides some public methods to process registered chains at CEC (Contenido Extension Chainer).

Usage:

// example of executing a cec without a parameter and return value
CEC_Hook::execute('Contenido.Content.Somewhere');

// example of executing a cec with a parameter but without a return value
$param = 'some value';
CEC_Hook::execute('Contenido.Content.Somewhere', $param);

// example of executing a cec with multiple parameter but without a return value
$param = array('foo' => $bar, 'foo2' => $bar2);
$param = CEC_Hook::execute('Contenido.Content.Somewhere', $param);


// example of executing a cec without a parameter but a return value (with predefined
// default return value)
CEC_Hook::setDefaultReturnValue('this is the default title');
$title = CEC_Hook::executeAndReturn('Contenido.Content.CreateTitletag');

// example of executing a cec with a parameter and a return value
// (usually the modified version of passed parameter)
$baseHref    = $cfgClient[$client]['path']['htmlpath'];
$newBaseHref = CEC_Hook::executeAndReturn('Contenido.Frontend.BaseHrefGeneration', $baseHref);


// example of executing a cec with a break condition and default return value
CEC_Hook::setBreakCondition(false, true); // break condition = "false", default return value = "true"
$allow = CEC_Hook::executeWhileBreakCondition('Contenido.Frontend.AllowEdit', $lang, $idcat, $idart, $auth->auth['uid']);
if ($allow == false) {
    die("You're not coming in!");
}

// another example of executing a cec with a break condition and default return value
CEC_Hook::setBreakCondition(true, false); // break condition = "true", default return value = "false"
$allow = CEC_Hook::executeWhileBreakCondition('Contenido.Frontend.CategoryAccess', $lang, $idcat, $auth->auth['uid']);
if ($allow == false) {
    die("I said, you're not coming in!");
}
Author
Murat Purc  

Constants

>VConstantint  BREAK_AT_TRUE = 'true'
Value to break the cec execution at a true result
Deprecated
see CEC_Hook::setConditions()  
int

>VConstantint  BREAK_AT_FALSE = 'false'
Value to break the cec execution at a false result
Deprecated
see CEC_Hook::setConditions()  
int

>VConstantint  BREAK_AT_NULL = 'null'
Value to break the cec execution at a null result
Deprecated
see CEC_Hook::setConditions()  
int

Properties

>VPropertyprivateint $_breakCondition = null
static
Temporaly stored break condition.
Default valuenullDetails
Type
int
>VPropertyprivatemixed $_defaultReturnValue = null
static
Temporaly stored default return value of CEC functions
Default valuenullDetails
Type
mixed
>VPropertyprivatebool $_overwriteArguments = true
static
Flag to overwrite arguments.
Default valuetrueDetails
Type
bool
Deprecated
No more needed  
>VPropertyprivateint $_returnArgumentPos = 1
static
Temporaly stored position of argument to return.

It's used by CEC_Hook::executeAndReturn() to store/extract the return value into/from arguments list.

Default value1Details
Type
int
>VPropertyprivatebool $_returnBreakConditionDirectly = false
static
Flag to return the set break condition directly.
Default valuefalseDetails
Type
bool
Deprecated
No more needed  

Methods

methodprivate_debug(mixed $var, string $msg = '') : void
static

Used to debug some status informations.

Writes the debug value into a logfile (see contenido/logs/cec_hook_debug.log).

Parameters
NameTypeDescription
$varmixed

The variable to dump

$msgstring

Additional message

methodprivate_reset() : void
static

Resets some properties to defaults

methodpublicexecute() : void
static

Method to execute registered functions for Contenido Extension Chainer (CEC).

Gets the desired CEC iterator and executes each registered chain function by passing the achieved arguments to it. There is

methodpublicexecuteAndReturn() : mixed
static

Method to execute registered functions for Contenido Extension Chainer (CEC).

Gets the desired CEC iterator and executes each registered chain function. You can pass as much parameter as you want.

Returns
TypeDescription
mixedParameter changed/processed by chain functions. Note: If no chain function is registered, the first parameter $param after $chainName will be returned
methodpublicexecuteWhileBreakCondition() : mixed
static

CEC function to process chains untill a break condition occurs.

Gets the desired CEC iterator and executes each registered chain function as long as defined break condition doesn't occur.

Returns
TypeDescription
mixedThe break condition or it's default value
methodpublicsetBreakCondition(mixed $condition, mixed $defaultReturnValue = null) : void
static

Temporaly setting of break condition and optional the default return value.

Parameters
NameTypeDescription
$conditionmixed
$defaultReturnValuemixed
methodpublicsetConditions(mixed $condition, bool $overwriteArguments = true, bool $returnbreakconditiondirectly = false, mixed $defaultReturnValue = null) : void
static

Temporaly setting of an execution conditions.

Parameters
NameTypeDescription
$conditionmixed

One of CEC_Hook constants, with following control mechanism: - CEC_Hook::BREAK_AT_TRUE = Breaks the iteration of cec functions and returns the parameter, if the result of an function is true. - CEC_Hook::BREAK_AT_FALSE = Breaks the iteration of cec functions and returns the parameter, if the result of an function is false. - CEC_Hook::BREAK_AT_NULL = Breaks the iteration of cec functions and returns the parameter, if the result of an function is null.

$overwriteArgumentsbool

Flag to prevent overwriting of passed parameter to execute(). Normally the parameter will be overwritten by return value of executed functions, but this is sometimes a not wanted side effect.

$returnbreakconditiondirectlybool

If a break condition is set and a chain function returns the condition set, setting this option forces the execute method to directly return that condition instead of the args

$defaultReturnValuemixed
Throws
ExceptionDescription
\InvalidArgumentExceptionIf passed type is not one of CEC_Hook constants.
Details
Deprecated
Function is no more needed, still exists due to downwards compatibility! This is usefull, if at least on of defined cec functions returns a specific value and the execution of further functions is no more needed. The defined condition will be reset in execute() method.  
methodpublicsetDefaultReturnValue(mixed $defaultReturnValue) : void
static

Temporaly setting of default return value.

Parameters
NameTypeDescription
$defaultReturnValuemixed
methodpublicsetReturnArgumentPos(int $pos) : void
static

Temporaly setting of position in argument to return.

Parameters
NameTypeDescription
$posint

Position, feasible value greater 0

Documentation was generated by phpDocumentor 2.0.0a12.