Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Events - Tasks, modules and autoloading
  • Hi everybody,

    Hoping this is in the correct forum, please move if required.

    Stay with me a minute while I "try" and explain a scenario..

    I wish to use a module to run a series of tasks. (This works perfectly).

    calling oil r module::class:method() is perfectly fine.

    But... I wish to register triggers that allow all modules on the system to have registerable code. This means that a module could contain a class that acts on an event.

    I load my modules easily enough with \Module::load(); (or config.php) which is perfect and works fine while calling methods statically or object based.

    However, because it uses autoloader to lazy load the classes, there doesn't seem to be an easy way to have the module register triggers for the classes contained within.

    A package comes close as I can call \Event::register() from inside the bootstrap (still not ideal).

    I suppose what I am looking for is an easy way to allow a module to be loaded (either through config or \Module::load()) and then automotically register it's internal events straight away. At the moment, the events won't be registered unless I make a call to the class first (loading it).

    Off the top of my head, the only way to do this would be to use \Finder and \Fuel::load() to load every file into memory (and possibly running an init() on each) in order for each class to register it's own triggers.

    Hoping this makes sense to somebodies brain other than my own.
  • HarroHarro
    Accepted Answer
    Currently that mechanism does not exist.

    It should not be to difficult to create. Extend the \Fuel\Core\Module class in your app, and modify the load() method to support a bootstrap.php. You can check Package::load() to see how that is done.

    Once done, you can add a bootstrap to a module the same way you can do it with a package.
  • Thanks @Harro, got it working..

    I did look at the package method of loading a bootstrap, which in testing worked perfectly, however, I wanted the class to be able to register itself, so I created a common class to extend from all my tasks which then iterated all classes in my modules, called \Fuel::load() and finally init_triggers() (inside class itself) to register it's own events.

    Hoping that makes sense.

    Thanks heaps for your help! Was invaluable!

Howdy, Stranger!

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

In this Discussion