-
-
Notifications
You must be signed in to change notification settings - Fork 345
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/3.x'
- Loading branch information
Showing
5 changed files
with
200 additions
and
6 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,64 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\DoctrineORMAdminBundle\Tests\Fixtures\DoctrineType; | ||
|
||
use Doctrine\DBAL\Platforms\AbstractPlatform; | ||
use Doctrine\DBAL\Types\ConversionException; | ||
use Doctrine\DBAL\Types\Type; | ||
use Sonata\DoctrineORMAdminBundle\Tests\Fixtures\Entity\ProductId; | ||
|
||
final class ProductIdType extends Type | ||
{ | ||
const NAME = 'ProductId'; | ||
|
||
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform): string | ||
{ | ||
return $platform->getIntegerTypeDeclarationSQL($fieldDeclaration); | ||
} | ||
|
||
public function requiresSQLCommentHint(AbstractPlatform $platform): bool | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* @param mixed $value | ||
*/ | ||
public function convertToPHPValue($value, AbstractPlatform $platform): ?ProductId | ||
{ | ||
if ($value === null || $value instanceof ProductId) { | ||
return $value; | ||
} | ||
|
||
try { | ||
return new ProductId((int) $value); | ||
} catch (\Throwable $e) { | ||
throw ConversionException::conversionFailed($value, $this->getName()); | ||
} | ||
} | ||
|
||
/** | ||
* @param mixed $value | ||
*/ | ||
public function convertToDatabaseValue($value, AbstractPlatform $platform): ?int | ||
{ | ||
$value = $this->convertToPHPValue($value, $platform); | ||
|
||
return $value !== null ? $value->getId() : null; | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return self::NAME; | ||
} | ||
} |
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,36 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\DoctrineORMAdminBundle\Tests\Fixtures\Entity; | ||
|
||
final class Product | ||
{ | ||
private $id; | ||
|
||
private $name; | ||
|
||
public function __construct(ProductId $id, string $name) | ||
{ | ||
$this->id = $id; | ||
$this->name = $name; | ||
} | ||
|
||
public function getId(): ProductId | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return $this->name; | ||
} | ||
} |
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,28 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\DoctrineORMAdminBundle\Tests\Fixtures\Entity; | ||
|
||
final class ProductId | ||
{ | ||
private $id; | ||
|
||
public function __construct(int $id) | ||
{ | ||
$this->id = $id; | ||
} | ||
|
||
public function getId(): int | ||
{ | ||
return $this->id; | ||
} | ||
} |
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