From 537708836351e213c6482ac4765ad2222e458b18 Mon Sep 17 00:00:00 2001 From: Jamie Snape Date: Tue, 2 Dec 2014 09:52:16 -0500 Subject: [PATCH] Replace use of glob in API docs since it not available on App Engine --- core/controllers/ApidocsController.php | 2 +- .../components/ApidocsComponent.php | 23 +++++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/core/controllers/ApidocsController.php b/core/controllers/ApidocsController.php index da004dbb5..9bea91085 100644 --- a/core/controllers/ApidocsController.php +++ b/core/controllers/ApidocsController.php @@ -49,7 +49,7 @@ public function indexAction() } $curResource = array(); $curResource['path'] = $resourcePath; - $curResource['discription'] = 'Operations about '.$resourcePath; + $curResource['description'] = 'Operations on the '.$resourcePath.' resource'; array_push($results['apis'], $curResource); } echo JsonComponent::encode($results); diff --git a/core/controllers/components/ApidocsComponent.php b/core/controllers/components/ApidocsComponent.php index 78c41c89c..7462c29e1 100644 --- a/core/controllers/components/ApidocsComponent.php +++ b/core/controllers/components/ApidocsComponent.php @@ -31,21 +31,26 @@ public function getEnabledResources() { $apiResources = array(); - foreach (glob(BASE_PATH.'/core/controllers/components/Api*.php') as $filename) { - $resoucename = preg_replace('/Component\.php/', '', substr(basename($filename), 3)); - if (!in_array($resoucename, array('helper', 'docs'))) { - $apiResources[] = '/'.$resoucename; + $directory = new DirectoryIterator(BASE_PATH.'/core/controllers/components'); + $matches = new RegexIterator($directory, '#Api(.*)Component\.php$#', RegexIterator::GET_MATCH); + + foreach ($matches as $match) { + if (!in_array($match[1], array('helper', 'docs'))) { + $apiResources[] = '/'.$match[1]; } } $modulesHaveApi = Zend_Registry::get('modulesHaveApi'); $enabledModules = Zend_Registry::get('modulesEnable'); $apiModules = array_intersect($modulesHaveApi, $enabledModules); + foreach ($apiModules as $apiModule) { - foreach (glob(BASE_PATH.'/modules/'.$apiModule.'/controllers/components/Api*.php') as $filename) { - $resourceName = preg_replace('/Component\.php/', '', substr(basename($filename), 3)); - if (!in_array($resourceName, array(''))) { - $apiResources[] = $apiModule.'/'.$resourceName; + $directory = new DirectoryIterator(BASE_PATH.'/modules/'.$apiModule.'/controllers/components'); + $matches = new RegexIterator($directory, '#Api(.*)Component\.php$#', RegexIterator::GET_MATCH); + + foreach ($matches as $match) { + if (!in_array($match[1], array(''))) { + $apiResources[] = $apiModule.'/'.$match[1]; } } } @@ -147,7 +152,7 @@ public function getResourceApiDocs($resource, $module = '') 'name' => 'useSession', 'paramType' => 'query', 'required' => false, - 'description' => 'Authenticate using the current Midas session', + 'description' => 'Authenticate using the current session', 'allowMultiple' => false, 'dataType' => 'string', );