|
@@ 190-206 (lines=17) @@
|
| 187 |
|
* @return \AppserverIo\Configuration\Interfaces\ConfigurationInterface The initialized configuration |
| 188 |
|
* @throws \Exception Is thrown if the file with the passed name is not a valid XML file |
| 189 |
|
*/ |
| 190 |
|
public function initFromFile($file) |
| 191 |
|
{ |
| 192 |
|
if (($root = simplexml_load_file($file)) === false) { |
| 193 |
|
$errors = array(); |
| 194 |
|
foreach (libxml_get_errors() as $error) { |
| 195 |
|
$errors[] = sprintf( |
| 196 |
|
'Found a schema validation error on line %s with code %s and message %s when validating configuration file %s', |
| 197 |
|
$error->line, |
| 198 |
|
$error->code, |
| 199 |
|
$error->message, |
| 200 |
|
$error->file |
| 201 |
|
); |
| 202 |
|
} |
| 203 |
|
throw new \Exception(implode(PHP_EOL, $errors)); |
| 204 |
|
} |
| 205 |
|
return $this->init($root); |
| 206 |
|
} |
| 207 |
|
|
| 208 |
|
/** |
| 209 |
|
* Initializes the configuration with the XML information passed as string. |
|
@@ 216-232 (lines=17) @@
|
| 213 |
|
* @return \AppserverIo\Configuration\Interfaces\ConfigurationInterface The initialized configuration |
| 214 |
|
* @throws \Exception Is thrown if the passed XML string is not valid |
| 215 |
|
*/ |
| 216 |
|
public function initFromString($string) |
| 217 |
|
{ |
| 218 |
|
if (($root = simplexml_load_string($string)) === false) { |
| 219 |
|
$errors = array(); |
| 220 |
|
foreach (libxml_get_errors() as $error) { |
| 221 |
|
$errors[] = sprintf( |
| 222 |
|
'Found a schema validation error on line %s with code %s and message %s when validating configuration file %s', |
| 223 |
|
$error->line, |
| 224 |
|
$error->code, |
| 225 |
|
$error->message, |
| 226 |
|
$error->file |
| 227 |
|
); |
| 228 |
|
} |
| 229 |
|
throw new \Exception(implode(PHP_EOL, $errors)); |
| 230 |
|
} |
| 231 |
|
return $this->init($root); |
| 232 |
|
} |
| 233 |
|
|
| 234 |
|
/** |
| 235 |
|
* Initializes the configuration with the XML information found |