public function testWriteFile() { $plist = new CFPropertyList(); $dict = new CFDictionary(); $names = new CFDictionary(); $names->add('given-name', new CFString('John')); $names->add('surname', new CFString('Dow')); $dict->add('names', $names); $pets = new CFArray(); $pets->add(new CFString('Jonny')); $pets->add(new CFString('Bello')); $dict->add('pets', $pets); $dict->add('age', new CFNumber(28)); $dict->add('birth-date', new CFDate(412035803)); $plist->add($dict); $plist->saveBinary(WRITE_BINARY_DATA_FILE); $this->assertTrue(is_file(WRITE_BINARY_DATA_FILE)); $this->assertTrue(filesize(WRITE_BINARY_DATA_FILE) > 32); $plist->load(WRITE_BINARY_DATA_FILE); unlink(WRITE_BINARY_DATA_FILE); }
$plist->saveXML(dirname(__FILE__) . '/example-create-04.xml.plist'); $plist->saveBinary(dirname(__FILE__) . '/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(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'); } 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(dirname(__FILE__) . '/example-create-04.xml.plist'); $plist->saveBinary(dirname(__FILE__) . '/example-create-04.binary.plist'); } catch (PListException $e) { echo 'User defined detection: ', $e->getMessage(), "\n"; }
$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"; } /* * 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'); } catch (PListException $e) { echo 'User defined detection: ', $e->getMessage(), "\n"; }
<?php /** * Examples for how to use CFPropertyList * Read a Binary PropertyList * @package plist * @subpackage plist.examples */ // just in case... error_reporting(E_ALL); ini_set('display_errors', 'on'); /** * Require CFPropertyList */ require_once dirname(__FILE__) . '/../CFPropertyList.php'; /* * create a new CFPropertyList instance which loads the sample.plist on construct. * since we know it's a binary file, we can skip format-determination */ $plist = new CFPropertyList(dirname(__FILE__) . '/sample.binary.plist', CFPropertyList::FORMAT_BINARY); /* * retrieve the array structure of sample.plist and dump to stdout */ echo '<pre>'; var_dump($plist->toArray()); echo '</pre>'; $plist->saveBinary(dirname(__FILE__) . '/sample.binary.plist');
<?php /** * Examples for how to use CFPropertyList * Read a PropertyList without knowing the type * @package plist * @subpackage plist.examples */ namespace CFPropertyList; // just in case... error_reporting(E_ALL); ini_set('display_errors', 'on'); /** * Require CFPropertyList */ require_once __DIR__ . '/../classes/CFPropertyList/CFPropertyList.php'; /* * create a new CFPropertyList instance which loads the sample.plist on construct. * since we know the format, use the automatic format-detection */ $plist = new CFPropertyList(__DIR__ . '/sample.binary.plist'); /* * retrieve the array structure of sample.plist and dump to stdout */ echo '<pre>'; var_dump($plist->toArray()); echo '</pre>'; $plist->saveBinary(__DIR__ . '/sample.binary.plist');