diff --git a/src/FilterHandler.php b/src/FilterHandler.php index dcf04f3..e6ae03b 100644 --- a/src/FilterHandler.php +++ b/src/FilterHandler.php @@ -18,7 +18,7 @@ use Yiisoft\Data\Db\FilterHandler\InFilterHandler; use Yiisoft\Data\Db\FilterHandler\LessThanFilterHandler; use Yiisoft\Data\Db\FilterHandler\LessThanOrEqualFilterHandler; -use Yiisoft\Data\Db\FilterHandler\LikeFilterHandler\LikeFilterHandlerFactory; +use Yiisoft\Data\Db\FilterHandler\LikeFilterHandler; use Yiisoft\Data\Db\FilterHandler\NotFilterHandler; use Yiisoft\Data\Db\FilterHandler\QueryFilterHandlerInterface; use Yiisoft\Data\Reader\FilterHandlerInterface; @@ -55,7 +55,7 @@ public function __construct( new GreaterThanOrEqualFilterHandler(), new LessThanFilterHandler(), new LessThanOrEqualFilterHandler(), - LikeFilterHandlerFactory::getLikeHandler(), + new LikeFilterHandler(), new InFilterHandler(), new ExistsFilterHandler(), new NotFilterHandler(), diff --git a/src/FilterHandler/LikeFilterHandler.php b/src/FilterHandler/LikeFilterHandler.php new file mode 100644 index 0000000..e7ba61c --- /dev/null +++ b/src/FilterHandler/LikeFilterHandler.php @@ -0,0 +1,23 @@ +getField(), $filter->getValue()]); + } +} diff --git a/src/FilterHandler/LikeFilterHandler/BaseLikeFilterHandler.php b/src/FilterHandler/LikeFilterHandler/BaseLikeFilterHandler.php deleted file mode 100644 index c869acd..0000000 --- a/src/FilterHandler/LikeFilterHandler/BaseLikeFilterHandler.php +++ /dev/null @@ -1,27 +0,0 @@ - '\%', - '_' => '\_', - '\\' => '\\\\', - ]; - - public function getFilterClass(): string - { - return Like::class; - } - - protected function prepareValue(string $value, bool $escape = false): string - { - return '%' . strtr($value, $this->escapingReplacements) . '%'; - } -} diff --git a/src/FilterHandler/LikeFilterHandler/LikeFilterHandlerFactory.php b/src/FilterHandler/LikeFilterHandler/LikeFilterHandlerFactory.php deleted file mode 100644 index 52f0840..0000000 --- a/src/FilterHandler/LikeFilterHandler/LikeFilterHandlerFactory.php +++ /dev/null @@ -1,26 +0,0 @@ - new SqliteLikeFilterHandler(), - 'mysql' => new MysqlLikeFilterHandler(), - 'pgsql' => new PostgresLikeFilterHandler(), - 'sqlsrv' => new MssqlLikeFilterHandler(), - 'oci' => new OracleLikeFilterHandler(), - default => throw new RuntimeException("$driverName database driver is not supported."), - }; - // @codeCoverageIgnoreEnd - } -} diff --git a/src/FilterHandler/LikeFilterHandler/MssqlLikeFilterHandler.php b/src/FilterHandler/LikeFilterHandler/MssqlLikeFilterHandler.php deleted file mode 100644 index cdddf86..0000000 --- a/src/FilterHandler/LikeFilterHandler/MssqlLikeFilterHandler.php +++ /dev/null @@ -1,28 +0,0 @@ -escapingReplacements['\\']); - } - - public function getCriteria(FilterInterface $filter, Context $context): ?Criteria - { - if ($filter->isCaseSensitive() === true) { - throw new NotSupportedFilterOptionException(optionName: 'caseSensitive', driverName: 'sqlsrv'); - } - - return new Criteria(['LIKE', $filter->getField(), $this->prepareValue($filter->getValue())]); - } -} diff --git a/src/FilterHandler/LikeFilterHandler/MysqlLikeFilterHandler.php b/src/FilterHandler/LikeFilterHandler/MysqlLikeFilterHandler.php deleted file mode 100644 index ca94eb6..0000000 --- a/src/FilterHandler/LikeFilterHandler/MysqlLikeFilterHandler.php +++ /dev/null @@ -1,29 +0,0 @@ -isCaseSensitive() !== true) { - return new Criteria(['LIKE', $filter->getField(), $this->prepareValue($filter->getValue())]); - } - - return new Criteria([ - 'LIKE BINARY', - $filter->getField(), - $this->prepareValue($filter->getValue(), escape: true), - ]); - } -} diff --git a/src/FilterHandler/LikeFilterHandler/OracleLikeFilterHandler.php b/src/FilterHandler/LikeFilterHandler/OracleLikeFilterHandler.php deleted file mode 100644 index 11f367a..0000000 --- a/src/FilterHandler/LikeFilterHandler/OracleLikeFilterHandler.php +++ /dev/null @@ -1,18 +0,0 @@ -getField(), $this->prepareValue($filter->getValue())]); - } -} diff --git a/src/FilterHandler/LikeFilterHandler/PostgresLikeFilterHandler.php b/src/FilterHandler/LikeFilterHandler/PostgresLikeFilterHandler.php deleted file mode 100644 index 1623849..0000000 --- a/src/FilterHandler/LikeFilterHandler/PostgresLikeFilterHandler.php +++ /dev/null @@ -1,22 +0,0 @@ -isCaseSensitive() !== true) { - return new Criteria(['ILIKE', $filter->getField(), $this->prepareValue($filter->getValue(), escape: true)]); - } - - return new Criteria(['LIKE', $filter->getField(), $this->prepareValue($filter->getValue())]); - } -} diff --git a/src/FilterHandler/LikeFilterHandler/SqliteLikeFilterHandler.php b/src/FilterHandler/LikeFilterHandler/SqliteLikeFilterHandler.php deleted file mode 100644 index aa8e70c..0000000 --- a/src/FilterHandler/LikeFilterHandler/SqliteLikeFilterHandler.php +++ /dev/null @@ -1,28 +0,0 @@ -escapingReplacements['\\']); - } - - public function getCriteria(FilterInterface $filter, Context $context): ?Criteria - { - if ($filter->isCaseSensitive() === true) { - throw new NotSupportedFilterOptionException(optionName: 'caseSensitive', driverName: 'sqlite'); - } - - return new Criteria(['LIKE', $filter->getField(), $this->prepareValue($filter->getValue())]); - } -}