Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
ResourceMetadataService
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 2
20
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getResourceMetadataValue
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
12
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) 2025 (original work) Open Assessment Technologies SA;
19 */
20
21declare(strict_types=1);
22
23namespace oat\tao\model\metadata\reader;
24
25use oat\generis\model\data\Ontology;
26use oat\tao\model\metadata\exception\MetadataNotExist;
27
28class ResourceMetadataService
29{
30    private Ontology $ontology;
31
32    public function __construct(Ontology $ontology)
33    {
34        $this->ontology = $ontology;
35    }
36
37    public function getResourceMetadataValue(string $resourceUri, string $metadataUri): string
38    {
39        $resource = $this->ontology->getResource($resourceUri);
40        $property = $this->ontology->getProperty($metadataUri);
41
42        if (!($resource->exists() && $property->exists())) {
43            throw new MetadataNotExist('Resource or property does not exist');
44        }
45
46        return (string) $resource->getOnePropertyValue($property) ?? '';
47    }
48}