Skip to content

Commit

Permalink
Merge pull request #12 from nickl-/master
Browse files Browse the repository at this point in the history
Merging back CipherSofts changes for PSR-0 and composer/packagist
  • Loading branch information
ckruse committed Jul 22, 2012
2 parents 2fa8a5d + 055cbb3 commit f44d6e8
Show file tree
Hide file tree
Showing 23 changed files with 146 additions and 75 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
docs
*tmp
composer.lock
vendor
.foundation
Makefile
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# CFPropertyList

This is a fork of CFPropertyList by Rodney Rehm, created for the purpose of reorganizing the CFPropertyList classes into PHP 5.3 namespacing, following PSR-0 rules.

PSR-0 Fork by Jarvis Badgley, https://github.com/ChiperSoft/CFPropertyList
Original by Rodney Rehm, https://github.com/rodneyrehm/CFPropertyList

---

The PHP implementation of Apple's PropertyList can handle XML PropertyLists as well as 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.

Note: CFPropertylist was originally hosted on [Google Code](http://code.google.com/p/cfpropertylist/)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* @package plist
* @version $Id$
*/
namespace CFPropertyList;

/**
* Facility for reading and writing binary PropertyLists. Ported from {@link http://www.opensource.apple.com/source/CF/CF-476.15/CFBinaryPList.c CFBinaryPList.c}.
Expand Down Expand Up @@ -123,8 +124,8 @@ protected static function make64Int($hi,$lo) {
if(function_exists("bcmul")) return bcadd(bcmul($hi,"4294967296"), $lo);

if(class_exists('Math_BigInteger')) {
$bi = new Math_BigInteger($hi);
return $bi->multiply(new Math_BigInteger("4294967296"))->add(new Math_BigInteger($lo))->toString();
$bi = new \Math_BigInteger($hi);
return $bi->multiply(new \Math_BigInteger("4294967296"))->add(new \Math_BigInteger($lo))->toString();
}

throw new PListException("either gmp or bc has to be installed, or the Math_BigInteger has to be available!");
Expand Down
32 changes: 17 additions & 15 deletions CFPropertyList.php → classes/CFPropertyList/CFPropertyList.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@
* @example example-modify-01.php Read, modify and save a PropertyList
*/

namespace CFPropertyList;
use \Iterator, \DOMDocument, \DOMException, DOMImplementation, DOMNode;

/**
* Require IOException, PListException, CFType and CFBinaryPropertyList
*/
$plistDirectory = dirname(__FILE__);
require_once($plistDirectory.'/IOException.php');
require_once($plistDirectory.'/PListException.php');
require_once($plistDirectory.'/CFType.php');
require_once($plistDirectory.'/CFBinaryPropertyList.php');
require_once($plistDirectory.'/CFTypeDetector.php');
require_once(__DIR__.'/IOException.php');
require_once(__DIR__.'/PListException.php');
require_once(__DIR__.'/CFType.php');
require_once(__DIR__.'/CFBinaryPropertyList.php');
require_once(__DIR__.'/CFTypeDetector.php');

/**
* Property List
Expand Down Expand Up @@ -93,15 +95,15 @@ class CFPropertyList extends CFBinaryPropertyList implements Iterator {
* @var array
*/
protected static $types = array(
'string' => 'CFString',
'real' => 'CFNumber',
'string' => 'CFString',
'real' => 'CFNumber',
'integer' => 'CFNumber',
'date' => 'CFDate',
'true' => 'CFBoolean',
'false' => 'CFBoolean',
'data' => 'CFData',
'array' => 'CFArray',
'dict' => 'CFDictionary'
'date' => 'CFDate',
'true' => 'CFBoolean',
'false' => 'CFBoolean',
'data' => 'CFData',
'array' => 'CFArray',
'dict' => 'CFDictionary'
);


Expand Down Expand Up @@ -271,7 +273,7 @@ protected function import(DOMNode $node, $parent) {
// skip if we can't handle the element
if(!isset(self::$types[$n->nodeName])) continue;

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

// find previous <key> if possible
Expand Down
2 changes: 2 additions & 0 deletions CFType.php → classes/CFPropertyList/CFType.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* @subpackage plist.types
* @version $Id$
*/
namespace CFPropertyList;
use \DOMDocument, \Iterator, \ArrayAccess;

/**
* Base-Class of all CFTypes used by CFPropertyList
Expand Down
14 changes: 9 additions & 5 deletions CFTypeDetector.php → classes/CFPropertyList/CFTypeDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
* @example example-create-03.php Using {@link CFTypeDetector} with {@link CFDate} and {@link CFData}
* @example example-create-04.php Using and extended {@link CFTypeDetector}
*/

namespace CFPropertyList;
use \DateTime, \Iterator;

class CFTypeDetector {

/**
Expand Down Expand Up @@ -129,10 +133,6 @@ public function toCFType($value) {
return $t;
break;

case is_numeric($value):
return new CFNumber($value);
break;

case is_bool($value):
return new CFBoolean($value);
break;
Expand All @@ -152,6 +152,10 @@ public function toCFType($value) {
throw new PListException('Could not determine CFType for resource of type '. get_resource_type($value));
break;

case is_numeric($value):
return new CFNumber($value);
break;

default:
if( $this->suppressExceptions )
return $this->defaultValue();
Expand All @@ -163,4 +167,4 @@ public function toCFType($value) {

}

?>

5 changes: 2 additions & 3 deletions IOException.php → classes/CFPropertyList/IOException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
* @package plist
* @version $Id$
*/
namespace CFPropertyList;

/**
* Basic Input / Output Exception
* @author Rodney Rehm <rodney.rehm@medialize.de>
* @author Christian Kruse <cjk@wwwtech.de>
* @package plist
*/
class IOException extends Exception {
class IOException extends \Exception {
/**
* Flag telling the File could not be found
*/
Expand Down Expand Up @@ -95,5 +96,3 @@ public static function writeError($path) {
}
}


?>
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
* @package plist
* @version $Id$
*/
namespace CFPropertyList;

/**
* Exception for errors with the PList format
* @author Rodney Rehm <rodney.rehm@medialize.de>
* @author Christian Kruse <cjk@wwwtech.de>
* @package plist
*/
class PListException extends Exception {
class PListException extends \Exception {

}


?>
32 changes: 32 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "ChiperSoft\/CFPropertyList",
"description": "This is a fork of CFPropertyList by Rodney Rehm, created for the purpose of reorganizing the CFPropertyList classes into PHP 5.3 namespacing, following PSR-0 rules.",
"version": "0.1.0",
"type": "library",
"time": "",
"homepage": "",
"license": "MIT",
"authors": [
{
"name": "ChiperSoft",
"email": "chiper@chipersoft.com"
},
{
"name": "Christian Kruse",
"email": "cjk@wwwtech.de"
},
{
"name": "Rodney Rehm",
"email": "mail+github@rodneyrehm.de"
},
{
"name": "Serge Paquet",
"email": "serge.paquet@libeo.com"
}
],
"autoload": {
"psr-0": {
"CFPropertyList":"classes\/"
}
}
}
7 changes: 4 additions & 3 deletions examples/example-create-01.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* @package plist
* @subpackage plist.examples
*/
namespace CFPropertyList;

// just in case...
error_reporting( E_ALL );
Expand All @@ -13,7 +14,7 @@
/**
* Require CFPropertyList
*/
require_once(dirname(__FILE__).'/../CFPropertyList.php');
require_once(__DIR__.'/../classes/CFPropertyList/CFPropertyList.php');


/*
Expand Down Expand Up @@ -55,12 +56,12 @@
/*
* Save PList as XML
*/
$plist->saveXML( dirname(__FILE__).'/example-create-01.xml.plist' );
$plist->saveXML( __DIR__.'/example-create-01.xml.plist' );


/*
* Save PList as Binary
*/
$plist->saveBinary( dirname(__FILE__).'/example-create-01.binary.plist' );
$plist->saveBinary( __DIR__.'/example-create-01.binary.plist' );

?>
8 changes: 5 additions & 3 deletions examples/example-create-02.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* @package plist
* @subpackage plist.examples
*/
namespace CFPropertyList;
use \DateTime, \DateTimeZone;

// just in case...
error_reporting( E_ALL );
Expand All @@ -13,7 +15,7 @@
/**
* Require CFPropertyList
*/
require_once(dirname(__FILE__).'/../CFPropertyList.php');
require_once(__DIR__.'/../classes/CFPropertyList/CFPropertyList.php');


/*
Expand Down Expand Up @@ -49,11 +51,11 @@
/*
* Save PList as XML
*/
$plist->saveXML( dirname(__FILE__).'/example-create-02.xml.plist' );
$plist->saveXML( __DIR__.'/example-create-02.xml.plist' );

/*
* Save PList as Binary
*/
$plist->saveBinary( dirname(__FILE__).'/example-create-02.binary.plist' );
$plist->saveBinary( __DIR__.'/example-create-02.binary.plist' );

?>
7 changes: 4 additions & 3 deletions examples/example-create-03.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @package plist
* @subpackage plist.examples
*/
namespace CFPropertyList;

// just in case...
error_reporting( E_ALL );
Expand All @@ -14,7 +15,7 @@
/**
* Require CFPropertyList
*/
require_once(dirname(__FILE__).'/../CFPropertyList.php');
require_once(__DIR__.'/../classes/CFPropertyList/CFPropertyList.php');


/*
Expand Down Expand Up @@ -47,11 +48,11 @@
/*
* Save PList as XML
*/
$plist->saveXML( dirname(__FILE__).'/example-create-03.xml.plist' );
$plist->saveXML( __DIR__.'/example-create-03.xml.plist' );

/*
* Save PList as Binary
*/
$plist->saveBinary( dirname(__FILE__).'/example-create-03.binary.plist' );
$plist->saveBinary( __DIR__.'/example-create-03.binary.plist' );

?>
17 changes: 9 additions & 8 deletions examples/example-create-04.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* @package plist
* @subpackage plist.examples
*/
namespace CFPropertyList;

// just in case...
error_reporting( E_ALL );
Expand All @@ -13,7 +14,7 @@
/**
* Require CFPropertyList
*/
require_once(dirname(__FILE__).'/../CFPropertyList.php');
require_once(__DIR__.'/../classes/CFPropertyList/CFPropertyList.php');

class DemoDetector extends CFTypeDetector {

Expand All @@ -32,7 +33,7 @@ public function toCFType($value) {
* We make use of CFTypeDetector, which truly is not almighty!
*/

$stack = new SplStack();
$stack = new \SplStack();
$stack[] = 1;
$stack[] = 2;
$stack[] = 3;
Expand All @@ -51,8 +52,8 @@ public function toCFType($value) {
$td = new CFTypeDetector();
$guessedStructure = $td->toCFType( $structure );
$plist->add( $guessedStructure );
$plist->saveXML( dirname(__FILE__).'/example-create-04.xml.plist' );
$plist->saveBinary( dirname(__FILE__).'/example-create-04.binary.plist' );
$plist->saveXML( __DIR__.'/example-create-04.xml.plist' );
$plist->saveBinary( __DIR__.'/example-create-04.binary.plist' );
}
catch( PListException $e ) {
echo 'Normal detection: ', $e->getMessage(), "\n";
Expand All @@ -66,8 +67,8 @@ public function toCFType($value) {
$td = new CFTypeDetector( false, true );
$guessedStructure = $td->toCFType( $structure );
$plist->add( $guessedStructure );
$plist->saveXML( dirname(__FILE__).'/example-create-04.xml.plist' );
$plist->saveBinary( dirname(__FILE__).'/example-create-04.binary.plist' );
$plist->saveXML( __DIR__.'/example-create-04.xml.plist' );
$plist->saveBinary( __DIR__.'/example-create-04.binary.plist' );
}
catch( PListException $e ) {
echo 'Silent detection: ', $e->getMessage(), "\n";
Expand All @@ -81,8 +82,8 @@ public function toCFType($value) {
$td = new DemoDetector();
$guessedStructure = $td->toCFType( $structure );
$plist->add( $guessedStructure );
$plist->saveXML( dirname(__FILE__).'/example-create-04.xml.plist' );
$plist->saveBinary( dirname(__FILE__).'/example-create-04.binary.plist' );
$plist->saveXML( __DIR__.'/example-create-04.xml.plist' );
$plist->saveBinary( __DIR__.'/example-create-04.binary.plist' );
}
catch( PListException $e ) {
echo 'User defined detection: ', $e->getMessage(), "\n";
Expand Down
Loading

0 comments on commit f44d6e8

Please sign in to comment.