mardi 22 décembre 2015

Laravel 5.1 wrong instance of Illuminate\Encryption\Encrypter

I have a class that I am trying to swap out the facade usage of Crypt::encrypt with dependency injection:

       <?php namespace App\Libraries;

        use Illuminate\Encryption\Encrypter;

        class MyClass
        {

            public function __construct(Encrypter $encrypter)
            {
                $this->encrypter= $encrypter;
            }

            public function myMethod()
            {
                $this->encrypter->crypt('somevalue');
            }

         }

The wrong instance is getting instantiated:

Argument 1 passed to App\Libraries\MyClass::__construct() must be an instance of Illuminate\Encryption\Encrypter, instance of Illuminate\Encryption\McryptEncrypter given

The facade resolves without an issue but I'd like to understand why DI is failing.

use Illuminate\Support\Facades\Crypt;
Crypt::encrypt('somevalue');

Any help appreciated.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire