]> git.immae.eu Git - github/wallabag/wallabag.git/blob - src/Wallabag/ApiBundle/Entity/Client.php
Create a custom swap to avoid error
[github/wallabag/wallabag.git] / src / Wallabag / ApiBundle / Entity / Client.php
1 <?php
2
3 namespace Wallabag\ApiBundle\Entity;
4
5 use Doctrine\ORM\Mapping as ORM;
6 use FOS\OAuthServerBundle\Entity\Client as BaseClient;
7 use JMS\Serializer\Annotation\Groups;
8 use JMS\Serializer\Annotation\SerializedName;
9 use JMS\Serializer\Annotation\VirtualProperty;
10 use Wallabag\UserBundle\Entity\User;
11
12 /**
13 * @ORM\Table("oauth2_clients")
14 * @ORM\Entity
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
25 /**
26 * @var string
27 *
28 * @ORM\Column(name="name", type="text", nullable=false)
29 *
30 * @Groups({"user_api_with_client"})
31 */
32 protected $name;
33
34 /**
35 * @ORM\OneToMany(targetEntity="RefreshToken", mappedBy="client", cascade={"remove"})
36 */
37 protected $refreshTokens;
38
39 /**
40 * @ORM\OneToMany(targetEntity="AccessToken", mappedBy="client", cascade={"remove"})
41 */
42 protected $accessTokens;
43
44 /**
45 * @var string
46 *
47 * @SerializedName("client_secret")
48 * @Groups({"user_api_with_client"})
49 */
50 protected $secret;
51
52 /**
53 * @ORM\ManyToOne(targetEntity="Wallabag\UserBundle\Entity\User", inversedBy="clients")
54 */
55 private $user;
56
57 public function __construct(User $user)
58 {
59 parent::__construct();
60 $this->user = $user;
61 }
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 }
86
87 /**
88 * @return User
89 */
90 public function getUser()
91 {
92 return $this->user;
93 }
94
95 /**
96 * @VirtualProperty
97 * @SerializedName("client_id")
98 * @Groups({"user_api_with_client"})
99 */
100 public function getClientId()
101 {
102 return $this->getId() . '_' . $this->getRandomId();
103 }
104 }