/** * Add a listener. * * @param string $target * @param string|callable $type * @param callable $callback * * @return Guard * * @throws InvalidArgumentException */ public function on($target, $type, $callback = null) { if (is_null($callback)) { $callback = $type; $type = '*'; } if (!is_callable($callback)) { throw new InvalidArgumentException('The linstener is not callable.'); } $type = strtolower($type); $listeners = $this->listeners->get("{$target}.{$type}") ?: []; array_push($listeners, $callback); $this->listeners->set("{$target}.{$type}", $listeners); return $this; }
/** * 魔术调用 * * @param string $method * @param array $args * * @return mixed */ public function __call($method, $args) { if (in_array($method, $this->events, true)) { $callback = array_shift($args); is_callable($callback) && $this->listeners->set($method, $callback); return; } }
/** * Override parent set() method. * * @param string $attribute * @param mixed $value */ public function set($attribute, $value = null) { parent::set($this->getRealKey($attribute), $value); }
/** * Override parent set() method. * * @param string $attribute * @param mixed $value */ public function set($attribute, $value = null) { if ($alias = array_search($attribute, $this->aliases, true)) { $attribute = $alias; } return parent::set($attribute, $value); }