Skip to content

Commit

Permalink
refactor plugin blade hook
Browse files Browse the repository at this point in the history
  • Loading branch information
yushine committed Jan 16, 2025
1 parent a074dbd commit 9182908
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions innopacks/plugin/src/Core/Blade/Hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,12 @@ protected function createCallbackObject(callable $callback, array $params): Call
*/
protected function run(string $hook, array $params, Callback $callback, ?string $output = null): mixed
{
if (! array_key_exists($hook, $this->watch)) {
return $output;
} elseif (! is_array($this->watch[$hook])) {
return $output;
}

if ($this->isUpdate) {
array_unshift($params, $output);
}
Expand All @@ -261,26 +267,21 @@ protected function run(string $hook, array $params, Callback $callback, ?string
array_unshift($params, $callback);
}

$this->outputs[$hook] = $output;

if (array_key_exists($hook, $this->watch)) {
if (is_array($this->watch[$hook])) {
foreach ($this->watch[$hook] as $function) {
if (! empty($this->stop[$hook])) {
unset($this->stop[$hook]);
$this->outputs[$hook] = '';
foreach ($this->watch[$hook] as $function) {
if (! empty($this->stop[$hook])) {
unset($this->stop[$hook]);

break;
}
break;
}

$output = call_user_func_array($function['function'], $params);
if ($this->isUpdate) {
$this->outputs[$hook] = $output;
$output = call_user_func_array($function['function'], $params);
if ($this->isUpdate) {
$this->outputs[$hook] = $output;

$params[1] = $output;
} else {
$this->outputs[$hook] .= $output;
}
}
$params[1] = $output;
} else {
$this->outputs[$hook] .= $output;
}
}

Expand Down

0 comments on commit 9182908

Please sign in to comment.