Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixing various typos.

Allowing detaching of comments from users
  • Loading branch information...
commit d28a78e96409219f5af9f53dc037f2595e133377 1 parent 215e40c
@Ocramius authored
Showing with 151 additions and 146 deletions.
  1. +76 −71 library/Entity/Comment.php
  2. +75 −75 library/Entity/User.php
View
147 library/Entity/Comment.php
@@ -1,72 +1,77 @@
-<?php
-namespace Entity;
-
-use Entity\User,
- Doctrine\ORM\Mapping as ORM;
-
-/**
- * @ORM\Entity
- */
-class Comment
-{
-
- /**
- * @ORM\Id()
- * @ORM\Column(type="integer")
- * @ORM\GeneratedValue(strategy="AUTO")
- * @var int
- */
- private $id;
-
- /**
- * @ORM\Column(type="string", length=255)
- * @var string
- */
- private $content;
-
- /**
- * @ORM\ManyToOne(targetEntity="Entity\User", inversedBy="comments")
- * @var User|null
- */
- private $user;
-
- public function __construct($content) {
- $this->setContent($content);
- }
-
- /**
- * @return int
- */
- public function getId() {
- return $this->id;
- }
-
- /**
- * @return string
- */
- public function getContent() {
- return $this->content;
- }
-
- /**
- * @param string $content
- */
- public function setName($content) {
- $this->content = (string) $content;
- }
-
- /**
- * @return User|null
- */
- public function getUser() {
- return $this->user;
- }
-
- /**
- * @param User $user
- */
- public function addPerson(User $user) {
- $this->user = $user;
- }
-
+<?php
+namespace Entity;
+
+use Entity\User,
+ InvalidArgumentException,
+ Doctrine\ORM\Mapping as ORM;
+
+/**
+ * @ORM\Entity
+ */
+class Comment
+{
+
+ /**
+ * @ORM\Id()
+ * @ORM\Column(type="integer")
+ * @ORM\GeneratedValue(strategy="AUTO")
+ * @var int
+ */
+ private $id;
+
+ /**
+ * @ORM\Column(type="string", length=255)
+ * @var string
+ */
+ private $content;
+
+ /**
+ * @ORM\ManyToOne(targetEntity="Entity\User", inversedBy="comments")
+ * @var User|null
+ */
+ private $user;
+
+ public function __construct($content) {
+ $this->setContent($content);
+ }
+
+ /**
+ * @return int
+ */
+ public function getId() {
+ return $this->id;
+ }
+
+ /**
+ * @return string
+ */
+ public function getContent() {
+ return $this->content;
+ }
+
+ /**
+ * @param string $content
+ */
+ public function setContent($content) {
+ $this->content = (string) $content;
+ }
+
+ /**
+ * @return User|null
+ */
+ public function getUser() {
+ return $this->user;
+ }
+
+ /**
+ * @param User $user
+ */
+ public function setUser($user) {
+ if($user === null || $user instanceof User) {
+ $this->user = $user;
+ } else {
+ throw new InvalidArgumentException('$user must be instance of Entity\User or null!');
+ }
+ }
+
}
View
150 library/Entity/User.php
@@ -1,76 +1,76 @@
-<?php
-namespace Entity;
-
-use Doctrine\Common\Collections\Collection,
- Doctrine\Common\Collections\ArrayCollection,
- Entity\Comment,
- Doctrine\ORM\Mapping as ORM;
-
-/**
- * @ORM\Entity
- */
-class User
-{
-
- /**
- * @ORM\Id()
- * @ORM\Column(type="integer")
- * @ORM\GeneratedValue(strategy="AUTO")
- * @var int
- */
- private $id;
-
- /**
- * @ORM\Column(type="string", length=255)
- * @var string
- */
- private $login;
-
- /**
- * @ORM\OneToMany(targetEntity="Entity\Comment", mappedBy="user")
- * @var Collection
- */
- private $comments;
-
- public function __construct($login) {
- $this->comments = new ArrayCollection();
- $this->setLogin($login);
- }
-
- /**
- * @return int
- */
- public function getId() {
- return $this->id;
- }
-
- /**
- * @return string
- */
- public function getLogin() {
- return $this->login;
- }
-
- /**
- * @param string $login
- */
- public function setLogin($login) {
- $this->login = (string) $login;
- }
-
- /**
- * @return Collection
- */
- public function getComments() {
- return $this->comments;
- }
-
- /**
- * @param Comment $comment
- */
- public function addPerson(Comment $comment) {
- $this->comments->add($comment);
- $comment->setUser($this);
- }
-
+<?php
+namespace Entity;
+
+use Doctrine\Common\Collections\Collection,
+ Doctrine\Common\Collections\ArrayCollection,
+ Entity\Comment,
+ Doctrine\ORM\Mapping as ORM;
+
+/**
+ * @ORM\Entity
+ */
+class User
+{
+
+ /**
+ * @ORM\Id()
+ * @ORM\Column(type="integer")
+ * @ORM\GeneratedValue(strategy="AUTO")
+ * @var int
+ */
+ private $id;
+
+ /**
+ * @ORM\Column(type="string", length=255)
+ * @var string
+ */
+ private $login;
+
+ /**
+ * @ORM\OneToMany(targetEntity="Entity\Comment", mappedBy="user")
+ * @var Collection
+ */
+ private $comments;
+
+ public function __construct($login) {
+ $this->comments = new ArrayCollection();
+ $this->setLogin($login);
+ }
+
+ /**
+ * @return int
+ */
+ public function getId() {
+ return $this->id;
+ }
+
+ /**
+ * @return string
+ */
+ public function getLogin() {
+ return $this->login;
+ }
+
+ /**
+ * @param string $login
+ */
+ public function setLogin($login) {
+ $this->login = (string) $login;
+ }
+
+ /**
+ * @return Collection
+ */
+ public function getComments() {
+ return $this->comments;
+ }
+
+ /**
+ * @param Comment $comment
+ */
+ public function addComment(Comment $comment) {
+ $this->comments->add($comment);
+ $comment->setUser($this);
+ }
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.