Skip to content
This repository has been archived by the owner on Sep 10, 2024. It is now read-only.

Custom main application class (instanceof instanceof Container class) #526

Open
HASSANDL opened this issue Apr 28, 2022 · 2 comments
Open

Comments

@HASSANDL
Copy link

I use instanceof Laravel\Lumen\Application for main app class (instanceof instanceof Container class) but you check app instanceof Container class in src/Concerns/WithApplication.php

/**
     * @return \Illuminate\Contracts\Container\Container|mixed
     * @throws \ReflectionException
     */
    public function getApplication()
    {
        if (! $this->app instanceof Container) {
            $this->app = $this->loadApplication();
            $this->bootstrap();
        }

        return $this->app;
    }

when start swoole show below error:

Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Http\Kernel] is not instantiable. in /var/www/ts_back/vendor/illuminate/container/Container.php:1089
Stack trace:
#0 /var/www/ts_back/vendor/illuminate/container/Container.php(886): Illuminate\Container\Container->notInstantiable()
#1 /var/www/ts_back/vendor/illuminate/container/Container.php(758): Illuminate\Container\Container->build()
#2 /var/www/ts_back/vendor/illuminate/container/Container.php(694): Illuminate\Container\Container->resolve()
#3 /var/www/ts_back/vendor/laravel/lumen-framework/src/Application.php(300): Illuminate\Container\Container->make()
#4 /var/www/ts_back/vendor/swooletw/laravel-swoole/src/Concerns/WithApplication.php(148): Laravel\Lumen\Application->make()
#5 /var/www/ts_back/vendor/swooletw/laravel-swoole/src/Concerns/WithApplication.php(31): SwooleTW\Http\Server\Manager->getBootstrappers()
#6 /var/www/ts_back/vendor/swooletw/laravel-swoole/src/Concerns/WithApplication.php(63): SwooleTW\H {"exception":"[object] (Symfony\\Component\\ErrorHandler\\Error\\FatalError(code: 0): Uncaught Illuminate\\Contracts\\Container\\BindingResolutionException: Target [Illuminate\\Contracts\\Http\\Kernel] is not instantiable. in /var/www/ts_back/vendor/illuminate/container/Container.php:1089

when I change to if (! is_subclass_of($this->app, 'Container')) { start without problem.

@Cryental
Copy link

I'm getting the same problem. Any fixes?

@64j
Copy link

64j commented Dec 14, 2022

I solved by checking in bootstrap/app.php file

Added a check at the beginning of the file

<?php

if (class_exists('\Illuminate\Container\Container')) {
    return \Illuminate\Container\Container::getInstance();
}

require_once __DIR__ . '/../vendor/autoload.php';

In order not to download an already connected file
https://github.com/swooletw/laravel-swoole/blob/master/src/Concerns/WithApplication.php#L52

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants