]>
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; |
0c00e525 JB |
7 | use JMS\Serializer\Annotation\Groups; |
8 | use JMS\Serializer\Annotation\SerializedName; | |
9 | use JMS\Serializer\Annotation\VirtualProperty; | |
f808b016 | 10 | use Wallabag\UserBundle\Entity\User; |
fcb1fba5 NL |
11 | |
12 | /** | |
13 | * @ORM\Table("oauth2_clients") | |
3a2d4cf9 | 14 | * @ORM\Entity(repositoryClass="Wallabag\ApiBundle\Repository\ClientRepository") |
fcb1fba5 NL |
15 | */ |
16 | class Client extends BaseClient | |
17 | { | |
18 | /** | |
19 | * @ORM\Id | |
20 | * @ORM\Column(type="integer") | |
21 | * @ORM\GeneratedValue(strategy="AUTO") | |
22 | */ | |
23 | protected $id; | |
24 | ||
9c545fe0 TC |
25 | /** |
26 | * @var string | |
27 | * | |
3ef75cc4 | 28 | * @ORM\Column(name="name", type="text", nullable=false) |
0c00e525 JB |
29 | * |
30 | * @Groups({"user_api_with_client"}) | |
9c545fe0 TC |
31 | */ |
32 | protected $name; | |
33 | ||
b0da721a NL |
34 | /** |
35 | * @ORM\OneToMany(targetEntity="RefreshToken", mappedBy="client", cascade={"remove"}) | |
36 | */ | |
37 | protected $refreshTokens; | |
38 | ||
ee32248f JB |
39 | /** |
40 | * @ORM\OneToMany(targetEntity="AccessToken", mappedBy="client", cascade={"remove"}) | |
41 | */ | |
42 | protected $accessTokens; | |
43 | ||
0c00e525 JB |
44 | /** |
45 | * @var string | |
46 | * | |
47 | * @SerializedName("client_secret") | |
48 | * @Groups({"user_api_with_client"}) | |
49 | */ | |
50 | protected $secret; | |
51 | ||
23406ca3 NL |
52 | /** |
53 | * @ORM\ManyToOne(targetEntity="Wallabag\UserBundle\Entity\User", inversedBy="clients") | |
54 | */ | |
55 | private $user; | |
56 | ||
57 | public function __construct(User $user) | |
fcb1fba5 NL |
58 | { |
59 | parent::__construct(); | |
23406ca3 | 60 | $this->user = $user; |
fcb1fba5 | 61 | } |
9c545fe0 TC |
62 | |
63 | /** | |
64 | * Get name. | |
65 | * | |
66 | * @return string | |
67 | */ | |
68 | public function getName() | |
69 | { | |
70 | return $this->name; | |
71 | } | |
72 | ||
73 | /** | |
74 | * Set name. | |
75 | * | |
76 | * @param string $name | |
77 | * | |
78 | * @return Client | |
79 | */ | |
80 | public function setName($name) | |
81 | { | |
82 | $this->name = $name; | |
83 | ||
84 | return $this; | |
85 | } | |
23406ca3 NL |
86 | |
87 | /** | |
88 | * @return User | |
89 | */ | |
90 | public function getUser() | |
91 | { | |
92 | return $this->user; | |
93 | } | |
0c00e525 JB |
94 | |
95 | /** | |
96 | * @VirtualProperty | |
97 | * @SerializedName("client_id") | |
98 | * @Groups({"user_api_with_client"}) | |
99 | */ | |
100 | public function getClientId() | |
101 | { | |
f808b016 | 102 | return $this->getId() . '_' . $this->getRandomId(); |
0c00e525 | 103 | } |
fcb1fba5 | 104 | } |