Skip to content

Commit

Permalink
Merge pull request #27 from rchavik/exclude-event-callbacks
Browse files Browse the repository at this point in the history
Exclude event callbacks when creating ACOs
  • Loading branch information
markstory committed Apr 7, 2013
2 parents 894c9e0 + bb9ec8d commit 2cc3ac9
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Lib/AclExtras.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,31 @@ protected function _checkNode($path, $alias, $parentId = null) {
return $node;
}

/**
* Get a list of registered callback methods
*/
protected function _getCallbacks($className) {
$reflection = new ReflectionClass($className);
$method = $reflection->getMethod('implementedEvents');
if (version_compare(phpversion(), '5.4', '>=')) {
$object = $reflection->newInstanceWithoutConstructor();
} else {
$object = unserialize(
sprintf('O:%d:"%s":0:{}', strlen($className), $className)
);
}
$implementedEvents = $method->invoke($object);
foreach ($implementedEvents as $event => $callable) {
if (is_string($callable)) {
$callbacks[] = $callable;
}
if (is_array($callable) && isset($callable['callable'])) {
$callbacks[] = $callable['callable'];
}
}
return $callbacks;
}

/**
* Check and Add/delete controller Methods
*
Expand All @@ -241,13 +266,15 @@ protected function _checkNode($path, $alias, $parentId = null) {
* @return void
*/
protected function _checkMethods($className, $controllerName, $node, $pluginPath = false) {
$excludes = $this->_getCallbacks($className);
$baseMethods = get_class_methods('Controller');
$actions = get_class_methods($className);
if ($actions == null) {
$this->err(__('Unable to get methods for "%s"', $className));
return false;
}
$methods = array_diff($actions, $baseMethods);
$methods = array_diff($methods, $excludes);
foreach ($methods as $action) {
if (strpos($action, '_', 0) === 0) {
continue;
Expand Down

0 comments on commit 2cc3ac9

Please sign in to comment.