Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
imorland opened this issue Oct 18, 2023 · 0 comments · Fixed by #3900 or #3903
Closed

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

imorland opened this issue Oct 18, 2023 · 0 comments · Fixed by #3900 or #3903
Assignees
Labels

Comments

@imorland
Copy link
Member

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

  • Flarum version: x.y.z
  • Website URL: http://example.com
  • Webserver: [e.g. apache, nginx]
  • Hosting environment: [e.g. shared, vps]
  • PHP version: x.y.z
  • Browser: [e.g. chrome 67, safari 11]

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.

@imorland imorland self-assigned this Oct 18, 2023
@imorland imorland changed the title [1.x] Support Invokable Classes in Console Extender's schedule method Support Invokable Classes in Console Extender's schedule method Oct 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
1 participant