hearsayit / HearsayRequireJSBundle

RequireJS integration for Symfony2.
130 stars 55 forks source link

Fix src() method in RequireJSHelper.php #71

Open liviucmg opened 10 years ago

liviucmg commented 10 years ago

Hi there,

I'm using PHP templates instead of Twig templates, and when initializing RequireJS using

/* @var Hearsay\RequireJSBundle\Templating\Helper\RequireJSHelper $requireJs */
$requireJs = $view['require_js'];
echo $requireJs->initialize();

I get the following error:

An exception has been thrown during the rendering of a template ("Template name "/media/Storage/backed-up-storage/work/picofnet/website/website/app/../src/Picof/BaseBundle/Resources/public/components/requirejs/requirejs" contains invalid characters.") in HearsayRequireJSBundle::initialize.html.twig at line 46.

Doesn't matter whether I use the default file

hearsay_require_js:
    require_js_src:      //cdnjs.cloudflare.com/ajax/libs/require.js/2.1.8/require.min.js

or a custom file

hearsay_require_js:
    require_js_src:      %kernel.root_dir%/../src/Picof/BaseBundle/Resources/public/components/requirejs/requirejs

The fix is easy. The RequireJSHelper::src() method should first check if the file is supported by the rendering engine, and only then check if it exists. Not the other way around like it is doing now.

I'm going to do a pull request, if that's alright.

Thanks!

liviucmg commented 10 years ago

Actually it seems that the lines also need to be wrapped up in a try-catch block, because $this->engine->supports is throwing an InvalidArgumentException.