issues/27: Harden ContentFilterDto query parsing; use DateTimeImmutable in UpdateTimestampTrait
This commit is contained in:
committed by
Valeriy Petrov
parent
7a4fda31a4
commit
4f76693fe1
@@ -34,9 +34,12 @@ final readonly class ContentFilterDto
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Symfony QueryBag может отдать массив при ?regionId[]=… — не передаём его в is_numeric (TypeError в PHP 8).
|
||||||
|
*/
|
||||||
private static function positiveInt(mixed $value): ?int
|
private static function positiveInt(mixed $value): ?int
|
||||||
{
|
{
|
||||||
if ($value === null || $value === '' || !is_numeric($value)) {
|
if ($value === null || $value === '' || !is_scalar($value) || !is_numeric($value)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,12 +48,19 @@ final readonly class ContentFilterDto
|
|||||||
return $value > 0 ? $value : null;
|
return $value > 0 ? $value : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* При ?active[]=… query->get вернёт массив — отбрасываем без вызова filter_var по нему.
|
||||||
|
*/
|
||||||
private static function nullableBool(mixed $value): ?bool
|
private static function nullableBool(mixed $value): ?bool
|
||||||
{
|
{
|
||||||
if ($value === null || $value === '') {
|
if ($value === null || $value === '') {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!is_scalar($value)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (is_bool($value)) {
|
if (is_bool($value)) {
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,19 +6,24 @@ namespace App\Entity\Behavior;
|
|||||||
|
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Требует у класса-сущности свойство `$updateAt` (mapped column).
|
||||||
|
*
|
||||||
|
* @property \DateTimeInterface|null $updateAt
|
||||||
|
*/
|
||||||
trait UpdateTimestampTrait
|
trait UpdateTimestampTrait
|
||||||
{
|
{
|
||||||
#[ORM\PrePersist]
|
#[ORM\PrePersist]
|
||||||
public function setInitialUpdateAt(): void
|
public function setInitialUpdateAt(): void
|
||||||
{
|
{
|
||||||
if ($this->updateAt === null) {
|
if ($this->updateAt === null) {
|
||||||
$this->updateAt = new \DateTime();
|
$this->updateAt = new \DateTimeImmutable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[ORM\PreUpdate]
|
#[ORM\PreUpdate]
|
||||||
public function refreshUpdateAt(): void
|
public function refreshUpdateAt(): void
|
||||||
{
|
{
|
||||||
$this->updateAt = new \DateTime();
|
$this->updateAt = new \DateTimeImmutable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user