Open ojhaujjwal opened 10 years ago
ping @Danielss89
@ojhaujjwal what happens in that case? failure? error?
Generally, there is no error but I don't see any point in starting session in CLI mode. We may check if request is HttpRequest or CliRequest.
public function isEmpty()
{
$request = $this->getServiceManager()->get('Request');
if (!$request instanceof HttpRequest) {
return true;
}
// previously the session was started here in CLI
if ($this->getStorage()->isEmpty()) {
return true;
}
$identity = $this->read();
if ($identity === null) {
$this->clear();
return true;
}
return false;
}
@ojhaujjwal yes, but I'm wondering if this shouldn't simply go back to Zend\Session
instead...
@Ocramius Yes. I don't know how but I think it will more easier if this is handled by Zend\Session
out-of-the-box.
@Danielss89 this is essentially a duplicate of #513
I've run into this issue myself with ZfcUser 1.x and I worked around it by creating a separate bootstrap file to use when running console commands with this addition above $app->run()
:
use ZfcUser\Authentication\Adapter\AdapterChain;
use ZfcUser\Authentication\Adapter\AdapterChainEvent;
use Zend\Authentication\Result;
$authService = $app->getServiceManager()->get('zfcuser_auth_service');
$authAdapterChain = new AdapterChain();
$authAdapterChain->getEventManager()->attach('authenticate', function(AdapterChainEvent $e) {
$e->setCode(Result::SUCCESS)
->setIdentity(1); // This forces the auth'd user to our consoleadmin user
});
$authAdapterChain->prepareForAuthentication(new \Zend\Console\Request());
$authService->authenticate($authAdapterChain);
ZfcUser\Authentication\Storage\Db
starts session whenisEmpty
method is called n session is not started. The problem appears when the current request is not HttpRequest (i.e. CliRequest). Is this an intended behaviour?