Пример #1
0
 private function open()
 {
     if ($this->xmlParser == null) {
         $this->xmlParser = new XmlParser($this->xmlFilePath);
         $this->xmlParser->addNodeHandler($this->nodeName, new NodeStrategyCollationDictionary(function ($node) {
             $this->lastResult = $node;
         }));
     }
 }
Пример #2
0
 public function testDictionaryStrategy()
 {
     $hit = false;
     $parser = new XmlParser("cache/unit-test-xml-stream.xml");
     $parser->addNodeHandler("dictionary", new NodeStrategyCollationDictionary(function ($node) use(&$hit) {
         $hit = $node;
     }));
     $parser->parse();
     $this->assertEquals("George", $hit["name"]);
     $this->assertEquals("tall", $hit["height"]);
     $this->assertCount(4, $hit["children"]);
     $this->assertEquals("son", $hit["children"]["joe"]);
     $this->assertEquals("deal", $hit["children"]["big"]);
     $this->assertCount(3, $hit["interest"]);
     $this->assertEquals("Fishing", $hit["interest"][0]);
     $this->assertCount(2, $hit["interest"][2]["complexInterest"]);
     $this->assertEquals("Knitting", $hit["interest"][2]["complexInterest"][1]);
     $this->assertCount(3, $hit["word"]);
     $this->assertEquals("a", $hit["word"][0]["name"]);
 }