11<?php
2+
23namespace Bexio ;
34
45use Jumbojett \OpenIDConnectClient ;
56
67abstract class AbstractClient
78{
89 const PROVIDER_URL = 'https://idp.bexio.com ' ;
10+
911 const API_URL = 'https://api.bexio.com ' ;
12+
1013 const API_DEFAULT_VERSION = '2.0 ' ;
1114
1215 const METHOD_GET = 'GET ' ;
16+
1317 const METHOD_POST = 'POST ' ;
18+
1419 const METHOD_PUT = 'PUT ' ;
20+
1521 const METHOD_DELETE = 'DELETE ' ;
22+
1623 const METHOD_PATCH = 'PATCH ' ;
1724
1825 private ?string $ accessToken = null ;
26+
1927 private ?string $ refreshToken = null ;
2028
2129 public function __construct (
2230 public string $ clientId ,
2331 public string $ clientSecret
24- ) {}
32+ ) {
33+ }
2534
2635 public function setAccessToken (string $ accessToken )
2736 {
@@ -47,13 +56,13 @@ public function persistTokens(string $tokensFile): bool
4756 {
4857 return false !== file_put_contents ($ tokensFile , json_encode ([
4958 'accessToken ' => $ this ->getAccessToken (),
50- 'refreshToken ' => $ this ->getRefreshToken ()
59+ 'refreshToken ' => $ this ->getRefreshToken (),
5160 ]));
5261 }
5362
5463 public function loadTokens (string $ tokensFile )
5564 {
56- if (!file_exists ($ tokensFile )) {
65+ if (! file_exists ($ tokensFile )) {
5766 throw new \Exception ('Tokens file not found: ' . $ tokensFile );
5867 }
5968 $ tokens = json_decode (file_get_contents ($ tokensFile ));
@@ -81,7 +90,7 @@ public function getOpenIDConnectClient(): OpenIDConnectClient
8190
8291 public function authenticate (string |array $ scopes , string $ redirectUrl )
8392 {
84- if (!is_array ($ scopes )) {
93+ if (! is_array ($ scopes )) {
8594 $ scopes = explode (' ' , $ scopes );
8695 }
8796
@@ -96,7 +105,7 @@ public function authenticate(string|array $scopes, string $redirectUrl)
96105
97106 public function isAccessTokenExpired ($ gracePeriod = 30 ): bool
98107 {
99- if (!$ this ->accessToken ) {
108+ if (! $ this ->accessToken ) {
100109 return true ;
101110 }
102111 $ payload = $ this ->getOpenIDConnectClient ()->getAccessTokenPayload ();
@@ -118,13 +127,17 @@ public function getFullApiUrl(string $path = '', array $query = []): string
118127 return implode ('/ ' , array_filter ([
119128 self ::API_URL ,
120129 1 === preg_match ('/\d\.\d\// ' , $ path ) ? '' : self ::API_DEFAULT_VERSION ,
121- empty ($ query ) ? $ path : $ path . '? ' . http_build_query ($ query )
130+ empty ($ query ) ? $ path : $ path . '? ' . http_build_query ($ query ),
122131 ]));
123132 }
124133
125134 abstract public function get (string $ path , array $ queryParams = []);
135+
126136 abstract public function post (string $ path , array $ data = [], array $ queryParams = []);
137+
127138 abstract public function put (string $ path , array $ data = [], array $ queryParams = []);
139+
128140 abstract public function delete (string $ path , array $ data = [], array $ queryParams = []);
141+
129142 abstract public function patch (string $ path , array $ data = [], array $ queryParams = []);
130143}
0 commit comments