Skip to content

Instantly share code, notes, and snippets.

@borislav-angelov
Created November 18, 2013 14:19
Show Gist options
  • Save borislav-angelov/7528503 to your computer and use it in GitHub Desktop.
Save borislav-angelov/7528503 to your computer and use it in GitHub Desktop.
<?php
<?php
abstract class Ai1ec_Event_Callback_Abstract {
protected $_registry = null;
protected $_registry_name = null;
protected $_method = null;
public function __construct(
Ai1ec_Object_Registry $registry,
$path,
$method
) {
$this->_registry = $registry;
$this->_registry_name = $path;
$this->_method = $method;
}
public function run( array $argv ) {
return $this->_registry->dispatch(
$this->_registry_name,
$this->_method,
$argv
);
}
}
class Ai1ec_Event_Callback_Filter extends Ai1ec_Event_Callback_Abstract {}
class Ai1ec_Event_Dispatcher {
public function register(
$hook,
Ai1ec_Event_Callback_Abstract $entity,
$priority = 10,
$accepted_args = 1
) {
if ($entity instanceof Ai1ec_Event_Callback_Filter) {
add_filter(
$hook,
array( $entity, 'run' ),
$priority,
$accepted_args
);
} else {
add_action(
$hook,
array( $entity, 'run' ),
$priority,
$accepted_args
);
}
return $this;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment