Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 11
CRAP
0.00% covered (danger)
0.00%
0 / 1
StylesheetRepository
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 11
132
0.00% covered (danger)
0.00%
0 / 1
 getPath
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
 listContents
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 read
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 write
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 writeStream
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 delete
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getFileSystem
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getOntology
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getFileSourceUnserializer
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getFileSystemService
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getFlySystemManagement
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3/**
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; under version 2
7 * of the License (non-upgradable).
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 *
18 * Copyright (c) 2021 (original work) Open Assessment Technologies SA;
19 */
20
21declare(strict_types=1);
22
23namespace oat\taoMediaManager\model\sharedStimulus\css\repository;
24
25use oat\generis\model\data\Ontology;
26use oat\oatbox\filesystem\FilesystemException;
27use oat\oatbox\filesystem\FilesystemInterface;
28use oat\oatbox\service\ConfigurableService;
29use oat\oatbox\filesystem\FileSystemService;
30use oat\taoMediaManager\model\fileManagement\FlySystemManagement;
31use oat\taoMediaManager\model\fileManagement\FileSourceUnserializer;
32use oat\taoMediaManager\model\TaoMediaOntology;
33
34class StylesheetRepository extends ConfigurableService
35{
36    public const STYLESHEETS_DIRECTORY = 'css';
37
38    public function getPath(string $uri): string
39    {
40        $passageResource = $this->getOntology()->getResource($uri);
41        $link = $passageResource->getUniquePropertyValue(
42            $passageResource->getProperty(TaoMediaOntology::PROPERTY_LINK)
43        );
44        $link = $this->getFileSourceUnserializer()->unserialize((string) $link);
45
46        return dirname((string) $link);
47    }
48
49    public function listContents(string $path): iterable
50    {
51        return $this->getFileSystem()->listContents($path);
52    }
53
54    /**
55     * @throws FilesystemException
56     */
57    public function read(string $path): string
58    {
59        return $this->getFileSystem()->read($path);
60    }
61
62    /**
63     * @throws FilesystemException
64     */
65    public function write(string $path, string $contents): void
66    {
67        $this->getFileSystem()->write($path, $contents);
68    }
69
70    /**
71     * @throws FilesystemException
72     */
73    public function writeStream(string $path, $streamResource): void
74    {
75        $this->getFileSystem()->writeStream($path, $streamResource);
76    }
77
78    /**
79     * @throws FilesystemException
80     */
81    public function delete(string $path): void
82    {
83        $this->getFileSystem()->delete($path);
84    }
85
86    private function getFileSystem(): FilesystemInterface
87    {
88        $flySystemManagementFs = $this->getFlySystemManagement()->getOption(FlySystemManagement::OPTION_FS);
89
90        return $this->getFileSystemService()->getFileSystem($flySystemManagementFs);
91    }
92
93    private function getOntology(): Ontology
94    {
95        return $this->getServiceLocator()->get(Ontology::SERVICE_ID);
96    }
97
98    private function getFileSourceUnserializer(): FileSourceUnserializer
99    {
100        return $this->getServiceLocator()->get(FileSourceUnserializer::class);
101    }
102
103    private function getFileSystemService(): FileSystemService
104    {
105        return $this->getServiceLocator()->get(FileSystemService::SERVICE_ID);
106    }
107
108    private function getFlySystemManagement(): FlySystemManagement
109    {
110        return $this->getServiceLocator()->get(FlySystemManagement::SERVICE_ID);
111    }
112}