@@ -27,13 +27,13 @@ |
||
27 | 27 | const REQ_TYPE_PATCH = 3; |
28 | 28 | const REQ_TYPE_DELETE = 4; |
29 | 29 | |
30 | - public static function isAllowPrint($reqType = self::REQ_TYPE_GET,$pType = self::PRINT_PRETTY){ |
|
31 | - if($pType == self::PRINT_PRETTY){ |
|
30 | + public static function isAllowPrint($reqType = self::REQ_TYPE_GET, $pType = self::PRINT_PRETTY) { |
|
31 | + if ($pType == self::PRINT_PRETTY) { |
|
32 | 32 | return true; |
33 | 33 | } |
34 | 34 | |
35 | - if($pType == self::PRINT_SILENT){ |
|
36 | - if($reqType == self::REQ_TYPE_DELETE){ |
|
35 | + if ($pType == self::PRINT_SILENT) { |
|
36 | + if ($reqType == self::REQ_TYPE_DELETE) { |
|
37 | 37 | return false; |
38 | 38 | } |
39 | 39 | } |
@@ -8,8 +8,8 @@ |
||
8 | 8 | |
9 | 9 | namespace JCFirebase; |
10 | 10 | |
11 | -use Requests; |
|
12 | 11 | use JCFirebase\JCFirebaseOption; |
12 | +use Requests; |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * Class JCFirebase |
@@ -40,9 +40,9 @@ discard block |
||
40 | 40 | public function getPathURI($path = '',$print = ''){ |
41 | 41 | //remove last slash from firebaseURI |
42 | 42 | $template = '/'; |
43 | - $this->firebaseURI = rtrim($this->firebaseURI,$template); |
|
44 | - $path = rtrim($path,$template); |
|
45 | - $path = ltrim($path,$template); |
|
43 | + $this->firebaseURI = rtrim($this->firebaseURI,$template); |
|
44 | + $path = rtrim($path,$template); |
|
45 | + $path = ltrim($path,$template); |
|
46 | 46 | |
47 | 47 | //check https |
48 | 48 | if(strpos($this->firebaseURI, 'http://') !== false){ |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | } |
56 | 56 | |
57 | 57 | if(strpos($this->firebaseDefaultPath,"/") !== 0){ |
58 | - throw new \Exception("firebase default path must contain /"); |
|
58 | + throw new \Exception("firebase default path must contain /"); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | $pathURI = $this->firebaseURI.$this->firebaseDefaultPath.$path.".json"; |
@@ -30,31 +30,31 @@ discard block |
||
30 | 30 | |
31 | 31 | public $requestOptions = array(); |
32 | 32 | |
33 | - public function __construct($firebaseURI,$firebaseSecret = '',$firebaseDefaultPath = '/') |
|
33 | + public function __construct($firebaseURI, $firebaseSecret = '', $firebaseDefaultPath = '/') |
|
34 | 34 | { |
35 | 35 | $this->firebaseSecret = $firebaseSecret; |
36 | 36 | $this->firebaseURI = $firebaseURI; |
37 | 37 | $this->firebaseDefaultPath = $firebaseDefaultPath; |
38 | 38 | } |
39 | 39 | |
40 | - public function getPathURI($path = '',$print = ''){ |
|
40 | + public function getPathURI($path = '', $print = '') { |
|
41 | 41 | //remove last slash from firebaseURI |
42 | 42 | $template = '/'; |
43 | - $this->firebaseURI = rtrim($this->firebaseURI,$template); |
|
44 | - $path = rtrim($path,$template); |
|
45 | - $path = ltrim($path,$template); |
|
43 | + $this->firebaseURI = rtrim($this->firebaseURI, $template); |
|
44 | + $path = rtrim($path, $template); |
|
45 | + $path = ltrim($path, $template); |
|
46 | 46 | |
47 | 47 | //check https |
48 | - if(strpos($this->firebaseURI, 'http://') !== false){ |
|
48 | + if (strpos($this->firebaseURI, 'http://') !== false) { |
|
49 | 49 | throw new \Exception("https is required."); |
50 | 50 | } |
51 | 51 | |
52 | 52 | //check firebaseURI |
53 | - if(empty($this->firebaseURI)){ |
|
53 | + if (empty($this->firebaseURI)) { |
|
54 | 54 | throw new \Exception("firebase URI is required"); |
55 | 55 | } |
56 | 56 | |
57 | - if(strpos($this->firebaseDefaultPath,"/") !== 0){ |
|
57 | + if (strpos($this->firebaseDefaultPath, "/") !== 0) { |
|
58 | 58 | throw new \Exception("firebase default path must contain /"); |
59 | 59 | } |
60 | 60 | |
@@ -62,11 +62,11 @@ discard block |
||
62 | 62 | |
63 | 63 | //set query data |
64 | 64 | $queryData = array(); |
65 | - if(!empty($print)){ |
|
65 | + if (!empty($print)) { |
|
66 | 66 | $queryData[JCFirebaseOption::OPTION_PRINT] = $print; |
67 | 67 | } |
68 | - if(!empty($queryData)){ |
|
69 | - $pathURI = $pathURI . '?' . http_build_query($queryData); |
|
68 | + if (!empty($queryData)) { |
|
69 | + $pathURI = $pathURI.'?'.http_build_query($queryData); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | return $pathURI; |
@@ -77,16 +77,16 @@ discard block |
||
77 | 77 | * @param array $options |
78 | 78 | * @return \Requests_Response |
79 | 79 | */ |
80 | - public function get($path = '',$options = array()){ |
|
80 | + public function get($path = '', $options = array()) { |
|
81 | 81 | return Requests::get( |
82 | - $this->mergeRequestPathURI($path,$options),$this->requestHeader, |
|
82 | + $this->mergeRequestPathURI($path, $options), $this->requestHeader, |
|
83 | 83 | $this->mergeRequestOptions($options) |
84 | 84 | ); |
85 | 85 | } |
86 | 86 | |
87 | - public function getShallow($path = '',$options = array()){ |
|
87 | + public function getShallow($path = '', $options = array()) { |
|
88 | 88 | return Requests::get($this->getPathURI( |
89 | - $path). '?' . http_build_query(array(JCFirebaseOption::OPTION_SHALLOW => JCFirebaseOption::SHALLOW_TRUE)), |
|
89 | + $path).'?'.http_build_query(array(JCFirebaseOption::OPTION_SHALLOW => JCFirebaseOption::SHALLOW_TRUE)), |
|
90 | 90 | $this->mergeRequestOptions($options) |
91 | 91 | ); |
92 | 92 | } |
@@ -96,8 +96,8 @@ discard block |
||
96 | 96 | * @param array $options |
97 | 97 | * @return \Requests_Response |
98 | 98 | */ |
99 | - public function put($path = '',$options = array()){ |
|
100 | - return Requests::put($this->getPathURI($path),$this->requestHeader,$this->mergeRequestOptions($options,true)); |
|
99 | + public function put($path = '', $options = array()) { |
|
100 | + return Requests::put($this->getPathURI($path), $this->requestHeader, $this->mergeRequestOptions($options, true)); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
@@ -105,8 +105,8 @@ discard block |
||
105 | 105 | * @param array $options |
106 | 106 | * @return \Requests_Response |
107 | 107 | */ |
108 | - public function post($path = '',$options = array()){ |
|
109 | - return Requests::post($this->getPathURI($path),$this->requestHeader,$this->mergeRequestOptions($options,true)); |
|
108 | + public function post($path = '', $options = array()) { |
|
109 | + return Requests::post($this->getPathURI($path), $this->requestHeader, $this->mergeRequestOptions($options, true)); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | /** |
@@ -114,8 +114,8 @@ discard block |
||
114 | 114 | * @param array $options |
115 | 115 | * @return \Requests_Response |
116 | 116 | */ |
117 | - public function patch($path = '',$options = array()){ |
|
118 | - return Requests::patch($this->getPathURI($path),$this->requestHeader,$this->mergeRequestOptions($options,true)); |
|
117 | + public function patch($path = '', $options = array()) { |
|
118 | + return Requests::patch($this->getPathURI($path), $this->requestHeader, $this->mergeRequestOptions($options, true)); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | /** |
@@ -123,31 +123,31 @@ discard block |
||
123 | 123 | * @param array $options |
124 | 124 | * @return \Requests_Response |
125 | 125 | */ |
126 | - public function delete($path = '',$options = array()){ |
|
127 | - return Requests::delete($this->getPathURI($path),$this->requestHeader,$this->mergeRequestOptions($options)); |
|
126 | + public function delete($path = '', $options = array()) { |
|
127 | + return Requests::delete($this->getPathURI($path), $this->requestHeader, $this->mergeRequestOptions($options)); |
|
128 | 128 | } |
129 | 129 | |
130 | - protected function mergeRequestOptions($options = array(),$jsonEncode = false){ |
|
130 | + protected function mergeRequestOptions($options = array(), $jsonEncode = false) { |
|
131 | 131 | $requestOptions = array(); |
132 | 132 | |
133 | - if(isset($options['data'])){ |
|
134 | - $requestOptions = array_merge($options['data'],$requestOptions); |
|
133 | + if (isset($options['data'])) { |
|
134 | + $requestOptions = array_merge($options['data'], $requestOptions); |
|
135 | 135 | } |
136 | 136 | |
137 | - if($jsonEncode){ |
|
137 | + if ($jsonEncode) { |
|
138 | 138 | $requestOptions = json_encode($requestOptions); |
139 | 139 | } |
140 | 140 | |
141 | 141 | return $requestOptions; |
142 | 142 | } |
143 | 143 | |
144 | - protected function mergeRequestPathURI($path='',$options = array(),$reqType = JCFirebaseOption::REQ_TYPE_GET){ |
|
144 | + protected function mergeRequestPathURI($path = '', $options = array(), $reqType = JCFirebaseOption::REQ_TYPE_GET) { |
|
145 | 145 | $print = ''; |
146 | - if(isset($options['print'])){ |
|
147 | - if(JCFirebaseOption::isAllowPrint($reqType,$options['print'])){ |
|
146 | + if (isset($options['print'])) { |
|
147 | + if (JCFirebaseOption::isAllowPrint($reqType, $options['print'])) { |
|
148 | 148 | $print = $options['print']; |
149 | 149 | } |
150 | 150 | } |
151 | - return $this->getPathURI($path,$print); |
|
151 | + return $this->getPathURI($path, $print); |
|
152 | 152 | } |
153 | 153 | } |
154 | 154 | \ No newline at end of file |