BlogPost.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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\SerializerBundle\Tests\Fixtures;
  18. use JMS\SerializerBundle\Annotation\Type;
  19. use JMS\SerializerBundle\Annotation\SerializedName;
  20. use JMS\SerializerBundle\Annotation\XmlRoot;
  21. use JMS\SerializerBundle\Annotation\XmlAttribute;
  22. use JMS\SerializerBundle\Annotation\XmlList;
  23. use Doctrine\Common\Collections\ArrayCollection;
  24. /** @XmlRoot("blog-post") */
  25. class BlogPost
  26. {
  27. /**
  28. * @Type("string")
  29. */
  30. private $title;
  31. /**
  32. * @Type("DateTime")
  33. * @XmlAttribute
  34. */
  35. private $createdAt;
  36. /**
  37. * @Type("boolean")
  38. * @SerializedName("is_published")
  39. * @XmlAttribute
  40. */
  41. private $published;
  42. /**
  43. * @Type("ArrayCollection<JMS\SerializerBundle\Tests\Fixtures\Comment>")
  44. * @XmlList(inline=true, entry="comment")
  45. */
  46. private $comments;
  47. /**
  48. * @Type("JMS\SerializerBundle\Tests\Fixtures\Author")
  49. */
  50. private $author;
  51. public function __construct($title, Author $author, \DateTime $createdAt)
  52. {
  53. $this->title = $title;
  54. $this->author = $author;
  55. $this->published = false;
  56. $this->comments = new ArrayCollection();
  57. $this->createdAt = $createdAt;
  58. }
  59. public function setPublished()
  60. {
  61. $this->published = true;
  62. }
  63. public function addComment(Comment $comment)
  64. {
  65. $this->comments->add($comment);
  66. }
  67. }