]>
Commit | Line | Data |
---|---|---|
fcb1fba5 NL |
1 | <?php |
2 | ||
3 | namespace Wallabag\ApiBundle\Entity; | |
4 | ||
fcb1fba5 | 5 | use Doctrine\ORM\Mapping as ORM; |
619cc453 | 6 | use FOS\OAuthServerBundle\Entity\Client as BaseClient; |
23406ca3 | 7 | use Wallabag\UserBundle\Entity\User; |
0c00e525 JB |
8 | use JMS\Serializer\Annotation\Groups; |
9 | use JMS\Serializer\Annotation\SerializedName; | |
10 | use JMS\Serializer\Annotation\VirtualProperty; | |
0f8268c9 | 11 | use Symfony\Component\Validator\Constraints as Assert; |
fcb1fba5 NL |
12 | |
13 | /** | |
14 | * @ORM\Table("oauth2_clients") | |
15 | * @ORM\Entity | |
16 | */ | |
17 | class Client extends BaseClient | |
18 | { | |
19 | /** | |
20 | * @ORM\Id | |
21 | * @ORM\Column(type="integer") | |
22 | * @ORM\GeneratedValue(strategy="AUTO") | |
23 | */ | |
24 | protected $id; | |
25 | ||
9c545fe0 TC |
26 | /** |
27 | * @var string | |
28 | * | |
3ef75cc4 | 29 | * @ORM\Column(name="name", type="text", nullable=false) |
0c00e525 JB |
30 | * |
31 | * @Groups({"user_api_with_client"}) | |
9c545fe0 TC |
32 | */ |
33 | protected $name; | |
34 | ||
b0da721a NL |
35 | /** |
36 | * @ORM\OneToMany(targetEntity="RefreshToken", mappedBy="client", cascade={"remove"}) | |
37 | */ | |
38 | protected $refreshTokens; | |
39 | ||
ee32248f JB |
40 | /** |
41 | * @ORM\OneToMany(targetEntity="AccessToken", mappedBy="client", cascade={"remove"}) | |
42 | */ | |
43 | protected $accessTokens; | |
44 | ||
0c00e525 JB |
45 | /** |
46 | * @var string | |
47 | * | |
48 | * @SerializedName("client_secret") | |
49 | * @Groups({"user_api_with_client"}) | |
50 | */ | |
51 | protected $secret; | |
52 | ||
23406ca3 NL |
53 | /** |
54 | * @ORM\ManyToOne(targetEntity="Wallabag\UserBundle\Entity\User", inversedBy="clients") | |
0f8268c9 | 55 | * @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=true) |
23406ca3 NL |
56 | */ |
57 | private $user; | |
58 | ||
0f8268c9 TC |
59 | /** |
60 | * @ORM\Column(type="string", nullable=true) | |
61 | */ | |
62 | private $image; | |
63 | ||
64 | /** | |
65 | * @ORM\Column(type="string", nullable=true) | |
66 | */ | |
67 | private $description; | |
68 | ||
69 | /** | |
70 | * @ORM\Column(type="string", nullable=true) | |
71 | */ | |
72 | private $appUrl; | |
73 | ||
74 | /** | |
75 | * @ORM\Column(type="datetime", nullable=true) | |
76 | */ | |
77 | private $createdAt; | |
78 | ||
79 | /** | |
80 | * Client constructor. | |
81 | * @param User|null $user | |
82 | */ | |
83 | public function __construct(User $user = null) | |
fcb1fba5 NL |
84 | { |
85 | parent::__construct(); | |
23406ca3 | 86 | $this->user = $user; |
0f8268c9 | 87 | $this->createdAt = new \DateTime(); |
fcb1fba5 | 88 | } |
9c545fe0 TC |
89 | |
90 | /** | |
91 | * Get name. | |
92 | * | |
93 | * @return string | |
94 | */ | |
95 | public function getName() | |
96 | { | |
97 | return $this->name; | |
98 | } | |
99 | ||
100 | /** | |
101 | * Set name. | |
102 | * | |
103 | * @param string $name | |
104 | * | |
105 | * @return Client | |
106 | */ | |
107 | public function setName($name) | |
108 | { | |
109 | $this->name = $name; | |
110 | ||
111 | return $this; | |
112 | } | |
23406ca3 NL |
113 | |
114 | /** | |
115 | * @return User | |
116 | */ | |
117 | public function getUser() | |
118 | { | |
119 | return $this->user; | |
120 | } | |
0c00e525 JB |
121 | |
122 | /** | |
123 | * @VirtualProperty | |
124 | * @SerializedName("client_id") | |
125 | * @Groups({"user_api_with_client"}) | |
126 | */ | |
127 | public function getClientId() | |
128 | { | |
0f8268c9 TC |
129 | return $this->getId() . '_' . $this->getRandomId(); |
130 | } | |
131 | ||
132 | /** | |
133 | * @return string | |
134 | */ | |
135 | public function getImage() | |
136 | { | |
137 | return $this->image; | |
138 | } | |
139 | ||
140 | /** | |
141 | * @param string $image | |
142 | */ | |
143 | public function setImage($image) | |
144 | { | |
145 | $this->image = $image; | |
146 | } | |
147 | ||
148 | /** | |
149 | * @return string | |
150 | */ | |
151 | public function getDescription() | |
152 | { | |
153 | return $this->description; | |
154 | } | |
155 | ||
156 | /** | |
157 | * @param string $description | |
158 | */ | |
159 | public function setDescription($description) | |
160 | { | |
161 | $this->description = $description; | |
162 | } | |
163 | ||
164 | /** | |
165 | * @return string | |
166 | */ | |
167 | public function getAppUrl() | |
168 | { | |
169 | return $this->appUrl; | |
170 | } | |
171 | ||
172 | /** | |
173 | * @param string $appUrl | |
174 | */ | |
175 | public function setAppUrl($appUrl) | |
176 | { | |
177 | $this->appUrl = $appUrl; | |
178 | } | |
179 | ||
180 | /** | |
181 | * @return \DateTime | |
182 | */ | |
183 | public function getCreatedAt() | |
184 | { | |
185 | return $this->createdAt; | |
0c00e525 | 186 | } |
fcb1fba5 | 187 | } |