Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 13 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| PortableElementParserAggregator | |
0.00% |
0 / 13 |
|
0.00% |
0 / 2 |
42 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
| getEligibleParser | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
12 | |||
| 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\taoQtiItem\model\portableElement\parser\element; |
| 23 | |
| 24 | use oat\taoQtiItem\model\portableElement\exception\PortableElementInconsistencyModelException; |
| 25 | use oat\taoQtiItem\model\portableElement\exception\PortableElementParserException; |
| 26 | use oat\taoQtiItem\model\portableElement\parser\PortableElementParser; |
| 27 | |
| 28 | class PortableElementParserAggregator |
| 29 | { |
| 30 | /** |
| 31 | * @var PortableElementParser[] |
| 32 | */ |
| 33 | protected $parsers; |
| 34 | |
| 35 | /** |
| 36 | * PortableElementParserAggregator constructor. |
| 37 | * Check if $parsers are valid. |
| 38 | * |
| 39 | * @param $parsers |
| 40 | * @throws PortableElementInconsistencyModelException |
| 41 | */ |
| 42 | public function __construct($parsers) |
| 43 | { |
| 44 | foreach ($parsers as $parser) { |
| 45 | if (! $parser instanceof PortableElementParser) { |
| 46 | throw new PortableElementInconsistencyModelException( |
| 47 | 'Portable element parser has to be child of PortableElementParser.' |
| 48 | ); |
| 49 | } |
| 50 | } |
| 51 | $this->parsers = $parsers; |
| 52 | } |
| 53 | |
| 54 | public function getEligibleParser($source) |
| 55 | { |
| 56 | /** @var PortableElementParser $parser */ |
| 57 | foreach ($this->parsers as $parser) { |
| 58 | if ($parser->hasValidPortableElement($source)) { |
| 59 | return $parser; |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | throw new PortableElementParserException( |
| 64 | 'This zip source is not compatible with any portable element. Manifest and/or engine file are missing ' |
| 65 | . ' or related extensions are not installed.' |
| 66 | ); |
| 67 | } |
| 68 | } |