@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Abstract Class for Callback Events.
|
||||
*
|
||||
* @author Time.ly Network Inc.
|
||||
* @since 2.0
|
||||
*
|
||||
* @package AI1EC
|
||||
* @subpackage AI1EC.Event
|
||||
*/
|
||||
abstract class Ai1ec_Event_Callback_Abstract {
|
||||
|
||||
/**
|
||||
* @var Ai1ec_Registry_Object The Object registry.
|
||||
*/
|
||||
protected $_registry = null;
|
||||
|
||||
/**
|
||||
* @var string The registry method name defined in the class map.
|
||||
*/
|
||||
protected $_registry_name = null;
|
||||
|
||||
/**
|
||||
* @var string The method invoked by the current callback.
|
||||
*/
|
||||
protected $_method = null;
|
||||
|
||||
/**
|
||||
* Initiate callback objects.
|
||||
*
|
||||
* @param Ai1ec_Registry_Object $registry Registry object.
|
||||
* @param string $path Registry method name defined in the class map.
|
||||
* @param string $method Method invoked by the currect callback.
|
||||
*
|
||||
* @return void Constructor does not return.
|
||||
*/
|
||||
public function __construct(
|
||||
Ai1ec_Registry_Object $registry,
|
||||
$path,
|
||||
$method
|
||||
) {
|
||||
$this->_registry = $registry;
|
||||
$this->_registry_name = $path;
|
||||
$this->_method = $method;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke the method added to the current callback.
|
||||
*
|
||||
* @return mixed Value returned by the current method.
|
||||
*/
|
||||
public function run() {
|
||||
$argv = func_get_args();
|
||||
return $this->_registry->dispatch(
|
||||
$this->_registry_name,
|
||||
$this->_method,
|
||||
$argv
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Event Callback Action creation.
|
||||
*
|
||||
* @author Time.ly Network Inc.
|
||||
* @since 2.0
|
||||
*
|
||||
* @instantiator new
|
||||
* @package AI1EC
|
||||
* @subpackage AI1EC.Event
|
||||
*/
|
||||
class Ai1ec_Event_Callback_Action extends Ai1ec_Event_Callback_Abstract {
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Event Callback Filter creation.
|
||||
*
|
||||
* @author Time.ly Network Inc.
|
||||
* @since 2.0
|
||||
*
|
||||
* @instantiator new
|
||||
* @package AI1EC
|
||||
* @subpackage AI1EC.Event
|
||||
*/
|
||||
class Ai1ec_Event_Callback_Filter extends Ai1ec_Event_Callback_Abstract {
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Event Callback Shortcode creation.
|
||||
*
|
||||
* @author Time.ly Network Inc.
|
||||
* @since 2.0
|
||||
*
|
||||
* @instantiator new
|
||||
* @package AI1EC
|
||||
* @subpackage AI1EC.Event
|
||||
*/
|
||||
class Ai1ec_Event_Callback_Shortcode extends Ai1ec_Event_Callback_Abstract {
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Event Dispatcher processing.
|
||||
*
|
||||
* @author Time.ly Network Inc.
|
||||
* @since 2.0
|
||||
*
|
||||
* @package AI1EC
|
||||
* @subpackage AI1EC.Event
|
||||
*/
|
||||
class Ai1ec_Event_Dispatcher extends Ai1ec_Base {
|
||||
|
||||
/**
|
||||
* Register callback object.
|
||||
*
|
||||
* @param string $hook Name of the event hook.
|
||||
* @param Ai1ec_Event_Callback_Abstract $entity Event Callback object.
|
||||
* @param integer $priority Priorify of the event hook execution.
|
||||
* @param integer $accepted_args Number of accepted method parameters.
|
||||
*
|
||||
* @return Ai1ec_Event_Dispatcher Event Dispatcher Object.
|
||||
*/
|
||||
public function register(
|
||||
$hook,
|
||||
Ai1ec_Event_Callback_Abstract $entity,
|
||||
$priority = 10,
|
||||
$accepted_args = 1
|
||||
) {
|
||||
$wp_method = 'add_action';
|
||||
if ( $entity instanceof Ai1ec_Event_Callback_Filter ) {
|
||||
$wp_method = 'add_filter';
|
||||
}
|
||||
$wp_method(
|
||||
$hook,
|
||||
array( $entity, 'run' ),
|
||||
$priority,
|
||||
$accepted_args
|
||||
);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a callback object and register it.
|
||||
*
|
||||
* @param string $hook Name of the event hook.
|
||||
* @param array $method Method to call.
|
||||
* @param integer $priority Priorify of the event hook execution.
|
||||
* @param integer $accepted_args Number of accepted method parameters.
|
||||
* @param string $type The type to add.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _register(
|
||||
$hook,
|
||||
array $method,
|
||||
$type,
|
||||
$priority = 10,
|
||||
$accepted_args = 1
|
||||
) {
|
||||
$action = $this->_registry->get(
|
||||
'event.callback.' . $type,
|
||||
$method[0],
|
||||
$method[1]
|
||||
);
|
||||
$this->register(
|
||||
$hook,
|
||||
$action,
|
||||
$priority,
|
||||
$accepted_args
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a filter.
|
||||
*
|
||||
* @param string $hook Name of the event hook.
|
||||
* @param array $method Method to call.
|
||||
* @param integer $priority Priorify of the event hook execution.
|
||||
* @param integer $accepted_args Number of accepted method parameters.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register_filter(
|
||||
$hook,
|
||||
array $method,
|
||||
$priority = 10,
|
||||
$accepted_args = 1
|
||||
) {
|
||||
$this->_register(
|
||||
$hook,
|
||||
$method,
|
||||
'filter',
|
||||
$priority,
|
||||
$accepted_args
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an action.
|
||||
*
|
||||
* @param string $hook Name of the event hook.
|
||||
* @param array $method Method to call.
|
||||
* @param integer $priority Priorify of the event hook execution.
|
||||
* @param integer $accepted_args Number of accepted method parameters.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register_action(
|
||||
$hook,
|
||||
array $method,
|
||||
$priority = 10,
|
||||
$accepted_args = 1
|
||||
) {
|
||||
$this->_register(
|
||||
$hook,
|
||||
$method,
|
||||
'action',
|
||||
$priority,
|
||||
$accepted_args
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a shortcode.
|
||||
*
|
||||
* @param string $shortcode Name of the shortcode tag.
|
||||
* @param array $method Method to call.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register_shortcode(
|
||||
$shortcode,
|
||||
array $method
|
||||
) {
|
||||
$entity = $this->_registry->get(
|
||||
'event.callback.shortcode',
|
||||
$method[0],
|
||||
$method[1]
|
||||
);
|
||||
add_shortcode( $shortcode, array( $entity, 'run' ) );
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user