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
Show file tree
Hide file tree
Changes from 3 commits
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
39 changes: 15 additions & 24 deletions examples/example-create-01.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@
*
* This file is part of 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.
*
* Copyright (c) 2018 Teclib'
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
Expand All @@ -34,7 +27,7 @@
* ------------------------------------------------------------------------------
* @author Christian Kruse <[email protected]>
* @copyright Copyright © 2018 Teclib
* @package plist
* @package CFPropertyList
* @license MIT
* @link https://github.com/TECLIB/CFPropertyList/
* ------------------------------------------------------------------------------
Expand All @@ -48,8 +41,8 @@
namespace CFPropertyList;

// just in case...
error_reporting( E_ALL );
ini_set( 'display_errors', 'on' );
error_reporting(E_ALL);
Copy link

@DIOHz0r DIOHz0r Apr 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really good to have this?....

Copy link
Collaborator Author

@btry btry Apr 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are examples to show how to use the library. They must be as simple as possible, straightforward. For me this is fine.

ini_set('display_errors', 'on');

/**
* Require CFPropertyList
Expand All @@ -66,42 +59,40 @@
* Manuall Create the sample.xml.plist
*/
// the Root element of the PList is a Dictionary
$plist->add( $dict = new CFDictionary() );
$plist->add($dict = new CFDictionary());

// <key>Year Of Birth</key><integer>1965</integer>
$dict->add( 'Year Of Birth', new CFNumber( 1965 ) );
$dict->add('Year Of Birth', new CFNumber(1965));

// <key>Date Of Graduation</key><date>2004-06-22T19:23:43Z</date>
$dict->add( 'Date Of Graduation', new CFDate( gmmktime( 19, 23, 43, 06, 22, 2004 ) ) );
$dict->add('Date Of Graduation', new CFDate(gmmktime(19, 23, 43, 06, 22, 2004)));

// <key>Pets Names</key><array/>
$dict->add( 'Pets Names', new CFArray() );
$dict->add('Pets Names', new CFArray());

// <key>Picture</key><data>PEKBpYGlmYFCPA==</data>
// to keep it simple we insert an already base64-encoded string
$dict->add( 'Picture', new CFData( 'PEKBpYGlmYFCPA==', true ) );
$dict->add('Picture', new CFData('PEKBpYGlmYFCPA==', true));

// <key>City Of Birth</key><string>Springfield</string>
$dict->add( 'City Of Birth', new CFString( 'Springfield' ) );
$dict->add('City Of Birth', new CFString('Springfield'));

// <key>Name</key><string>John Doe</string>
$dict->add( 'Name', new CFString( 'John Doe' ) );
$dict->add('Name', new CFString('John Doe'));

// <key>Kids Names</key><array><string>John</string><string>Kyra</string></array>
$dict->add( 'Kids Names', $array = new CFArray() );
$array->add( new CFString( 'John' ) );
$array->add( new CFString( 'Kyra' ) );
$dict->add('Kids Names', $array = new CFArray());
$array->add(new CFString('John'));
$array->add(new CFString('Kyra'));


/*
* Save PList as XML
*/
$plist->saveXML( __DIR__.'/example-create-01.xml.plist' );
$plist->saveXML(__DIR__.'/example-create-01.xml.plist');


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

?>
$plist->saveBinary(__DIR__.'/example-create-01.binary.plist');
31 changes: 12 additions & 19 deletions examples/example-create-02.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@
*
* This file is part of 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.
*
* Copyright (c) 2018 Teclib'
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
Expand All @@ -34,7 +27,7 @@
* ------------------------------------------------------------------------------
* @author Christian Kruse <[email protected]>
* @copyright Copyright © 2018 Teclib
* @package plist
* @package CFPropertyList
* @license MIT
* @link https://github.com/TECLIB/CFPropertyList/
* ------------------------------------------------------------------------------
Expand All @@ -47,11 +40,13 @@
* @subpackage plist.examples
*/
namespace CFPropertyList;
use \DateTime, \DateTimeZone;

use \DateTime;
use \DateTimeZone;

// just in case...
error_reporting( E_ALL );
ini_set( 'display_errors', 'on' );
error_reporting(E_ALL);
ini_set('display_errors', 'on');

/**
* Require CFPropertyList
Expand All @@ -73,8 +68,8 @@
'Year Of Birth' => 1965,
// Note: dates cannot be guessed, so this will become a CFNumber and be treated as an integer
// See example-04.php for a possible workaround
'Date Of Graduation' => gmmktime( 19, 23, 43, 06, 22, 2004 ),
'Date Of Birth' => new DateTime( '1984-09-07 08:15:23', new DateTimeZone( 'Europe/Berlin' ) ),
'Date Of Graduation' => gmmktime(19, 23, 43, 06, 22, 2004),
'Date Of Birth' => new DateTime('1984-09-07 08:15:23', new DateTimeZone('Europe/Berlin')),
'Pets Names' => array(),
// Note: data cannot be guessed, so this will become a CFString
// See example-03.php for a possible workaround
Expand All @@ -85,18 +80,16 @@
);

$td = new CFTypeDetector();
$guessedStructure = $td->toCFType( $structure );
$plist->add( $guessedStructure );
$guessedStructure = $td->toCFType($structure);
$plist->add($guessedStructure);


/*
* Save PList as XML
*/
$plist->saveXML( __DIR__.'/example-create-02.xml.plist' );
$plist->saveXML(__DIR__.'/example-create-02.xml.plist');

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

