Passed
Push — master ( 262b3f...86674d )
by Yannick
09:44
created

OnlyofficeFormatsManager::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
/**
3
 * (c) Copyright Ascensio System SIA 2025.
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 *     http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
use Onlyoffice\DocsIntegrationSdk\Manager\Formats\FormatsManager;
18
use Onlyoffice\DocsIntegrationSdk\Util\CommonError;
19
20
class OnlyofficeFormatsManager extends FormatsManager
21
{
22
    public function __construct()
23
    {
24
        $formats = self::getFormats();
25
        $this->formatsList = self::buildNamedFormatsArray($formats);
26
    }
27
28
    private static function getFormats()
29
    {
30
        $formats = file_get_contents(dirname(__DIR__).
31
        DIRECTORY_SEPARATOR.
32
        'vendor'.
33
        DIRECTORY_SEPARATOR.
34
        'onlyoffice'.
35
        DIRECTORY_SEPARATOR.
36
        'docs-integration-sdk'.
37
        DIRECTORY_SEPARATOR.
38
        'resources'.
39
        DIRECTORY_SEPARATOR.
40
        'assets'.
41
        DIRECTORY_SEPARATOR.
42
        'document-formats'.
43
        DIRECTORY_SEPARATOR.
44
        'onlyoffice-docs-formats.txt');
45
46
        if (empty($formats)) {
47
            $formats = file_get_contents(dirname(__DIR__).
48
            DIRECTORY_SEPARATOR.
49
            'vendor'.
50
            DIRECTORY_SEPARATOR.
51
            'onlyoffice'.
52
            DIRECTORY_SEPARATOR.
53
            'docs-integration-sdk'.
54
            DIRECTORY_SEPARATOR.
55
            'resources'.
56
            DIRECTORY_SEPARATOR.
57
            'assets'.
58
            DIRECTORY_SEPARATOR.
59
            'document-formats'.
60
            DIRECTORY_SEPARATOR.
61
            'onlyoffice-docs-formats.json');
62
        }
63
64
        if (!empty($formats)) {
65
            $formats = json_decode($formats);
66
            if (!empty($formats)) {
67
                return $formats;
68
            }
69
            throw new \Exception(CommonError::message(CommonError::EMPTY_FORMATS_ASSET));
70
        }
71
        throw new \Exception(CommonError::message(CommonError::EMPTY_FORMATS_ASSET));
72
    }
73
}
74