mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 20:17:24 +08:00
Hook filter and action sep
This commit is contained in:
@@ -679,7 +679,7 @@ class TrackerRepository extends BaseRepository
|
|||||||
$spStateReal = $torrent->spStateReal;
|
$spStateReal = $torrent->spStateReal;
|
||||||
$log .= "[SP_STATE_REAL]: $spStateReal";
|
$log .= "[SP_STATE_REAL]: $spStateReal";
|
||||||
$promotionInfo = apply_filter('torrent_promotion', $torrent->toArray());
|
$promotionInfo = apply_filter('torrent_promotion', $torrent->toArray());
|
||||||
do_log("promotionInfo from filter torrent_promotion by torrent: " . $torrent->toArray() . ", get : " . json_encode($promotionInfo));
|
do_log("promotionInfo from filter torrent_promotion by torrent: " . $torrent->id . ", get : " . json_encode($promotionInfo));
|
||||||
if ($promotionInfo['sp_state'] != $spStateReal) {
|
if ($promotionInfo['sp_state'] != $spStateReal) {
|
||||||
$spStateReal = $promotionInfo['sp_state'];
|
$spStateReal = $promotionInfo['sp_state'];
|
||||||
$log .= "[CHANGE_SP_STATE_REAL_BY_FILTER_TORRENT_PROMOTION]: $spStateReal";
|
$log .= "[CHANGE_SP_STATE_REAL_BY_FILTER_TORRENT_PROMOTION]: $spStateReal";
|
||||||
|
|||||||
+16
-10
@@ -6,8 +6,6 @@ class Hook
|
|||||||
{
|
{
|
||||||
private static array $callbacks = [];
|
private static array $callbacks = [];
|
||||||
|
|
||||||
private bool $isDoingAction = false;
|
|
||||||
|
|
||||||
public function addFilter($name, $function, $priority, $argc)
|
public function addFilter($name, $function, $priority, $argc)
|
||||||
{
|
{
|
||||||
$id = $this->buildUniqueId($function);
|
$id = $this->buildUniqueId($function);
|
||||||
@@ -43,20 +41,16 @@ class Hook
|
|||||||
}
|
}
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
reset(self::$callbacks[$name]);
|
reset(self::$callbacks[$name]);
|
||||||
do_log("name: $name, argc: " . (func_num_args() - 1));
|
// do_log("name: $name, argc: " . (func_num_args() - 1));
|
||||||
do {
|
do {
|
||||||
foreach ((array)current(self::$callbacks[$name]) as $id => $callback) {
|
foreach ((array)current(self::$callbacks[$name]) as $id => $callback) {
|
||||||
$args[1] = $value;
|
$args[1] = $value;
|
||||||
// do_log("name: $name, id: $id, before, params: " . json_encode(array_slice($args, 1, $callback['argc'])));
|
// do_log("name: $name, id: $id, before, params: " . json_encode(array_slice($args, 1, $callback['argc'])));
|
||||||
$value = call_user_func_array($callback['function'], array_slice($args, 1, $callback['argc']));
|
$value = call_user_func_array($callback['function'], array_slice($args, 1, $callback['argc']));
|
||||||
if ($this->isDoingAction) {
|
|
||||||
$value = $args[1];
|
|
||||||
}
|
|
||||||
// do_log("name: $name, id: $id, after, value: " . var_export($value, true));
|
// do_log("name: $name, id: $id, after, value: " . var_export($value, true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (next(self::$callbacks[$name]) !== false);
|
while (next(self::$callbacks[$name]) !== false);
|
||||||
$this->isDoingAction = false;
|
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,10 +59,22 @@ class Hook
|
|||||||
return $this->addFilter($name, $function, $priority, $argc);
|
return $this->addFilter($name, $function, $priority, $argc);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function doAction($name, ...$args)
|
public function doAction($name, $value = '')
|
||||||
{
|
{
|
||||||
$this->isDoingAction = true;
|
if (!isset(self::$callbacks[$name])) {
|
||||||
$this->applyFilter(...func_get_args());
|
do_log("No this hook: $name");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$args = func_get_args();
|
||||||
|
reset(self::$callbacks[$name]);
|
||||||
|
// do_log("name: $name, argc: " . (func_num_args() - 1));
|
||||||
|
do {
|
||||||
|
foreach ((array)current(self::$callbacks[$name]) as $id => $callback) {
|
||||||
|
// do_log("name: $name, id: $id, before, params: " . json_encode(array_slice($args, 1, $callback['argc'])));
|
||||||
|
call_user_func_array($callback['function'], array_slice($args, 1, $callback['argc']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (next(self::$callbacks[$name]) !== false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dump()
|
public function dump()
|
||||||
|
|||||||
Reference in New Issue
Block a user