I've created a ServiceProvider in Laravel5 that registers two singletons to the service container:
ServiceProvider
namespace App\Providers;
use App\Services\Passwords\FileMakerPasswordBroker;
use App\Services\Passwords\FileMakerTokenRepository;
use Illuminate\Support\ServiceProvider;
class FileMakerPasswordResetServiceProvider extends ServiceProvider
{
protected $defer = true;
public function provides(){
return ['fm.password','fm.password.token'];
}
public function register()
{
$this->registerPasswordBroker();
$this->registerTokenRepository();
}
protected function registerPasswordBroker(){
$this->app->singleton('fm.password', function ($app){
return new FileMakerPasswordBroker;
});
}
protected function registerTokenRepository(){
$this->app->singleton('fm.password.token', function ($app){
return new FileMakerTokenRepository;
});
}
}
I've just started so the two concrete classes being created are just empty class declarations:
TokenRepository
namespace App\Services\Passwords;
class FileMakerTokenRepository {
}
PasswordBroker
namespace App\Services\Passwords;
class FileMakerPasswordBroker {
}
And I've registered my service provider in my config/app.php
class:
app.php
...
'providers' => [
...
App\Providers\FileMakerPasswordResetServiceProvider::class
...
The problem is, I can't resolve the singletons out of the service container:
A dev controller
...
use Illuminate\Foundation\Application;
class DevController extends Controller
{
protected $app;
public function __construct(Application $app){
$this->app = $app;
}
public function testPasswordReset(){
// This throws an error
return $this->app->make('fm.password.token');
}
...
When I try to make the singleton, I get the error
ReflectionException in Container.php line 736: Class fm.password.token does not exist
I walked back through the documentation on binding and resolving from the service container and it looks like everything is right, but I'm obviously missing something.
Is there a step I'm missing or something I'm missing re: resolving a singleton from the service container?
Update
Here's a screen shot of the stack if that helps:
Aucun commentaire:
Enregistrer un commentaire