From 039c20c837250dae1ed5f6f72c7efb4d42aeff15 Mon Sep 17 00:00:00 2001 From: Paul Rock Date: Wed, 24 Jul 2019 00:16:34 +0300 Subject: [PATCH] smart logic like in ORM added to where method of Query class --- src/Query.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Query.php b/src/Query.php index 0f1aa05..5b2ccb8 100644 --- a/src/Query.php +++ b/src/Query.php @@ -73,15 +73,24 @@ class Query implements QueryInterface /** * Where logic of query * - * @param string $key - * @param bool $value - * @param string|null $operator + * @param string $key Key which need to find + * @param bool|string|int $value Value which need to check (by default true) + * @param bool|string|int $operator It may be one from list [-,=,>,<] * @return \RouterOS\Query * @throws \RouterOS\Exceptions\ClientException * @since 1.0.0 */ - public function where(string $key, $value = true, string $operator = ''): self + public function where(string $key, $operator = '=', $value = null): self { + if ($operator !== '=' && null === $value) { + + // Client may set only two parameters, that mean what $operator is $value + $value = $operator; + + // And operator should be "=" + $operator = '='; + } + if (!empty($operator)) { // If operator is available in list if (\in_array($operator, self::AVAILABLE_OPERATORS, true)) {