X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FApiBundle%2FEntity%2FClient.php;h=e6f98f98ca332db03ddec68659a8def8b5d70cf0;hb=1953a872932a63792293b4aec087880265ba89f7;hp=f7898ac82852292835175581a2ea0b797738ed1d;hpb=ee32248f43baef7e995c9e420cd00a137e626cf0;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/ApiBundle/Entity/Client.php b/src/Wallabag/ApiBundle/Entity/Client.php index f7898ac8..e6f98f98 100644 --- a/src/Wallabag/ApiBundle/Entity/Client.php +++ b/src/Wallabag/ApiBundle/Entity/Client.php @@ -4,6 +4,10 @@ namespace Wallabag\ApiBundle\Entity; use Doctrine\ORM\Mapping as ORM; use FOS\OAuthServerBundle\Entity\Client as BaseClient; +use JMS\Serializer\Annotation\Groups; +use JMS\Serializer\Annotation\SerializedName; +use JMS\Serializer\Annotation\VirtualProperty; +use Wallabag\UserBundle\Entity\User; /** * @ORM\Table("oauth2_clients") @@ -21,7 +25,9 @@ class Client extends BaseClient /** * @var string * - * @ORM\Column(name="name", type="text", nullable=true) + * @ORM\Column(name="name", type="text", nullable=false) + * + * @Groups({"user_api_with_client"}) */ protected $name; @@ -35,9 +41,23 @@ class Client extends BaseClient */ protected $accessTokens; - public function __construct() + /** + * @var string + * + * @SerializedName("client_secret") + * @Groups({"user_api_with_client"}) + */ + protected $secret; + + /** + * @ORM\ManyToOne(targetEntity="Wallabag\UserBundle\Entity\User", inversedBy="clients") + */ + private $user; + + public function __construct(User $user) { parent::__construct(); + $this->user = $user; } /** @@ -63,4 +83,22 @@ class Client extends BaseClient return $this; } + + /** + * @return User + */ + public function getUser() + { + return $this->user; + } + + /** + * @VirtualProperty + * @SerializedName("client_id") + * @Groups({"user_api_with_client"}) + */ + public function getClientId() + { + return $this->getId() . '_' . $this->getRandomId(); + } }