doc: Use Params::getRequired() in ModuleController

refs #9644
This commit is contained in:
Eric Lippmann 2015-07-28 13:59:59 +02:00
parent 794e4a1e1e
commit 5c5dea616d

View File

@ -10,16 +10,15 @@ class Doc_ModuleController extends DocController
/** /**
* Get the path to a module documentation * Get the path to a module documentation
* *
* @param string $module The name of the module * @param string $module The name of the module
* @param string $default The default path * @param string $default The default path
* @param bool $suppressErrors Whether to not throw an exception if the module documentation is not * @param bool $suppressErrors Whether to not throw an exception if the module documentation is not available
* available
* *
* @return string|null Path to the documentation or null if the module documentation is not * @return string|null Path to the documentation or null if the module documentation is not available
* available and errors are suppressed * and errors are suppressed
* *
* @throws Zend_Controller_Action_Exception If the module documentation is not available and errors are not * @throws \Icinga\Exception\Http\HttpNotFoundException If the module documentation is not available and errors
* suppressed * are not suppressed
*/ */
protected function getPath($module, $default, $suppressErrors = false) protected function getPath($module, $default, $suppressErrors = false)
{ {
@ -59,17 +58,10 @@ class Doc_ModuleController extends DocController
* *
* @param string $moduleName * @param string $moduleName
* *
* @throws Zend_Controller_Action_Exception If the required parameter 'moduleName' is empty or if the * @throws \Icinga\Exception\Http\HttpNotFoundException If the given module is not installed
* given module is not installed
*/ */
protected function assertModuleInstalled($moduleName) protected function assertModuleInstalled($moduleName)
{ {
if (empty($moduleName)) {
throw new Zend_Controller_Action_Exception(
sprintf($this->translate('Missing parameter \'%s\''), 'moduleName'),
404
);
}
$moduleManager = Icinga::app()->getModuleManager(); $moduleManager = Icinga::app()->getModuleManager();
if (! $moduleManager->hasInstalled($moduleName)) { if (! $moduleManager->hasInstalled($moduleName)) {
$this->httpNotFound($this->translate('Module \'%s\' is not installed'), $moduleName); $this->httpNotFound($this->translate('Module \'%s\' is not installed'), $moduleName);
@ -79,11 +71,13 @@ class Doc_ModuleController extends DocController
/** /**
* View the toc of a module's documentation * View the toc of a module's documentation
* *
* @see assertModuleInstalled() * @throws \Icinga\Exception\MissingParameterException If the required parameter 'moduleName' is empty
* @throws \Icinga\Exception\Http\HttpNotFoundException If the given module is not installed
* @see assertModuleInstalled()
*/ */
public function tocAction() public function tocAction()
{ {
$module = $this->getParam('moduleName'); $module = $this->params->getRequired('moduleName');
$this->assertModuleInstalled($module); $this->assertModuleInstalled($module);
$this->view->moduleName = $module; $this->view->moduleName = $module;
try { try {
@ -101,21 +95,16 @@ class Doc_ModuleController extends DocController
/** /**
* View a chapter of a module's documentation * View a chapter of a module's documentation
* *
* @throws Zend_Controller_Action_Exception If the required parameter 'chapterId' is missing or if an error in * @throws \Icinga\Exception\MissingParameterException If one of the required parameters 'moduleName' and
* the documentation module's library occurs * 'chapter' is empty
* @throws \Icinga\Exception\Http\HttpNotFoundException If the given module is not installed
* @see assertModuleInstalled() * @see assertModuleInstalled()
*/ */
public function chapterAction() public function chapterAction()
{ {
$module = $this->getParam('moduleName'); $module = $this->params->getRequired('moduleName');
$this->assertModuleInstalled($module); $this->assertModuleInstalled($module);
$chapter = $this->getParam('chapter'); $chapter = $this->params->getRequired('chapter');
if ($chapter === null) {
throw new Zend_Controller_Action_Exception(
sprintf($this->translate('Missing parameter %s'), 'chapter'),
404
);
}
$this->view->moduleName = $module; $this->view->moduleName = $module;
try { try {
$this->renderChapter( $this->renderChapter(
@ -132,11 +121,13 @@ class Doc_ModuleController extends DocController
/** /**
* View a module's documentation as PDF * View a module's documentation as PDF
* *
* @see assertModuleInstalled() * @throws \Icinga\Exception\MissingParameterException If the required parameter 'moduleName' is empty
* @throws \Icinga\Exception\Http\HttpNotFoundException If the given module is not installed
* @see assertModuleInstalled()
*/ */
public function pdfAction() public function pdfAction()
{ {
$module = $this->getParam('moduleName'); $module = $this->params->getRequired('moduleName');
$this->assertModuleInstalled($module); $this->assertModuleInstalled($module);
$this->renderPdf( $this->renderPdf(
$this->getPath($module, Icinga::app()->getModuleManager()->getModuleDir($module, '/doc')), $this->getPath($module, Icinga::app()->getModuleManager()->getModuleDir($module, '/doc')),