OCA\Richdocuments\File::getByShareToken PHP Method

getByShareToken() public static method

public static getByShareToken ( $token )
    public static function getByShareToken($token)
    {
        $linkItem = \OCP\Share::getShareByToken($token, false);
        if (is_array($linkItem) && isset($linkItem['uid_owner'])) {
            // seems to be a valid share
            $rootLinkItem = \OCP\Share::resolveReShare($linkItem);
        } else {
            throw new \Exception('This file was probably unshared');
        }
        $file = new File($rootLinkItem['file_source'], $rootLinkItem, $token);
        if (isset($linkItem['share_with']) && !empty($linkItem['share_with'])) {
            $file->setPasswordProtected(true);
        }
        return $file;
    }

Usage Example

 protected function validateSession($session)
 {
     try {
         if (is_null($this->shareToken)) {
             new File($session->getFileId());
         } else {
             File::getByShareToken($this->shareToken);
         }
     } catch (\Exception $e) {
         $this->logger->warning('Error. Session no longer exists. ' . $e->getMessage(), ['app' => $this->appName]);
         $ex = new BadRequestException();
         $ex->setBody(implode(',', $this->request->getParams()));
         throw $ex;
     }
 }