Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Format and Inflector classes bug
  • Sorry, I didn't really know where to put it, so let it be here, nor have I searched the entire forums to find whether someone reported it already or not. I have found a bug in Format class, like the title says. There are two bugs actually. First of them is kind of major one.
    Firstly, the easy and not-so-bad one: after converting from xml when there were few nested structures (arrays in arrays), nested ones are objects, not arrays. Quick solution for _from_xml method:
    $data = (array) simplexml_load_string($string, 'SimpleXMLElement', LIBXML_NOCDATA);
    $data = array_map('self::parseInnerXml', $data);
    return $data;
    
    and parsing method:
    protected static function parseInnerXml($obj) {
    
     if($obj instanceof SimpleXMLElement)
      return (array) $obj;
    
     return $obj;
    
    }
    

    The second one is also in XML parse function, however this time it's in toXml method.
    if ($structure == NULL)
    {
     $structure = simplexml_load_string("<?xml version='1.0' encoding='utf-8'?><$basenode />");
    }
    
    Okay, but what if $structure is not a null? Well, that's the point. Error.
    Quick solution:
    if (is_null($structure))
     $structure = "<?xml version='1.0' encoding='utf-8'?>";
    $structure = simplexml_load_string("$structure<$basenode />");
    

    Plus the bug in Inflector class. The following code:
    public static function camelize($underscored_word)
    {
     return preg_replace('/(^|_)(.)/e', "strtoupper('\\1\\2')", strval($underscored_word));
    }
    
    will never return a CamelCased string as it returns Almost_Camel_Cased string. Fix:
    return preg_replace('/(^|_)(.)/e', "strtoupper('\\2')", strval($underscored_word));
    

    Thanks for attention. PS.: Sorry for my terrible English.
  • Actually the CamelCase method is still a leftover from the origin of the Inflector when it's classify method didn't respect underscores. The problem is that in Fuel underscores have meaning (= directory seperator) and as such shouldn't be removed when using classify() on something. This should be solved in another way or the camelcase method should be removed probably for clarity. As it's against our coding guidelines, and especially camelcasing underscores makes no sense in Fuel. Could you report the Format class bugs to the bugtracker? That's where any bugreports should go.
  • To let you know: in the develop branch the Inflector::camelize() works as expected again, the Inflector::classify() won't use it anymore though.

Howdy, Stranger!

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

In this Discussion