1 | <?php |
||
3 | namespace Surge\LaravelSalesforce; |
||
4 | |||
5 | class SalesforceAuth |
||
6 | { |
||
7 | /** |
||
8 | * @var string |
||
9 | */ |
||
10 | public $id; |
||
11 | |||
12 | /** |
||
13 | * @var string |
||
14 | */ |
||
15 | public $accessToken; |
||
16 | |||
17 | /** |
||
18 | * @var string |
||
19 | */ |
||
20 | public $instanceUrl; |
||
21 | |||
22 | /** |
||
23 | * @var string |
||
24 | */ |
||
25 | public $url; |
||
26 | |||
27 | /** |
||
28 | * @var bool |
||
29 | */ |
||
30 | private $authenticated = false; |
||
31 | |||
32 | public function isAuthenticated(): bool |
||
36 | |||
37 | public function __construct($client) |
||
43 | |||
44 | /** |
||
45 | * Login. |
||
46 | */ |
||
47 | private function login() |
||
48 | { |
||
49 | $body = [ |
||
50 | 'grant_type' => 'password', |
||
51 | 'client_id' => config('sf.client_id'), |
||
52 | 'client_secret' => config('sf.client_secret'), |
||
53 | 'username' => config('sf.username'), |
||
54 | 'password' => config('sf.password'), |
||
55 | ]; |
||
56 | |||
57 | $response = $this->client->post('https://login.salesforce.com/services/oauth2/token', [ |
||
58 | 'form_params' => $body, |
||
59 | ])->getBody()->getContents(); |
||
60 | |||
61 | $responseObject = \GuzzleHttp\json_decode($response); |
||
62 | |||
63 | $this->id = $responseObject->id; |
||
64 | $this->accessToken = $responseObject->access_token; |
||
65 | $this->instanceUrl = $responseObject->instance_url; |
||
66 | $this->url = $responseObject->instance_url.$this->version['url']; |
||
67 | |||
68 | if ($this->accessToken !== null) { |
||
69 | $this->authenticated = true; |
||
70 | } |
||
71 | } |
||
73 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: