简体   繁体   English

目标 [Illuminate\\Contracts\\Debug\\ExceptionHandler] 不可实例化

[英]Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable

I'm using Eloquent in combination with Slim Framework to build a small API.我将 Eloquent 与 Slim Framework 结合使用来构建一个小型 API。 For some reason, I am getting this error, and I can't locate the problem:出于某种原因,我收到此错误,但找不到问题所在:

Target [Illuminate\\Contracts\\Debug\\ExceptionHandler] is not instantiable.

Database settings are correct.数据库设置正确。 This error is thrown in my staging environment on the server.此错误是在服务器上的暂存环境中引发的。 Locally, with MySQL 5.6.29, it works perfectly.在本地,使用 MySQL 5.6.29,它可以完美运行。 Although I don't think it's related to MySQL 5.7 because I have another app running on the same server with the same version of Eloquent.虽然我认为它与 MySQL 5.7 无关,因为我在同一台服务器上运行了另一个应用程序,使用相同版本的 Eloquent。

Can anyone point me in the right direction?任何人都可以指出我正确的方向吗?

I'm using:我正在使用:

  • Eloquent Version: 5.3.23雄辩版本: 5.3.23
  • PHP Version: 5.6.28 PHP 版本: 5.6.28
  • Database Driver & Version: MySQL 5.7.16数据库驱动和版本:MySQL 5.7.16

Backtrace回溯

/path/to/app/shared/vendor/illuminate/container/Container.php:644 
Illuminate\Container\Container -> make
/path/to/app/shared/vendor/illuminate/database/Connectors/ConnectionFactory.php:130 
call_user_func 
/path/to/app/shared/vendor/illuminate/database/Connection.php:964 
Illuminate\Database\Connection -> getPdo 
/path/to/app/shared/vendor/illuminate/database/Connection.php:832 
Illuminate\Database\Connection -> reconnectIfMissingConnection 
/path/to/app/shared/vendor/illuminate/database/Connection.php:717 
Illuminate\Database\Connection -> run 
/path/to/app/shared/vendor/illuminate/database/Connection.php:350 
Illuminate\Database\Connection -> select 
/path/to/app/shared/vendor/illuminate/database/Query/Builder.php:1648 
Illuminate\Database\Query\Builder -> runSelect 
/path/to/app/shared/vendor/illuminate/database/Query/Builder.php:1634 
Illuminate\Database\Query\Builder -> get 
/path/to/app/shared/vendor/illuminate/database/Eloquent/Builder.php:632 
Illuminate\Database\Eloquent\Builder -> getModels 
/path/to/app/shared/vendor/illuminate/database/Eloquent/Builder.php:327 
Illuminate\Database\Eloquent\Builder -> get 
/path/to/app/shared/vendor/illuminate/database/Eloquent/Builder.php:297 
Illuminate\Database\Eloquent\Builder -> first 
...

I'm suspecting it has something to do with an unregistered error handler:我怀疑它与未注册的错误处理程序有关:

github link github链接

But how can I register the custom error handler when not using Laravel?但是在不使用 Laravel 时如何注册自定义错误处理程序?

UPDATE The solution of @patricus can be implemented as follows:更新@patricus 的解决方案可以实现如下:

// bootstrap Eloquent ORM
$container = new Container();
$container->singleton(
  'Illuminate\Contracts\Debug\ExceptionHandler'
, 'My\Custom\DatabaseExceptionHandler'
);

$factory    = new ConnectionFactory( $container );
$connection = $factory->make([
  'driver'    => 'mysql'
, 'host'      => App::config( 'database_host' )
, 'database'  => App::config( 'database_name' )
, 'username'  => App::config( 'database_user' )
, 'password'  => App::config( 'database_password' )
, 'charset'   => App::config( 'database_charset' )
, 'collation' => App::config( 'database_collate' )
, 'prefix'    => ''
]);

$resolver = new ConnectionResolver();
$resolver->addConnection( 'default', $connection );
$resolver->setDefaultConnection( 'default' );

// initialize connection
Model::setConnectionResolver( $resolver );

You should be able to access the container to register your own exception handler through the capsule.您应该能够访问容器以通过胶囊注册您自己的异常处理程序。

$capsule = new \Illuminate\Database\Capsule\Manager();

$capsule->getContainer()->singleton(
    \Illuminate\Contracts\Debug\ExceptionHandler::class,
    \Your\ExceptionHandler\Implementation::class
);

If you want a real quick, very dumb, exception handler, you can use this:如果你想要一个真正快速、非常愚蠢的异常处理程序,你可以使用这个:

class DumbExceptionHandler implements \Illuminate\Contracts\Debug\ExceptionHandler
{
    public function report(Exception $e)
    {
        //
    }

    public function render($request, Exception $e)
    {
        throw $e;
    }

    public function renderForConsole($output, Exception $e)
    {
        throw $e;
    }
}

NB: untested.注意:未经测试。 I believe this should work looking at the code.我相信这应该可以查看代码。

请确保您的 xampp 服务器和数据库服务器正在运行。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Laravel 5.8 目标 [Illuminate\Contracts\Debug\ExceptionHandler] 不可实例化 - Laravel 5.8 Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable 目标 [Illuminate\Contracts\Broadcasting\Factory] 不可实例化 - Target [Illuminate\Contracts\Broadcasting\Factory] is not instantiable Laravel “目标 [Illuminate\\Contracts\\Bus\\Dispatcher] 不可实例化。” - Laravel "Target [Illuminate\Contracts\Bus\Dispatcher] is not instantiable." PHPUnit 给出错误:目标 [Illuminate\Contracts\View\Factory] 不可实例化 - PHPUnit gives error: Target [Illuminate\Contracts\View\Factory] is not instantiable Illuminate\\Contracts\\Filesystem\\Factory 不可实例化 - Illuminate\Contracts\Filesystem\Factory is not instantiable Laravel 5.1:Auth::logout() 不起作用并且目标 [Illuminate\\Contracts\\Auth\\Registrar] 不是可实例化的错误 - Laravel 5.1: Auth::logout() is not working and Target [Illuminate\Contracts\Auth\Registrar] is not instantiable error 目标 [Laravel\Fortify\Contracts\RegisterViewResponse] 不可实例化 - target [Laravel\Fortify\Contracts\RegisterViewResponse] is not instantiable 目标 [Illuminate\View\ViewFinderInterface] 在构建 [Illuminate\View\Factory] 时不可实例化 - Target [Illuminate\View\ViewFinderInterface] is not instantiable while building [Illuminate\View\Factory] Laravel错误:无法实例化目标[Illuminate \\ View \\ Engines \\ EngineInterface] - Laravel error: Target [Illuminate\View\Engines\EngineInterface] is not instantiable Illuminate\\Contracts\\Container\\BindingResolutionException 目标类 [UserControl] 不存在 - Illuminate\Contracts\Container\BindingResolutionException Target class [UserControl] does not exist
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM