SingleStringCastableIdEntity.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Bridge\Doctrine\Tests\Fixtures;
  11. use Doctrine\ORM\Mapping\Column;
  12. use Doctrine\ORM\Mapping\Entity;
  13. use Doctrine\ORM\Mapping\GeneratedValue;
  14. use Doctrine\ORM\Mapping\Id;
  15. /** @Entity */
  16. class SingleStringCastableIdEntity
  17. {
  18. /**
  19. * @Id
  20. * @Column(type="string")
  21. * @GeneratedValue(strategy="NONE")
  22. */
  23. protected $id;
  24. /** @Column(type="string", nullable=true) */
  25. public $name;
  26. public function __construct($id, $name)
  27. {
  28. $this->id = new StringCastableObjectIdentity($id);
  29. $this->name = $name;
  30. }
  31. public function __toString()
  32. {
  33. return (string) $this->name;
  34. }
  35. }
  36. class StringCastableObjectIdentity
  37. {
  38. protected $id;
  39. public function __construct($id)
  40. {
  41. $this->id = $id;
  42. }
  43. public function __toString()
  44. {
  45. return (string) $this->id;
  46. }
  47. }