@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | throw new \Exception("firebase default path must contain /"); |
67 | 67 | } |
68 | 68 | |
69 | - $pathURI = $this->firebaseURI . $this->firebaseDefaultPath . $path . ".json"; |
|
69 | + $pathURI = $this->firebaseURI.$this->firebaseDefaultPath.$path.".json"; |
|
70 | 70 | |
71 | 71 | //set query data |
72 | 72 | $queryData = array(); |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | $queryData[JCFirebaseOption::OPTION_PRINT] = $print; |
75 | 75 | } |
76 | 76 | if (!empty($queryData)) { |
77 | - $pathURI = $pathURI . '?' . http_build_query($queryData); |
|
77 | + $pathURI = $pathURI.'?'.http_build_query($queryData); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | $this->refreshToken(); |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | public function getShallow($path = '', $options = array()) |
86 | 86 | { |
87 | 87 | return Requests::get( |
88 | - $this->getPathURI($path) . '?' . http_build_query(array( |
|
88 | + $this->getPathURI($path).'?'.http_build_query(array( |
|
89 | 89 | JCFirebaseOption::OPTION_SHALLOW => JCFirebaseOption::SHALLOW_TRUE |
90 | 90 | )), |
91 | 91 | $this->requestHeader, |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | |
153 | 153 | protected function refreshToken() |
154 | 154 | { |
155 | - $this->requestHeader['Authorization'] = 'Bearer ' . $this->auth->getAccessToken(); |
|
155 | + $this->requestHeader['Authorization'] = 'Bearer '.$this->auth->getAccessToken(); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | protected function addDataToPathURI($path = '', $options = array(), $reqType = JCFirebaseOption::REQ_TYPE_GET) |
@@ -12,63 +12,63 @@ |
||
12 | 12 | use Requests; |
13 | 13 | |
14 | 14 | class OAuth { |
15 | - /* |
|
15 | + /* |
|
16 | 16 | * token life time in second |
17 | 17 | * */ |
18 | - public $tokenLifeTime; |
|
19 | - public $key; |
|
20 | - public $iss; |
|
18 | + public $tokenLifeTime; |
|
19 | + public $key; |
|
20 | + public $iss; |
|
21 | 21 | |
22 | - protected $expireTimestamp; |
|
23 | - protected $accessToken; |
|
22 | + protected $expireTimestamp; |
|
23 | + protected $accessToken; |
|
24 | 24 | |
25 | - /** |
|
26 | - * OAuth constructor. |
|
27 | - * |
|
28 | - * @param $key |
|
29 | - * @param $iss |
|
30 | - */ |
|
31 | - public function __construct( $key, $iss, $tokenLifeTime = 3600 ) { |
|
32 | - $this->key = $key; |
|
33 | - $this->iss = $iss; |
|
34 | - $this->tokenLifeTime = $tokenLifeTime; |
|
35 | - } |
|
25 | + /** |
|
26 | + * OAuth constructor. |
|
27 | + * |
|
28 | + * @param $key |
|
29 | + * @param $iss |
|
30 | + */ |
|
31 | + public function __construct( $key, $iss, $tokenLifeTime = 3600 ) { |
|
32 | + $this->key = $key; |
|
33 | + $this->iss = $iss; |
|
34 | + $this->tokenLifeTime = $tokenLifeTime; |
|
35 | + } |
|
36 | 36 | |
37 | - protected function requestAccessToken() { |
|
38 | - $currentTimestamp = time(); |
|
39 | - $this->expireTimestamp = $currentTimestamp + $this->tokenLifeTime; |
|
40 | - $jsonToken = array( |
|
41 | - "iss" => $this->iss, |
|
42 | - "scope" => "https://www.googleapis.com/auth/firebase.database https://www.googleapis.com/auth/userinfo.email", |
|
43 | - "aud" => "https://www.googleapis.com/oauth2/v4/token", |
|
44 | - "exp" => $this->expireTimestamp, |
|
45 | - "iat" => $currentTimestamp |
|
46 | - ); |
|
47 | - $jwt = JWT::encode( $jsonToken, $this->key, 'RS256' ); |
|
37 | + protected function requestAccessToken() { |
|
38 | + $currentTimestamp = time(); |
|
39 | + $this->expireTimestamp = $currentTimestamp + $this->tokenLifeTime; |
|
40 | + $jsonToken = array( |
|
41 | + "iss" => $this->iss, |
|
42 | + "scope" => "https://www.googleapis.com/auth/firebase.database https://www.googleapis.com/auth/userinfo.email", |
|
43 | + "aud" => "https://www.googleapis.com/oauth2/v4/token", |
|
44 | + "exp" => $this->expireTimestamp, |
|
45 | + "iat" => $currentTimestamp |
|
46 | + ); |
|
47 | + $jwt = JWT::encode( $jsonToken, $this->key, 'RS256' ); |
|
48 | 48 | |
49 | - $OAuthResponse = Requests::post( 'https://www.googleapis.com/oauth2/v4/token', array(), array( |
|
50 | - 'grant_type' => 'urn:ietf:params:oauth:grant-type:jwt-bearer', |
|
51 | - 'assertion' => $jwt |
|
52 | - ) ); |
|
49 | + $OAuthResponse = Requests::post( 'https://www.googleapis.com/oauth2/v4/token', array(), array( |
|
50 | + 'grant_type' => 'urn:ietf:params:oauth:grant-type:jwt-bearer', |
|
51 | + 'assertion' => $jwt |
|
52 | + ) ); |
|
53 | 53 | |
54 | - if ( $OAuthResponse->status_code == 200 ) { |
|
55 | - $this->accessToken = json_decode( $OAuthResponse->body )->access_token; |
|
54 | + if ( $OAuthResponse->status_code == 200 ) { |
|
55 | + $this->accessToken = json_decode( $OAuthResponse->body )->access_token; |
|
56 | 56 | |
57 | - return true; |
|
58 | - } |
|
57 | + return true; |
|
58 | + } |
|
59 | 59 | |
60 | - return false; |
|
61 | - } |
|
60 | + return false; |
|
61 | + } |
|
62 | 62 | |
63 | - public function getAccessToken() { |
|
64 | - $currentTime = time(); |
|
65 | - if ( $this->expireTimestamp < $currentTime ) { |
|
66 | - $startTime = time(); |
|
67 | - $this->requestAccessToken(); |
|
68 | - $endTime = time(); |
|
69 | - $this->expireTimestamp -= ( $endTime - $startTime ); |
|
70 | - } |
|
63 | + public function getAccessToken() { |
|
64 | + $currentTime = time(); |
|
65 | + if ( $this->expireTimestamp < $currentTime ) { |
|
66 | + $startTime = time(); |
|
67 | + $this->requestAccessToken(); |
|
68 | + $endTime = time(); |
|
69 | + $this->expireTimestamp -= ( $endTime - $startTime ); |
|
70 | + } |
|
71 | 71 | |
72 | - return $this->accessToken; |
|
73 | - } |
|
72 | + return $this->accessToken; |
|
73 | + } |
|
74 | 74 | } |
75 | 75 | \ No newline at end of file |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | * @param $key |
29 | 29 | * @param $iss |
30 | 30 | */ |
31 | - public function __construct( $key, $iss, $tokenLifeTime = 3600 ) { |
|
31 | + public function __construct($key, $iss, $tokenLifeTime = 3600) { |
|
32 | 32 | $this->key = $key; |
33 | 33 | $this->iss = $iss; |
34 | 34 | $this->tokenLifeTime = $tokenLifeTime; |
@@ -44,15 +44,15 @@ discard block |
||
44 | 44 | "exp" => $this->expireTimestamp, |
45 | 45 | "iat" => $currentTimestamp |
46 | 46 | ); |
47 | - $jwt = JWT::encode( $jsonToken, $this->key, 'RS256' ); |
|
47 | + $jwt = JWT::encode($jsonToken, $this->key, 'RS256'); |
|
48 | 48 | |
49 | - $OAuthResponse = Requests::post( 'https://www.googleapis.com/oauth2/v4/token', array(), array( |
|
49 | + $OAuthResponse = Requests::post('https://www.googleapis.com/oauth2/v4/token', array(), array( |
|
50 | 50 | 'grant_type' => 'urn:ietf:params:oauth:grant-type:jwt-bearer', |
51 | 51 | 'assertion' => $jwt |
52 | - ) ); |
|
52 | + )); |
|
53 | 53 | |
54 | - if ( $OAuthResponse->status_code == 200 ) { |
|
55 | - $this->accessToken = json_decode( $OAuthResponse->body )->access_token; |
|
54 | + if ($OAuthResponse->status_code == 200) { |
|
55 | + $this->accessToken = json_decode($OAuthResponse->body)->access_token; |
|
56 | 56 | |
57 | 57 | return true; |
58 | 58 | } |
@@ -62,11 +62,11 @@ discard block |
||
62 | 62 | |
63 | 63 | public function getAccessToken() { |
64 | 64 | $currentTime = time(); |
65 | - if ( $this->expireTimestamp < $currentTime ) { |
|
65 | + if ($this->expireTimestamp < $currentTime) { |
|
66 | 66 | $startTime = time(); |
67 | 67 | $this->requestAccessToken(); |
68 | 68 | $endTime = time(); |
69 | - $this->expireTimestamp -= ( $endTime - $startTime ); |
|
69 | + $this->expireTimestamp -= ($endTime - $startTime); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | return $this->accessToken; |
@@ -10,33 +10,33 @@ |
||
10 | 10 | |
11 | 11 | |
12 | 12 | class JCFirebaseOption { |
13 | - const __default = null; |
|
14 | - |
|
15 | - const OPTION_SHALLOW = 'shallow'; |
|
16 | - const SHALLOW_TRUE = 'true'; |
|
17 | - const SHALLOW_FALSE = 'false'; |
|
18 | - |
|
19 | - const OPTION_PRINT = 'print'; |
|
20 | - const PRINT_PRETTY = 'pretty'; |
|
21 | - const PRINT_SILENT = 'silent'; |
|
22 | - |
|
23 | - const REQ_TYPE_GET = 0; |
|
24 | - const REQ_TYPE_PUT = 1; |
|
25 | - const REQ_TYPE_POST = 2; |
|
26 | - const REQ_TYPE_PATCH = 3; |
|
27 | - const REQ_TYPE_DELETE = 4; |
|
28 | - |
|
29 | - public static function isAllowPrint( $reqType = self::REQ_TYPE_GET, $pType = self::PRINT_PRETTY ) { |
|
30 | - if ( $pType == self::PRINT_PRETTY ) { |
|
31 | - return true; |
|
32 | - } |
|
33 | - |
|
34 | - if ( $pType == self::PRINT_SILENT ) { |
|
35 | - if ( $reqType == self::REQ_TYPE_DELETE ) { |
|
36 | - return false; |
|
37 | - } |
|
38 | - } |
|
39 | - |
|
40 | - return true; |
|
41 | - } |
|
13 | + const __default = null; |
|
14 | + |
|
15 | + const OPTION_SHALLOW = 'shallow'; |
|
16 | + const SHALLOW_TRUE = 'true'; |
|
17 | + const SHALLOW_FALSE = 'false'; |
|
18 | + |
|
19 | + const OPTION_PRINT = 'print'; |
|
20 | + const PRINT_PRETTY = 'pretty'; |
|
21 | + const PRINT_SILENT = 'silent'; |
|
22 | + |
|
23 | + const REQ_TYPE_GET = 0; |
|
24 | + const REQ_TYPE_PUT = 1; |
|
25 | + const REQ_TYPE_POST = 2; |
|
26 | + const REQ_TYPE_PATCH = 3; |
|
27 | + const REQ_TYPE_DELETE = 4; |
|
28 | + |
|
29 | + public static function isAllowPrint( $reqType = self::REQ_TYPE_GET, $pType = self::PRINT_PRETTY ) { |
|
30 | + if ( $pType == self::PRINT_PRETTY ) { |
|
31 | + return true; |
|
32 | + } |
|
33 | + |
|
34 | + if ( $pType == self::PRINT_SILENT ) { |
|
35 | + if ( $reqType == self::REQ_TYPE_DELETE ) { |
|
36 | + return false; |
|
37 | + } |
|
38 | + } |
|
39 | + |
|
40 | + return true; |
|
41 | + } |
|
42 | 42 | } |
43 | 43 | \ No newline at end of file |
@@ -26,13 +26,13 @@ |
||
26 | 26 | const REQ_TYPE_PATCH = 3; |
27 | 27 | const REQ_TYPE_DELETE = 4; |
28 | 28 | |
29 | - public static function isAllowPrint( $reqType = self::REQ_TYPE_GET, $pType = self::PRINT_PRETTY ) { |
|
30 | - if ( $pType == self::PRINT_PRETTY ) { |
|
29 | + public static function isAllowPrint($reqType = self::REQ_TYPE_GET, $pType = self::PRINT_PRETTY) { |
|
30 | + if ($pType == self::PRINT_PRETTY) { |
|
31 | 31 | return true; |
32 | 32 | } |
33 | 33 | |
34 | - if ( $pType == self::PRINT_SILENT ) { |
|
35 | - if ( $reqType == self::REQ_TYPE_DELETE ) { |
|
34 | + if ($pType == self::PRINT_SILENT) { |
|
35 | + if ($reqType == self::REQ_TYPE_DELETE) { |
|
36 | 36 | return false; |
37 | 37 | } |
38 | 38 | } |