BlogPost.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /*
  3. * Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. namespace JMS\Serializer\Tests\Fixtures;
  18. use JMS\Serializer\Annotation\Type;
  19. use JMS\Serializer\Annotation\SerializedName;
  20. use JMS\Serializer\Annotation\XmlRoot;
  21. use JMS\Serializer\Annotation\XmlAttribute;
  22. use JMS\Serializer\Annotation\XmlList;
  23. use JMS\Serializer\Annotation\Groups;
  24. use Doctrine\Common\Collections\ArrayCollection;
  25. use PhpCollection\Sequence;
  26. /** @XmlRoot("blog-post") */
  27. class BlogPost
  28. {
  29. /**
  30. * @Type("string")
  31. * @Groups({"comments","post"})
  32. */
  33. private $title;
  34. /**
  35. * @Type("DateTime")
  36. * @XmlAttribute
  37. */
  38. private $createdAt;
  39. /**
  40. * @Type("boolean")
  41. * @SerializedName("is_published")
  42. * @XmlAttribute
  43. * @Groups({"post"})
  44. */
  45. private $published;
  46. /**
  47. * @Type("ArrayCollection<JMS\Serializer\Tests\Fixtures\Comment>")
  48. * @XmlList(inline=true, entry="comment")
  49. * @Groups({"comments"})
  50. */
  51. private $comments;
  52. /**
  53. * @Type("PhpCollection\Sequence<JMS\Serializer\Tests\Fixtures\Comment>")
  54. * @XmlList(inline=true, entry="comment2")
  55. * @Groups({"comments"})
  56. */
  57. private $comments2;
  58. /**
  59. * @Type("JMS\Serializer\Tests\Fixtures\Author")
  60. * @Groups({"post"})
  61. */
  62. private $author;
  63. public function __construct($title, Author $author, \DateTime $createdAt)
  64. {
  65. $this->title = $title;
  66. $this->author = $author;
  67. $this->published = false;
  68. $this->comments = new ArrayCollection();
  69. $this->comments2 = new Sequence();
  70. $this->createdAt = $createdAt;
  71. }
  72. public function setPublished()
  73. {
  74. $this->published = true;
  75. }
  76. public function addComment(Comment $comment)
  77. {
  78. $this->comments->add($comment);
  79. $this->comments2->add($comment);
  80. }
  81. }