-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(search): Allow multiple search terms in UnifiedController
Signed-off-by: Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>
- Loading branch information
Showing
13 changed files
with
584 additions
and
61 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
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,48 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @copyright 2023 Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com> | ||
* | ||
* @author Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
namespace OC\Search; | ||
|
||
use Throwable; | ||
|
||
abstract class Filter { | ||
public readonly mixed $value; | ||
|
||
public function __construct( | ||
public readonly string $name, | ||
string $value | ||
) { | ||
try { | ||
$this->value = $this->parse($value); | ||
} catch (InvalidFilter $e) { | ||
throw $e; | ||
} catch (Throwable $e) { | ||
throw new InvalidFilter($name, $value, $e); | ||
} | ||
} | ||
|
||
abstract protected function parse(string $value): mixed; | ||
} |
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,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @copyright 2023 Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com> | ||
* | ||
* @author Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
namespace OC\Search\Filter; | ||
|
||
use OC\Search\Filter; | ||
|
||
class TypeBool extends Filter { | ||
protected function parse(string $value): bool { | ||
return match ($value) { | ||
'true', 'yes', 'y', '1' => true, | ||
'false', 'no', 'n', '0', '' => false, | ||
}; | ||
} | ||
|
||
public function get(): bool { | ||
return $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,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @copyright 2023 Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com> | ||
* | ||
* @author Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
namespace OC\Search\Filter; | ||
|
||
use DateTimeImmutable; | ||
use OC\Search\Filter; | ||
|
||
class TypeDateTime extends Filter { | ||
protected function parse(string $value): DateTimeImmutable { | ||
if (filter_var($value, FILTER_VALIDATE_INT)) { | ||
$value = '@'.$value; | ||
} | ||
|
||
return new DateTimeImmutable($value); | ||
} | ||
|
||
public function get(): DateTimeImmutable { | ||
return $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,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @copyright 2023 Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com> | ||
* | ||
* @author Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
namespace OC\Search\Filter; | ||
|
||
use OC\Search\Filter; | ||
use OC\Search\InvalidFilter; | ||
|
||
class TypeFloat extends Filter { | ||
protected function parse(string $value): float { | ||
$value = filter_var($value, FILTER_VALIDATE_FLOAT); | ||
if ($value === false) { | ||
throw new InvalidFilter($this->name, $value); | ||
} | ||
|
||
return $value; | ||
} | ||
|
||
public function get(): float { | ||
return $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,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @copyright 2023 Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com> | ||
* | ||
* @author Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
namespace OC\Search\Filter; | ||
|
||
use OC\Search\Filter; | ||
use OC\Search\InvalidFilter; | ||
|
||
class TypeInt extends Filter { | ||
protected function parse(string $value): int { | ||
$value = filter_var($value, FILTER_VALIDATE_INT); | ||
if ($value === false) { | ||
throw new InvalidFilter($this->name, $value); | ||
} | ||
|
||
return $value; | ||
} | ||
|
||
public function get(): int { | ||
return $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,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @copyright 2023 Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com> | ||
* | ||
* @author Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
namespace OC\Search\Filter; | ||
|
||
use OC\Search\Filter; | ||
|
||
class TypeJson extends Filter { | ||
protected function parse(string $value): mixed { | ||
return json_decode(json: $value, associative: true, flags: JSON_THROW_ON_ERROR); | ||
} | ||
|
||
public function get(): mixed { | ||
return $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,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @copyright 2023 Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com> | ||
* | ||
* @author Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
namespace OC\Search\Filter; | ||
|
||
use OC\Search\Filter; | ||
use OC\Search\InvalidFilter; | ||
|
||
class TypeString extends Filter { | ||
protected function parse(string $value): string { | ||
if ($value === '') { | ||
throw new InvalidFilter($this->name, $value); | ||
} | ||
return $value; | ||
} | ||
|
||
public function get(): string { | ||
return $this->value; | ||
} | ||
} |
Oops, something went wrong.