This repository has been archived by the owner on Jan 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added test case for custom field; parameter should binded with type
- Loading branch information
1 parent
2b72469
commit 8cc7419
Showing
6 changed files
with
156 additions
and
2 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
test/assets/module/ZFTestApigilityDb/config/xml/ZFTestApigilityDb.Entity.Product.dcm.xml
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,9 @@ | ||
<?xml version="1.0"?> | ||
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xsi="http://www.w3.org/2001/XMLSchema-instance" schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> | ||
<entity name="ZFTestApigilityDb\Entity\Product"> | ||
<id name="id" type="rev"> | ||
<generator strategy="CUSTOM"/> | ||
<custom-id-generator class="ZFTestApigilityDb\Type\RevGenerator"/> | ||
</id> | ||
</entity> | ||
</doctrine-mapping> |
13 changes: 13 additions & 0 deletions
13
test/assets/module/ZFTestApigilityDb/src/ZFTestApigilityDb/Entity/Product.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,13 @@ | ||
<?php | ||
|
||
namespace ZFTestApigilityDb\Entity; | ||
|
||
class Product | ||
{ | ||
protected $id; | ||
|
||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
test/assets/module/ZFTestApigilityDb/src/ZFTestApigilityDb/Type/RevGenerator.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,18 @@ | ||
<?php | ||
|
||
namespace ZFTestApigilityDb\Type; | ||
|
||
use Doctrine\ORM\EntityManager; | ||
use Doctrine\ORM\Id\AbstractIdGenerator; | ||
|
||
class RevGenerator extends AbstractIdGenerator | ||
{ | ||
public function generate(EntityManager $em, $entity) | ||
{ | ||
do { | ||
$value = md5(time() . mt_rand()); | ||
} while ($value === strrev($value)); | ||
|
||
return $value; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
test/assets/module/ZFTestApigilityDb/src/ZFTestApigilityDb/Type/RevType.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,44 @@ | ||
<?php | ||
|
||
namespace ZFTestApigilityDb\Type; | ||
|
||
use Doctrine\DBAL\Types\Type; | ||
use Doctrine\DBAL\Platforms\AbstractPlatform; | ||
|
||
class RevType extends Type | ||
{ | ||
const NAME = 'rev'; | ||
|
||
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) | ||
{ | ||
return $platform->getGuidTypeDeclarationSQL($fieldDeclaration); | ||
} | ||
|
||
public function convertToPHPValue($value, AbstractPlatform $platform) | ||
{ | ||
if (! $value) { | ||
return null; | ||
} | ||
|
||
return strrev($value); | ||
} | ||
|
||
public function convertToDatabaseValue($value, AbstractPlatform $platform) | ||
{ | ||
if (! $value) { | ||
return null; | ||
} | ||
|
||
return strrev($value); | ||
} | ||
|
||
public function getName() | ||
{ | ||
return static::NAME; | ||
} | ||
|
||
public function requiresSQLCommentHint(AbstractPlatform $platform) | ||
{ | ||
return true; | ||
} | ||
} |
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