Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_getJsonPath function doesn't allow query strings #19

Closed
solyoung opened this issue Feb 2, 2015 · 6 comments
Closed

_getJsonPath function doesn't allow query strings #19

solyoung opened this issue Feb 2, 2015 · 6 comments
Assignees

Comments

@solyoung
Copy link

solyoung commented Feb 2, 2015

The Firebase API offers orderBy and advanced query options. The _getJsonPath function currently appends ".json" to the end of the path without regard to the $path. This should be corrected so that query strings can be passed in the $path.

I may fork and solve, but at least wanted the issue reported in case I don't get back here.

@markdrake
Copy link

I'm having the same issue as solyoung. I wanted to use the query options but as you hard code the auth variable as the only query param available you make it impossible to use this without modification. I know it's a very simple wrapper but a more dynamic params approach would be ideal.

@ktamas77
Copy link
Owner

ktamas77 commented May 8, 2015

Thank you for your suggestion, this is a very important feature. I marked it as a todo.

@ktamas77 ktamas77 self-assigned this May 8, 2015
@reedgz
Copy link

reedgz commented Jun 6, 2015

I would love to see this feature as well. Then we can use shallow copy and other query options.
'https://samplechat.firebaseio-demo.com/.json?shallow=true'

@solyoung
Copy link
Author

Here's a suggestion that would allow query functionality to get through that function (it's how I have the code modified in the meantime):
private function _getJsonPath($path)
{
$url = $this->_baseURI;
$path = ltrim($path, '/');
$qaToken = (strpos($path, '?') == FALSE) ? '?' : '&';
$auth = ($this->_token == '') ? '' : $qaToken . 'auth=' . $this->_token;
$incJSON = (strpos($path, '.json') == FALSE) ? '.json' : '';
return $url . $path . $incJSON . $auth;
}

*note, if you use the above, you need to include .json in your original request. e.g. $firebaseLib->get('test.json?orderBy=email'); If you don't include .json, the above will still append .json at the end of that path.

@askinner2004
Copy link

I modified the firebaseLib.php file with the following lines to add some query functionality:
...
private $_options;
...
//This functions sets the options and ensures that the data is enclosed in QUOTATIONS
//Just before submitting the data, works really great.
public function setOptions($options = NULL)
{
if($options !== NULL)
{
foreach($options as $f => $v)
{
$new_options[$f] = '"' . $v . '"';
}
} else {
$new_options = $options;
}
$this->_options = $new_options;
}
...
// I modified this function to build the query string just before submitting
// and it converts %22 to QUOTATION marks before returning.
private function _getJsonPath($path)
{
$url = $this->_baseURI;
$path = ltrim($path, '/');
$auth = ($this->_token == '') ? '' : 'auth=' . $this->_token;
if($this->_options != NULL)
{
$data = http_build_query($this->_options);
$auth = "?". str_replace('%22','"',$data) . "&" . $auth;
} else {
$auth = "?" . $auth;
}
$new_url = $url . $path . '.json' . $auth;
return $new_url;

}

@ktamas77
Copy link
Owner

Query parameters are supported in version v2.1.0

https://github.com/ktamas77/firebase-php/releases/tag/v2.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants