1 | <?php |
||
10 | trait MultiauthActions |
||
11 | { |
||
12 | /** |
||
13 | * The route to generate the access token. The default value is the standard |
||
14 | * route from Laravel\Passport. |
||
15 | * |
||
16 | * @var string |
||
17 | */ |
||
18 | protected $oauthTokenRoute = 'oauth/token'; |
||
19 | |||
20 | /** |
||
21 | * @codeCoverageIgnore |
||
22 | */ |
||
23 | public function setUp() |
||
29 | |||
30 | /** |
||
31 | * Set the the Authorization header with an access token created using |
||
32 | * Laravel Passport. The method `ẁithHeader` of trait `MakesHttpRequests` is |
||
33 | * avaiable after version 5.5 of Laravel Framework. |
||
34 | * |
||
35 | * @todo Change way to issue token from $this->json() to creating accessing |
||
36 | * AccessTokenController@issueToken directly. |
||
37 | * @todo Pass this method to PassportMultiauth::actingAs(). |
||
38 | * |
||
39 | * @param \Illuminate\Contracts\Auth\Authenticatable $user |
||
40 | * @param string $scope |
||
41 | * @return $this |
||
42 | */ |
||
43 | 10 | public function multiauthActingAs(Authenticatable $user, $scope = '') |
|
53 | |||
54 | /** |
||
55 | * Get multiauth header to be used on request to get access token. |
||
56 | * |
||
57 | * @param \Illuminate\Contracts\Auth\Authenticatable $user |
||
58 | * @param string $scope |
||
59 | * @return string |
||
60 | */ |
||
61 | 9 | public function multiauthAccessToken(Authenticatable $user, $scope = '') |
|
94 | |||
95 | /** |
||
96 | * Get the user provider on configs. |
||
97 | * |
||
98 | * @todo Move to class specialized in check auth configs. |
||
99 | * @param \Illuminate\Contracts\Auth\Authenticatable $user |
||
100 | * @return string |
||
101 | */ |
||
102 | 8 | protected function getUserProvider(Authenticatable $user) |
|
113 | |||
114 | /** |
||
115 | * Check if provider is the default provider used by Laravel\Passport. |
||
116 | * |
||
117 | * @todo Move to class specialized in check auth configs. |
||
118 | * @param string $provider |
||
119 | * @return bool |
||
120 | */ |
||
121 | 8 | protected function isDefaultProvider($provider) |
|
125 | } |
||
126 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.