Using and extended

  1. <?php
  2. /**
  3.  * Examples for how to use CFPropertyList
  4.  * Create the PropertyList sample.xml.plist by using {@link CFTypeDetector}.
  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. class DemoDetector extends CFTypeDetector {
  19.   
  20.   public function toCFType($value{
  21.     if$value instanceof PListException {
  22.       return new CFString$value->getMessage() );
  23.     }
  24.  
  25.     return parent::toCFType($value);
  26.   }
  27.   
  28. }
  29.  
  30. /*
  31.  * import the array structure to create the sample.xml.plist
  32.  * We make use of CFTypeDetector, which truly is not almighty!
  33.  */
  34.  
  35. $stack new SplStack();
  36. $stack[1;
  37. $stack[2;
  38. $stack[3;
  39.  
  40. $structure array(
  41.   'NullValueTest' => null,
  42.   'IteratorTest' => $stack,
  43.   'ObjectTest' => new PListException('Just a test...'),
  44. );
  45.  
  46. /*
  47.  * Try default detection
  48.  */
  49. try {
  50.   $plist new CFPropertyList();
  51.   $td new CFTypeDetector();  
  52.   $guessedStructure $td->toCFType$structure );
  53.   $plist->add$guessedStructure );
  54.   $plist->saveXMLdirname(__FILE__).'/example-create-04.xml.plist' );
  55.   $plist->saveBinarydirname(__FILE__).'/example-create-04.binary.plist' );
  56. }
  57. catchPListException $e {
  58.   echo 'Normal detection: '$e->getMessage()"\n";
  59. }
  60.  
  61. /*
  62.  * Try detection by omitting exceptions
  63.  */
  64. try {
  65.   $plist new CFPropertyList();
  66.   $td new CFTypeDetectorfalsetrue );  
  67.   $guessedStructure $td->toCFType$structure );
  68.   $plist->add$guessedStructure );
  69.   $plist->saveXMLdirname(__FILE__).'/example-create-04.xml.plist' );
  70.   $plist->saveBinarydirname(__FILE__).'/example-create-04.binary.plist' );
  71. }
  72. catchPListException $e {
  73.   echo 'Silent detection: '$e->getMessage()"\n";
  74. }
  75.  
  76. /*
  77.  * Try detection with an extended version of CFTypeDetector
  78.  */
  79. try {
  80.   $plist new CFPropertyList();
  81.   $td new DemoDetector();  
  82.   $guessedStructure $td->toCFType$structure );
  83.   $plist->add$guessedStructure );
  84.   $plist->saveXMLdirname(__FILE__).'/example-create-04.xml.plist' );
  85.   $plist->saveBinarydirname(__FILE__).'/example-create-04.binary.plist' );
  86. }
  87. catchPListException $e {
  88.   echo 'User defined detection: '$e->getMessage()"\n";
  89. }
  90.  
  91. ?>

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