Lumen-framework: Laravel\Lumen\Application does not implement Illuminate\Contracts\Foundation\Application

Created on 5 Mar 2019  路  22Comments  路  Source: laravel/lumen-framework

  • Lumen Version: 5.8
  • PHP Version: any
  • Database Driver & Version: any

Description:

Laravel\Lumen\Application is meant as a replacement for Illuminate\Foundation\Application, however, it doesn't implement Illuminate\Contracts\Foundation\Application.

This causes certain DocBlocks to be inaccurate when a library is used with Lumen.

E.g., in https://github.com/illuminate/support/blob/2b426a413e7c9da4b08845b71877b5de450293b5/ServiceProvider.php#L10-L15

Additionally, some libraries use specific type-hinting, and these can fail in Lumen, even though there's nothing in the code that would prevent Lumen from being used.

E.g., in https://github.com/laravel/cashier/blob/75052f4408ad29d87ac9e0169fa5bab5adb850d3/src/Http/Middleware/VerifyWebhookSignature.php#L34

There's nothing in Laravel Cashier's code that prevents it from being compatible with Lumen, however this middleware can't be used, because it requires that the $app be an implementation of Illuminate\Contracts\Foundation\Application, which Laravel\Lumen\Application is not.

Changes needed:

The following errors occur when Laravel\Lumen\Application implements Illuminate\Contracts\Foundation\Application:

  1. PHP Fatal error: Declaration of Laravel\Lumen\Application::register($provider) must be compatible with Illuminate\Contracts\Foundation\Application::register($provider, $force = false) in /home/drj/repos/work/medology/raven/vendor/laravel/lumen-framework/src/Application.php on line 21

  2. PHP Fatal error: Declaration of Laravel\Lumen\Application::registerDeferredProvider($provider) must be compatible with Illuminate\Contracts\Foundation\Application::registerDeferredProvider($provider, $service = NULL) in /home/drj/repos/work/medology/raven/vendor/laravel/lumen-framework/src/Application.php on line 21

  3. PHP Fatal error: Class Laravel\Lumen\Application contains 5 abstract methods and must therefore be declared abstract or implement the remaining methods (Illuminate\Contracts\Foundation\Application::registerConfiguredProviders, Illuminate\Contracts\Foundation\Application::booting, Illuminate\Contracts\Foundation\Application::booted, ...) in /home/drj/repos/work/medology/raven/vendor/laravel/lumen-framework/src/Application.php on line 21

Most helpful comment

@driesvints The issue isn't about making Lumen compatible with Cashier. That would be a side effect, but it's not the issue. The issue is making Lumen more compatible with Laravel.

There are many places in the Laravel codebase in which $app is typed (in DocBlock) as Illuminate\Foundation\Application|Illuminate\Contracts\Foundation\Application, but Laravel\Lumen\Application is neither of those. Having Laravel\Lumen\Application implement that interface would fix this.

All 22 comments

