/** * 控制器执行主逻辑函数 * @param null $uri * @param null $absolutePath * @throws MAuthorizationException * @throws MFileopsException */ public function invoke($uri = null, $absolutePath = null) { // 调用父类初始化函数,注册自定义的异常和错误处理逻辑 parent::init(); $params = $_REQUEST; // 检查参数 if (isset($params) === false || $params == null) { throw new MAuthorizationException(Yii::t('api', 'Invalid parameters')); } // 获取用户数据,如user_id $user = MUserManager::getInstance()->getCurrentUser(); $this->userId = $user["user_id"]; $includeDeleted = false; // 处理删除的同样也需要返回 if (isset($params["include_deleted"])) { $includeDeleted = $params["include_deleted"]; } $this->locale = "bytes"; if (isset($params["locale"])) { $this->locale = $params["locale"]; } $includeDeleted = MUtils::convertToBool($includeDeleted); $urlManager = new MUrlManager(); $path = MUtils::convertStandardPath($urlManager->parsePathFromUrl($uri)); $this->root = $urlManager->parseRootFromUrl($path); if ($path === false) { $path = "/"; } $pathPart = explode('/', $path); // 根目录 if (count($pathPart) <= 2) { $response = $this->handleRootPath($includeDeleted); } else { $response = $this->handleNotRootPath($path, $includeDeleted); } echo json_encode($response); }