mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fixing access to private and protected variables in Xml class.
This commit is contained in:
parent
3039645a17
commit
14b6a7ac5e
2 changed files with 38 additions and 19 deletions
|
@ -302,10 +302,10 @@ class XmlNode extends Object {
|
|||
* @access private
|
||||
*/
|
||||
function __tagOptions($name, $option = null) {
|
||||
if (isset($this->__tags[$name])) {
|
||||
$tagOpts = $this->__tags[$name];
|
||||
} elseif (isset($this->__tags[strtolower($name)])) {
|
||||
$tagOpts = $this->__tags[strtolower($name)];
|
||||
if (isset($this->_tags[$name])) {
|
||||
$tagOpts = $this->_tags[$name];
|
||||
} elseif (isset($this->_tags[strtolower($name)])) {
|
||||
$tagOpts = $this->_tags[strtolower($name)];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
@ -810,18 +810,18 @@ class Xml extends XmlNode {
|
|||
* XML document header
|
||||
*
|
||||
* @var string
|
||||
* @access private
|
||||
* @access protected
|
||||
*/
|
||||
private $__header = null;
|
||||
protected $_header = null;
|
||||
|
||||
/**
|
||||
* Default array keys/object properties to use as tag names when converting objects or array
|
||||
* structures to XML. Set by passing $options['tags'] to this object's constructor.
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
* @access protected
|
||||
*/
|
||||
private $__tags = array();
|
||||
protected $_tags = array();
|
||||
|
||||
/**
|
||||
* XML document version
|
||||
|
@ -868,7 +868,7 @@ class Xml extends XmlNode {
|
|||
foreach (array('version', 'encoding', 'namespaces') as $key) {
|
||||
$this->{$key} = $options[$key];
|
||||
}
|
||||
$this->__tags = $options['tags'];
|
||||
$this->_tags = $options['tags'];
|
||||
parent::__construct('#document');
|
||||
|
||||
if ($options['root'] !== '#document') {
|
||||
|
@ -898,7 +898,7 @@ class Xml extends XmlNode {
|
|||
return false;
|
||||
}
|
||||
$this->__rawData = null;
|
||||
$this->__header = null;
|
||||
$this->_header = null;
|
||||
|
||||
if (strstr($input, "<")) {
|
||||
$this->__rawData = $input;
|
||||
|
@ -926,7 +926,7 @@ class Xml extends XmlNode {
|
|||
function parse() {
|
||||
$this->__initParser();
|
||||
$this->__rawData = trim($this->__rawData);
|
||||
$this->__header = trim(str_replace(
|
||||
$this->_header = trim(str_replace(
|
||||
array('<' . '?', '?' . '>'),
|
||||
array('', ''),
|
||||
substr($this->__rawData, 0, strpos($this->__rawData, '?' . '>'))
|
||||
|
@ -1098,8 +1098,8 @@ class Xml extends XmlNode {
|
|||
$data = parent::toString($options, 0);
|
||||
|
||||
if ($options['header']) {
|
||||
if (!empty($this->__header)) {
|
||||
return $this->header($this->__header) . "\n" . $data;
|
||||
if (!empty($this->_header)) {
|
||||
return $this->header($this->_header) . "\n" . $data;
|
||||
}
|
||||
return $this->header() . "\n" . $data;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,25 @@
|
|||
*/
|
||||
App::import('Core', 'Xml');
|
||||
|
||||
/**
|
||||
* Test XML Class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs
|
||||
*/
|
||||
class TestXml extends Xml {
|
||||
|
||||
/**
|
||||
* Return the protected _header instance variable
|
||||
*
|
||||
* @return string Header
|
||||
* @access public
|
||||
*/
|
||||
function getHeader() {
|
||||
return $this->_header;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* XmlTest class
|
||||
*
|
||||
|
@ -488,17 +507,17 @@ class XmlTest extends CakeTestCase {
|
|||
$raw = '<?xml version="1.0" encoding="ISO-8859-1" ?><prices><price>1.0</price></prices>';
|
||||
$array = array('Prices' => array('price' => 1.0));
|
||||
|
||||
$xml = new Xml($raw);
|
||||
$xml = new TestXml($raw);
|
||||
$this->assertEqual($xml->toArray(), $array);
|
||||
$this->assertEqual($xml->__header, 'xml version="1.0" encoding="ISO-8859-1"');
|
||||
$this->assertEqual($xml->getHeader(), 'xml version="1.0" encoding="ISO-8859-1"');
|
||||
|
||||
$xml = new Xml(' ' . $raw);
|
||||
$xml = new TestXml(' ' . $raw);
|
||||
$this->assertEqual($xml->toArray(), $array);
|
||||
$this->assertEqual($xml->__header, 'xml version="1.0" encoding="ISO-8859-1"');
|
||||
$this->assertEqual($xml->getHeader(), 'xml version="1.0" encoding="ISO-8859-1"');
|
||||
|
||||
$xml = new Xml("\n" . $raw);
|
||||
$xml = new TestXml("\n" . $raw);
|
||||
$this->assertEqual($xml->toArray(), $array);
|
||||
$this->assertEqual($xml->__header, 'xml version="1.0" encoding="ISO-8859-1"');
|
||||
$this->assertEqual($xml->getHeader(), 'xml version="1.0" encoding="ISO-8859-1"');
|
||||
}
|
||||
|
||||
/* Not implemented yet */
|
||||
|
|
Loading…
Reference in a new issue