static function run($configData) { self::init($configData); $router = Api_Core_Factory::createRouter(); $controllerName = $router->getControllerName(); $controllerClassName = "Api_Application_{$controllerName}_Controller"; $controller = new $controllerClassName(); $actionName = $router->getActionName(); $action = 'action' . $actionName; if (!method_exists($controller, $action)) { http_response_code(404); Api_Core_Application::end(); } $controller->{$action}(); }
public function actionGetLast() { $domainName = filter_input(INPUT_GET, 'domain_name'); $response = Api_Component_Factory::createResponse(); if (!$this->isHaveAccessForDomain(self::GET_LAST_ACTION, $domainName, INPUT_GET)) { $response->setError(true)->setSuccess(false)->addMessage("access denied"); http_response_code(403); echo $this->renderView('json', array('data' => $response->getData())); Api_Core_Application::end(); } $helper = new Api_Application_Api_Helper_Backup(); $storage = Api_Component_Factory::createFileStorage(); $files = $helper->getLastFileUrl($domainName, $storage); $lastFile = end($files); if (empty($lastFile)) { $response->setError(true)->setSuccess(false)->addMessage("file not found"); http_response_code(404); echo $this->renderView('json', array('data' => $response->getData())); } else { $url = $storage->getFileUrl($lastFile["file"]); if (ob_get_level()) { ob_end_clean(); } header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="' . basename($lastFile["file"]) . '"'); header('Content-transfer-encoding: binary'); // Required? Not sure.. set_time_limit(60 * 50); if ($fd = fopen($url, 'r')) { while (!feof($fd)) { print fread($fd, 1024); } fclose($fd); } $storage->closeFileUrl($lastFile["file"]); Api_Core_Application::end(); } }