1 | <?php |
||
2 | |||
3 | /* |
||
4 | * @copyright 2014 Mautic Contributors. All rights reserved |
||
5 | * @author Mautic |
||
6 | * |
||
7 | * @link http://mautic.org |
||
8 | * |
||
9 | * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html |
||
10 | */ |
||
11 | |||
12 | namespace Mautic\ApiBundle\Event; |
||
13 | |||
14 | use Mautic\ApiBundle\Entity\oAuth1\Consumer; |
||
15 | use Mautic\ApiBundle\Entity\oAuth2\Client; |
||
16 | use Mautic\CoreBundle\Event\CommonEvent; |
||
17 | use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException; |
||
18 | |||
19 | /** |
||
20 | * Class ClientEvent. |
||
21 | */ |
||
22 | class ClientEvent extends CommonEvent |
||
23 | { |
||
24 | /** |
||
25 | * @var string |
||
26 | */ |
||
27 | private $apiMode; |
||
28 | |||
29 | /** |
||
30 | * @param Client|Consumer $client |
||
31 | * @param bool $isNew |
||
32 | */ |
||
33 | public function __construct($client, $isNew = false) |
||
34 | { |
||
35 | if (!$client instanceof Client && !$client instanceof Consumer) { |
||
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
36 | throw new MethodNotAllowedHttpException(['Client', 'Consumer']); |
||
37 | } |
||
38 | |||
39 | $this->apiMode = ($client instanceof Client) ? 'oauth2' : 'oauth1'; |
||
40 | |||
41 | $this->entity = $client; |
||
42 | $this->isNew = $isNew; |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * Returns the Client entity. |
||
47 | * |
||
48 | * @return Client |
||
49 | */ |
||
50 | public function getClient() |
||
51 | { |
||
52 | return $this->entity; |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * Returns the api mode. |
||
57 | * |
||
58 | * @return string |
||
59 | */ |
||
60 | public function getApiMode() |
||
61 | { |
||
62 | return $this->apiMode; |
||
63 | } |
||
64 | } |
||
65 |