?>
$plist->saveBinary(__DIR__.'/example-create-02.binary.plist');
27 changes: 9 additions & 18 deletions examples/example-create-03.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@
*
* This file is part of 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.
*
* Copyright (c) 2018 Teclib'
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
Expand All @@ -34,7 +27,7 @@
* ------------------------------------------------------------------------------
* @author Christian Kruse <[email protected]>
* @copyright Copyright © 2018 Teclib
* @package plist
* @package CFPropertyList
* @license MIT
* @link https://github.com/TECLIB/CFPropertyList/
* ------------------------------------------------------------------------------
Expand All @@ -50,8 +43,8 @@
namespace CFPropertyList;

// just in case...
error_reporting( E_ALL );
ini_set( 'display_errors', 'on' );
error_reporting(E_ALL);
ini_set('display_errors', 'on');

/**
* Require CFPropertyList
Expand All @@ -72,28 +65,26 @@
$structure = array(
'Year Of Birth' => 1965,
// Note: dates cannot be guessed, it thus has to be specified explicitly
'Date Of Graduation' => new CFDate( gmmktime( 19, 23, 43, 06, 22, 2004 ) ),
'Date Of Graduation' => new CFDate(gmmktime(19, 23, 43, 06, 22, 2004)),
'Pets Names' => array(),
// Note: data cannot be guessed, it thus has to be specified explicitly
'Picture' => new CFData( 'PEKBpYGlmYFCPA==', true ),
'Picture' => new CFData('PEKBpYGlmYFCPA==', true),
'City Of Birth' => 'Springfield',
'Name' => 'John Doe',
'Kids Names' => array( 'John', 'Kyra' ),
);

$td = new CFTypeDetector();
$guessedStructure = $td->toCFType( $structure );
$plist->add( $guessedStructure );
$guessedStructure = $td->toCFType($structure);
$plist->add($guessedStructure);


/*
* Save PList as XML
*/
$plist->saveXML( __DIR__.'/example-create-03.xml.plist' );
$plist->saveXML(__DIR__.'/example-create-03.xml.plist');

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

?>
$plist->saveBinary(__DIR__.'/example-create-03.binary.plist');
83 changes: 36 additions & 47 deletions examples/example-create-04.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@
*
* This file is part of 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.
*
* Copyright (c) 2018 Teclib'
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
Expand All @@ -34,7 +27,7 @@
* ------------------------------------------------------------------------------
* @author Christian Kruse <[email protected]>
* @copyright Copyright © 2018 Teclib
* @package plist
* @package CFPropertyList
* @license MIT
* @link https://github.com/TECLIB/CFPropertyList/
* ------------------------------------------------------------------------------
Expand All @@ -49,24 +42,25 @@
namespace CFPropertyList;

// just in case...
error_reporting( E_ALL );
ini_set( 'display_errors', 'on' );
error_reporting(E_ALL);
ini_set('display_errors', 'on');

/**
* Require CFPropertyList
*/
require_once(__DIR__.'/../vendor/autoload.php');

class DemoDetector extends CFTypeDetector {

public function toCFType($value) {
if( $value instanceof PListException ) {
return new CFString( $value->getMessage() );
}
class DemoDetector extends CFTypeDetector
{

return parent::toCFType($value);
}
public function toCFType($value)
{
if ($value instanceof PListException) {
return new CFString($value->getMessage());
}

return parent::toCFType($value);
}
}

/*
Expand All @@ -89,45 +83,40 @@ public function toCFType($value) {
* Try default detection
*/
try {
$plist = new CFPropertyList();
$td = new CFTypeDetector();
$guessedStructure = $td->toCFType( $structure );
$plist->add( $guessedStructure );
$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";
$plist = new CFPropertyList();
$td = new CFTypeDetector();
$guessedStructure = $td->toCFType($structure);
$plist->add($guessedStructure);
$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";
}

/*
* Try detection by omitting exceptions
*/
try {
$plist = new CFPropertyList();
$td = new CFTypeDetector( array('suppressExceptions' => true) );
$guessedStructure = $td->toCFType( $structure );
$plist->add( $guessedStructure );
$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";
$plist = new CFPropertyList();
$td = new CFTypeDetector(array('suppressExceptions' => true));
$guessedStructure = $td->toCFType($structure);
$plist->add($guessedStructure);
$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";
}

/*
* Try detection with an extended version of CFTypeDetector
*/
try {
$plist = new CFPropertyList();
$td = new DemoDetector();
$guessedStructure = $td->toCFType( $structure );
$plist->add( $guessedStructure );
$plist->saveXML( __DIR__.'/example-create-04.xml.plist' );
$plist->saveBinary( __DIR__.'/example-create-04.binary.plist' );
$plist = new CFPropertyList();
$td = new DemoDetector();
$guessedStructure = $td->toCFType($structure);
$plist->add($guessedStructure);
$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";
}
catch( PListException $e ) {
echo 'User defined detection: ', $e->getMessage(), "\n";
}

?>
Loading