Closed antonioribeiro closed 10 years ago
What are you binding to your interface and where are you binding it ?
Using a bindings.php separate file loaded in app/start/globals.php
require app_path().'/bindings.php';
To bind the interface to the concrete class:
App::bind(
'App\Repositories\DataRepositoryInterface',
'App\Repositories\DataRepository'
);
Also tried to put this in routes file.
Also tried to use the concrete class instead of the interface.
Where do you add the command? start/artisan.php
?
Yes!
Have you tried a composer dump
? Odd that it works in your controller.
Also maybe try a fresh composer update
to make sure you're totally up to date.
Did that too, while trying to figure out. Did it again now, got a new commit, but still the same. App is a fresh 4.1 install, so this is also not an upgrade-from-4.0-problem.
There's something I think might help understand it better: trying to instantiate the concrete class in artisan.php
<?php
$dataRepository = new App\Repositories\DataRepository;
//Artisan::resolve('App\Commands\Whitelist');
Gives the same error:
PHP Fatal error: Class 'App\DataRepository' not found in /application.dve/app/start/artisan.php on line 14
I was trying to instantiate it and pass to App::add().
Your fatal error says class "App\DataRepository" instead of "App\Repositories\DataRepository"...?
Was a typo. I'm actually editing the error, to not expose application name:
This is it unedited:
removed
Are you able to paste the real, unedited bindings as well, and an unedited command file?
full bindings:
removed
Where do these files live? What is the file structure like? What is your composer.json file?
And full artisan.php
removed
This is the controller that works fine:
<? namespace ConsultorioDigital\Controllers;
use Controller;
use Redirect;
use ConsultorioDigital\Repositories\DataRepositoryInterface;
class FirewallController extends BaseController {
private $dataRepository;
public function __construct(DataRepositoryInterface $dataRepository)
{
$this->dataRepository = $dataRepository;
}
public function whitelist($ip)
{
return Redirect::to('/')->withMessages(
$this->
dataRepository->
firewall->
addToWhitelist($ip)->
getMessages()
);
}
}
Hmm, I totally confused as to why this wouldn't be working then. Can you set a debug statement to make sure your binding is registered?
Another strange thing that happens in the process, looks like it finds the dependency, but just prints it out in the terminal:
The top of that file has no php... just <?
Can you paste that whole interface file?
Gosh, that was dumb. It was just a missing php after <?.
That one and anoter 10 other files where I just copied and pasted the namespace...
But why was that working in the first place?
Sorry.
No prob.
This is what I have:
Adding the command to Artisan via resolve():
The Command:
Trying to use the command gives me this error:
But I also have this controller where the same resolution works fine:
Without the dependency command works fine.
Am I doing something wrong or it's a bug?