1 | <?php |
||
18 | class JCFirebase |
||
19 | { |
||
20 | const OPTION_SHALLOW = 'shallow'; |
||
21 | |||
22 | public $firebaseSecret; |
||
23 | public $firebaseURI; |
||
24 | public $firebaseDefaultPath; |
||
25 | |||
26 | public $requestHeader = array( |
||
27 | 'accept' => 'application/json', |
||
28 | 'contentType' => 'application/json; charset=utf-8', |
||
29 | 'dataType' => 'json' |
||
30 | ); |
||
31 | |||
32 | public $requestOptions = array(); |
||
33 | |||
34 | public function __construct($firebaseURI,$firebaseSecret = '',$firebaseDefaultPath = '/') |
||
35 | { |
||
36 | $this->firebaseSecret = $firebaseSecret; |
||
37 | $this->firebaseURI = $firebaseURI; |
||
38 | $this->firebaseDefaultPath = $firebaseDefaultPath; |
||
39 | } |
||
40 | |||
41 | public function getPathURI($path = ''){ |
||
42 | //remove .json or last slash from firebaseURI |
||
43 | $templates = array( |
||
44 | '.json', |
||
45 | '/.json', |
||
46 | '/' |
||
47 | ); |
||
48 | foreach ($templates as $template){ |
||
49 | $this->firebaseURI = rtrim($this->firebaseURI,$template); |
||
50 | } |
||
51 | |||
52 | //check https |
||
53 | if(strpos($this->firebaseURI, 'http://') !== false){ |
||
54 | throw new \Exception("https is required."); |
||
55 | } |
||
56 | |||
57 | //check firebaseURI |
||
58 | if(strlen($this->firebaseURI) == 0){ |
||
59 | throw new \Exception("firebase URI is required"); |
||
60 | } |
||
61 | |||
62 | $pathURI = $this->firebaseURI.$this->firebaseDefaultPath.$path.".json"; |
||
63 | return $pathURI; |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * @param string $path |
||
68 | * @param array $options |
||
69 | * @return \Requests_Response |
||
70 | */ |
||
71 | public function get($path = '',$options = array()){ |
||
72 | return Requests::get($this->getPathURI($path),$this->requestHeader,$this->mergeRequestOptions($options)); |
||
|
|||
73 | } |
||
74 | |||
75 | public function getShallow($path = '',$options = array()){ |
||
76 | return Requests::get($this->getPathURI($path). '?' . http_build_query(array(self::OPTION_SHALLOW => 'true')), |
||
77 | $this->mergeRequestOptions($options)); |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * @param string $path |
||
82 | * @param array $options |
||
83 | * @return \Requests_Response |
||
84 | */ |
||
85 | public function put($path = '',$options = array()){ |
||
86 | return Requests::put($this->getPathURI($path),$this->requestHeader,$this->mergeRequestOptions($options,true)); |
||
87 | } |
||
88 | |||
89 | /** |
||
90 | * @param string $path |
||
91 | * @param array $options |
||
92 | * @return \Requests_Response |
||
93 | */ |
||
94 | public function post($path = '',$options = array()){ |
||
95 | return Requests::post($this->getPathURI($path),$this->requestHeader,$this->mergeRequestOptions($options,true)); |
||
96 | } |
||
97 | |||
98 | /** |
||
99 | * @param string $path |
||
100 | * @param array $options |
||
101 | * @return \Requests_Response |
||
102 | */ |
||
103 | public function patch($path = '',$options = array()){ |
||
104 | return Requests::patch($this->getPathURI($path),$this->requestHeader,$this->mergeRequestOptions($options,true)); |
||
105 | } |
||
106 | |||
107 | /** |
||
108 | * @param string $path |
||
109 | * @param array $options |
||
110 | * @return \Requests_Response |
||
111 | */ |
||
112 | public function delete($path = '',$options = array()){ |
||
115 | |||
116 | protected function mergeRequestOptions($options = array(),$encode = false){ |
||
117 | $requestOptions = array(); |
||
118 | |||
119 | if(isset($options['data'])){ |
||
120 | $requestOptions = array_merge($options['data'],$requestOptions); |
||
121 | } |
||
122 | |||
129 | } |
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.