Changeset View
Changeset View
Standalone View
Standalone View
branches/5.3.x/core/kernel/utility/event.php
Show First 20 Lines • Show All 128 Lines • ▼ Show 20 Line(s) | |||||
*/ | */ | ||||
private $pseudoClass = ''; | private $pseudoClass = ''; | ||||
/** | /** | ||||
* Create event from given prefix, special, name and specific params. | * Create event from given prefix, special, name and specific params. | ||||
* Parameter $params could be be an an array with following keys: "prefix", "special" (optional), "name". | * Parameter $params could be be an an array with following keys: "prefix", "special" (optional), "name". | ||||
* Parameter $params could be a string in format: "prefix:name" or "prefix.special:name". | * Parameter $params could be a string in format: "prefix:name" or "prefix.special:name". | ||||
* | * | ||||
* @param mixed $params | * @param mixed $params Params. | ||||
* @param Array $specific_params event specific params (none by default) | * @param array $specific_params Event specific params (none by default). | ||||
* @return kEvent | * | ||||
* @access public | * @throws InvalidArgumentException When incorrect event string given. | ||||
*/ | */ | ||||
public function __construct($params = Array(), $specific_params = null) | public function __construct($params = Array(), $specific_params = null) | ||||
{ | { | ||||
parent::__construct(); | parent::__construct(); | ||||
if ($params) { | if ( $params ) { | ||||
if ( is_array($params) ) { | if ( is_array($params) ) { | ||||
$prefix = isset($params['prefix']) ? $params['prefix'] : false; | $prefix = isset($params['prefix']) ? $params['prefix'] : false; | ||||
$special = isset($params['special']) ? $params['special'] : false; | $special = isset($params['special']) ? $params['special'] : false; | ||||
if ($prefix) { | if ( $prefix ) { | ||||
$this->Init($prefix, $special); | $this->Init($prefix, $special); | ||||
} | } | ||||
$this->Name = isset($params['name']) ? $params['name'] : ''; | $this->Name = isset($params['name']) ? $params['name'] : ''; | ||||
} | } | ||||
elseif ( is_string($params) ) { | elseif ( is_string($params) ) { | ||||
if (preg_match('/([^.:]*)[.]{0,1}([^:]*):(.*)/', $params, $regs)) { | if ( preg_match('/([^.:]*)[.]{0,1}([^:]*):(.*)/', $params, $regs) ) { | ||||
$prefix = $regs[1]; | $prefix = $regs[1]; | ||||
$special = $regs[2]; | $special = $regs[2]; | ||||
if ($prefix) { | if ( $prefix ) { | ||||
$this->Init($prefix, $special); | $this->Init($prefix, $special); | ||||
} | } | ||||
$this->Name = $regs[3]; | $this->Name = $regs[3]; | ||||
} | } | ||||
else { | else { | ||||
throw new Exception('Invalid event string: "<strong>' . $params . '</strong>". Should be in "prefix[.special]:OnEvent" format'); | $error_msg = 'Invalid event string: "<strong>' . $params . '</strong>". '; | ||||
$error_msg .= 'Should be in "prefix[.special]:OnEvent" format'; | |||||
throw new InvalidArgumentException($error_msg); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
if ( isset($specific_params) ) { | if ( isset($specific_params) ) { | ||||
$this->specificParams = $specific_params; | $this->specificParams = $specific_params; | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 262 Lines • ▼ Show 20 Line(s) | |||||
return $section; | return $section; | ||||
} | } | ||||
public function __toString() | public function __toString() | ||||
{ | { | ||||
return $this->getPrefixSpecial() . ':' . $this->Name; | return $this->getPrefixSpecial() . ':' . $this->Name; | ||||
} | } | ||||
} | } | ||||
No newline at end of file |