Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Dependencies in creating a package... (parser)
  • I'm working on a fairly robust form building package that I'm looking to open source when I get it completed... and I'm using the mustache template system as a dependency for the package... I'd rather have this loaded automatically from the package rather than require the user to add it to their packages list in the master config. So right now I'm loading the package in the _init() for the class as follows:
    class Formloader
    {
        public static function _init()
        {
           \Fuel::add_package("parser");
        }
    }
    
    Which works fine, as long as the package is called before the first instance of a \View:: is called... Otherwise, the parser's view does not override the main app's view class and the \Mustache lib is not loaded... (an "ErrorException [ Error ]: Class 'Mustache' not found" is thrown) I could actually do without the forge method given in the \Parser\View, I just wanted to know the best way to go about getting the _init to run, or to manually override the \View with the \Parser\View after the \View has already been called. Thanks.
  • Looking at it again, it looks like the View_Mustache (and similar classes) should be extending View, rather than \View, fixing the instance described above.
    class View_Mustache extends View
    
    rather than the current:
    class View_Mustache extends \View
    

    Seems to work for me, and I've added a pull request with these changes https://github.com/fuel/parser/pull/38
  • Best way is to just tell people to add both your package and the Parser package to their always_load. Next best solution is to put this into your package's bootstrap:
    // check whether the Parser package is available
    if ( ! class_exists('Parser\\View'))
    {
        // if not, load it
        Package::load('parser');
    }
    
  • Ah, putting it in the bootstrap makes a lot of sense, I'll do that. Thanks.

Howdy, Stranger!

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

In this Discussion