rockettheme / toolbox

RocketTheme\Toolbox package contains a set of reusable PHP interfaces, classes and traits.
MIT License
21 stars 16 forks source link

UniformResourceLocator::findResource seems to fail with query parameters #7

Open alexweissman opened 8 years ago

alexweissman commented 8 years ago

findResource seems to have trouble resolving URIs that contain query parameters. For example, this seems to work fine:

$locator = new UniformResourceLocator(MY_BASE_DIR);
$locator->addPath('assets', '', 'assets');
echo $locator->findResource('images/favicon.ico', false);
// prints "assets/images/favicon.ico"

However if I do this:

$locator = new UniformResourceLocator(MY_BASE_DIR);
$locator->addPath('assets', '', 'assets');
echo $locator->findResource('images/favicon.ico?v=2', false);
// prints the empty string

Not sure if this is the intended behavior.

mahagr commented 8 years ago

Its not meant to be used with URLs; it just locates files from the filesystem.

alexweissman commented 8 years ago

Fair enough. However, in many applications (including Grav) there is a relationship between relative file paths and relative URLs. Is there an alternative preferred way to build URLs? Or, should I just do something like:

$locator->findResource('images/favicon.ico', false) . '?v=2';

mahagr commented 8 years ago

For urls there's twig function called url() (both in Grav and Gantry), which uses streams internally.