Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
85.71% |
6 / 7 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| EncoderService | |
85.71% |
6 / 7 |
|
0.00% |
0 / 1 |
3.03 | |
0.00% |
0 / 1 |
| get | |
85.71% |
6 / 7 |
|
0.00% |
0 / 1 |
3.03 | |||
| 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) 2015 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * @author Mikhail Kamarouski, <kamarouski@1pt.com> |
| 20 | */ |
| 21 | |
| 22 | namespace oat\taoItems\model\pack; |
| 23 | |
| 24 | use oat\taoItems\model\pack\encoders\Encoding; |
| 25 | use ReflectionClass; |
| 26 | use tao_models_classes_Service; |
| 27 | |
| 28 | /** |
| 29 | * Class EncoderService |
| 30 | * Factory retrieve encoder by his name |
| 31 | * @package oat\taoItems\model\pack |
| 32 | */ |
| 33 | class EncoderService extends tao_models_classes_Service |
| 34 | { |
| 35 | /** |
| 36 | * @param $type |
| 37 | * |
| 38 | * @return Encoding |
| 39 | * @throws ExceptionMissingEncoder |
| 40 | */ |
| 41 | public function get($type) |
| 42 | { |
| 43 | $class = __NAMESPACE__ . '\\encoders\\' . ucfirst($type) . 'Encoder'; |
| 44 | if ( |
| 45 | class_exists($class) && in_array( |
| 46 | 'oat\taoItems\model\pack\encoders\Encoding', |
| 47 | class_implements($class) |
| 48 | ) |
| 49 | ) { |
| 50 | return (new ReflectionClass($class))->newInstanceArgs(array_slice(func_get_args(), 1, func_num_args())); |
| 51 | } |
| 52 | throw new ExceptionMissingEncoder('Encoder missing : ' . $class); |
| 53 | } |
| 54 | } |