Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
88.89% |
8 / 9 |
|
80.00% |
4 / 5 |
CRAP | |
0.00% |
0 / 1 |
| OntologyAwareTrait | |
88.89% |
8 / 9 |
|
80.00% |
4 / 5 |
8.09 | |
0.00% |
0 / 1 |
| getModel | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
4 | |||
| setModel | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getResource | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getClass | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getProperty | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 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) 2016 (original work) Open Assessment Technologies SA |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\generis\model; |
| 23 | |
| 24 | use oat\generis\model\data\ModelManager; |
| 25 | use oat\generis\model\data\Ontology; |
| 26 | use Laminas\ServiceManager\ServiceLocatorAwareInterface; |
| 27 | |
| 28 | /** |
| 29 | * Trait for classes that want to access the ontology |
| 30 | * |
| 31 | * @author Joel Bout <joel@taotesting.com> |
| 32 | */ |
| 33 | trait OntologyAwareTrait |
| 34 | { |
| 35 | /** |
| 36 | * @var Ontology |
| 37 | */ |
| 38 | private $ontology; |
| 39 | |
| 40 | /** |
| 41 | * Return the used model |
| 42 | * @return Ontology |
| 43 | */ |
| 44 | public function getModel() |
| 45 | { |
| 46 | if (is_null($this->ontology)) { |
| 47 | return ($this instanceof ServiceLocatorAwareInterface && !is_null($this->getServiceLocator())) |
| 48 | ? $this->getServiceLocator()->get(Ontology::SERVICE_ID) |
| 49 | : ModelManager::getModel(); |
| 50 | } |
| 51 | return $this->ontology; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Sets the model to use |
| 56 | * @param Ontology $model |
| 57 | */ |
| 58 | public function setModel(Ontology $model) |
| 59 | { |
| 60 | $this->ontology = $model; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * @param string $uri |
| 65 | * @return \core_kernel_classes_Resource |
| 66 | */ |
| 67 | public function getResource($uri) |
| 68 | { |
| 69 | return $this->getModel()->getResource($uri); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * @param string $uri |
| 74 | * @return \core_kernel_classes_Class |
| 75 | */ |
| 76 | public function getClass($uri) |
| 77 | { |
| 78 | return $this->getModel()->getClass($uri); |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * @param string $uri |
| 83 | * @return \core_kernel_classes_Property |
| 84 | */ |
| 85 | public function getProperty($uri) |
| 86 | { |
| 87 | return $this->getModel()->getProperty($uri); |
| 88 | } |
| 89 | } |