public function __construct($discoverPath = null, $outputDir = null, $excludedPath = null, $config_path = null) { Configuration::init(realpath($config_path)); Manual::init(Configuration::get('templatePath')); //Configuration::display(); if (is_null($discoverPath)) { $discoverPath = Configuration::get('discoverPath'); } if (is_null($outputDir)) { $outputDir = Configuration::get('outputDir'); } if (is_null($excludedPath)) { $excludedPath = Configuration::get('excludedPath'); } $this->dirDiscoverer = new DirDiscoverer($discoverPath, $excludedPath); $this->docGener = new StaticSwaggerDocGenerater($outputDir); }
public function gen($resourceList = null, $outputDir = null) { $apiDocs = array(); $dir = is_null($outputDir) ? $this->outputDir : $outputDir; if (false === $this->buildDir($dir)) { die("invalid output path"); } $resourceList = is_null($resourceList) ? $this->resourceList : $resourceList; $apiDocs['apis'] = array(); array_walk($resourceList, function ($resource) use(&$apiDocs, $dir) { $path = $resource['resource']; array_push($apiDocs['apis'], array('path' => $path)); $path = $dir . DIRECTORY_SEPARATOR . substr($path, 1); file_put_contents($path, json_encode($resource, JSON_PRETTY_PRINT)); echo '[Generated] ' . $path . "\n"; }); $path = $dir . DIRECTORY_SEPARATOR . 'api-docs.json'; $apiDocs['apiVersion'] = Configuration::get('apiVersion'); $apiDocs['swaggerVersion'] = Configuration::get('apiVersion'); $apiDocs['basePath'] = Configuration::get('resourceListPath'); file_put_contents($path, json_encode($apiDocs, JSON_PRETTY_PRINT)); echo '[Generated] ' . $path . "\n"; echo '[Done] ^_^' . "\n"; }
public function interprete() { $params = $this->params; //var_dump($params); foreach ($this->manual as $rule) { $key = $rule->key; if ($rule->type === 'interpreter') { $manual = $rule->desc; $params = $this->filterParams($key); if (count($params) === 0) { continue; } if (isset($rule->isArray) && $rule->isArray === true && is_array($params[$key])) { $params = $params[$key]; foreach ($params as $param) { $p = array($key => $param); $interpreter = new Interpreter($p, $this->startNode, Manual::get($manual)); $interpreter->interprete(); } } else { $interpreter = new Interpreter($params, $this->startNode, Manual::get($manual)); $interpreter->interprete(); } } else { if ($rule->type === 'global') { $this->setAttr($key, Configuration::get($key)); } else { if (array_key_exists($key, $params)) { if (isset($params[$key]) && $params[$key] !== null) { switch ($rule->type) { case 'token': $attr = is_null($rule->desc) ? $key : $rule->desc; $this->setAttr($attr, $params[$key]); break; case 'rule': $attrList = explode(' ', $rule->desc); $valueList = explode(' ', $params[$key], count($attrList)); while ($attr = array_shift($attrList)) { $value = array_shift($valueList); $this->setAttr($attr, $value); } break; } } } } } } }