Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 15 |
|
0.00% |
0 / 10 |
CRAP | |
0.00% |
0 / 1 |
| tao_helpers_data_GenerisAdapter | |
0.00% |
0 / 15 |
|
0.00% |
0 / 10 |
156 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| getOptions | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| setOptions | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| addOption | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| import | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| export | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| getValidators | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getValidator | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 | |||
| setValidators | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getErrorMessages | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| addErrorMessage | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
| hasErrors | |
0.00% |
0 / 1 |
|
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) 2008-2010 (original work) Deutsche Institut für Internationale Pädagogische Forschung |
| 19 | * (under the project TAO-TRANSFER); |
| 20 | * 2009-2012 (update and modification) Public Research Centre Henri Tudor |
| 21 | * (under the project TAO-SUSTAIN & TAO-DEV); |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | /** |
| 26 | * This class enables you to manage interfaces with data. |
| 27 | * It provides the default prototype to adapt the data import/export from/to any |
| 28 | * format. |
| 29 | * |
| 30 | * @abstract |
| 31 | * @access public |
| 32 | * @author Bertrand Chevrier, <bertrand.chevrier@tudor.lu> |
| 33 | * @package tao |
| 34 | |
| 35 | */ |
| 36 | abstract class tao_helpers_data_GenerisAdapter |
| 37 | { |
| 38 | /** |
| 39 | * Short description of attribute options |
| 40 | * |
| 41 | * @access protected |
| 42 | * @var array |
| 43 | */ |
| 44 | protected $options = []; |
| 45 | |
| 46 | /** |
| 47 | * List of validators applied during importing to data |
| 48 | * @var array |
| 49 | */ |
| 50 | protected $validators = []; |
| 51 | |
| 52 | /** |
| 53 | * @var array |
| 54 | */ |
| 55 | protected $errorMessages = []; |
| 56 | |
| 57 | // --- OPERATIONS --- |
| 58 | |
| 59 | /** |
| 60 | * Short description of method __construct |
| 61 | * |
| 62 | * @access public |
| 63 | * @author Bertrand Chevrier, <bertrand.chevrier@tudor.lu> |
| 64 | * @param array $options |
| 65 | * @return mixed |
| 66 | */ |
| 67 | public function __construct($options = []) |
| 68 | { |
| 69 | |
| 70 | $this->options = $options; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * get the adapter options |
| 75 | * |
| 76 | * @access public |
| 77 | * @author Bertrand Chevrier, <bertrand.chevrier@tudor.lu> |
| 78 | * @return array |
| 79 | */ |
| 80 | public function getOptions() |
| 81 | { |
| 82 | $returnValue = []; |
| 83 | |
| 84 | |
| 85 | |
| 86 | $returnValue = $this->options; |
| 87 | |
| 88 | |
| 89 | |
| 90 | return (array) $returnValue; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * set the adapter options |
| 95 | * |
| 96 | * @access public |
| 97 | * @author Bertrand Chevrier, <bertrand.chevrier@tudor.lu> |
| 98 | * @param array $options |
| 99 | * @return mixed |
| 100 | */ |
| 101 | public function setOptions($options = []) |
| 102 | { |
| 103 | |
| 104 | $this->options = $options; |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * add a new option |
| 109 | * |
| 110 | * @access public |
| 111 | * @author Bertrand Chevrier, <bertrand.chevrier@tudor.lu> |
| 112 | * @param string $name |
| 113 | * @param mixed $value |
| 114 | * @return mixed |
| 115 | */ |
| 116 | public function addOption($name, $value) |
| 117 | { |
| 118 | |
| 119 | $this->options[$name] = $value; |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * import prototype: import the source into the destination class |
| 124 | * |
| 125 | * @abstract |
| 126 | * @access public |
| 127 | * @author Bertrand Chevrier, <bertrand.chevrier@tudor.lu> |
| 128 | * @param string $source |
| 129 | * @param core_kernel_classes_Class $destination |
| 130 | * @return boolean |
| 131 | */ |
| 132 | abstract public function import($source, core_kernel_classes_Class $destination = null); |
| 133 | |
| 134 | /** |
| 135 | * export prototype: export the source class |
| 136 | * |
| 137 | * @abstract |
| 138 | * @access public |
| 139 | * @author Bertrand Chevrier, <bertrand.chevrier@tudor.lu> |
| 140 | * @param core_kernel_classes_Class $source |
| 141 | * @return string |
| 142 | */ |
| 143 | abstract public function export(core_kernel_classes_Class $source = null); |
| 144 | |
| 145 | /** |
| 146 | * @return array |
| 147 | */ |
| 148 | public function getValidators() |
| 149 | { |
| 150 | return $this->validators; |
| 151 | } |
| 152 | |
| 153 | /** |
| 154 | * @param $target |
| 155 | * @return array |
| 156 | */ |
| 157 | public function getValidator($target) |
| 158 | { |
| 159 | return isset($this->validators[$target]) ? $this->validators[$target] : []; |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * @param array $validators |
| 164 | */ |
| 165 | public function setValidators($validators) |
| 166 | { |
| 167 | $this->validators = $validators; |
| 168 | } |
| 169 | |
| 170 | /** |
| 171 | * @return array |
| 172 | */ |
| 173 | public function getErrorMessages() |
| 174 | { |
| 175 | return $this->errorMessages; |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * @param string $target |
| 180 | * @param common_report_Report $message |
| 181 | */ |
| 182 | public function addErrorMessage($target, $message) |
| 183 | { |
| 184 | if (is_string($target)) { |
| 185 | $this->errorMessages[$target][] = $message; |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | /** |
| 190 | * @return boolean |
| 191 | */ |
| 192 | public function hasErrors() |
| 193 | { |
| 194 | return count($this->getErrorMessages()) > 0; |
| 195 | } |
| 196 | } |