Skip to content

Commit c1c123d

Browse files
committed
Internal references on other packages, configuration fix
1 parent 0adde50 commit c1c123d

File tree

10 files changed

+648
-632
lines changed

10 files changed

+648
-632
lines changed

Classes/TechDivision/DocViewer/AccessManager.php

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,30 @@
1111
class AccessManager extends AbstractModuleController
1212
{
1313

14-
/**
15-
* Files which are used as entry files
16-
* @Flow\InjectConfiguration("packages")
17-
* @var array
18-
*/
19-
protected $packagesConfiguration;
14+
/**
15+
* Files which are used as entry files
16+
* @Flow\InjectConfiguration("packages")
17+
* @var array
18+
*/
19+
protected $packagesConfiguration;
2020

21-
/**
22-
* @Flow\Inject
23-
* @var \Neos\Flow\Package\PackageManagerInterface
24-
*/
25-
protected $packageManager;
21+
/**
22+
* @Flow\Inject
23+
* @var \Neos\Flow\Package\PackageManagerInterface
24+
*/
25+
protected $packageManager;
2626

27-
/**
28-
* Determines if given package key should be accessable
29-
*
30-
* @param string $packageKey
31-
* @return bool
32-
*/
33-
public function isPackageAccessable($packageKey) {
34-
return $this->packageManager->isPackageActive($packageKey) && !in_array($packageKey, $this->packagesConfiguration['hide']);
35-
}
27+
/**
28+
* Determines if given package key should be accessable
29+
*
30+
* @param string $packageKey
31+
* @return bool
32+
*/
33+
public function isPackageAccessable($packageKey) {
34+
return $this->packageManager->isPackageActive($packageKey) &&
35+
(!array_key_exists($packageKey, $this->packagesConfiguration['hide']) ||
36+
!$this->packagesConfiguration['hide'][$packageKey]
37+
);
38+
}
3639

3740
}

Classes/TechDivision/DocViewer/Controller/ModuleController.php

Lines changed: 118 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -18,122 +18,122 @@
1818
class ModuleController extends AbstractModuleController
1919
{
2020

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+
}
139139
}

Classes/TechDivision/DocViewer/Controller/ResourceController.php

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77
use TechDivision\DocViewer\Exceptions\FileNotInsideDocumentationException;
88
use TechDivision\DocViewer\Exceptions\PackageNotAccessibleException;
9-
use TechDivision\DocViewer\File\Parser;
109
use TechDivision\DocViewer\Util;
1110
use Neos\Flow\Annotations as Flow;
1211

@@ -20,44 +19,46 @@
2019
class ResourceController extends \Neos\Flow\Mvc\Controller\ActionController
2120
{
2221

23-
/**
24-
* @Flow\Inject
25-
* @var \TechDivision\DocViewer\AccessManager
26-
*/
27-
protected $accessManager;
28-
29-
/**
30-
* @Flow\Inject
31-
* @var \Neos\Flow\Package\PackageManagerInterface
32-
*/
33-
protected $packageManager;
34-
35-
/**
36-
* Serves static files
37-
*
38-
* @param string $package
39-
* @param string $filePath
40-
* @return mixed
41-
*/
42-
public function rawAction($package, $filePath) {
43-
44-
// check if given package is valid
45-
if (!$this->accessManager->isPackageAccessable($package)) {
46-
throw new PackageNotAccessibleException("You are not allowed to access the package " . $package);
47-
}
48-
49-
$docDir = Util::getDocumentPath($this->packageManager->getPackage($package));
50-
$filePath = realpath($docDir . DIRECTORY_SEPARATOR . Util::urlDecodeFilePath($filePath));
51-
52-
// take care given file path is sub path of the doc dir of the package
53-
if(strpos($filePath, $docDir) < 0 || strpos($filePath, $docDir) === false) {
54-
throw new FileNotInsideDocumentationException("You are not allowed to access files outside the documentation folder");
55-
}
56-
57-
$contentType = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $filePath);
58-
$this->response->setHeader("Content-Type", $contentType);
59-
60-
return file_get_contents($filePath);
61-
62-
}
22+
/**
23+
* @Flow\Inject
24+
* @var \TechDivision\DocViewer\AccessManager
25+
*/
26+
protected $accessManager;
27+
28+
/**
29+
* @Flow\Inject
30+
* @var \Neos\Flow\Package\PackageManagerInterface
31+
*/
32+
protected $packageManager;
33+
34+
/**
35+
* Serves static files
36+
*
37+
* @param string $package
38+
* @param string $filePath
39+
* @return mixed
40+
* @throws PackageNotAccessibleException
41+
* @throws FileNotInsideDocumentationException
42+
*/
43+
public function rawAction($package, $filePath) {
44+
45+
// check if given package is valid
46+
if (!$this->accessManager->isPackageAccessable($package)) {
47+
throw new PackageNotAccessibleException("You are not allowed to access the package " . $package);
48+
}
49+
50+
$docDir = Util::getDocumentPath($this->packageManager->getPackage($package));
51+
$filePath = realpath($docDir . DIRECTORY_SEPARATOR . Util::urlDecodeFilePath($filePath));
52+
53+
// take care given file path is sub path of the doc dir of the package
54+
if(strpos($filePath, $docDir) < 0 || strpos($filePath, $docDir) === false) {
55+
throw new FileNotInsideDocumentationException("You are not allowed to access files outside the documentation folder");
56+
}
57+
58+
$contentType = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $filePath);
59+
$this->response->setHeader("Content-Type", $contentType);
60+
61+
return file_get_contents($filePath);
62+
63+
}
6364
}

0 commit comments

Comments
 (0)