onlyoffice / docs-integration-sdk
ONLYOFFICE Docs integration SDK
v1.0.1
2024-10-16 11:25 UTC
Requires
- vlucas/phpdotenv: ^5.6
This package is not auto-updated.
Last update: 2024-12-11 12:20:43 UTC
README
ONLYOFFICE Docs Integration PHP SDK provides common interfaces and default implementations for integrating ONLYOFFICE Document Server into your own website or application on PHP.
Prerequisites
- PHP: version 7.4.0 and higher
Managers
Services
Usage
- Implement the methods of the abstract DocumentManager class:
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"; }
- Implement the methods of the abstract JwtManager class (use third-party libraries for JWT encoding and decoding, whichever is convenient for you):
public function encode($token, $key, $algorithm = "HS256") { return "SOME.JWT.STRING"; } public function decode($token, $key, $algorithm = "HS256") { return json_encode([]); }
- Implement the methods of the abstract SettingsManager class:
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); }
- Implement the methods of the abstract SettingsManager class:
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); }
- Create a class that implements the HttpClientInterface interface (use PHP Client URL Library or any other third-party library to make requests):
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\"}"; } }
- Implement the method of the abstract RequestService class:
public function getFileUrlForConvert() { return "https://example-server.example/file-url-for-check-convert"; }
- Use DocEditorConfigService to create a config model for the editors in your own controllers.