AbstractWith v1.0.0
Базовый класс fluent-билдеров с маршрутизацией __call в WithHandler.
Описание: Абстрактный базовый класс для fluent-билдеров. Неизвестные вызовы методов передаёт в WithHandler, если метаданные класса содержат соответствующую виртуальную операцию.
Namespace: Devcraft\Abstracts
С версии: 1.0.0
См. также:
__call(string $methodName, array $arguments): mixed
Описание: Если WithHandler::handles($this, $methodName) истинно — вызывает WithHandler::call(...) и возвращает результат (обычно $this). Иначе бросает BadMethodCallException.
Параметры:
$methodName(string): имя вызванного метода$arguments(array): аргументы вызова
Пример:
use Devcraft\Abstracts\AbstractWith;
use Devcraft\Attributes\With;
use Devcraft\Attributes\WithItem;
final class Query extends AbstractWith
{
#[With]
private ?int $page = null;
#[With, WithItem('string')]
private array $tags = [];
#[WithItem('string', ['string', 'null'])]
private array $labels = [];
public function page(): ?int
{
return $this->page;
}
public function tags(): array
{
return $this->tags;
}
public function labels(): array
{
return $this->labels;
}
}
$query = (new Query())
->withPage(1)
->withTagsItem('proxy')
->withLabelsItem('status', 'ready');
$query->page(); // 1
$query->tags(); // ['proxy']
$query->labels(); // ['status' => 'ready']