Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
54.55% |
6 / 11 |
|
83.33% |
5 / 6 |
CRAP | |
0.00% |
0 / 1 |
| common_persistence_Persistence | |
54.55% |
6 / 11 |
|
83.33% |
5 / 6 |
11.60 | |
0.00% |
0 / 1 |
| getPersistence | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| __construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getDriver | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setDriver | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getParams | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setParams | |
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) 2013 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | * @author Lionel Lecaque <lionel@taotesting.com> |
| 21 | * @license GPLv2 |
| 22 | * @package generis |
| 23 | * |
| 24 | */ |
| 25 | |
| 26 | use oat\generis\Helper\UuidPrimaryKeyTrait; |
| 27 | |
| 28 | abstract class common_persistence_Persistence |
| 29 | { |
| 30 | use UuidPrimaryKeyTrait; |
| 31 | |
| 32 | /** |
| 33 | * Driver of the persistence |
| 34 | * |
| 35 | * @var common_persistence_Driver |
| 36 | */ |
| 37 | private $driver; |
| 38 | |
| 39 | /** |
| 40 | * Persistence parameters |
| 41 | * |
| 42 | * @var array |
| 43 | */ |
| 44 | private $params = []; |
| 45 | |
| 46 | public static function getPersistence($driverId) |
| 47 | { |
| 48 | $returnValue = common_persistence_Manager::getPersistence($driverId); |
| 49 | $class = get_called_class(); |
| 50 | if (!$returnValue instanceof $class) { |
| 51 | common_Logger::w('Got a ', get_class($returnValue) . ' instead of ' . $class); |
| 52 | } |
| 53 | return $returnValue; |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Constructor |
| 58 | * |
| 59 | * @access public |
| 60 | * @author "Lionel Lecaque, <lionel@taotesting.com>" |
| 61 | * @param array $params |
| 62 | * @param common_persistence_driver $driver |
| 63 | * |
| 64 | * phpcs:disable PEAR.Functions.ValidDefaultValue |
| 65 | */ |
| 66 | public function __construct($params = [], common_persistence_driver $driver) |
| 67 | { |
| 68 | $this->setParams($params); |
| 69 | $this->setDriver($driver); |
| 70 | } |
| 71 | // phpcs:enable PEAR.Functions.ValidDefaultValue |
| 72 | |
| 73 | /** |
| 74 | * Retrieve persistence's driver |
| 75 | * |
| 76 | * @access public |
| 77 | * @author "Lionel Lecaque, <lionel@taotesting.com>" |
| 78 | * @return common_persistence_driver |
| 79 | */ |
| 80 | public function getDriver() |
| 81 | { |
| 82 | return $this->driver; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Set the persistence |
| 87 | * |
| 88 | * @access protected |
| 89 | * @author "Lionel Lecaque, <lionel@taotesting.com>" |
| 90 | * @param common_persistence_Driver $driver |
| 91 | */ |
| 92 | protected function setDriver(common_persistence_Driver $driver) |
| 93 | { |
| 94 | $this->driver = $driver; |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Retrieve persistence's parameters |
| 99 | * |
| 100 | * @access protected |
| 101 | * @author "Lionel Lecaque, <lionel@taotesting.com>" |
| 102 | * @return array: |
| 103 | */ |
| 104 | protected function getParams() |
| 105 | { |
| 106 | return $this->params; |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * set persistence's parameters |
| 111 | * |
| 112 | * @access protected |
| 113 | * @author "Lionel Lecaque, <lionel@taotesting.com>" |
| 114 | * @param array $params |
| 115 | */ |
| 116 | protected function setParams($params) |
| 117 | { |
| 118 | $this->params = $params; |
| 119 | } |
| 120 | } |