|
18 | 18 | class ModuleController extends AbstractModuleController |
19 | 19 | { |
20 | 20 |
|
21 | | - /** |
22 | | - * @Flow\Inject |
23 | | - * @var \Neos\Flow\Package\PackageManagerInterface |
24 | | - */ |
25 | | - protected $packageManager; |
26 | | - |
27 | | - /** |
28 | | - * Files which are used as entry files |
29 | | - * @Flow\InjectConfiguration("packages") |
30 | | - * @var array |
31 | | - */ |
32 | | - protected $packagesConfiguration; |
33 | | - |
34 | | - /** |
35 | | - * @Flow\Inject |
36 | | - * @var \TechDivision\DocViewer\AccessManager |
37 | | - */ |
38 | | - protected $accessManager; |
39 | | - |
40 | | - /** |
41 | | - * Routes to list or show action depending on configuration |
42 | | - * @return void |
43 | | - */ |
44 | | - public function indexAction() { |
45 | | - if(isset($this->packagesConfiguration['entryPackage']) && $this->accessManager->isPackageAccessable($this->packagesConfiguration['entryPackage'])) { |
46 | | - $this->forward('show', null, null, array('package' => $this->packagesConfiguration['entryPackage'])); |
47 | | - } else { |
48 | | - $this->forward('list'); |
49 | | - } |
50 | | - } |
51 | | - |
52 | | - /** |
53 | | - * Lists packages with documentation depending on configuration |
54 | | - * @return void |
55 | | - */ |
56 | | - public function listAction() { |
57 | | - |
58 | | - $packageGroups = array(); |
59 | | - |
60 | | - foreach($this->packagesConfiguration['visibleTypes'] as $type) { |
61 | | - $packageGroups[$type] = array(); |
62 | | - } |
63 | | - foreach ($this->packageManager->getAvailablePackages() as $package) { |
64 | | - |
65 | | - if(!$this->accessManager->isPackageAccessable($package->getPackageKey())) { |
66 | | - continue; |
67 | | - } |
68 | | - |
69 | | - /** @var Package $package */ |
70 | | - $packagePath = substr($package->getPackagepath(), strlen(FLOW_PATH_PACKAGES)); |
71 | | - $packageGroup = substr($packagePath, 0, strpos($packagePath, '/')); |
72 | | - |
73 | | - if(!in_array($packageGroup, $this->packagesConfiguration['visibleTypes'])) { |
74 | | - continue; |
75 | | - } |
76 | | - |
77 | | - $tree = new Tree($package, $this->controllerContext->getRequest()->getHttpRequest()->getBaseUri()); |
78 | | - |
79 | | - if(!$tree->isDirectoryWithContent()) { |
80 | | - continue; |
81 | | - } |
82 | | - |
83 | | - $packageGroups[$packageGroup][$package->getPackageKey()] = array( |
84 | | - 'sanitizedPackageKey' => str_replace('.', '', $package->getPackageKey()), |
85 | | - 'version' => $package->getInstalledVersion(), |
86 | | - 'name' => $package->getComposerManifest('name'), |
87 | | - 'type' => $package->getComposerManifest('type'), |
88 | | - //'description' => $package->getPackageMetaData()->getDescription() |
89 | | - 'description' => $package->getComposerManifest('description') |
90 | | - ); |
91 | | - |
92 | | - } |
93 | | - |
94 | | - $this->view->assign('projectVersion', $this->packageManager->getPackage('TechDivision.DocViewer')->getInstalledVersion()); |
95 | | - $this->view->assign('packageGroups', $packageGroups); |
96 | | - } |
97 | | - |
98 | | - /** |
99 | | - * Shows documentation of given package |
100 | | - * @param string $package |
101 | | - * @param string $filePath |
102 | | - * @throws PackageNotAccessibleException |
103 | | - * @return void |
104 | | - */ |
105 | | - public function showAction($package, $filePath = null) { |
106 | | - $baseUri = $this->controllerContext->getRequest()->getHttpRequest()->getBaseUri(); |
107 | | - |
108 | | - if (!$this->accessManager->isPackageAccessable($package)) { |
109 | | - throw new PackageNotAccessibleException("You are not allowed to access the package " . $package); |
110 | | - } |
111 | | - $package = $this->packageManager->getPackage($package); |
112 | | - $this->view->assign('packageKey', $package->getPackageKey()); |
113 | | - |
114 | | - $tree = new Tree($package, $baseUri); |
115 | | - |
116 | | - if(!$tree->isDirectoryWithContent()) { |
117 | | - $this->addFlashMessage('No documention could be found'); |
118 | | - } |
119 | | - $this->view->assign('node', $tree->getRootNode()); |
120 | | - |
121 | | - if($filePath) { |
122 | | - $file = $tree->findFileNodeByPath($filePath); |
123 | | - }else { |
124 | | - $file = $tree->findEntryFile(); |
125 | | - } |
126 | | - |
127 | | - if($file) { |
128 | | - $parser = new Parser($baseUri, $this->getControllerContext()); |
129 | | - $this->view->assign('currentFile', $file); |
130 | | - try { |
131 | | - $documentContent = $parser->parseFile($file); |
132 | | - $this->view->assign('doc', $documentContent); |
133 | | - }catch (ParsingNotAllowedException $e) { |
134 | | - $this->addFlashMessage($e->getMessage()); |
135 | | - } |
136 | | - } |
137 | | - $this->view->assign('projectVersion', $this->packageManager->getPackage('TechDivision.DocViewer')->getInstalledVersion()); |
138 | | - } |
| 21 | + /** |
| 22 | + * @Flow\Inject |
| 23 | + * @var \Neos\Flow\Package\PackageManagerInterface |
| 24 | + */ |
| 25 | + protected $packageManager; |
| 26 | + |
| 27 | + /** |
| 28 | + * Files which are used as entry files |
| 29 | + * @Flow\InjectConfiguration("packages") |
| 30 | + * @var array |
| 31 | + */ |
| 32 | + protected $packagesConfiguration; |
| 33 | + |
| 34 | + /** |
| 35 | + * @Flow\Inject |
| 36 | + * @var \TechDivision\DocViewer\AccessManager |
| 37 | + */ |
| 38 | + protected $accessManager; |
| 39 | + |
| 40 | + /** |
| 41 | + * Routes to list or show action depending on configuration |
| 42 | + * @return void |
| 43 | + */ |
| 44 | + public function indexAction() { |
| 45 | + if(isset($this->packagesConfiguration['entryPackage']) && $this->accessManager->isPackageAccessable($this->packagesConfiguration['entryPackage'])) { |
| 46 | + $this->forward('show', null, null, array('package' => $this->packagesConfiguration['entryPackage'])); |
| 47 | + } else { |
| 48 | + $this->forward('list'); |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * Lists packages with documentation depending on configuration |
| 54 | + * @return void |
| 55 | + */ |
| 56 | + public function listAction() { |
| 57 | + |
| 58 | + $packageGroups = array(); |
| 59 | + |
| 60 | + foreach($this->packagesConfiguration['visibleTypes'] as $type) { |
| 61 | + $packageGroups[$type] = array(); |
| 62 | + } |
| 63 | + foreach ($this->packageManager->getAvailablePackages() as $package) { |
| 64 | + |
| 65 | + if(!$this->accessManager->isPackageAccessable($package->getPackageKey())) { |
| 66 | + continue; |
| 67 | + } |
| 68 | + |
| 69 | + /** @var Package $package */ |
| 70 | + $packagePath = substr($package->getPackagepath(), strlen(FLOW_PATH_PACKAGES)); |
| 71 | + $packageGroup = substr($packagePath, 0, strpos($packagePath, '/')); |
| 72 | + |
| 73 | + if(!in_array($packageGroup, $this->packagesConfiguration['visibleTypes'])) { |
| 74 | + continue; |
| 75 | + } |
| 76 | + |
| 77 | + $tree = new Tree($package, $this->controllerContext->getRequest()->getHttpRequest()->getBaseUri()); |
| 78 | + |
| 79 | + if(!$tree->isDirectoryWithContent()) { |
| 80 | + continue; |
| 81 | + } |
| 82 | + |
| 83 | + $packageGroups[$packageGroup][$package->getPackageKey()] = array( |
| 84 | + 'sanitizedPackageKey' => str_replace('.', '', $package->getPackageKey()), |
| 85 | + 'version' => $package->getInstalledVersion(), |
| 86 | + 'name' => $package->getComposerManifest('name'), |
| 87 | + 'type' => $package->getComposerManifest('type'), |
| 88 | + //'description' => $package->getPackageMetaData()->getDescription() |
| 89 | + 'description' => $package->getComposerManifest('description') |
| 90 | + ); |
| 91 | + |
| 92 | + } |
| 93 | + |
| 94 | + $this->view->assign('projectVersion', $this->packageManager->getPackage('TechDivision.DocViewer')->getInstalledVersion()); |
| 95 | + $this->view->assign('packageGroups', $packageGroups); |
| 96 | + } |
| 97 | + |
| 98 | + /** |
| 99 | + * Shows documentation of given package |
| 100 | + * @param string $package |
| 101 | + * @param string $filePath |
| 102 | + * @throws PackageNotAccessibleException |
| 103 | + * @return void |
| 104 | + */ |
| 105 | + public function showAction($package, $filePath = null) { |
| 106 | + $baseUri = $this->controllerContext->getRequest()->getHttpRequest()->getBaseUri(); |
| 107 | + |
| 108 | + if (!$this->accessManager->isPackageAccessable($package)) { |
| 109 | + throw new PackageNotAccessibleException("You are not allowed to access the package " . $package); |
| 110 | + } |
| 111 | + $package = $this->packageManager->getPackage($package); |
| 112 | + $this->view->assign('packageKey', $package->getPackageKey()); |
| 113 | + |
| 114 | + $tree = new Tree($package, $baseUri); |
| 115 | + |
| 116 | + if(!$tree->isDirectoryWithContent()) { |
| 117 | + $this->addFlashMessage('No documention could be found'); |
| 118 | + } |
| 119 | + $this->view->assign('node', $tree->getRootNode()); |
| 120 | + |
| 121 | + if($filePath) { |
| 122 | + $file = $tree->findFileNodeByPath($filePath); |
| 123 | + }else { |
| 124 | + $file = $tree->findEntryFile(); |
| 125 | + } |
| 126 | + |
| 127 | + if($file) { |
| 128 | + $parser = new Parser($baseUri, $this->getControllerContext()); |
| 129 | + $this->view->assign('currentFile', $file); |
| 130 | + try { |
| 131 | + $documentContent = $parser->parseFile($file); |
| 132 | + $this->view->assign('doc', $documentContent); |
| 133 | + }catch (ParsingNotAllowedException $e) { |
| 134 | + $this->addFlashMessage($e->getMessage()); |
| 135 | + } |
| 136 | + } |
| 137 | + $this->view->assign('projectVersion', $this->packageManager->getPackage('TechDivision.DocViewer')->getInstalledVersion()); |
| 138 | + } |
139 | 139 | } |
0 commit comments