/** * Alias to Register Methods * * - $data 为 null => \Lego\Register\Register::get * - $data 不为 null => \Lego\Register\Register::register * * @param $class * @param string|null $path * @param array $data * @return \Lego\Register\Data\Data */ function lego_register($class, $path = null, array $data = null) { if (is_null($data)) { return Register::get($class, $path); } return Register::register($class, $path, $data); }
public static function availableFields() { $fields = []; /** @var self $data */ foreach (Register::get(self::class, null, []) as $data) { $fields[$data->name()] = $data->data(); } return array_merge($fields, self::internalFields()); }
public static function getResponse() { $path = Request::get(self::REQUEST_PARAM); if (!$path) { return null; } /** @var self $data */ $data = Register::get(self::class, $path); if (!$data) { return null; } return $data->response(); }
public function afterRegistered() { $globals = Register::get(self::class, self::class); foreach ($this->data() as $name => &$callable) { if ($name === self::class) { continue; } if (is_string($callable) && array_key_exists($callable, $globals)) { $callable = $globals[$callable]; lego_assert(is_callable($callable), '$callable is not callable.'); } // Register to ResponseData ResponseData::add($name, $callable); } }
public static function response() { $path = Request::get(self::GET_PARAM); if (!$path) { return null; } $provider = Register::get(self::class, self::class); if (!$provider) { return null; } $response = $provider->data($path); if (is_null($response)) { return null; } return call_user_func($response, Request::all()); }
/** * Alias to Register Methods * * - $data 为 null => \Lego\Register\Register::get * - $data 不为 null => \Lego\Register\Register::register * * @param $name * @param mixed $data * @param string|null $dataName * @return \Lego\Register\Data\Data */ function lego_register($name, $data = null, $dataName = null) { return Register::register($name, $data, $dataName); }
/** * 自动补全的结果集 * @param callable $callable */ public function match($callable) { $responsePath = $this->responsePath(); Register::register(AutoCompleteData::class, $this->source()->original(), [$responsePath => $callable]); $this->remote = ResponseData::url($responsePath); }