Skip to content

Commit

Permalink
allow nette/utils 4.0 (#632)
Browse files Browse the repository at this point in the history
  • Loading branch information
hrach authored Jul 1, 2023
1 parent b8e87d4 commit 28c98dd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
11 changes: 8 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -64,5 +64,10 @@
"branch-alias": {
"dev-master": "4.0-dev"
}
},
"config": {
"allow-plugins": {
"phpstan/extension-installer": true
}
}
}
1 change: 1 addition & 0 deletions src/Bridges/NetteDI/OrmExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 20 additions & 2 deletions src/Collection/Functions/CompareLikeFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, '~') . '.*$~';
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 28c98dd

Please sign in to comment.