Fix warnings from file_get_contents() in Xml::build()

Use HttpSocket to get proper exceptions when trying to load XML from
remote servers.

Fixes #3379
This commit is contained in:
mark_story 2012-11-19 14:46:45 -05:00
parent 6b4afb989e
commit fb275c5fa2
2 changed files with 11 additions and 3 deletions

View file

@ -177,6 +177,7 @@ class XmlTest extends CakeTestCase {
array(null),
array(false),
array(''),
array('http://localhost/notthere.xml'),
);
}

View file

@ -18,6 +18,7 @@
* @since CakePHP v .0.10.3.1400
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('HttpSocket', 'Network/Http');
/**
* XML handling for Cake.
@ -97,9 +98,15 @@ class Xml {
return self::fromArray((array)$input, $options);
} elseif (strpos($input, '<') !== false) {
return self::_loadXml($input, $options);
} elseif (file_exists($input) || strpos($input, 'http://') === 0 || strpos($input, 'https://') === 0) {
$input = file_get_contents($input);
return self::_loadXml($input, $options);
} elseif (file_exists($input)) {
return self::_loadXml(file_get_contents($input), $options);
} elseif (strpos($input, 'http://') === 0 || strpos($input, 'https://') === 0) {
$socket = new HttpSocket();
$response = $socket->get($input);
if (!$response->isOk()) {
throw new XmlException(__d('cake_dev', 'XML cannot be read.'));
}
return self::_loadXml($response->body, $options);
} elseif (!is_string($input)) {
throw new XmlException(__d('cake_dev', 'Invalid input.'));
}