Pull out functionality

This commit is contained in:
Dennis Eichhorn 2018-07-07 18:56:46 +02:00
parent bc08e052eb
commit 1823076513

View File

@ -116,17 +116,7 @@ final class Controller extends ModuleAbstract implements WebInterface
public function viewHelpGeneral(RequestAbstract $request, ResponseAbstract $response, $data = null) : \Serializable
{
$view = new View($this->app, $request, $response);
if ($request->getData('page') === 'README' || $request->getData('page') === null) {
$path = \realpath(__DIR__ . '/../../Documentation/README.md');
} else {
$path = \realpath(__DIR__ . '/../../Documentation/' . $request->getData('page') . '.md');
}
if ($path === false) {
$response->getHeader()->setStatusCode(RequestStatusCode::R_403);
$path = \realpath(__DIR__ . '/../../Documentation/README.md');
}
$path = $this->getHelpGeneralPath($request);
$content = Markdown::parse(\file_get_contents($path));
$navigation = Markdown::parse(\file_get_contents(__DIR__ . '/../../Documentation/SUMMARY.md'));
@ -138,6 +128,31 @@ final class Controller extends ModuleAbstract implements WebInterface
return $view;
}
/**
* Create markdown parsing path
*
* @param RequestAbstract $request Request
*
* @return string
*
* @since 1.0.0
* @codeCoverageIgnore
*/
private function getHelpGeneralPath(RequestAbstract $request) : string
{
if ($request->getData('page') === 'README' || $request->getData('page') === null) {
$path = \realpath(__DIR__ . '/../../Documentation/README.md');
} else {
$path = \realpath(__DIR__ . '/../../Documentation/' . $request->getData('page') . '.md');
}
if ($path === false) {
$path = \realpath(__DIR__ . '/../../Documentation/README.md');
}
return $path;
}
/**
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
@ -175,7 +190,30 @@ final class Controller extends ModuleAbstract implements WebInterface
}
$view = new View($this->app, $request, $response);
$path = $this->getHelpModulePath($request);
$content = Markdown::parse(\file_get_contents($path));
$navigation = Markdown::parse(\file_get_contents(\realpath(__DIR__ . '/../' . $request->getData('id') . '/Docs/Help/en/SUMMARY.md')));
$view->setTemplate('/Modules/Help/Theme/Backend/help-module');
$view->setData('content', $content);
$view->setData('navigation', $navigation);
return $view;
}
/**
* Create markdown parsing path
*
* @param RequestAbstract $request Request
*
* @return string
*
* @since 1.0.0
* @codeCoverageIgnore
*/
private function getHelpModulePath(RequestAbstract $request) : string
{
if ($request->getData('page') === 'table-of-contencts' || $request->getData('page') === null) {
$path = \realpath(__DIR__ . '/../' . $request->getData('id') . '/Docs/introduction.md');
} else {
@ -183,19 +221,10 @@ final class Controller extends ModuleAbstract implements WebInterface
}
if ($path === false) {
$view->setTemplate('/Web/Backend/Error/403_inline');
$response->getHeader()->setStatusCode(RequestStatusCode::R_403);
return $view;
$path = \realpath(__DIR__ . '/../' . $request->getData('id') . '/Docs/introduction.md');
}
$content = Markdown::parse(\file_get_contents($path));
$navigation = Markdown::parse(\file_get_contents(\realpath(__DIR__ . '/../' . $request->getData('id') . '/Docs/Help/en/table_of_contents.md')));
$view->setTemplate('/Modules/Help/Theme/Backend/help-module');
$view->setData('content', $content);
$view->setData('navigation', $navigation);
return $view;
return $path;
}
/**
@ -211,17 +240,7 @@ final class Controller extends ModuleAbstract implements WebInterface
public function viewHelpDeveloper(RequestAbstract $request, ResponseAbstract $response, $data = null) : \Serializable
{
$view = new View($this->app, $request, $response);
if ($request->getData('page') === 'README' || $request->getData('page') === null) {
$path = \realpath(__DIR__ . '/../../Developer-Guide/README.md');
} else {
$path = \realpath(__DIR__ . '/../../Developer-Guide/' . $request->getData('page') . '.md');
}
if ($path === false) {
$response->getHeader()->setStatusCode(RequestStatusCode::R_403);
$path = \realpath(__DIR__ . '/../../Developer-Guide/README.md');
}
$path = $this->getHelpDeveloperPath($request);
$content = Markdown::parse(\file_get_contents($path));
$navigation = Markdown::parse(\file_get_contents(__DIR__ . '/../../Developer-Guide/SUMMARY.md'));
@ -232,4 +251,29 @@ final class Controller extends ModuleAbstract implements WebInterface
return $view;
}
/**
* Create markdown parsing path
*
* @param RequestAbstract $request Request
*
* @return string
*
* @since 1.0.0
* @codeCoverageIgnore
*/
private function getHelpDeveloperPath(RequestAbstract $request) : string
{
if ($request->getData('page') === 'README' || $request->getData('page') === null) {
$path = \realpath(__DIR__ . '/../../Developer-Guide/README.md');
} else {
$path = \realpath(__DIR__ . '/../../Developer-Guide/' . $request->getData('page') . '.md');
}
if ($path === false) {
$path = \realpath(__DIR__ . '/../../Developer-Guide/README.md');
}
return $path;
}
}