Giter Site home page Giter Site logo

cfpropertylist's Introduction

CFPropertyList

Teclib' Banner

License MIT Follow twitter Project Status: Active Conventional Commits

Teclib’ is an open source software editor that offers a vast range of fully integrated open source technology packages, to better respond to business needs.

Visit our Website Teclib'.

Table of Contents

Synopsis

The PHP implementation of Apple's PropertyList can handle both XML and binary PropertyLists. It offers functionality to easily convert data between worlds, e.g. recalculating timestamps from unix epoch to apple epoch and vice versa. A feature to automagically create (guess) the plist structure from a normal PHP data structure will help you dump your data to plist in no time.

CFPropertyList does not rely on any "Apple proprietary" components, like plutil. CFPropertyList runs on any Operating System with PHP and some standard extensions installed.

Although you might want to deliver data to your iPhone application, you might want to run those server side services on your standard Linux (or even Windows) environment, rather than buying an expensive Apple Server. With CFPropertyList you now have the power to provide data from your favorite Operating System.

Build Status

Release channel Beta Channel
unit tests unit tests

Installation

See or How to install article.

Documentation

We maintain a detailed documentation of the project on the Website, check the Development Development and How-tos sections.

Versioning

In order to provide transparency on our release cycle and to maintain backward compatibility, Flyve MDM is maintained under the Semantic Versioning guidelines. We are committed to following and complying with the rules, the best we can.

See the tags section of our GitHub project for changelogs for each release version. Release announcement posts on the official Teclib' blog contain summaries of the most noteworthy changes made in each release.

Contact

You can contact us through any of our channels, check our Contact section

Contribute

Want to file a bug, contribute some code, or improve documentation? Excellent! Read up on our guidelines for contributing and then check out one of our issues in the Issues Dashboard.

Copying

  • Code: you can redistribute it and/or modify it under the terms of the MIT License (MIT).
  • Documentation: released under Attribution 4.0 International (CC BY 4.0).

cfpropertylist's People

Contributors

ajsb85 avatar alts avatar btry avatar ckruse avatar ddebin avatar dwlnetnl avatar huongnv13 avatar jasper2virtual avatar ksassnowski avatar lpotherat avatar mcfedr avatar naylin15 avatar nickl- avatar robbertkl avatar rodneyrehm avatar stormsweeper avatar twipped avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cfpropertylist's Issues

Error for xml based plists.

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

Trouble installing

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

Information for project site

Observed Results

Add the following information on gh-pages

  • Requirements & limitations
  • Related
  • How to install

Expected behavior

How to use within a PHP class?

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.
    // ...
  }
  // ...
}

new CFNumber(0) = format error

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:

Index

It appears that having makes the plist invalid, at least, xCode complains that the isn't in the correct format.

Any idea?

Thanks,

PHP 8.1 Compatibility

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.

CFTypeDetector has an error

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;
   }

Maintainers Wanted

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.

Binary data detection fix

Add this to the type detector, just above the case is_string

  case substr_count($value, "\x00") > 0:
    return new CFData($value);
  break;

Uncaught exception

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

How to disable base64 decoding?

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>

XML Parser: Invalid Character Was Found in Text Content

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);

Output of toXML() for <real>s is locale-dependent and causes creation of invalid PList-XML

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

  • Linux 5.4, PHP 7.4.3 using CLI, Composer-Package rodneyrehm/plist v2.0.2

Package does not auto-update on packagist

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.

url wrappers that dont support stat() wont work with is_readable()

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?

Assistance with example

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!

saveXml creates empty tags in short notation except for empty strings

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;
    }

DevOps tasks

  • Continuous integration
  • Continuous deployment
  • Continuous delivery
  • Changelog
  • Test reports
  • Coverage reports
  • Code documentation
  • Artifacts for downloads and release description

Empty tags created for integer = 0

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.

Error reading large plist files

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

Packagist package has the wrong name

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.

Bug with UTF8-Characters in toBinary()

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]

CFPropertyList Problem

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.

Type detector interpreting string as integer

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.

Potential misnamed variable in loadBinaryStream in CFPropertyList.php

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?

`CF$UID` cannot be squashed to integer

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:
image

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>

This will parse to:
image

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.

unpack() problems

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.

TypeDetecting Dictionary fails

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.