Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit 5377088

Browse files
author
Jamie Snape
committed
Replace use of glob in API docs since it not available on App Engine
1 parent a4c1a86 commit 5377088

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

core/controllers/ApidocsController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function indexAction()
4949
}
5050
$curResource = array();
5151
$curResource['path'] = $resourcePath;
52-
$curResource['discription'] = 'Operations about '.$resourcePath;
52+
$curResource['description'] = 'Operations on the '.$resourcePath.' resource';
5353
array_push($results['apis'], $curResource);
5454
}
5555
echo JsonComponent::encode($results);

core/controllers/components/ApidocsComponent.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,26 @@ public function getEnabledResources()
3131
{
3232
$apiResources = array();
3333

34-
foreach (glob(BASE_PATH.'/core/controllers/components/Api*.php') as $filename) {
35-
$resoucename = preg_replace('/Component\.php/', '', substr(basename($filename), 3));
36-
if (!in_array($resoucename, array('helper', 'docs'))) {
37-
$apiResources[] = '/'.$resoucename;
34+
$directory = new DirectoryIterator(BASE_PATH.'/core/controllers/components');
35+
$matches = new RegexIterator($directory, '#Api(.*)Component\.php$#', RegexIterator::GET_MATCH);
36+
37+
foreach ($matches as $match) {
38+
if (!in_array($match[1], array('helper', 'docs'))) {
39+
$apiResources[] = '/'.$match[1];
3840
}
3941
}
4042

4143
$modulesHaveApi = Zend_Registry::get('modulesHaveApi');
4244
$enabledModules = Zend_Registry::get('modulesEnable');
4345
$apiModules = array_intersect($modulesHaveApi, $enabledModules);
46+
4447
foreach ($apiModules as $apiModule) {
45-
foreach (glob(BASE_PATH.'/modules/'.$apiModule.'/controllers/components/Api*.php') as $filename) {
46-
$resourceName = preg_replace('/Component\.php/', '', substr(basename($filename), 3));
47-
if (!in_array($resourceName, array(''))) {
48-
$apiResources[] = $apiModule.'/'.$resourceName;
48+
$directory = new DirectoryIterator(BASE_PATH.'/modules/'.$apiModule.'/controllers/components');
49+
$matches = new RegexIterator($directory, '#Api(.*)Component\.php$#', RegexIterator::GET_MATCH);
50+
51+
foreach ($matches as $match) {
52+
if (!in_array($match[1], array(''))) {
53+
$apiResources[] = $apiModule.'/'.$match[1];
4954
}
5055
}
5156
}
@@ -147,7 +152,7 @@ public function getResourceApiDocs($resource, $module = '')
147152
'name' => 'useSession',
148153
'paramType' => 'query',
149154
'required' => false,
150-
'description' => 'Authenticate using the current Midas session',
155+
'description' => 'Authenticate using the current session',
151156
'allowMultiple' => false,
152157
'dataType' => 'string',
153158
);

0 commit comments

Comments
 (0)