I don't know if this is related but I'm also getting
Unresolvable dependency resolving [Parameter #0 [ <required> $app ]] in class Illuminate\Support\Manager when using LumenPassport and accessing the route oauth/token
But this is fixed by adding \Laravel\Lumen\Application as type-hint in Illuminate\support\Manager.php::_construct()

So this:

    /**
     * Create a new manager instance.
     *
     * @param  \Illuminate\Contracts\Foundation\Application  $app
     * @return void
     */
    public function __construct(\Laravel\Lumen\Application $app)
    {
        $this->app = $app;
    }

Instead of

    /**
     * Create a new manager instance.
     *
     * @param  \Illuminate\Contracts\Foundation\Application  $app
     * @return void
     */
    public function __construct($app)
    {
        $this->app = $app;
    }

Unfortunately Lumen isn't compatible with Cashier.

@driesvints but it is with LumenPassport so...
Why is the issue solved by adding the type hinting?

how did you install passport in lumen? did you used this https://github.com/dusterio/lumen-passport?

im using https://github.com/dusterio/lumen-passport in lumen, work great in lumen 5.7, but after upgrading to lumen 5.8, same issue with @dvdbot

I don't know if this is related but I'm also getting
Unresolvable dependency resolving [Parameter #0 [ $app ]] in class Illuminate\Support\Manager when using LumenPassport and accessing the route oauth/token
But this is fixed by adding Laravel\Lumen\Application as type-hint in Illuminate\support\Manager.php::_construct()

We can apply this to both accepted

    /**
     * Create a new manager instance.
     *
     * @param  \Illuminate\Contracts\Foundation\Application $app
     * @return void
     */
    public function __construct(\Illuminate\Contracts\Foundation\Application $app)
    {
        $this->app = $app;
    }

@lloricode How did you get it to work with:

  /**
     * Create a new manager instance.
     *
     * @param  \Illuminate\Contracts\Foundation\Application $app
     * @return void
     */
    public function __construct(\Illuminate\Contracts\Foundation\Application $app)
    {
        $this->app = $app;
    }

I tried using \Illuminate\Contracts\Foundation\Application but that gave me errors about mismatching types - so I fixed it by using \Laravel\Lumen\Application

I'll try upgrading my Lumen-Passport :joy:
The release wasn't there yesterday :joy:

dont need to do that, there another isuue that already solve, you can eun composer update now

@dvdbot yes,

@lloricode I just checked - everything seems to work now!

@driesvints The issue isn't about making Lumen compatible with Cashier. That would be a side effect, but it's not the issue. The issue is making Lumen more compatible with Laravel.

There are many places in the Laravel codebase in which $app is typed (in DocBlock) as Illuminate\Foundation\Application|Illuminate\Contracts\Foundation\Application, but Laravel\Lumen\Application is neither of those. Having Laravel\Lumen\Application implement that interface would fix this.

@goodevilgenius I feel you, related bug #895.

They should really focus on framework compatibility instead of relying on us to duplicate code everywhere.

@driesvints I'm still unclear on why this issue was closed. Your only comment was about compatibility with Cashier, which wasn't the issue at hand.

Is it this project's stance that Lumen is not going to be compatible with Illuminate libraries? Because that's the issue at hand right now. Many Illuminate libraries, used by Lumen, expect the IOC container to implement lluminate\Contracts\Foundation\Application, which it could with some changes, but doesn't currently.

Either the Illuminate libraries should be changed to expect Illuminate\Container\Container or Illuminate\Contracts\Container\Container (which change should be made on laravel/framework), or Laravel\Lumen\Application should implement Illuminate\Contracts\Foundation\Application, as I've suggested.

@goodevilgenius It's not our focus to make Lumen compatible with any of the Laravel libraries. As for Illuminate components: if you find specific issues with compatibility issues with some components that you feel shouldn't be the case then please create separate issues for this.

Please note that Lumen itself isn't meant to be compatible with every single component.

@driesvints

if you find specific issues with compatibility issues with some components that you feel shouldn't be the case then please create separate issues for this.

That's what this issue is. I feel that Laravel\Lumen\Application should be compatible with Illuminate\Foundation\Application by implementing Illuminate\Contracts\Foundation\Application

That is the specific compatibility issue that I feel should be addressed, as stated in the issue description.

The issue, as stated, is not "Make Lumen compatible with all Illuminate libraries" or "Make Lumen compatible with Laravel Cashier" but simply "Laravel\Lumen\Application does not implement Illuminate\Contracts\Foundation\Application".

@goodevilgenius currently a bit swamped but will try to take a look next thursday

Hey there @goodevilgenius. I've been looking this over and giving it some more thought. First of all:

I feel that Laravel\Lumen\Application should be compatible with Illuminate\Foundation\Application

This is something that isn't wanted because of these being two totally separate frameworks. It's the core essence that they're different because they serve two totally separate use cases. In fact, it's actually totally silly that Illuminate\Contracts\Foundation\Application exists in the first place and I feel this should be revisited the future.

However, I do agree with you that we should take a look at the individual places where the implementation of the Lumen application seems out of place. For example, you mentioned:

This causes certain DocBlocks to be inaccurate when a library is used with Lumen.

E.g., in https://github.com/illuminate/support/blob/2b426a413e7c9da4b08845b71877b5de450293b5/ServiceProvider.php#L10-L15

This is actually a very good point and you're absolutely right about this. Due to the fact that Lumen isn't Laravel there seems to be going on something weird here. I only see one Application specific call in that class and it's the routesAreCached one which probably needs some thought.

I think in this specific situation that it's wanted to split the base service provider up into two separate ones: an abstract one which accepts container as its argument and a foundation one which accepts application as its argument. I'll give this some more thought and perhaps try to whip up a proposal.

Please feel free to indicate other situations where you feel that there's something wrong going dependency-wise.

@driesvints Thanks for having a look at this.

I can understand the perspective here, and it makes complete sense.

I think there are a number of libraries (both Illuminate and third-party) that have service providers that ask for Illuminate\Contracts\Foundation\Application where Illuminate\Contracts\Container\Container would be sufficient. That is probably the bigger problem, and issues should probably be opened on laravel/framework to address those cases.

I don't have an exhaustive list of the instances I found. I didn't look very deeply, TBH.

I don't have an exhaustive list of the instances I found.

No worries. Feel free to open up an issue if you find any.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

georgeboot picture georgeboot  路  4Comments

gfazioli picture gfazioli  路  5Comments

matthewsuan picture matthewsuan  路  3Comments

timrogers picture timrogers  路  3Comments

codercms picture codercms  路  4Comments