Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Update headers and style refactor #55

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions src/CFPropertyList/CFPropertyList.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,9 @@ public function load($file = null, $format = null)
case CFPropertyList::FORMAT_BINARY:
$this->readBinary($file);
break;
case CFPropertyList::FORMAT_AUTO: // what we now do is ugly, but neccessary to recognize the file format

case CFPropertyList::FORMAT_AUTO:
// what we now do is ugly, but neccessary to recognize the file format
$fd = fopen($file, "rb");
if (($magic_number = fread($fd, 8)) === false) {
throw IOException::notReadable($file);
Expand All @@ -256,8 +258,10 @@ public function load($file = null, $format = null)
break;
}
$this->detectedFormat = CFPropertyList::FORMAT_XML;
// else: xml format, break not neccessary
// Fall back to CFPropertyList::FORMAT_XML

case CFPropertyList::FORMAT_XML:
// else: xml format, break not neccessary
$doc = new DOMDocument();
$prevXmlErrors = libxml_use_internal_errors(true);
libxml_clear_errors();
Expand Down Expand Up @@ -299,7 +303,9 @@ public function parse($str = null, $format = null)
case CFPropertyList::FORMAT_BINARY:
$this->parseBinary($str);
break;
case CFPropertyList::FORMAT_AUTO: // what we now do is ugly, but neccessary to recognize the file format

case CFPropertyList::FORMAT_AUTO:
// what we now do is ugly, but neccessary to recognize the file format
if (($magic_number = substr($str, 0, 8)) === false) {
throw IOException::notReadable("<string>");
}
Expand All @@ -316,8 +322,10 @@ public function parse($str = null, $format = null)
break;
}
$this->detectedFormat = CFPropertyList::FORMAT_XML;
// else: xml format, break not neccessary
// no break: fallback to FORMAT_XML

case CFPropertyList::FORMAT_XML:
// else: xml format, break not neccessary
$doc = new DOMDocument();
$prevXmlErrors = libxml_use_internal_errors(true);
libxml_clear_errors();
Expand Down Expand Up @@ -348,27 +356,27 @@ protected function getLibxmlErrors()
*/
protected function import(DOMNode $node, $parent)
{
// abort if there are no children
// abort if there are no children
if (!$node->childNodes->length) {
return;
}

foreach ($node->childNodes as $n) {
// skip if we can't handle the element
// skip if we can't handle the element
if (!isset(self::$types[$n->nodeName])) {
continue;
}

$class = __NAMESPACE__ . '\\'.self::$types[$n->nodeName];
$key = null;

// find previous <key> if possible
// find previous <key> if possible
$ps = $n->previousSibling;
while ($ps && $ps->nodeName == '#text' && $ps->previousSibling) {
$ps = $ps->previousSibling;
}

// read <key> if possible
// read <key> if possible
if ($ps && $ps->nodeName == 'key') {
$key = $ps->firstChild->nodeValue;
}
Expand Down Expand Up @@ -409,11 +417,11 @@ protected function import(DOMNode $node, $parent)
break;
}

// Dictionaries need a key
// Dictionaries need a key
if ($parent instanceof CFDictionary) {
$parent->add($key, $value);
} // others don't
else {
} else {
// others don't
$parent->add($value);
}
}
Expand Down