teclib / cfpropertylist Goto Github PK
View Code? Open in Web Editor NEWPHP Implementation of Apple's PList (binary and xml)
Home Page: http://teclib.github.io/CFPropertyList/
License: MIT License
PHP Implementation of Apple's PList (binary and xml)
Home Page: http://teclib.github.io/CFPropertyList/
License: MIT License
Not sure if you've seen this before, but I couldn't find anything exactly the same on google. I'm using this library along with the Plist server for Drupal to interface with an iOS app. I get the following error upon any HTTP request I make:
/path/to/CFBinaryPropertyList.php on line 467.
I'm using PHP 5.3.5 on an Apache server with Drupal 6. This very well could be the Plist Server modules fault. But the Error is coming from your file, so I thought I would ask you first. The plist server module can be found here: http://drupal.org/project/plist_server. Thanks for the help.
Can I directly use plist data in variables instead of reading plist data in files
Add the following information on gh-pages
using https://github.com/briansea/ulysses3-export
$ ./ulyssesToFiles.php
Fatal error: Uncaught CFPropertyList\IOException: /Users/matt/Library/Mobile Documents/X5AZV975AG~com~soulmen~ulysses3/Documents/Library/Info.ulgroup in /Users/matt/Downloads/2018-04-28/ulysses3-export-master/vendor/rodneyrehm/plist/classes/CFPropertyList/IOException.php:68
Stack trace:
#0 /Users/matt/Downloads/2018-04-28/ulysses3-export-master/vendor/rodneyrehm/plist/classes/CFPropertyList/CFPropertyList.php(199): CFPropertyList\IOException::notReadable('/Users/matt/Lib...')
#1 /Users/matt/Downloads/2018-04-28/ulysses3-export-master/vendor/rodneyrehm/plist/classes/CFPropertyList/CFPropertyList.php(129): CFPropertyList\CFPropertyList->load()
#2 /Users/matt/Downloads/2018-04-28/ulysses3-export-master/ulyssesToFiles.php(26): CFPropertyList\CFPropertyList->__construct('/Users/matt/Lib...', 2)
#3 /Users/matt/Downloads/2018-04-28/ulysses3-export-master/ulyssesToFiles.php(20): CFPropertyList\parseFolder('/Users/matt/Lib...')
#4 {main}
thrown in /Users/matt/Downloads/2018-04-28/ulysses3-export-master/vendor/rodneyrehm/plist/classes/CFPropertyList/IOException.php on line 68
Regression bug caused by issue #11.
Given:
$plist = new CFPropertyList();
$dict = new CFDictionary();
$dict->add('string', new CFString(''));
$dict->add('number', new CFNumber(0));
$dict->add('double', new CFNumber(0.0));
$plist->add($dict);
print $plist->toXML();
Current:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"><dict><key>string</key><string/><key>number</key><integer/><key>double</key><real/></dict></plist>
Expected:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"><dict><key>string</key><string/><key>number</key><integer>0</integer><key>double</key><real>0</real></dict></plist>
Actual implementation creates empty tags also for integer and real elements.
CFType may have a null value https://github.com/TECLIB/CFPropertyList/blob/develop/src/CFPropertyList/CFType.php#L63 and attempt to call createTextNode https://github.com/TECLIB/CFPropertyList/blob/develop/src/CFPropertyList/CFType.php#L110 with that null value. This is deprecated in php 8 and throws the error:
Passing null to parameter #1 ($data) of type string is deprecated
This is related to: https://wiki.php.net/rfc/deprecate_null_to_scalar_internal_arg and should be fixed before passing null to non-nullable arguments is removed in a future php version.
the CFTypeDetector uses is_numeric to determine if the value is a number (OR a numeric string) to convert to a CFNumber. Any numeric string will be converted to a CFNumber, even if some values may be converted to CFString. This is not consistent enough behavior for my iPhone app to rely on.
Moving the is_string function before the is_numeric function will allow me to keep my string values as strings, especially if I explicitly juggle the type using (string)$value.
Other users of this library may get inconsistent results when trying to work with strings which may or may not always be numeric, like a phone number.
Examples tell almost nothing.
it would be useful to serialize the CFPropertyList object in order to store it in PHP sessions in a transparent manner.
Hi,
Was getting this error trying to create XML based plists.
Notice: Undefined variable: content in CFPropertyList->loadXMLStream() (line 144 of /Applications/XAMPP/xamppfiles/htdocs/dev_af/sites/all/modules/rest_server_plist/lib/cfpropertylist/CFPropertyList.php).
line 144: $this->parse($content,CFPropertyList::FORMAT_XML);
the fix: $this->parse($contents,CFPropertyList::FORMAT_XML);
sorry, I don't have patching tools.
Cheers
my structure (should become a CFDictionary):
$structure = array(
'uid' => $uid,
'filename' => $clientfile,
'identifier' => $packageinfo['identifier'],
'version' => $packageinfo['version'],
'installKBytes' => $packageinfo->payload['installKBytes'],
'numberOfFiles' => $packageinfo->payload['numberOfFiles']
);
i try to:
$td = new CFTypeDetector();
$guessedStructure = $td->toCFType($structure);
$packagelist->add($guessedStructure);
var_dump($packagelist->toArray());
results in:
Fatal error: Uncaught exception 'CFPropertyList\PListException' with message 'Could not determine CFType for object of type SimpleXMLElement' in /Library/WebServer/Documents/CFPropertyList/CFTypeDetector.php:122
Stack trace:
#0 /Library/WebServer/Documents/CFPropertyList/CFTypeDetector.php(138): CFPropertyList\CFTypeDetector->toCFType(Object(SimpleXMLElement))
#1 /Library/WebServer/Documents/upload.php(77): CFPropertyList\CFTypeDetector->toCFType(Array)
#2 {main}
thrown in /Library/WebServer/Documents/CFPropertyList/CFTypeDetector.php on line 122
Hi there,
it seems that there is a bug in the toBinary() function.
my sample php-code does this:
$plist = new CFPropertyList();
$plist->add($tmpDict = new CFDictionary());
$tmpDict->add('name', new CFString("Täst"));
echo $plist->toBinary();
Attention on the german ue-character in "Test" <-----
The output is not readable by NSPropertyListSerialization.
i saw that the last byte in the data is the value 0x16 but it should be 0x19 (compared with binary generated by Apple's Property List Editor!
I had a look into the toBinary()-function in CFBinaryPropertyList.php and found the following:
the function uniqueAndCountValues() counts the $stringSize from the original string value and not the utf16-value. so at the end the $table_offset is incorrect. I am right?
protected $stringSize = 0; // The length of all strings in the file (byte length, not character length)
best regards
Gabriel Gritsch
[email protected]
current class distribution into files is annoying
Here is a patch
diff --git a/CFTypeDetector.php b/CFTypeDetector.php
index 9964393..df083ed 100644
--- a/CFTypeDetector.php
+++ b/CFTypeDetector.php
@@ -61,6 +61,12 @@ class CFTypeDetector {
$previousKey = $key;
}
+ // additional check
+ // @editor Azat Khuzhin
+ if ($numericKeys) {
+ if (count($value) == 1 && $previousKey != 0) $numericKeys = false;
+ }
+
return !$numericKeys;
}
Hello
I have the below property list that I'm using TECLIB/CFPropertyList to ready it into an array, how can I instruct TECLIB/CFPropertyList NOT to decode any base64?
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Token</key> <data> RNN9LVelUIViUX55+bqeBezQjY5KCN/R8poooMa1WjJE= </data> <key>UnlockToken</key> <data> REFUQQAABORWRVJTAAAABAAAAAVUWVBFAAAABAAAAAJVVUlEAAAAEKw1LnPYSkFziXjU KJ7QcRlri7tjIGrbCB8bUpihrKpS5nheOPTbtuglD+SLX24ENtFLW8lQQktZAAAAICWb C3Sehmr80hjANnmeRPQuElPYgYh5WOoFwuhey4RGVVVJRAAAABBPWAlDj+BMx6R7c+3O uJodQ0xBUwAAAAQAAAABV1JBUAAAAAQAAAADS1RZUAAAAAQAAAAAV1BLWQAAACiM5qlx ZtTlVKBFYnzSAPD33Sd75NDuFfyOq4E9gUstYgwPu+MI5MyFU0lHTgAAABRAECYSVlhZ iNHfzkx2kpBmTGu6Yg== </data> </dict> </plist>
Hi, Rodney,
Wandering through your code a bit, found this in CFPropertyList.php:
public function loadBinaryStream($stream) {
if(($contents = stream_get_contents($stream)) === FALSE) throw IOException::notReadable('<stream>');
$this->parse($content,CFPropertyList::FORMAT_BINARY);
}
Am I seeing a problem between "$contents" on the first line and "$content" on the second line?
Because it's plist instead of CFPropertyList. Some fake package is using the name CFPropertyList that doesn't even work. I reported it for you.
HTTP and HTTPS are atleast two wrappers that dont support the stat() function. Here are some referenses. (http://se.php.net/manual/en/wrappers.http.php)
To get the CFPropertyList to work with http-urls i had to comment out the is_readable line in CFPropertyList.php:189
//if(!is_readable($file)) throw IOException::notReadable($file);
From what i can tell it throws exceptions at all other file read locations anyway so is that line really necessary? Could you write around is_readable and use something else?
Is your feature request related to a problem? Please describe.
The latest release on Github is version 2.0.2
. However, the newest version available on Packagist is v2.0.1
. The package current doesn't auto-update on packagist.
Describe the solution you'd like
We should set up auto updating in packagist and make the latest version available.
I'm not sure if I'm correct, but I think CFDictionary::add() should throw an exception if key is empty, as this will end up with an malformed plist
The following sample code:
$plist = new CFPropertyList\CFPropertyList();
$plist->add($dict = new \CFPropertyList\CFDictionary());
$dict->add('Index', new CFPropertyList\CFNumber(0));
echo $plist->toXML(true);
output this plist:
IndexIt appears that having makes the plist invalid, at least, xCode complains that the isn't in the correct format.
Any idea?
Thanks,
Describe the bug
Parsing plists produced by NSKeyedArchiver
produces a tree of dependencies where references are marked with CF$UID
pointing to the main tree. The library squashes these into integers making it impossible to distinguish references from real values.
To Reproduce
Attempt to parse the following plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>test1</key>
<dict>
<key>CF$UID</key>
<integer>123</integer>
</dict>
<key>test2</key>
<integer>321</integer>
</dict>
</plist>
As an array it will result in:
This doesn't seem like a problem until you encounter a structure like:
<dict>
<key>$class</key>
<dict>
<key>CF$UID</key>
<integer>89</integer>
</dict>
<key>accumulatedDataSize</key>
<integer>7723067</integer>
<key>allURLs</key>
<dict>
<key>CF$UID</key>
<integer>8</integer>
</dict>
</dict>
As you can see it's impossible to distinguish what's is a reference and what is an integer. Obviously these are two different things.
I traced the origin of this to 2ea0483 and no further changes has been made.
Expected behavior
UID type should be decoded to a simple DTO which can have a toInteger()
method.
Per @rodneyrehm's comment in #34 (#34 (comment)), I wanted to create an issue on the topic of potentially finding a new maintainer (mostly to not muck up #34 with off-topic discussion).
I do not have enough background in PHP to become the maintainer of this project, but I'd be happy to at least be a steward of the project to try and help find a more suitable maintainer.
One option would be to list the project on https://github.com/pickhardt/maintainers-wanted.
There are currently 30 people watching this repo, and 77 forks. Perhaps someone will see this and offer to help maintain it.
Greetings! When I try to use CFPropertyList within my own PHP class, PHP says my class can't be found, since my class isn't supposed to be part of the CFPropertyList namespace - or any explicit namespace, for that matter.
On the other hand, if I remove the namespace line, CFPropertyList can't be found. Catch-22!
I didn't see any examples of handling this properly within the source, so I figured I'd check in. Clues/advice appreciated!
The source is more or less this:
namespace CFPropertyList;
require_once("my/path/to/CFPropertyList.php");
class myClass {
// ...
function someFunction() {
// ...
$di = new DOMImplementation(); // This sort of thing works.
$plist = new CFPropertyList(); // This does not.
// ...
}
// ...
}
Hi, @Naylin15
The htmlproofer
show 2 erros in Travis CI.
Could you fix it?
- ./_site/projects.html
* External link https://TECLIB.github.io/react-winjs failed: 404 No error
* External link https://teclib.github.io/CFPropertyList/apple-touch-icon.png failed: 404 No error
htmlproofer 3.7.2 | Error: HTML-Proofer found 2 failures!
Reference:
https://travis-ci.org/TECLIB/CFPropertyList/branches
Hi,
CFType creates empty tags in short notation, which is very useful. But it does not work for empty strings.
For empty strings we got which should be
I have a little patch for you that might fix this issue.
Here is the patch for CFType.php:62
/**
Get XML-Node.
@param DOMDocument $doc DOMDocument to create DOMNode in
@param string $nodeName Name of element to create
@return DOMNode Node created based on CType
@uses $value as nodeValue
*/
public function toXML(DOMDocument $doc, $nodeName) {
$node = $doc->createElement($nodeName);
if ('' != $this->value) {
$text = $doc->createTextNode($this->value);
$node->appendChild($text);
}
return $node;
}
some bug report ( PHP_VERSION: 5.3.18, LIBXML_VERSION: 20800, LIBXML_NOXMLDECL: 2)
PHP Warning: DOMDocument::loadXML(): Char 0x0 out of allowed range in Entity, line: 5892 in /private/tmp/CFPropertyList/classes/CFPropertyList/CFPropertyList.php on line 256
PHP Fatal error: Uncaught exception 'DOMException' in /private/tmp/CFPropertyList/classes/CFPropertyList/CFPropertyList.php:256
A possible solution:
preg_replace('/[^\x{0009}\x{000a}\x{000d}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}]+/u', '', $str);
PHP 8.1 introduced return type declarations for most internal methods. Several classes in this library implement various built-in interfaces such as Iterator
and ArrayAccess
. These classes currently cause deprecation warnings since they don't provide the proper return type hints.
There are two ways to approach this problem.
Approach 1: Add #[ReturnTypeWillChange]
Attribute
PHP 8.1 introduces the #[ReturnTypeWillChange]
attribute which can be used to temporarily suppress the deprecation notice until PHP 9. Since the attribute syntax is backwards compatible (older versions will treat it as a code comment), this would not break backwards compatibility. It is, however, not a real solution as it simply hides the issue.
Approach 2: Adding the missing type hints
The "correct" solution would be to add the missing type hints to the various interface methods. This would of course be a breaking change as return types are only supported since PHP 7.0.
That being said, this project currently supports PHP versions all the way down to PHP 5.6, which as been EOL for close to 3 years. I think it's reasonable to tag a new version which fixes the deprecation notices in PHP 8.1 and drops support for all PHP versions that don't receive security fixes anymore (< PHP 7.4).
I'd be happy to provide the necessary pull requests.
I've scoured trying to find an example to pull a selected field from an array. I can pull fields based on key name just fine, however having an issue determining how to utilize CFP to pull a value from an array, using PHP.
Any assistance would be greatly appreciated. I've greatly appreciated the library having been made available thus far, thanks guys!
Describe the bug
When using a locale that uses commas (,) instead of points (.) as decimal delimiter, the output of CFPropertyList::toXML() uses this charater for <real>
s which is invalid PList-Data. The cause is probably some implicit toString conversion that will use the current locale.
To Reproduce
Execute this script:
<?php
use CFPropertyList\CFPropertyList;
require_once('vendor/autoload.php');
$example = <<<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"><dict><key>ExampleReal</key><real>1.5</real></dict></plist>
EOF;
setlocale(LC_ALL, 'de_DE.UTF-8');
$plist = new CFPropertyList();
$plist->parse($example);
echo $plist->toXML();
It's output will be:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"><dict><key>ExampleReal</key><real>1,5</real></dict></plist>
Expected behavior
This output:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"><dict><key>ExampleReal</key><real>1.5</real></dict></plist>
(1.5
instead of 1,5
)
Desktop
With pearhub.org being down indefinitely I thought I'd try an offline install from the tar but I get this error:
could not extract the package.xml file from "/Users/adam/Downloads/CFPropertyList-1.1.1.tgz"
install failed
Add this to the type detector, just above the case is_string
case substr_count($value, "\x00") > 0:
return new CFData($value);
break;
thanks for the plist reader!
I am using a form to have users submit their itunes.xml plist to the site, which then parses the data and displays statistics about their listening habits.
It works fine when uploaded files ~ 20mb, but a 72mb is throwing the following error.
Warning: DOMDocument::loadXML(): (null)(null)xmlSAX2Characters: out of memory in Entity, line: 538384 in ..../classes/CFPropertyList/CFPropertyList.php on line 267.
I've increased the memory on my php server to 528mb and have a long time out to help troubleshoot this, but I didn't get anywhere.
You can test it yourself at:
http://jacobraccuia.com/most_listened.php
Is this a server error or bug here?
Thanks
Hello Folk. I have a little problem when using your library.
I'm using CFPropertyList to extract some binary data from plist saved in an ipad and use it in a web app. I save the data saved as a plist with php in a .plist file and then use
$plist = new CFPropertyList( dirname(FILE).'/sample.plist', CFPropertyList::FORMAT_BINARY );
I succesfully extracted the data almost all the times but when trying to read a .plist file that has 762KB it gives me an error.
Do you have an idea of what is happening?
Thank you very much in advance for your time.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.