zfcampus/zf-content-negotiation — pull request #22 by weierophinney (2014-08-20 19:18:01+00:00)
Title: ZF Content Negotiation via Apigility throws exception for Zend\Console\Request

Hello

After adding Apigility to an existing application running the "console" part of the application throws an exception. Our quick fix was to not load zf content negotiation if running from cli.

Here is the stack trace. Any suggestions would greatly be appreciated.

```
======================================================================
The application has thrown an exception!
======================================================================
Zend\Mvc\Exception\DomainException
The event used does not contain a valid Request, but must.
----------------------------------------------------------------------
/var/www/my_application/vendor/zendframework/zendframework/library/Zend/Mvc/Controller/Plugin/AcceptableViewModelSelector.php:241
#0 /var/www/my_application/vendor/zendframework/zendframework/library/Zend/Mvc/Controller/Plugin/AcceptableViewModelSelector.php(133): Zend\Mvc\Controller\Plugin\AcceptableViewModelSelector->getRequest()
#1 /var/www/my_application/vendor/zendframework/zendframework/library/Zend/Mvc/Controller/Plugin/AcceptableViewModelSelector.php(114): Zend\Mvc\Controller\Plugin\AcceptableViewModelSelector->match(NULL)
#2 /var/www/my_application/vendor/zendframework/zendframework/library/Zend/Mvc/Controller/Plugin/AcceptableViewModelSelector.php(88): Zend\Mvc\Controller\Plugin\AcceptableViewModelSelector->getViewModelName(NULL, true, NULL)
#3 /var/www/my_application/vendor/zendframework/zendframework/library/Zend/Mvc/Controller/Plugin/AcceptableViewModelSelector.php(71): Zend\Mvc\Controller\Plugin\AcceptableViewModelSelector->getViewModel(NULL, true, NULL)
#4 /var/www/my_application/vendor/zfcampus/zf-content-negotiation/src/AcceptListener.php(98): Zend\Mvc\Controller\Plugin\AcceptableViewModelSelector->__invoke(NULL, true)
#5 [internal function]: ZF\ContentNegotiation\AcceptListener->__invoke(Object(Zend\Mvc\MvcEvent))
#6 /var/www/my_application/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(468): call_user_func(Object(ZF\ContentNegotiation\AcceptListener), Object(Zend\Mvc\MvcEvent))
#7 /var/www/my_application/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#8 /var/www/my_application/vendor/zendframework/zendframework/library/Zend/Mvc/Controller/AbstractController.php(117): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#9 /var/www/my_application/vendor/zendframework/zendframework/library/Zend/Mvc/Controller/Plugin/Forward.php(138): Zend\Mvc\Controller\AbstractController->dispatch(Object(Zend\Console\Request), Object(Zend\Console\Response))
#10 /var/www/my_application/vendor/I-am-vendor/MyLibrary/src/MyLibrary/Controller/ConsoleController.php(135): Zend\Mvc\Controller\Plugin\Forward->dispatch('FeedUpload\Cont...', Array)
#11 /var/www/my_application/vendor/I-am-vendor/MyLibrary/src/MyLibrary/Controller/ConsoleController.php(49): MyLibrary\Controller\ConsoleController->prepareAndRunTasks(Array, 'FeedUpload\Cont...')
#12 /var/www/my_application/vendor/zendframework/zendframework/library/Zend/Mvc/Controller/AbstractActionController.php(83): MyLibrary\Controller\ConsoleController->startAction()
#13 [internal function]: Zend\Mvc\Controller\AbstractActionController->onDispatch(Object(Zend\Mvc\MvcEvent))
#14 /var/www/my_application/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
#15 /var/www/my_application/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#16 /var/www/my_application/vendor/zendframework/zendframework/library/Zend/Mvc/Controller/AbstractController.php(117): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#17 /var/www/my_application/vendor/zendframework/zendframework/library/Zend/Mvc/DispatchListener.php(114): Zend\Mvc\Controller\AbstractController->dispatch(Object(Zend\Console\Request), Object(Zend\Console\Response))
#18 [internal function]: Zend\Mvc\DispatchListener->onDispatch(Object(Zend\Mvc\MvcEvent))
#19 /var/www/my_application/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
#20 /var/www/my_application/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#21 /var/www/my_application/vendor/zendframework/zendframework/library/Zend/Mvc/Application.php(313): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#22 /var/www/my_application/public/index.php(23): Zend\Mvc\Application->run()
```