XaminProject / handlebars.php

Handlebars processor for php
331 stars 134 forks source link

Pass an instance of \Handlebars\Arguments to a helper #90

Open JustBlackBird opened 9 years ago

JustBlackBird commented 9 years ago

It will be more convenient if a helper receives an instance of \Handlebars\Arguments instead of arguments string. In this case a helper should know nothing about parsing and just uses already prepared arguments. Also if we parse an arguments string before calling a helper we can guarantee that arguments string is valid.

I could provide a pull request, if the maintainers are interesting in it.

fzerorubigd commented 9 years ago

Its a good idea. But what about BC break? How we can maintain backward compatibility? And if we can not, I think its time to migrate to another branch (develop for example)

JustBlackBird commented 9 years ago

\Handlebars\Arguments has magic __toString method. Thus it can be freely used in string context. The only problem is is_numeric function that used directly on arguments string in several places.

fzerorubigd commented 9 years ago

Can you point the exact location of problems? maybe we can fix them.

JustBlackBird commented 9 years ago

is_numeric is a compatibility problem for custom helpers. Here is an example:

$args = '92'; // just string
is_numeric($args); // returns true

// The same argument string but wrapped with the class
$args = new \Handlebars\Arguments('92');
is_numeric($args); // returns false