From 28c98dd0f6ac559983b4c7f40d1dc2871e4c3c0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20=C5=A0kr=C3=A1=C5=A1ek?= Date: Sat, 1 Jul 2023 12:25:02 +0200 Subject: [PATCH] allow nette/utils 4.0 (#632) --- composer.json | 11 +++++++--- src/Bridges/NetteDI/OrmExtension.php | 1 + .../Functions/CompareLikeFunction.php | 22 +++++++++++++++++-- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index f78f2710..fab63bc3 100644 --- a/composer.json +++ b/composer.json @@ -23,16 +23,16 @@ "ext-json": "*", "ext-ctype": "*", "nette/caching": "~2.5 || ~3.0", - "nette/utils": "~2.5 || ~3.0", + "nette/utils": "~3.0 || ~4.0", "nette/tokenizer": "~2.3 || ~3.0", "nextras/dbal": "~4.0@dev" }, "require-dev": { "nette/bootstrap": "~2.4 || ~3.0", - "nette/di": "~2.4 >=2.4.10 || ~3.0", + "nette/di": "~3.0", "nette/finder": "~2.4 || ~3.0", "nette/neon": "~2.4 || ~3.0", - "nette/tester": "~2.3", + "nette/tester": "~2.3.5", "marc-mabe/php-enum": "~3.0", "mockery/mockery": "~1.2", "phpstan/extension-installer": "1.0.5", @@ -64,5 +64,10 @@ "branch-alias": { "dev-master": "4.0-dev" } + }, + "config": { + "allow-plugins": { + "phpstan/extension-installer": true + } } } diff --git a/src/Bridges/NetteDI/OrmExtension.php b/src/Bridges/NetteDI/OrmExtension.php index b3b9622a..5c13ada6 100644 --- a/src/Bridges/NetteDI/OrmExtension.php +++ b/src/Bridges/NetteDI/OrmExtension.php @@ -6,6 +6,7 @@ use Nette\Caching\Cache; use Nette\DI\CompilerExtension; use Nette\DI\ContainerBuilder; +use Nette\PhpGenerator\ClassType; use Nextras\Dbal\IConnection; use Nextras\Orm\Entity\Reflection\IMetadataParserFactory; use Nextras\Orm\Entity\Reflection\MetadataParser; diff --git a/src/Collection/Functions/CompareLikeFunction.php b/src/Collection/Functions/CompareLikeFunction.php index cb05f99b..785b373e 100644 --- a/src/Collection/Functions/CompareLikeFunction.php +++ b/src/Collection/Functions/CompareLikeFunction.php @@ -83,10 +83,10 @@ protected function evaluateInPhp(int $mode, $sourceValue, $targetValue): bool return Strings::match($sourceValue, $regexp) !== null; } elseif ($mode === LikeExpression::MODE_STARTS_WITH) { - return Strings::startsWith($sourceValue, $targetValue); + return self::startsWith($sourceValue, $targetValue); } elseif ($mode === LikeExpression::MODE_ENDS_WITH) { - return Strings::endsWith($sourceValue, $targetValue); + return self::endsWith($sourceValue, $targetValue); } elseif ($mode === LikeExpression::MODE_CONTAINS) { $regexp = '~^.*' . preg_quote($targetValue, '~') . '.*$~'; @@ -115,4 +115,22 @@ protected function evaluateInDb(int $mode, DbalExpressionResult $expression, $va throw new InvalidStateException(); } } + + + /** + * Starts the $haystack string with the prefix $needle? + */ + private static function startsWith(string $haystack, string $needle): bool + { + return strncmp($haystack, $needle, strlen($needle)) === 0; + } + + + /** + * Ends the $haystack string with the suffix $needle? + */ + private static function endsWith(string $haystack, string $needle): bool + { + return $needle === '' || substr($haystack, -strlen($needle)) === $needle; + } }