public function work($json) { if (!isset($json['project'])) { return; } if (!isset($json['body']['version']) || !isset($json['body']['remote_path'])) { return; } if (!isset($json['body']['version']['Major']) || !isset($json['body']['version']['Minor']) || !isset($json['body']['version']['Build'])) { return; } $remote_path = $json['body']['remote_path']; $project = $json['project']; $version = versionToString($json['body']['version']['Major'], $json['body']['version']['Minor'], $json['body']['version']['Build']); if (!projectExists($project, $this->config) || !versionExists($version, $json['project'], $this->config)) { $this->error('NOT_FOUND'); return; } $path_before_version = getPathToProject($project, $this->config) . DIRECTORY_SEPARATOR; $path_after_version = DIRECTORY_SEPARATOR . $remote_path; $file_path = $path_before_version . $version . $path_after_version; if (file_exists($file_path)) { $this->setResponseAsFile(); $this->setContent(file_get_contents($file_path)); return; } else { $lowerVersions = array_reverse(versionsLower($version, $project, $this->config)); foreach ($lowerVersions as $v) { $newPath = $path_before_version . $v . $path_after_version; if (file_exists($newPath)) { $this->setResponseAsFile(); $this->setContent(file_get_contents($newPath)); return; } } $this->error('NOT_FOUND'); $this->addBody("path", $file_path); $this->addBody("rel", $remote_path); } }
function projectExists($project, $config) { $project_dir = getPathToProject($project, $config); if (file_exists($project_dir)) { return true; } return false; }