PHP code example of onlyoffice / docs-integration-sdk

1. Go to this page and download the library: Download onlyoffice/docs-integration-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

onlyoffice / docs-integration-sdk example snippets


    public function getDocumentKey(string $fileId, bool $embedded = false)
    {
        return self::generateRevisionId($fileId);
    }

    public function getDocumentName(string $fileId)
    {
        return "sample.docx";
    }

    public static function getLangMapping()
    {
        return null;
    }

    public static function getFileUrl(string $fileId)
    {
        return "https://example-server.example/fileId/download/";
    }

    public static function getCallbackUrl(string $fileId)
    {
        return "https://example-server.example/callback";
    }

    public static function getGobackUrl(string $fileId)
    {
        return "https://example-server.example/filelist";
    }

    public static function getCreateUrl(string $fileId)
    {
        return "https://example-server.example/fileId";
    }
    

    public function encode($token, $key, $algorithm = "HS256")
    {
        return "SOME.JWT.STRING";
    }

    public function decode($token, $key, $algorithm = "HS256")
    {
        return json_encode([]);
    }
    

    public function getServerUrl()
    {
        return "https://example-server.example/";
    }

    public function getSetting($settingName)
    {
        return null;
    }

    public function setSetting($settingName, $value, $createSetting = false)
    {
        // if ($createSetting === true) {
            // $this->yourMethodForCreateNewSetting($settingName, $value);
            // return;
        // }
        // $this->yourMethodForSetNewValueForSetting($settingName, $value);
    }
    

    public function processTrackerStatusEditing()
    {
        // $someTrackResult["error"] = 0;
        // return json_encode($someTrackResult);
    }

    public function processTrackerStatusMustsave()
    {
        // $someTrackResult["error"] = 0;
        // return json_encode($someTrackResult);
    }

    public function processTrackerStatusCorrupted()
    {
        // $someTrackResult["error"] = 0;
        // return json_encode($someTrackResult);
    }

    public function processTrackerStatusClosed()
    {
        // $someTrackResult["error"] = 0;
        // return json_encode($someTrackResult);
    }

    public function processTrackerStatusForcesave()
    {
        // $someTrackResult["error"] = 0;
        // return json_encode($someTrackResult);
    }
    

    class YourHttpClient implements HttpClientInterface
    {
        public function __construct()
        {
            $this->responseStatusCode = null;
            $this->responseBody = null;
        }

        public function getStatusCode()
        {
            return $this->responseStatusCode;
        }

        public function getBody()
        {
            return $this->responseBody;
        }

        public function request($url, $method = 'GET', $opts = [])
        {
            $this->responseStatusCode = 200;
            $this->responseBody = "{\"status\": \"OK\"}";
        }
    }
    

    public function getFileUrlForConvert()
    {
        return "https://example-server.example/file-url-for-check-convert";
    }