Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 10 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| ServiceConfigDriver | |
0.00% |
0 / 10 |
|
0.00% |
0 / 2 |
20 | |
0.00% |
0 / 1 |
| getContent | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| getPath | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| 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) 2017 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\oatbox\service; |
| 23 | |
| 24 | use common_Utils; |
| 25 | use oat\oatbox\config\ConfigurationDriver; |
| 26 | |
| 27 | /** |
| 28 | * Class ServiceConfigDriver |
| 29 | * |
| 30 | * Driver dedicated to store only ConfigurableService into config |
| 31 | * |
| 32 | * @package oat\oatbox\service |
| 33 | */ |
| 34 | class ServiceConfigDriver extends \common_persistence_PhpFileDriver implements ConfigurationDriver |
| 35 | { |
| 36 | /** |
| 37 | * Get the config content associated to given $key |
| 38 | * $key has to be a configurable service |
| 39 | * |
| 40 | * @param string $key |
| 41 | * @param mixed $value |
| 42 | * @return null|string |
| 43 | */ |
| 44 | protected function getContent($key, $value) |
| 45 | { |
| 46 | if (! $value instanceof ConfigurableService) { |
| 47 | return null; |
| 48 | } |
| 49 | $content = $value->getHeader() . PHP_EOL . "return " . common_Utils::toHumanReadablePhpString($value) . ";" |
| 50 | . PHP_EOL; |
| 51 | return $content; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Get the path associated to the given key |
| 56 | * Must be a two part key (e.q. path into a config folder) |
| 57 | * |
| 58 | * @param string $key |
| 59 | * @return string |
| 60 | */ |
| 61 | protected function getPath($key) |
| 62 | { |
| 63 | $parts = explode('/', $key); |
| 64 | $path = substr(parent::getPath(array_shift($parts)), 0, -4); |
| 65 | foreach ($parts as $part) { |
| 66 | $path .= DIRECTORY_SEPARATOR . $this->sanitizeReadableFileName($part); |
| 67 | } |
| 68 | return $path . '.conf.php'; |
| 69 | } |
| 70 | } |