vite config : ignore /local and /public/** to improve perf
This commit is contained in:
parent
3c9eed7804
commit
c11a85e7f8
32 changed files with 1235 additions and 858 deletions
|
|
@ -2,28 +2,71 @@
|
|||
|
||||
namespace Kirby\Kql;
|
||||
|
||||
use Kirby\Query\Query as BaseQuery;
|
||||
use Kirby\Toolkit\Query as BaseQuery;
|
||||
|
||||
/**
|
||||
* Extends the core Query class with the KQL-specific
|
||||
* functionalities to intercept the segments chain calls
|
||||
*
|
||||
* @package Kirby KQL
|
||||
* @author Nico Hoffmann <nico@getkirby.com>
|
||||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier
|
||||
* @license https://getkirby.com/license
|
||||
*/
|
||||
class Query extends BaseQuery
|
||||
{
|
||||
/**
|
||||
* Intercepts the chain of segments called
|
||||
* on each other by replacing objects with
|
||||
* their corresponding Interceptor which
|
||||
* handles blocking calls to restricted methods
|
||||
*/
|
||||
public function intercept(mixed $result): mixed
|
||||
protected function interceptor($object)
|
||||
{
|
||||
return is_object($result) ? Interceptor::replace($result): $result;
|
||||
return Interceptor::replace($object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves the query if anything
|
||||
* can be found. Otherwise returns null.
|
||||
*
|
||||
* @param string $query
|
||||
* @return mixed
|
||||
*/
|
||||
protected function resolve(string $query)
|
||||
{
|
||||
// direct key access in arrays
|
||||
if (is_array($this->data) === true && array_key_exists($query, $this->data) === true) {
|
||||
$value = $this->data[$query];
|
||||
|
||||
// closure resolver
|
||||
if (is_a($value, 'Closure') === true) {
|
||||
$value = $value();
|
||||
}
|
||||
|
||||
return $this->interceptor($value);
|
||||
}
|
||||
|
||||
$parts = $this->parts($query);
|
||||
$data = $this->data;
|
||||
$value = null;
|
||||
|
||||
while (count($parts)) {
|
||||
$part = array_shift($parts);
|
||||
$info = $this->part($part);
|
||||
$method = $info['method'];
|
||||
$value = null;
|
||||
|
||||
if (is_array($data)) {
|
||||
$value = $data[$method] ?? null;
|
||||
} elseif (is_object($data)) {
|
||||
$data = $this->interceptor($data);
|
||||
|
||||
if (method_exists($data, $method) || method_exists($data, '__call')) {
|
||||
$value = $data->$method(...$info['args']);
|
||||
}
|
||||
} elseif (is_scalar($data)) {
|
||||
return $data;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (is_a($value, 'Closure') === true) {
|
||||
$value = $value(...$info['args']);
|
||||
}
|
||||
|
||||
if (is_array($value) === true) {
|
||||
$data = $value;
|
||||
} elseif (is_object($value) === true) {
|
||||
$data = $this->interceptor($value);
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue