flarum / framework

Simple forum software for building great communities.
http://flarum.org/
6.27k stars 826 forks source link

Support Invokable Classes in Console Extender's schedule method #3899

Closed imorland closed 10 months ago

imorland commented 10 months ago

Current Behavior

When using the Console extender's schedule method, it's currently required to pass an instantiated object (either a closure or an invokable class). Based on the docblock and patterns in other extenders, there's an expectation that the method should also accept the ::class syntax for invokable classes. However, this isn't currently supported, leading to unexpected behavior.

(new Extend\Console())
    ->schedule(Console\ProcessEraseRequests::class, Console\DailySchedule::class); 
// Throws error: Call to undefined function Console\DailySchedule()

Steps to Reproduce

  1. Create a new Console extender.
  2. Use the schedule method with the ::class syntax for the callback.
  3. Observe the error when the scheduled command is invoked.

Expected Behavior

(new Extend\Console())
    ->schedule(Console\ProcessEraseRequests::class, Console\DailySchedule::class); 
// Should work, given that Console\DailySchedule is an invokable class

Screenshots

No response

Environment

Output of php flarum info

Output of "php flarum info", run this in terminal in your Flarum directory.

Possible Solution

Modify the Console extender to support both instantiated objects and the ::class syntax for invokable classes. This can be done using a similar approach to the Filesystem extender, utilizing the ContainerUtil::wrapCallback method.

Additional Context

This inconsistency can lead to confusion, especially given that other extenders in Flarum handle both closures and invokable classes correctly.

Tests should be added to ensure that this behavior is correctly implemented and maintained in the future.