123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- <?php
- class OC_Hook {
- public static $thrownExceptions = [];
- private static $registered = [];
-
- public static function connect($signalClass, $signalName, $slotClass, $slotName) {
-
-
- if (!array_key_exists($signalClass, self::$registered)) {
- self::$registered[$signalClass] = [];
- }
-
-
- if (!array_key_exists($signalName, self::$registered[$signalClass])) {
- self::$registered[$signalClass][$signalName] = [];
- }
-
- foreach (self::$registered[$signalClass][$signalName] as $hook) {
- if ($hook['class'] === $slotClass and $hook['name'] === $slotName) {
- return false;
- }
- }
-
- self::$registered[$signalClass][$signalName][] = [
- "class" => $slotClass,
- "name" => $slotName
- ];
-
- return true;
- }
-
- public static function emit($signalClass, $signalName, $params = []) {
-
-
- if (!array_key_exists($signalClass, self::$registered)) {
- return false;
- }
-
-
- if (!array_key_exists($signalName, self::$registered[$signalClass])) {
- return false;
- }
-
- foreach (self::$registered[$signalClass][$signalName] as $i) {
- try {
- call_user_func([ $i["class"], $i["name"] ], $params);
- } catch (Exception $e) {
- self::$thrownExceptions[] = $e;
- \OC::$server->getLogger()->logException($e);
- if ($e instanceof \OCP\HintException) {
- throw $e;
- }
- if ($e instanceof \OC\ServerNotAvailableException) {
- throw $e;
- }
- }
- }
- return true;
- }
-
- public static function clear($signalClass = '', $signalName = '') {
- if ($signalClass) {
- if ($signalName) {
- self::$registered[$signalClass][$signalName] = [];
- } else {
- self::$registered[$signalClass] = [];
- }
- } else {
- self::$registered = [];
- }
- }
-
- public static function getHooks() {
- return self::$registered;
- }
- }
|