Skip to content

Commit

Permalink
Fixing access to private and protected variables in Xml class.
Browse files Browse the repository at this point in the history
  • Loading branch information
predominant committed Apr 4, 2010
1 parent 3039645 commit 14b6a7a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 19 deletions.
26 changes: 13 additions & 13 deletions cake/libs/xml.php
Expand Up @@ -302,10 +302,10 @@ function normalize($object, $keyName = null, $options = array()) {
* @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;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -868,7 +868,7 @@ function __construct($input = null, $options = array()) {
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') {
Expand Down Expand Up @@ -898,7 +898,7 @@ function load($input) {
return false;
}
$this->__rawData = null;
$this->__header = null;
$this->_header = null;

if (strstr($input, "<")) {
$this->__rawData = $input;
Expand Down Expand Up @@ -926,7 +926,7 @@ function load($input) {
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, '?' . '>'))
Expand Down Expand Up @@ -1098,8 +1098,8 @@ function toString($options = array()) {
$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;
}
Expand Down
31 changes: 25 additions & 6 deletions cake/tests/cases/libs/xml.test.php
Expand Up @@ -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
*
Expand Down Expand Up @@ -488,17 +507,17 @@ function testParsingWithNonStandardWhitespace() {
$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 */
Expand Down

0 comments on commit 14b6a7a

Please sign in to comment.