mirror of
https://github.com/shlinkio/shlink.git
synced 2026-11-02 20:30:15 -06:00
Remove dependency on laminas/laminas-inputfilter
This commit is contained in:
1 parent
878bfbcd88
commit
d8f80278f5
4 files changed
+11
-53
No files matched your search
@@ -12,8 +12,6 @@ use donatj\UserAgent\UserAgentParser;
|
||||
use GuzzleHttp\Psr7\Query;
|
||||
use Hidehalo\Nanoid\Client as NanoidClient;
|
||||
use Jaybizzle\CrawlerDetect\CrawlerDetect;
|
||||
use Laminas\Filter\Word\CamelCaseToUnderscore;
|
||||
use Laminas\InputFilter\InputFilter;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Shlinkio\Shlink\Common\Util\DateRange;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlMode;
|
||||
@@ -26,6 +24,8 @@ use function array_reduce;
|
||||
use function explode;
|
||||
use function implode;
|
||||
use function is_array;
|
||||
use function mb_strtolower;
|
||||
use function preg_replace;
|
||||
use function print_r;
|
||||
use function Shlinkio\Shlink\Common\buildDateRange;
|
||||
use function Shlinkio\Shlink\Common\normalizeOptionalDate;
|
||||
@@ -128,33 +128,6 @@ function splitLocale(string $locale): array
|
||||
return [$lang, $countryCode];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param InputFilter<mixed> $inputFilter
|
||||
*/
|
||||
function getOptionalIntFromInputFilter(InputFilter $inputFilter, string $fieldName): int|null
|
||||
{
|
||||
$value = $inputFilter->getValue($fieldName);
|
||||
return $value !== null ? (int) $value : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param InputFilter<mixed> $inputFilter
|
||||
*/
|
||||
function getOptionalBoolFromInputFilter(InputFilter $inputFilter, string $fieldName): bool|null
|
||||
{
|
||||
$value = $inputFilter->getValue($fieldName);
|
||||
return $value !== null ? (bool) $value : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param InputFilter<mixed> $inputFilter
|
||||
*/
|
||||
function getNonEmptyOptionalValueFromInputFilter(InputFilter $inputFilter, string $fieldName): mixed
|
||||
{
|
||||
$value = $inputFilter->getValue($fieldName);
|
||||
return empty($value) ? null : $value;
|
||||
}
|
||||
|
||||
function arrayToString(array $array, int $indentSize = 4): string
|
||||
{
|
||||
$indent = str_repeat(' ', $indentSize);
|
||||
@@ -210,12 +183,13 @@ function fieldWithUtf8Charset(FieldBuilder $field, array $emConfig, string $coll
|
||||
|
||||
function camelCaseToSnakeCase(string $value): string
|
||||
{
|
||||
static $filter;
|
||||
if ($filter === null) {
|
||||
$filter = new CamelCaseToUnderscore();
|
||||
}
|
||||
|
||||
return strtolower($filter->filter($value));
|
||||
// Handle cases like "HTTPServerError" -> "http_server_error"
|
||||
$value = preg_replace('/([A-Z])([A-Z][a-z])/u', '$1_$2', $value);
|
||||
// Handle cases like "myVariable" -> "my_variable"
|
||||
// @phpstan-ignore argument.type
|
||||
$value = preg_replace('/([a-z0-9])([A-Z])/u', '$1_$2', $value);
|
||||
// @phpstan-ignore argument.type
|
||||
return mb_strtolower($value);
|
||||
}
|
||||
|
||||
function toProblemDetailsType(string $errorCode): string
|
||||
|
||||
@@ -5,7 +5,6 @@ declare(strict_types=1);
|
||||
namespace Shlinkio\Shlink\Core\Exception;
|
||||
|
||||
use Fig\Http\Message\StatusCodeInterface;
|
||||
use Laminas\InputFilter\InputFilterInterface;
|
||||
use Mezzio\ProblemDetails\Exception\CommonProblemDetailsExceptionTrait;
|
||||
use Mezzio\ProblemDetails\Exception\ProblemDetailsExceptionInterface;
|
||||
use Throwable;
|
||||
@@ -26,16 +25,6 @@ class ValidationException extends InvalidArgumentException implements ProblemDet
|
||||
|
||||
private(set) array $invalidElements;
|
||||
|
||||
/**
|
||||
* @param InputFilterInterface<mixed> $inputFilter
|
||||
* @deprecated
|
||||
*/
|
||||
public static function fromInputFilter(InputFilterInterface $inputFilter, Throwable|null $prev = null): self
|
||||
{
|
||||
// @phpstan-ignore-next-line
|
||||
return static::fromArray($inputFilter->getMessages(), $prev);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, string[]|string> $invalidData
|
||||
*/
|
||||
|
||||
@@ -5,7 +5,6 @@ declare(strict_types=1);
|
||||
namespace ShlinkioTest\Shlink\Core\Exception;
|
||||
|
||||
use Fig\Http\Message\StatusCodeInterface;
|
||||
use Laminas\InputFilter\InputFilterInterface;
|
||||
use LogicException;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
@@ -20,7 +19,7 @@ use function print_r;
|
||||
class ValidationExceptionTest extends TestCase
|
||||
{
|
||||
#[Test, DataProvider('provideExceptions')]
|
||||
public function createsExceptionFromInputFilter(Throwable|null $prev): void
|
||||
public function createsExceptionFromArray(Throwable|null $prev): void
|
||||
{
|
||||
$invalidData = [
|
||||
'foo' => 'bar',
|
||||
@@ -32,10 +31,7 @@ class ValidationExceptionTest extends TestCase
|
||||
'something' => {$barValue}
|
||||
EOT;
|
||||
|
||||
$inputFilter = $this->createMock(InputFilterInterface::class);
|
||||
$inputFilter->expects($this->once())->method('getMessages')->with()->willReturn($invalidData);
|
||||
|
||||
$e = ValidationException::fromInputFilter($inputFilter, $prev);
|
||||
$e = ValidationException::fromArray($invalidData, $prev);
|
||||
|
||||
self::assertEquals($invalidData, $e->invalidElements);
|
||||
self::assertEquals(['invalidElements' => array_keys($invalidData)], $e->getAdditionalData());
|
||||
|
||||
Reference in new issue
Block a user