|
| 1 | +<?php namespace App\Http\Controllers; |
| 2 | + |
| 3 | +use App\Documentation; |
| 4 | +use Illuminate\Routing\Controller; |
| 5 | +use Illuminate\Contracts\Cache\Cache; |
| 6 | +use Illuminate\Contracts\Filesystem\Filesystem; |
| 7 | + |
| 8 | +class DocsController extends Controller { |
| 9 | + |
| 10 | + /** |
| 11 | + * The documentation repository. |
| 12 | + * |
| 13 | + * @var Documentation |
| 14 | + */ |
| 15 | + protected $docs; |
| 16 | + |
| 17 | + /** |
| 18 | + * Create a new controller instance. |
| 19 | + * |
| 20 | + * @param Documentation $docs |
| 21 | + * @return void |
| 22 | + */ |
| 23 | + public function __construct(Documentation $docs) |
| 24 | + { |
| 25 | + $this->docs = $docs; |
| 26 | + } |
| 27 | + |
| 28 | + /** |
| 29 | + * Show the root documentation page (/docs). |
| 30 | + * |
| 31 | + * @return Response |
| 32 | + */ |
| 33 | + public function showRootPage() |
| 34 | + { |
| 35 | + return redirect(url('docs/'.DEFAULT_VERSION)); |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * Show a documentation page. |
| 40 | + * |
| 41 | + * @return Response |
| 42 | + */ |
| 43 | + public function show($version, $page = null) |
| 44 | + { |
| 45 | + if ( ! $this->isVersion($version)) { |
| 46 | + return redirect(url('docs/'.DEFAULT_VERSION.'/'.$version)); |
| 47 | + } |
| 48 | + |
| 49 | + return view('layouts.docs', [ |
| 50 | + 'index' => $this->docs->getIndex($version), |
| 51 | + 'content' => $this->docs->get($version, $page ?: 'introduction'), |
| 52 | + 'currentVersion' => $version, |
| 53 | + 'versions' => $this->getDocVersions(), |
| 54 | + ]); |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * Determine if the given URL segment is a valid version. |
| 59 | + * |
| 60 | + * @param string $version |
| 61 | + * @return bool |
| 62 | + */ |
| 63 | + protected function isVersion($version) |
| 64 | + { |
| 65 | + return in_array($version, ['dev', '5.0', '4.2', '4.1', '4.0']); |
| 66 | + } |
| 67 | + |
| 68 | + /** |
| 69 | + * Get the available documentation versions. |
| 70 | + * |
| 71 | + * @return array |
| 72 | + */ |
| 73 | + protected function getDocVersions() |
| 74 | + { |
| 75 | + return [ |
| 76 | + 'master' => 'Dev', |
| 77 | + '4.2' => '4.2', |
| 78 | + '4.1' => '4.1', |
| 79 | + '4.0' => '4.0', |
| 80 | + ]; |
| 81 | + } |
| 82 | + |
| 83 | +} |
0 commit comments