mecha-cms / mecha

Minimalist content management system.

Home Page:https://mecha-cms.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hook Sorting Should Be Done Once

taufik-nurrohman opened this issue · comments

$any = (new Anemon(self::$lot[1][$c][$id]))->sort([1, 'stack']);

Whenever a Hook::fire() is invoked, a task to sort the added hooks by stack property is performed. This task can be reduced by only doing the sorting once. But I need an indicator to tell the Hook that it needs to do the sorting:

  1. Invoking Hook::set() should trigger the sorting again.
  2. Invoking Hook::get() should not trigger the sorting.
  3. Invoking Hook::let() should not trigger the sorting as it’s just an action to remove or halt a hook.
  4. Invoking Hook::fire() for the first time should trigger the sorting.
  5. Invoking Hook::fire() for the second time and the rest should not trigger the sorting, as it’s already done in the first invoke.

if (count($value = $this->value) <= 1) {
if (!$preserve_key) {
$this->value = array_values($this->value);
}
return $this;
}

If the array input contains only 1 item or empty, we can skip the sorting task entirely! 😄