generated from yiisoft/package-template
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5953675
commit 88e119b
Showing
15 changed files
with
358 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
## 1.0.0 under development | ||
|
||
- Initial release. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Data\Db\Filter; | ||
|
||
use InvalidArgumentException; | ||
|
||
final class Between extends CompareFilter | ||
{ | ||
/** | ||
* @param mixed $column | ||
*/ | ||
public function __construct($column, ?array $value, ?string $table = null) | ||
{ | ||
if (is_array($value) && count($value) !== 2) { | ||
throw new InvalidArgumentException('Value must be a [from, to] array.'); | ||
} | ||
|
||
parent::__construct($column, $value, $table); | ||
} | ||
|
||
public static function getOperator(): string | ||
{ | ||
return 'between'; | ||
} | ||
|
||
/** | ||
* @param mixed $value | ||
*/ | ||
private static function isEmpty($value): bool | ||
{ | ||
return $value !== null && $value !== ''; | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
if (is_array($this->value)) { | ||
$value = $this->value; | ||
$start = array_shift($value); | ||
$end = array_pop($value); | ||
|
||
if (!self::isEmpty($start) && !self::isEmpty($end)) { | ||
return [self::getOperator(), $this->column, $start, $end]; | ||
} | ||
|
||
if (!self::isEmpty($start)) { | ||
return [GreaterThanOrEqual::getOperator(), $this->column, $start]; | ||
} | ||
|
||
if (!self::isEmpty($end)) { | ||
return [LessThanOrEqual::getOperator(), $this->column, $end]; | ||
} | ||
|
||
return []; | ||
} | ||
|
||
return parent::toArray(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Data\Db\Filter; | ||
|
||
final class ILike extends Like | ||
{ | ||
public static function getOperator(): string | ||
{ | ||
return 'ilike'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Data\Db\Filter; | ||
|
||
use Yiisoft\Data\Reader\Filter\Not as FilterNot; | ||
use Yiisoft\Data\Reader\Filter\FilterInterface; | ||
|
||
final class Not implements FilterInterface | ||
{ | ||
private FilterInterface $filter; | ||
|
||
public function __construct(FilterInterface $filter) | ||
{ | ||
$this->filter = $filter; | ||
} | ||
|
||
public static function getOperator(): string | ||
{ | ||
return FilterNot::getOperator(); | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
$array = $this->filter->toArray(); | ||
|
||
if ($array === []) { | ||
return []; | ||
} | ||
|
||
switch ($array[0]) { | ||
case 'IS': | ||
$array[0] .= ' ' . self::getOperator(); | ||
break; | ||
case Exists::getOperator(): case In::getOperator(): case Between::getOperator(): | ||
$array[0] = self::getOperator() . ' ' . $array[0]; | ||
break; | ||
default: | ||
$array = [self::getOperator(), $array]; | ||
} | ||
|
||
return $array; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Data\Db\Filter; | ||
|
||
use RuntimeException; | ||
use Stringable; | ||
|
||
final class NotEquals extends CompareFilter | ||
{ | ||
public static function getOperator(): string | ||
{ | ||
return '!='; | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
if ($this->value === null) { | ||
if ($this->ignoreNull) { | ||
return []; | ||
} | ||
|
||
if (is_string($this->column)) { | ||
return ['NOT', [$this->column => null]]; | ||
} | ||
|
||
if ($this->column instanceof Stringable) { | ||
return ['NOT', [$this->column->__toString() => null]]; | ||
} | ||
|
||
throw new RuntimeException(); | ||
} | ||
|
||
return [self::getOperator(), $this->column, $this->value]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Data\Db\Processor; | ||
|
||
use Yiisoft\Data\Db\Filter\Between as FilterBetween; | ||
|
||
class Between extends CompareProcessor | ||
{ | ||
public function getOperator(): string | ||
{ | ||
return FilterBetween::getOperator(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Data\Db\Processor; | ||
|
||
use Yiisoft\Data\Db\Filter\ILike as ILikeFilter; | ||
use Yiisoft\Data\Db\Processor\CompareProcessor; | ||
|
||
class ILike extends CompareProcessor | ||
{ | ||
public function getOperator(): string | ||
{ | ||
return ILikeFilter::getOperator(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Data\Db\Processor; | ||
|
||
use Yiisoft\Data\Db\Filter\Not as FilterNot; | ||
|
||
final class Not extends CompareProcessor | ||
{ | ||
public function getOperator(): string | ||
{ | ||
return FilterNot::getOperator(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Data\Db\Processor; | ||
|
||
use Yiisoft\Data\Db\Filter\NotEquals as NotEqualsFilter; | ||
|
||
final class NotEquals extends CompareProcessor | ||
{ | ||
public function getOperator(): string | ||
{ | ||
return NotEqualsFilter::getOperator(); | ||
} | ||
} |
Oops, something went wrong.