* For example, navigating to /commodity/ displays the available functions. * This is included from ../private/summary.php */ /* * This is used to display a summary of functions available for a * particular sub-directory. For example, /v1/ itself uses this. */ function buildApiIndex($path, &$results) { global $basePath; // Scan the sub-directories: $files = scandir($basePath . $path); foreach ($files as $fileName) { if (strstr($fileName, '.')) { // Ignore all files, . and .. continue; } // The folder is, for example, entity/create. // We know it's an API function if the folder contains a summary.json file in it. // Otherwise, we recurse further. $folder = $path . '/' . $fileName; if (file_exists($basePath . $folder . '/summary.json')) { if (file_exists($basePath . $folder . '/index.php')) { // API function found! We just add the full folder for now. // Note that this will be e.g. '/v1/entity/create' array_push($results['functions'], $folder); } else { // Otherwise we have a type definition, such as an error. array_push($results['types'], $folder); } } else {
<?php // Include the index functionality: include '../private/Functions/index.php'; // The index consists of functions and types. Build a set to collect them into. $set = array('functions' => array(), 'types' => array()); // The sub-directory we're on is $path. Find the functions for this path and put them into $set: buildApiIndex($path, $set); echo '{'; // Output the functions: outputIndex('functions', $set['functions']); echo ','; // Output the types: outputIndex('types', $set['types']); echo '}'; // These results should be cached - the response is always the same so: // cache();