@@ -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 | } |
@@ -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 .json or last slash from firebaseURI |
42 | 42 | $templates = array( |
43 | 43 | '.json', |
44 | 44 | '/.json', |
45 | 45 | '/' |
46 | 46 | ); |
47 | - foreach ($templates as $template){ |
|
48 | - $this->firebaseURI = rtrim($this->firebaseURI,$template); |
|
47 | + foreach ($templates as $template) { |
|
48 | + $this->firebaseURI = rtrim($this->firebaseURI, $template); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | //check https |
52 | - if(strpos($this->firebaseURI, 'http://') !== false){ |
|
52 | + if (strpos($this->firebaseURI, 'http://') !== false) { |
|
53 | 53 | throw new \Exception("https is required."); |
54 | 54 | } |
55 | 55 | |
56 | 56 | //check firebaseURI |
57 | - if(strlen($this->firebaseURI) == 0){ |
|
57 | + if (strlen($this->firebaseURI) == 0) { |
|
58 | 58 | throw new \Exception("firebase URI is required"); |
59 | 59 | } |
60 | 60 | |
@@ -62,12 +62,12 @@ discard block |
||
62 | 62 | |
63 | 63 | $queryData = array(); |
64 | 64 | |
65 | - if(strlen($print) > 0){ |
|
65 | + if (strlen($print) > 0) { |
|
66 | 66 | $queryData[JCFirebaseOption::OPTION_PRINT] = $print; |
67 | 67 | } |
68 | 68 | |
69 | - if(count($queryData) > 0){ |
|
70 | - $pathURI = $pathURI . '?' . http_build_query($queryData); |
|
69 | + if (count($queryData) > 0) { |
|
70 | + $pathURI = $pathURI.'?'.http_build_query($queryData); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | return $pathURI; |
@@ -78,16 +78,16 @@ discard block |
||
78 | 78 | * @param array $options |
79 | 79 | * @return \Requests_Response |
80 | 80 | */ |
81 | - public function get($path = '',$options = array()){ |
|
81 | + public function get($path = '', $options = array()) { |
|
82 | 82 | return Requests::get( |
83 | - $this->mergeRequestPathURI($path,$options),$this->requestHeader, |
|
83 | + $this->mergeRequestPathURI($path, $options), $this->requestHeader, |
|
84 | 84 | $this->mergeRequestOptions($options) |
85 | 85 | ); |
86 | 86 | } |
87 | 87 | |
88 | - public function getShallow($path = '',$options = array()){ |
|
88 | + public function getShallow($path = '', $options = array()) { |
|
89 | 89 | return Requests::get($this->getPathURI( |
90 | - $path). '?' . http_build_query(array(JCFirebaseOption::OPTION_SHALLOW => JCFirebaseOption::SHALLOW_TRUE)), |
|
90 | + $path).'?'.http_build_query(array(JCFirebaseOption::OPTION_SHALLOW => JCFirebaseOption::SHALLOW_TRUE)), |
|
91 | 91 | $this->mergeRequestOptions($options) |
92 | 92 | ); |
93 | 93 | } |
@@ -97,8 +97,8 @@ discard block |
||
97 | 97 | * @param array $options |
98 | 98 | * @return \Requests_Response |
99 | 99 | */ |
100 | - public function put($path = '',$options = array()){ |
|
101 | - return Requests::put($this->getPathURI($path),$this->requestHeader,$this->mergeRequestOptions($options,true)); |
|
100 | + public function put($path = '', $options = array()) { |
|
101 | + return Requests::put($this->getPathURI($path), $this->requestHeader, $this->mergeRequestOptions($options, true)); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
@@ -106,8 +106,8 @@ discard block |
||
106 | 106 | * @param array $options |
107 | 107 | * @return \Requests_Response |
108 | 108 | */ |
109 | - public function post($path = '',$options = array()){ |
|
110 | - return Requests::post($this->getPathURI($path),$this->requestHeader,$this->mergeRequestOptions($options,true)); |
|
109 | + public function post($path = '', $options = array()) { |
|
110 | + return Requests::post($this->getPathURI($path), $this->requestHeader, $this->mergeRequestOptions($options, true)); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -115,8 +115,8 @@ discard block |
||
115 | 115 | * @param array $options |
116 | 116 | * @return \Requests_Response |
117 | 117 | */ |
118 | - public function patch($path = '',$options = array()){ |
|
119 | - return Requests::patch($this->getPathURI($path),$this->requestHeader,$this->mergeRequestOptions($options,true)); |
|
118 | + public function patch($path = '', $options = array()) { |
|
119 | + return Requests::patch($this->getPathURI($path), $this->requestHeader, $this->mergeRequestOptions($options, true)); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
@@ -124,31 +124,31 @@ discard block |
||
124 | 124 | * @param array $options |
125 | 125 | * @return \Requests_Response |
126 | 126 | */ |
127 | - public function delete($path = '',$options = array()){ |
|
128 | - return Requests::delete($this->getPathURI($path),$this->requestHeader,$this->mergeRequestOptions($options)); |
|
127 | + public function delete($path = '', $options = array()) { |
|
128 | + return Requests::delete($this->getPathURI($path), $this->requestHeader, $this->mergeRequestOptions($options)); |
|
129 | 129 | } |
130 | 130 | |
131 | - protected function mergeRequestOptions($options = array(),$encode = false){ |
|
131 | + protected function mergeRequestOptions($options = array(), $encode = false) { |
|
132 | 132 | $requestOptions = array(); |
133 | 133 | |
134 | - if(isset($options['data'])){ |
|
135 | - $requestOptions = array_merge($options['data'],$requestOptions); |
|
134 | + if (isset($options['data'])) { |
|
135 | + $requestOptions = array_merge($options['data'], $requestOptions); |
|
136 | 136 | } |
137 | 137 | |
138 | - if($encode){ |
|
138 | + if ($encode) { |
|
139 | 139 | $requestOptions = json_encode($requestOptions); |
140 | 140 | } |
141 | 141 | |
142 | 142 | return $requestOptions; |
143 | 143 | } |
144 | 144 | |
145 | - protected function mergeRequestPathURI($path='',$options = array(),$reqType = JCFirebaseOption::REQ_TYPE_GET){ |
|
145 | + protected function mergeRequestPathURI($path = '', $options = array(), $reqType = JCFirebaseOption::REQ_TYPE_GET) { |
|
146 | 146 | $print = ''; |
147 | - if(isset($options['print'])){ |
|
148 | - if(JCFirebaseOption::isAllowPrint($reqType,$options['print'])){ |
|
147 | + if (isset($options['print'])) { |
|
148 | + if (JCFirebaseOption::isAllowPrint($reqType, $options['print'])) { |
|
149 | 149 | $print = $options['print']; |
150 | 150 | } |
151 | 151 | } |
152 | - return $pathURI = $this->getPathURI($path,$print); |
|
152 | + return $pathURI = $this->getPathURI($path, $print); |
|
153 | 153 | } |
154 | 154 | } |
155 | 155 | \ No newline at end of file |