Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug #21656 [DoctrineBridge] Fixed validating custom doctrine type col…
…umns (dmaicher) This PR was merged into the 3.2 branch. Discussion ---------- [DoctrineBridge] Fixed validating custom doctrine type columns | Q | A | ------------- | --- | Branch? | 3.1 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #21619 | License | MIT | Doc PR | - This fixes #21619 by not assuming the invalid `$value` is a Doctrine entity if its an object Commits ------- ad59370 [DoctrineBridge] Fixed validating custom doctrine type columns
- Loading branch information
Showing
5 changed files
with
154 additions
and
2 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
src/Symfony/Bridge/Doctrine/Tests/Fixtures/SingleIntIdStringWrapperNameEntity.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,33 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bridge\Doctrine\Tests\Fixtures; | ||
|
||
use Doctrine\ORM\Mapping\Id; | ||
use Doctrine\ORM\Mapping\Column; | ||
use Doctrine\ORM\Mapping\Entity; | ||
use Symfony\Bridge\Doctrine\Tests\Fixtures\Type\StringWrapper; | ||
|
||
/** @Entity */ | ||
class SingleIntIdStringWrapperNameEntity | ||
{ | ||
/** @Id @Column(type="integer") */ | ||
protected $id; | ||
|
||
/** @Column(type="string_wrapper", nullable=true) */ | ||
public $name; | ||
|
||
public function __construct($id, $name) | ||
{ | ||
$this->id = $id; | ||
$this->name = $name; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/Symfony/Bridge/Doctrine/Tests/Fixtures/Type/StringWrapper.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,36 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bridge\Doctrine\Tests\Fixtures\Type; | ||
|
||
class StringWrapper | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $string; | ||
|
||
/** | ||
* @param string $string | ||
*/ | ||
public function __construct($string = null) | ||
{ | ||
$this->string = $string; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getString() | ||
{ | ||
return $this->string; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/Symfony/Bridge/Doctrine/Tests/Fixtures/Type/StringWrapperType.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,42 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bridge\Doctrine\Tests\Fixtures\Type; | ||
|
||
use Doctrine\DBAL\Platforms\AbstractPlatform; | ||
use Doctrine\DBAL\Types\StringType; | ||
|
||
class StringWrapperType extends StringType | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function convertToDatabaseValue($value, AbstractPlatform $platform) | ||
{ | ||
return $value instanceof StringWrapper ? $value->getString() : null; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function convertToPHPValue($value, AbstractPlatform $platform) | ||
{ | ||
return new StringWrapper($value); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getName() | ||
{ | ||
return 'string_wrapper'; | ||
} | ||
} |
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