Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Where to put a base class?
  • Hi,

    I created a 'queue' package (like in Laravel), which uses a Message Queue (Beanstalk, etc) to free up the application fronted from running a lot of code.

    The queue executes a job class, which always extends a class called 'Job'. The problem is that the package requires to have a queue software installed on the server which is not always an option, so my code has to be able tor run without the queue package.

    This is true for code wrapped in a package as well, not only for frontend code. i don't really like making dependencies between packages (except special cases like Ormauth).

    So my solution would be to run only the job class with the given argument, and only use queue package, when it is available.




    if(\Package::loaded('queue'))
    {
    \Queue::push('Job_Email', $args);
    }
    else
    {
    $job = new Job_Email($args);
    $job->run();
    }




    The problem is that these job classes extends a base class called 'Job', which is now in the queue package.

    My question is: Where to put this Job class? The easiest way would be pushing the Job class to the fuel core, but I do not know whether this class could be part of the core. Other possibilities: put it in the application when I need it, but it in a base package which is always loaded.

    What do you think?

    Thanks for help
  • Actually there is also a driver in queue package, called Direct, which runs the queued job immediately, but it also needs to have the queue package.
  • Changing the core is always a bad idea, it should not be touched.

    If you see it as a core extension, and you need modularity or re-use for other applications, a separate package is the way to go. Your queue package could do a \Package::load() of this package in its bootstrap so you only have to load 'queue' to make it working.

Howdy, Stranger!

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

In this Discussion