]> Raphaël G. Git Repositories - treebundle/blob - Entity/Resource.php
Add repository factory
[treebundle] / Entity / Resource.php
1 <?php declare(strict_types=1);
2
3 /*
4 * This file is part of the Rapsys TreeBundle package.
5 *
6 * (c) Raphaël Gertz <symfony@rapsys.eu>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Rapsys\TreeBundle\Entity;
13
14 use Doctrine\Common\Collections\Collection;
15 use Doctrine\Common\Collections\ArrayCollection;
16 use Doctrine\ORM\Event\PreUpdateEventArgs;
17
18 /**
19 * Resource
20 */
21 class Resource {
22 /**
23 * @var int
24 */
25 private ?int $id;
26
27 /**
28 * @var \DateTime
29 */
30 private \DateTime $created;
31
32 /**
33 * @var \DateTime
34 */
35 private \DateTime $updated;
36
37 /**
38 * Constructor
39 *
40 * @param string $path The resource path
41 */
42 public function __construct(private User $user, private string $path) {
43 $this->created = new \DateTime('now');
44 $this->updated = new \DateTime('now');
45 }
46
47 /**
48 * Get id
49 *
50 * @return ?int
51 */
52 public function getId(): ?int {
53 return $this->id;
54 }
55
56 /**
57 * Set user
58 *
59 * @param \Rapsys\BlogBundle\Entity\User $user
60 *
61 * @return Resource
62 */
63 public function setUser(User $user): Resource {
64 $this->user = $user;
65
66 return $this;
67 }
68
69 /**
70 * Get user
71 *
72 * @return \Rapsys\BlogBundle\Entity\User
73 */
74 public function getUser(): User {
75 return $this->user;
76 }
77
78 /**
79 * Set path
80 *
81 * @param string $path
82 *
83 * @return Resource
84 */
85 public function setPath(string $path): Resource {
86 $this->path = $path;
87
88 return $this;
89 }
90
91 /**
92 * Get path
93 *
94 * @return string
95 */
96 public function getPath(): string {
97 return $this->path;
98 }
99
100 /**
101 * Set created
102 *
103 * @param \DateTime $created
104 *
105 * @return Resource
106 */
107 public function setCreated(\DateTime $created): Resource {
108 $this->created = $created;
109
110 return $this;
111 }
112
113 /**
114 * Get created
115 *
116 * @return \DateTime
117 */
118 public function getCreated(): \DateTime {
119 return $this->created;
120 }
121
122 /**
123 * Set updated
124 *
125 * @param \DateTime $updated
126 *
127 * @return Resource
128 */
129 public function setUpdated(\DateTime $updated): Resource {
130 $this->updated = $updated;
131
132 return $this;
133 }
134
135 /**
136 * Get updated
137 *
138 * @return \DateTime
139 */
140 public function getUpdated(): \DateTime {
141 return $this->updated;
142 }
143
144 /**
145 * {@inheritdoc}
146 */
147 public function preUpdate(PreUpdateEventArgs $eventArgs): ?Resource {
148 //Check that we have an snippet instance
149 if (($entity = $eventArgs->getEntity()) instanceof Resource) {
150 //Set updated value
151 return $entity->setUpdated(new \DateTime('now'));
152 }
153 }
154 }