我正在尝试使用Laravel之外的Laravel queue package和数据库驱动程序,但是在解析命名空间时遇到了错误。
$concrete
的值是'db'。
$reflector = new ReflectionClass($concrete);
异常消息:
Fatal error: Uncaught exception 'ReflectionException' with message 'Class db does not exist' in ..vendor\illuminate\container\Container.php on line 736
ReflectionException: Class db does not exist in ..vendor\illuminate\container\Container.php on line 736
我也使用了照明数据库软件包,它工作正常,但是这个会抛出异常。
答案 0 :(得分:1)
需要手动解析数据库连接并将此连接添加到队列管理器
从数据库管理器获取mysql连接:
$connection = Capsule::schema()->getConnection();
$container = new Container();
抓取队列管理器实例:
$manager = $queue->getQueueManager();
解决连接:
$resolver = new \Illuminate\Database\ConnectionResolver(['default' => $connection]);
添加与队列管理器的连接:
$manager->addConnector('database', function () use ($resolver) {
return new DatabaseConnector($resolver);
});
完成!
还需要添加Illuminate Encryptionn包
完整代码:
<?php
/**
* Created by PhpStorm.
* User: Dmitry
* Date: 05.08.2015
* Time: 19:32
*/
require_once "../vendor/autoload.php";
require_once '../db/db_inc.php'; // DB Capsule config
use Illuminate\Container\Container;
use Illuminate\Queue\Capsule\Manager as Queue;
use Illuminate\Database\Capsule\Manager as Capsule;
use Illuminate\Queue\Connectors\DatabaseConnector;
$connection = Capsule::schema()->getConnection();
$queue = new Queue();
$queue->addConnection([
'driver' => 'database',
'table' => 'jobs', // Required for database connection
'connection' => 'default',
'host' => 'localhost',
'queue' => 'default',
]);
$queue->getContainer()->bind('encrypter', function() {
return new \Illuminate\Encryption\Encrypter('1111111111111111');
});
$queue->getContainer()->bind('request', function() {
return new \Illuminate\Http\Request();
});
$manager = $queue->getQueueManager();
$resolver = new \Illuminate\Database\ConnectionResolver(['default' => $connection]);
$manager->addConnector('database', function () use ($resolver) {
return new DatabaseConnector($resolver);
});
$queue->setAsGlobal();
Queue::push('SomeJobClass', ['parameters']);