/framework/core/xml/PropertyList.php

http://zoop.googlecode.com/ · PHP · 106 lines · 101 code · 4 blank · 1 comment · 5 complexity · f9326849d661f2ec9915c5b3ab8a0f75 MD5 · raw file

  1. <?
  2. class PropertyList
  3. {
  4. public $data;
  5. function PropertyList($filename)
  6. {
  7. $doc = new XmlDom();
  8. $rootNode = $doc->parseFile($filename);
  9. $this->handlePList($rootNode);
  10. }
  11. function handlePList($curNode)
  12. {
  13. $children = $curNode->getChildren();
  14. for($thisNode = $children->current(); $children->valid(); $thisNode = $children->next())
  15. {
  16. if($thisNode->getName() != '#text')
  17. {
  18. $this->data = array();
  19. $this->handleDict($thisNode, $this->data);
  20. }
  21. }
  22. }
  23. function handleDict($curNode, &$dataNode)
  24. {
  25. $curKey = NULL;
  26. $children = $curNode->getChildren();
  27. for($thisNode = $children->current(); $children->valid(); $thisNode = $children->next())
  28. {
  29. {
  30. switch($thisNode->getName())
  31. {
  32. case 'key':
  33. $nodeContent = $thisNode->getTextContent();
  34. $curKey = $nodeContent['content'];
  35. break;
  36. // these next 4 could probably just be one rule
  37. case 'string':
  38. assert($curKey !== NULL);
  39. $nodeContent = $thisNode->getTextContent();
  40. $dataNode[$curKey] = $nodeContent['content'];
  41. $curKey = NULL;
  42. break;
  43. case 'integer':
  44. assert($curKey !== NULL);
  45. $nodeContent = $thisNode->getTextContent();
  46. $dataNode[$curKey] = $nodeContent['content'];
  47. $curKey = NULL;
  48. break;
  49. case 'real':
  50. assert($curKey !== NULL);
  51. $nodeContent = $thisNode->getTextContent();
  52. $dataNode[$curKey] = $nodeContent['content'];
  53. $curKey = NULL;
  54. break;
  55. case 'true':
  56. assert($curKey !== NULL);
  57. $dataNode[$curKey] = 1;
  58. $curKey = NULL;
  59. break;
  60. case 'false':
  61. assert($curKey !== NULL);
  62. $dataNode[$curKey] = 0;
  63. $curKey = NULL;
  64. break;
  65. case 'dict':
  66. assert($curKey !== NULL);
  67. $dataNode[$curKey] = array();
  68. $this->handleDict($thisNode, $dataNode[$curKey]);
  69. $curKey = NULL;
  70. break;
  71. case 'array':
  72. assert($curKey !== NULL);
  73. $dataNode[$curKey] = array();
  74. $this->handleArray($thisNode, $dataNode[$curKey]);
  75. $curKey = NULL;
  76. break;
  77. }
  78. }
  79. }
  80. }
  81. function handleArray($curNode, &$dataNode)
  82. {
  83. $children = $curNode->getChildren();
  84. for($thisNode = $children->current(); $children->valid(); $thisNode = $children->next())
  85. {
  86. {
  87. switch($thisNode->getName())
  88. {
  89. case 'dict':
  90. $newDict = array();
  91. $this->handleDict($thisNode, $newDict);
  92. $dataNode[] = $newDict;
  93. break;
  94. case 'string':
  95. $dataNode[] = $thisNode->getTextContent();
  96. break;
  97. }
  98. }
  99. }
  100. }
  101. }
  102. ?>