Index: branches/5.2.x/core/kernel/event_handler.php
===================================================================
diff -u -N -r13840 -r14095
--- branches/5.2.x/core/kernel/event_handler.php (.../event_handler.php) (revision 13840)
+++ branches/5.2.x/core/kernel/event_handler.php (.../event_handler.php) (revision 14095)
@@ -1,6 +1,6 @@
getPrefixSpecial(true) instead of
- * $event->Prefix_Special as usual. This is due PHP
+ * $event->getPrefixSpecial() as usual. This is due PHP
* is converting "." symbols in variable names during
* submit info "_". $event->getPrefixSpecial optional
* 1st parameter returns correct corrent Prefix_Special
@@ -29,7 +29,7 @@
*
* 2. When using $this->Application->LinkVar on variables submitted
* from the form which contains $Prefix_Special then note 1st item.
- * Example: LinkVar($event->getPrefixSpecial(true).'_varname', $event->Prefix_Special.'_varname')
+ * Example: LinkVar($event->getPrefixSpecial(true).'_varname', $event->getPrefixSpecial().'_varname')
*
*/
@@ -40,82 +40,83 @@
class kEventHandler extends kBase {
/**
- * In case if event should be handled with mehod,
- * which name differs from event name, then it
- * should be specified here.
+ * In case if event should be handled with method, which name differs from
+ * event name, then it should be specified here.
* key - event name, value - event method
*
* @var Array
* @access protected
*/
- var $eventMethods = Array();
+ protected $eventMethods = Array ();
/**
* Defines mapping vs event names and permission names
*
* @var Array
+ * @access protected
*/
- var $permMapping = Array();
+ protected $permMapping = Array ();
+ public function __construct()
+ {
+ parent::__construct();
+
+ $this->mapEvents();
+ $this->mapPermissions();
+ }
+
/**
* Define alternative event processing method names
*
- * @see $eventMethods
+ * @see kEventHandler::$eventMethods
* @access protected
*/
- function mapEvents()
+ protected function mapEvents()
{
}
/**
* Allows to override standart permission mapping
*
+ * @access protected
+ * @see kEventHandler::$permMapping
*/
- function mapPermissions()
+ protected function mapPermissions()
{
}
- function getPrefixSpecial()
- {
- trigger_error('Usage of getPrefixSpecial() this method is forbidden in kEventHandler class children. Use $event->getPrefixSpecial(true); instead', E_USER_ERROR);
- }
-
/**
- * Set's prefix and special
+ * Returns prefix and special (when present) joined by a "."
*
- * @param string $prefix
- * @param string $special
- * @access public
+ * @return string
+ * @access private
*/
- function Init($prefix, $special)
+ public function getPrefixSpecial()
{
- parent::Init($prefix, $special);
-
- $this->mapEvents();
- $this->mapPermissions();
+ throw new Exception('Usage of getPrefixSpecial() method is forbidden in kEventHandler class children. Use $event->getPrefixSpecial(true); instead');
}
/**
- * Process Event
+ * Executes event, specified in $event variable
*
* @param kEvent $event
* @access public
*/
- function processEvent(&$event)
+ public function processEvent(&$event)
{
$event_name = $event->Name;
if ( array_key_exists($event_name, $this->eventMethods) ) {
$event_name = $this->eventMethods[$event_name];
}
- if (method_exists($this, $event_name)) {
+ if ( method_exists($this, $event_name) ) {
$this->$event_name($event);
}
else {
- trigger_error('event ' . $event->Name . ' not implemented in class ' . get_class($this) . '', E_USER_ERROR);
+ throw new Exception('Event ' . $event->Name . ' not implemented in class ' . get_class($this) . '');
}
}
@@ -125,20 +126,21 @@
* @param kEvent $event
* @access protected
*/
- function OnBuild(&$event)
+ protected function OnBuild(&$event)
{
- /*echo 'building:
';
- print_pre($event);*/
+
}
/**
* Returns to previous template in opener stack
*
* @param kEvent $event
+ * @access protected
*/
- function OnGoBack(&$event)
+ protected function OnGoBack(&$event)
{
$url = $this->Application->RecallVar('export_finish_url');
+
if ($url) {
$this->Application->Redirect('external:' . $url);
}
@@ -147,44 +149,28 @@
}
/**
- * Apply some special processing to
- * object beeing recalled before using
- * it in other events that call prepareObject
+ * Apply some special processing to object beeing
+ * recalled before using it in other events that
+ * call prepareObject
*
- * @param Object $object
+ * @param kDBBase $object
* @param kEvent $event
* @access protected
*/
- function prepareObject(&$object, &$event)
+ protected function prepareObject(&$object, &$event)
{
- // processing here
- }
- /**
- * Creates new event as child of
- * event passed as $event param
- *
- * @param kEvent $event
- * @access protected
- */
- function &inheritEvent(&$event, $name = null)
- {
- $child_event = new kEvent();
- $child_event->MasterEvent =& $event;
- $child_event->Prefix = $event->Prefix;
- $child_event->Special = $event->Special;
- $child_event->Prefix_Special = $event->Prefix_Special;
- $child_event->Name = $name;
-
- return $child_event;
}
/**
- * Checks permissions of user
+ * Checks user permission to execute given $event
*
* @param kEvent $event
+ * @access public
+ *
+ * @return bool
*/
- function CheckPermission(&$event)
+ public function CheckPermission(&$event)
{
$perm_helper =& $this->Application->recallObject('PermissionsHelper');
/* @var $perm_helper kPermissionsHelper */
@@ -197,9 +183,9 @@
*
* @param kEvent $event
*/
- function OnAfterConfigRead(&$event)
+ protected function OnAfterConfigRead(&$event)
{
- // readonly, for hooking only!
+
}
}
\ No newline at end of file