-
-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
184 additions
and
4 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
49 changes: 49 additions & 0 deletions
49
tests/Doctrine/Tests/Common/DataFixtures/TestEntity/Link.php
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,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\Common\DataFixtures\TestEntity; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
use Doctrine\Tests\Common\DataFixtures\TestValueObjects\Uuid; | ||
|
||
/** | ||
* @ORM\Entity | ||
*/ | ||
class Link | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\Column(type="uuid") | ||
* | ||
* @var Uuid | ||
*/ | ||
private $id; | ||
|
||
/** | ||
* @ORM\Column(length=150) | ||
* | ||
* @var string | ||
*/ | ||
private $url; | ||
|
||
public function __construct(Uuid $id) | ||
{ | ||
$this->id = $id; | ||
} | ||
|
||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getUrl() | ||
{ | ||
return $this->url; | ||
} | ||
|
||
public function setUrl($url) | ||
{ | ||
$this->url = $url; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
tests/Doctrine/Tests/Common/DataFixtures/TestTypes/UuidType.php
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,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\Common\DataFixtures\TestTypes; | ||
|
||
use Doctrine\DBAL\Platforms\AbstractPlatform; | ||
use Doctrine\DBAL\Types\Type; | ||
use Doctrine\Tests\Common\DataFixtures\TestValueObjects\Uuid; | ||
|
||
class UuidType extends Type | ||
{ | ||
public const NAME = 'uuid'; | ||
|
||
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) | ||
{ | ||
$field_declaration['length'] = 36; | ||
$field_declaration['fixed'] = true; | ||
|
||
return $platform->getVarcharTypeDeclarationSQL($field_declaration); | ||
} | ||
|
||
public function convertToPHPValue($value, AbstractPlatform $platform) | ||
{ | ||
return $value === null ? null : new Uuid($value); | ||
} | ||
|
||
public function convertToDatabaseValue($value, AbstractPlatform $platform) | ||
{ | ||
return $value === null ? null : (string) $value; | ||
} | ||
|
||
public function getName() | ||
{ | ||
return self::NAME; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
tests/Doctrine/Tests/Common/DataFixtures/TestValueObjects/Uuid.php
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,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\Common\DataFixtures\TestValueObjects; | ||
|
||
use JsonSerializable; | ||
use Serializable; | ||
|
||
class Uuid implements JsonSerializable, Serializable | ||
{ | ||
/** @var string $id */ | ||
private $id; | ||
|
||
public function __construct($id) | ||
{ | ||
$this->id = $id; | ||
} | ||
|
||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function jsonSerialize() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function serialize() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function unserialize($serialized) | ||
{ | ||
$this->id = $serialized; | ||
} | ||
|
||
public function __toString() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public static function unknown() | ||
{ | ||
return new self('00000000-0000-0000-C000-000000000046'); | ||
} | ||
} |