You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Consider making fURL::get() return the entire URL - including the domain and query string (if set). Alternatively, add a new method to return the entire URL, perhaps fURL::getURL().
Comment by vxnick:
Perhaps consider adding fURL::getProtocol() to return http://, https://, ftp://, etc, and to save on manually checking whether SSL is set in $_SERVER or the port is 443, etc.
Comment by vxnick:
fURL::getAnchor() might be another useful method - return an anchor if it exists (some/url#anchor).
fURL::getProtocol() - returns http://, etc
fURL::getHost() - returns example.com, with any non-standard port
fURL::getPath() - the current fURL::get(), /path/to/script
fURL::getQuery() - return ?key=value
Unfortunately the anchor is never sent to the server, so we can't return that.
The other issue I see is methods that return a combination of the above parts. For instance the protocol and host are often used together (currently fURL::getDomain()). Perhaps fURL::get() should return the whole URL by default, but optionally allow the programmer to pass in the parts they want?
Or perhaps all of the different methods should be discarded for a single fURL::get() which you can pass elements into? This would also make it so it could allow schema (http) and port (80) without extra methods.
Comment by vxnick:
I like the idea of passing elements into fURL::get() - that seems like a really nice solution.
Comment by mantaworks:
The problem with passing elements in is that they might not go together. What's the expected output of fURLget('protocol', 'path') or fURLget('query', 'host')? There's ambiguity.
I'd say a method like fURL::getAllParts() or fURL::split() that returns an associative array with all the parts named would be the way to go. You'd still have the parts you're interested in displayed clearly, without being extremely verbose.
parse_url() will return the fragment if you pass in a URL that contains one. The issue is that browsers don't send the fragment to the web server, so we can't get it.
How about allowing only a single element to be specified, but with a < before or > after to indicate the element requested plus everything before it or everything after it?
// Would return http://example.com
fURL::get('<hostname');
// Would return /path/to/script?key=val
fURL::get('path>');
When working with URLs we are all looking for a way to get a single result usually containing the most specific, or least specific pieces.
The text was updated successfully, but these errors were encountered:
If you're looking towards method cleanup in general, can I also add that I would like to see fURL as instantiable and able to modify (as it can with the current URL) a particular URL...
I'm not sure how you would go about cleanly maintaining backwards compatibility and not have more confusing methods, but it would be nice if I could create a URL object with any URL I want and use replaceInQueryString() and removeFromQueryString() or equivalents.
Similar to fDate() these objects could be immutable, so the methods always return new instances with differing internal states... the __toString() could always return the full URL, calling fURL::get() without a parameter would create an fURL object of the current URL. Idea being, if I pass fURL::get() to a method that takes a string, the __toString() method should be invoked, maintaining some if not all backwards compatibility.
Oh, and lastly, any ORM registered URL columns for validation, etc, could return fURL objects. Could even keep things consistent with a prepare() method, perhaps that could replaced %tokens with values. $url->prepare('%s%d%p/%r?%q') [scheme, domain, port, request, query]
Ticket #369 by vxnick:
Consider making fURL::get() return the entire URL - including the domain and query string (if set). Alternatively, add a new method to return the entire URL, perhaps fURL::getURL().
Comment by vxnick:
Perhaps consider adding fURL::getProtocol() to return http://, https://, ftp://, etc, and to save on manually checking whether SSL is set in $_SERVER or the port is 443, etc.
Comment by vxnick:
fURL::getAnchor() might be another useful method - return an anchor if it exists (some/url#anchor).
Comment by @wbond:
Yeah, it seems like there should be:
fURL::getProtocol() - returns http://, etc
fURL::getHost() - returns example.com, with any non-standard port
fURL::getPath() - the current fURL::get(), /path/to/script
fURL::getQuery() - return ?key=value
Unfortunately the anchor is never sent to the server, so we can't return that.
The other issue I see is methods that return a combination of the above parts. For instance the protocol and host are often used together (currently fURL::getDomain()). Perhaps fURL::get() should return the whole URL by default, but optionally allow the programmer to pass in the parts they want?
fURL::get() - the whole URL http://example.com:81/path/to/script?key=value
fURL::get('protocol', 'host') - http://example.com:81
fURL::get('path', 'query') - /path/to/script?key=value
Or perhaps all of the different methods should be discarded for a single fURL::get() which you can pass elements into? This would also make it so it could allow schema (http) and port (80) without extra methods.
Comment by vxnick:
I like the idea of passing elements into fURL::get() - that seems like a really nice solution.
Comment by mantaworks:
The problem with passing elements in is that they might not go together. What's the expected output of fURLget('protocol', 'path') or fURLget('query', 'host')? There's ambiguity.
I'd say a method like fURL::getAllParts() or fURL::split() that returns an associative array with all the parts named would be the way to go. You'd still have the parts you're interested in displayed clearly, without being extremely verbose.
Comment by alexleeds:
According to the php parse_url function (http://php.net/manual/en/function.parse-url.php) it is possible to get the "fragment" (aka the part after the #)
parse_url('http://username:password@hostname/path?arg=value#anchor') returns:
Comment by @wbond:
@alexleeds
parse_url() will return the fragment if you pass in a URL that contains one. The issue is that browsers don't send the fragment to the web server, so we can't get it.
Comment by @wbond:
@mantaworks
How about allowing only a single element to be specified, but with a < before or > after to indicate the element requested plus everything before it or everything after it?
When working with URLs we are all looking for a way to get a single result usually containing the most specific, or least specific pieces.
The text was updated successfully, but these errors were encountered: