samedi 26 décembre 2015

Laravel 5.1 illuminate/queue capsule error 'Class encrypter does not exist'

I have the need to push jobs on a queue from outside the Laravel framework. Found the queue capsule manager that should make this possible:

http://ift.tt/1vaiU8W

Trying the following as per their example code:

<?php

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

use Illuminate\Queue\Capsule\Manager as Queue;

$queue = new Queue;

$queue->addConnection([
    'driver' => 'sync',
]);

$queue->setAsGlobal();

$queue->push(function($job)
{
    echo "test!\n";
    $job->delete();
});

Running this code results in the following error:

PHP Fatal error:  Uncaught exception 'ReflectionException' with message 'Class encrypter does not exist' in vendor/laravel/framework/src/Illuminate/Container/Container.php:741
Stack trace:
#0 vendor/laravel/framework/src/Illuminate/Container/Container.php(741): ReflectionClass->__construct('encrypter')
#1 vendor/laravel/framework/src/Illuminate/Container/Container.php(631): Illuminate\Container\Container->build('encrypter', Array)
#2 vendor/laravel/framework/src/Illuminate/Container/Container.php(1163): Illuminate\Container\Container->make('encrypter')
#3 vendor/laravel/framework/src/Illuminate/Queue/QueueManager.php(117): Illuminate\Container\Container->offsetGet('encrypter')
#4 vendor/laravel/framework/src/Illuminate/Queue/Capsule/Manager.php(135): Illuminate\Queue\QueueM in vendor/laravel/framework/src/Illuminate/Container/Container.php on line 741

Fatal error: Uncaught exception 'ReflectionException' with message 'Class encrypter does not exist' in vendor/laravel/framework/src/Illuminate/Container/Container.php:741
Stack trace:
#0 vendor/laravel/framework/src/Illuminate/Container/Container.php(741): ReflectionClass->__construct('encrypter')
#1 vendor/laravel/framework/src/Illuminate/Container/Container.php(631): Illuminate\Container\Container->build('encrypter', Array)
#2 vendor/laravel/framework/src/Illuminate/Container/Container.php(1163): Illuminate\Container\Container->make('encrypter')
#3 vendor/laravel/framework/src/Illuminate/Queue/QueueManager.php(117): Illuminate\Container\Container->offsetGet('encrypter')
#4 vendor/laravel/framework/src/Illuminate/Queue/Capsule/Manager.php(135): Illuminate\Queue\QueueM in vendor/laravel/framework/src/Illuminate/Container/Container.php on line 741

Searching on this subject I found something that said to add the following code:

$queue->getContainer()->bind('encrypter', function() {
    return new Illuminate\Encryption\Encrypter('nInrMfTMQngxqRvoFpjstYjZX0qH1Nlr', 'AES-256-CBC');
});
$queue->getContainer()->bind('request', function() {
    return new Illuminate\Http\Request();
});

Which does not seem to be a solution, because I then get the following error:

PHP Fatal error:  Uncaught exception 'Illuminate\Contracts\Container\BindingResolutionException' with message 'Target [Illuminate\Contracts\Encryption\Encrypter] is not instantiable.' in vendor/laravel/framework/src/Illuminate/Container/Container.php:749
Stack trace:
#0 vendor/laravel/framework/src/Illuminate/Container/Container.php(631): Illuminate\Container\Container->build('Illuminate\\Cont...', Array)
#1 vendor/laravel/framework/src/Illuminate/Container/Container.php(842): Illuminate\Container\Container->make('Illuminate\\Cont...')
#2 vendor/laravel/framework/src/Illuminate/Container/Container.php(805): Illuminate\Container\Container->resolveClass(Object(ReflectionParameter))
#3 vendor/laravel/framework/src/Illuminate/Container/Container.php(776): Illuminate\Container\Container->getDependencies(Array, Array)
#4  in vendor/laravel/framework/src/Illuminate/Container/Container.php on line 749

Binding those should not be needed though, judging by the documentation from illuminate/queue.

This occurs with laravel 5.1.27. Any thoughts/solutions?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire