Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
55.56% |
15 / 27 |
|
57.14% |
4 / 7 |
CRAP | |
0.00% |
0 / 1 |
| ImsManifestMapping | |
55.56% |
15 / 27 |
|
57.14% |
4 / 7 |
27.84 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| setNamespace | |
42.86% |
3 / 7 |
|
0.00% |
0 / 1 |
4.68 | |||
| getNamespace | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setPrefix | |
42.86% |
3 / 7 |
|
0.00% |
0 / 1 |
4.68 | |||
| getPrefix | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setSchemaLocation | |
42.86% |
3 / 7 |
|
0.00% |
0 / 1 |
4.68 | |||
| getSchemaLocation | |
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) 2014 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\taoQtiItem\model\qti\metadata\imsManifest; |
| 23 | |
| 24 | use InvalidArgumentException; |
| 25 | |
| 26 | /** |
| 27 | * Describes a Mapping between a given XML namespace, its prefix, and a XSD (XML Schema Definition) location. |
| 28 | * |
| 29 | * As an example, in an IMS Manifest File, such a mapping could be performed to represent |
| 30 | * how metadata from the IMS Metadata domain should be serialized from an XML perspective. |
| 31 | * |
| 32 | * namespace: "http://www.imsglobal.org/xsd/imsmd_v1p2" |
| 33 | * prefix: "imsmd" |
| 34 | * schemaLocation: "http://www.imsglobal.org/xsd/imsmd_v1p2p2.xsd" |
| 35 | * |
| 36 | * @author Jérôme Bogaerts <jerome@taotesting.com> |
| 37 | * @author Antoine Robin <antoine.robin@vesperiagroup.com> |
| 38 | */ |
| 39 | class ImsManifestMapping |
| 40 | { |
| 41 | /** |
| 42 | * An XML namespace. |
| 43 | * |
| 44 | * @var string |
| 45 | */ |
| 46 | private $namespace; |
| 47 | |
| 48 | /** |
| 49 | * An XML prefix. |
| 50 | * |
| 51 | * @var string |
| 52 | */ |
| 53 | private $prefix; |
| 54 | |
| 55 | /** |
| 56 | * An XSD (XML Schema Definition) schema location. |
| 57 | * |
| 58 | * @var string |
| 59 | */ |
| 60 | private $schemaLocation; |
| 61 | |
| 62 | /** |
| 63 | * Create a new ImsManifestMapping object. |
| 64 | * |
| 65 | * @param string $namespace An XML namespace. |
| 66 | * @param string $prefix An XML prefix. |
| 67 | * @param string $schemaLocation An XSD (XML Schema Definition) schema location. |
| 68 | * @throws InvalidArgumentException If one of the arguments is invalid. |
| 69 | */ |
| 70 | public function __construct($namespace, $prefix, $schemaLocation) |
| 71 | { |
| 72 | $this->setNamespace($namespace); |
| 73 | $this->setPrefix($prefix); |
| 74 | $this->setSchemaLocation($schemaLocation); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Set the XML namespace of the mapping. |
| 79 | * |
| 80 | * @param string $namespace An XML namespace e.g. "http://www.imsglobal.org/xsd/imsmd_v1p2p2". |
| 81 | * @throws InvalidArgumentException If $namespace is not a string or an empty string. |
| 82 | */ |
| 83 | public function setNamespace($namespace) |
| 84 | { |
| 85 | if (is_string($namespace) === false) { |
| 86 | $msg = "The namespace argument must be a string."; |
| 87 | throw new InvalidArgumentException($msg); |
| 88 | } elseif ($namespace === '') { |
| 89 | $msg = "The namespace argument must be a non-empty string."; |
| 90 | throw new InvalidArgumentException($msg); |
| 91 | } else { |
| 92 | $this->namespace = $namespace; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Get the XML namespace. |
| 98 | * |
| 99 | * @return string An XML namespace e.g. "http://www.imsglobal.org/xsd/imsmd_v1p2p2". |
| 100 | */ |
| 101 | public function getNamespace() |
| 102 | { |
| 103 | return $this->namespace; |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * Set the XML prefix of the mapping. |
| 108 | * |
| 109 | * @param string $prefix An XML prefix e.g. "imsmd". |
| 110 | * @throws InvalidArgumentException If $prefix is not a string or an empty string. |
| 111 | */ |
| 112 | public function setPrefix($prefix) |
| 113 | { |
| 114 | if (is_string($prefix) === false) { |
| 115 | $msg = "The prefix argument must be a string."; |
| 116 | throw new InvalidArgumentException($msg); |
| 117 | } elseif ($prefix === '') { |
| 118 | $msg = "The prefix argument must be a non-empty string."; |
| 119 | throw new InvalidArgumentException($msg); |
| 120 | } else { |
| 121 | $this->prefix = $prefix; |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Get the XML prefix of the mapping. |
| 127 | * |
| 128 | * @return string An XML prefix e.g. "imsmd". |
| 129 | */ |
| 130 | public function getPrefix() |
| 131 | { |
| 132 | return $this->prefix; |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * Set the XSD (XML Schema Definition) schema location of the mapping. |
| 137 | * |
| 138 | * @param string $schemaLocation A schema location e.g. "http://www.imsglobal.org/xsd/imsmd_v1p2p2.xsd". |
| 139 | * @throws InvalidArgumentException If $schemaLocatuion is not a string or an empty string. |
| 140 | */ |
| 141 | public function setSchemaLocation($schemaLocation) |
| 142 | { |
| 143 | if (is_string($schemaLocation) === false) { |
| 144 | $msg = "The schemaLocation argument must be a string."; |
| 145 | throw new InvalidArgumentException($msg); |
| 146 | } elseif ($schemaLocation === '') { |
| 147 | $msg = "The schemaLocation argument cannot be empty."; |
| 148 | throw new InvalidArgumentException($msg); |
| 149 | } else { |
| 150 | $this->schemaLocation = $schemaLocation; |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | /** |
| 155 | * Get the XSD (XML Schema Definition) schema location of the mapping. |
| 156 | * |
| 157 | * @return string A schema location e.g. "http://www.imsglobal.org/xsd/imsmd_v1p2p2.xsd". |
| 158 | */ |
| 159 | public function getSchemaLocation() |
| 160 | { |
| 161 | return $this->schemaLocation; |
| 162 | } |
| 163 | } |