ylvarw /
module
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Anax\Controller; |
||
| 4 | |||
| 5 | use Anax\Commons\ContainerInjectableInterface; |
||
| 6 | use Anax\Commons\ContainerInjectableTrait; |
||
| 7 | |||
| 8 | /** |
||
| 9 | * A controller for flat file markdown content. |
||
| 10 | */ |
||
| 11 | class FlatFileContentController implements ContainerInjectableInterface |
||
| 12 | { |
||
| 13 | use ContainerInjectableTrait; |
||
| 14 | |||
| 15 | |||
| 16 | |||
| 17 | /** |
||
| 18 | * Render a page using flat file content. |
||
| 19 | * |
||
| 20 | * @param array $args as a variadic to catch all arguments. |
||
| 21 | * |
||
| 22 | * @return mixed as null when flat file is not found and otherwise a |
||
| 23 | * complete response object with content to render. |
||
| 24 | * |
||
| 25 | * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
||
| 26 | */ |
||
| 27 | public function catchAll(...$args) |
||
|
0 ignored issues
–
show
|
|||
| 28 | { |
||
| 29 | // Get the current route and see if it matches a content/file |
||
| 30 | $path = $this->di->get("request")->getRoute(); |
||
| 31 | $file1 = ANAX_INSTALL_PATH . "/content/{$path}.md"; |
||
| 32 | $file2 = ANAX_INSTALL_PATH . "/content/{$path}/index.md"; |
||
| 33 | |||
| 34 | $file = is_file($file1) ? $file1 : null; |
||
| 35 | $file = is_file($file2) ? $file2 : $file; |
||
| 36 | |||
| 37 | if (!$file) { |
||
| 38 | return; |
||
| 39 | } |
||
| 40 | |||
| 41 | // Check that file is really in the right place |
||
| 42 | $real = realpath($file); |
||
| 43 | $base = realpath(ANAX_INSTALL_PATH . "/content/"); |
||
| 44 | if (strncmp($base, $real, strlen($base))) { |
||
| 45 | return; |
||
| 46 | } |
||
| 47 | |||
| 48 | // Get content from markdown file |
||
| 49 | $content = file_get_contents($file); |
||
| 50 | $content = $this->di->get("textfilter")->parse( |
||
| 51 | $content, |
||
| 52 | ["frontmatter", "variable", "shortcode", "markdown", "titlefromheader"] |
||
| 53 | ); |
||
| 54 | |||
| 55 | // Add content as a view and then render the page |
||
| 56 | $page = $this->di->get("page"); |
||
| 57 | $page->add("anax/v2/article/default", [ |
||
| 58 | "content" => $content->text, |
||
| 59 | "frontmatter" => $content->frontmatter, |
||
| 60 | ]); |
||
| 61 | |||
| 62 | return $page->render($content->frontmatter); |
||
| 63 | } |
||
| 64 | } |
||
| 65 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.