Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
FuelPHP 1.5.3 config security uri_filter to convert hyphens to camel-case
  • I'm just upgrading 1.4 to 1.5.3, and have hit a problem with the security config.

    In order to be able to use hyphens in URLs, I had the following config:
        'security' => array(
    'uri_filter' => array(
    'htmlentities',
    function($uri) {
    return str_replace(' ', '', ucwords(str_replace('-', ' ', $uri)));
    },
    ),
    ),
    This would route a URL this-is-a-test to class Controller_ThisIsATest.

    In version 1.5.3, this throws an error "ErrorException [ Warning ]: array_flip(): Can only flip STRING and INTEGER values!" from COREPATH/classes/security.php @ line 67.

    What can I do to have hyphens in URLs in version 1.5?

    Thanks, Chris
  • Does replacing
    is_array($config) and \Config::set('security.'.$setting, array_keys(array_flip($config)));
    by
    is_array($config) and \Config::set('security.'.$setting, array_unique($config));
    fix it?
  • Thanks for the suggestion, Harro, but it gives me "ErrorException [ Error ]: Object of class Closure could not be converted to string".

    I've modified the _init() 'duplicate filters' code to:
    try {
    $config = \Config::get('security.'.$setting, array());
    is_array($config) and \Config::set('security.'.$setting, array_keys(array_flip($config)));
    } catch (\ErrorException $e) {
    // if array contains anonymous function, don't bother trying to remove duplicates
    continue;
    }
    which seems to take care of things – unless you have a better solution?

    Thanks, Chris
  • HarroHarro
    Accepted Answer
    Not at the moment. I've created an issue for it so it can be looked at.

    It is not a good idea to skip duplicate detection, and will make your application very slow (the filter is called hunderds of times in a single request) and may break stuff due to double encoding.
  • I shall try to be sure here's no duplicates in the config until there's a more solid solution! Thanks, Chris
  • Fixed in 1.6/develop.

    If you want to stay on 1.5.3, you might want to backport Arr::unique(), and the line in Security::_init() that caused the error.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion