Using the CFPropertyList API

  1. <?php
  2. /**
  3.  * Examples for how to use CFPropertyList
  4.  * Create the PropertyList sample.xml.plist by using the CFPropertyList API.
  5.  * @package plist
  6.  * @subpackage plist.examples
  7.  */
  8.  
  9. // just in case...
  10. error_reportingE_ALL );
  11. ini_set'display_errors''on' );
  12.  
  13. /**
  14.  * Require CFPropertyList
  15.  */
  16. require_once(dirname(__FILE__).'/../CFPropertyList.php');
  17.  
  18.  
  19. /*
  20.  * create a new CFPropertyList instance without loading any content
  21.  */
  22. $plist new CFPropertyList();
  23.  
  24. /*
  25.  * Manuall Create the sample.xml.plist 
  26.  */
  27. // the Root element of the PList is a Dictionary
  28. $plist->add$dict new CFDictionary() );
  29.  
  30. // <key>Year Of Birth</key><integer>1965</integer>
  31. $dict->add'Year Of Birth'new CFNumber1965 ) );
  32.  
  33. // <key>Date Of Graduation</key><date>2004-06-22T19:23:43Z</date>
  34. $dict->add'Date Of Graduation'new CFDategmmktime19234306222004 ) ) );
  35.  
  36. // <key>Pets Names</key><array/>
  37. $dict->add'Pets Names'new CFArray() );
  38.  
  39. // <key>Picture</key><data>PEKBpYGlmYFCPA==</data>
  40. // to keep it simple we insert an already base64-encoded string
  41. $dict->add'Picture'new CFData'PEKBpYGlmYFCPA=='true ) );
  42.  
  43. // <key>City Of Birth</key><string>Springfield</string>
  44. $dict->add'City Of Birth'new CFString'Springfield' ) );
  45.  
  46. // <key>Name</key><string>John Doe</string>
  47. $dict->add'Name'new CFString'John Doe' ) );
  48.  
  49. // <key>Kids Names</key><array><string>John</string><string>Kyra</string></array>
  50. $dict->add'Kids Names'$array new CFArray() );
  51. $array->addnew CFString'John' ) );
  52. $array->addnew CFString'Kyra' ) );
  53.  
  54.  
  55. /*
  56.  * Save PList as XML
  57.  */
  58. $plist->saveXMLdirname(__FILE__).'/example-create-01.xml.plist' );
  59.  
  60.  
  61. /*
  62.  * Save PList as Binary
  63.  */
  64. $plist->saveBinarydirname(__FILE__).'/example-create-01.binary.plist' );
  65.  
  66. ?>

Documentation generated on Fri, 01 Jan 2010 21:33:34 +0100 by phpDocumentor 1.4.1