Beispiel #1
0
 public function generate(RecordInterface $data)
 {
     $visitor = new Visitor\HtmlWriterVisitor();
     $graph = new GraphTraverser();
     $graph->traverse($data, $visitor);
     return $this->getTemplate($visitor->getOutput());
 }
 public function testTraverse()
 {
     $visitor = new StdClassSerializeVisitor();
     $graph = new GraphTraverser();
     $graph->traverse($this->getRecord(), $visitor);
     $this->assertEquals($this->getExpected(), $visitor->getObject());
 }
Beispiel #3
0
 public function testTraverse()
 {
     $visitor = new HtmlWriterVisitor();
     $graph = new GraphTraverser();
     $graph->traverse($this->getRecord(), $visitor);
     $this->assertXmlStringEqualsXmlString($this->getExpected(), $visitor->getOutput());
 }
Beispiel #4
0
 public function write(RecordInterface $record)
 {
     $visitor = new Visitor\StdClassSerializeVisitor();
     $graph = new GraphTraverser();
     $graph->traverse($record, $visitor);
     return JsonParser::encode($visitor->getObject(), JSON_PRETTY_PRINT);
 }
Beispiel #5
0
 public function write(RecordInterface $record)
 {
     $visitor = new Visitor\StdClassSerializeVisitor();
     $graph = new GraphTraverser();
     $graph->traverse($record, $visitor);
     return http_build_query($visitor->getObject(), '', '&');
 }
Beispiel #6
0
 public function write(RecordInterface $record)
 {
     $xmlWriter = new XMLWriter();
     $xmlWriter->openMemory();
     $xmlWriter->setIndent(true);
     $xmlWriter->startDocument('1.0', 'UTF-8');
     $xmlWriter->startElement('soap:Envelope');
     $xmlWriter->writeAttribute('xmlns:soap', 'http://schemas.xmlsoap.org/soap/envelope/');
     if ($record instanceof ExceptionRecord) {
         $xmlWriter->startElement('soap:Body');
         $xmlWriter->startElement('soap:Fault');
         $xmlWriter->writeElement('faultcode', 'soap:Server');
         $xmlWriter->writeElement('faultstring', $record->getMessage());
         if ($record->getTrace()) {
             $xmlWriter->startElement('detail');
             $graph = new GraphTraverser();
             $graph->traverse($record, new Visitor\XmlWriterVisitor($xmlWriter, $this->namespace));
             $xmlWriter->endElement();
         }
         $xmlWriter->endElement();
         $xmlWriter->endElement();
     } else {
         $xmlWriter->startElement('soap:Body');
         $record = new Record($this->requestMethod . 'Response', $record->getRecordInfo()->getFields());
         $graph = new GraphTraverser();
         $graph->traverse($record, new Visitor\XmlWriterVisitor($xmlWriter, $this->namespace));
         $xmlWriter->endElement();
     }
     $xmlWriter->endElement();
     $xmlWriter->endDocument();
     return $xmlWriter->outputMemory();
 }
Beispiel #7
0
 public function testTraverseCallStack()
 {
     $record = $this->getRecord();
     $visitor = new SpyVisitor();
     $graph = new GraphTraverser();
     $graph->traverse($record, $visitor);
     $expect = array('0 PSX\\Data\\Record\\SpyVisitor::visitObjectStart', '1 PSX\\Data\\Record\\SpyVisitor::visitObjectValueStart', '2 PSX\\Data\\Record\\SpyVisitor::visitValue', '3 PSX\\Data\\Record\\SpyVisitor::visitObjectValueEnd', '4 PSX\\Data\\Record\\SpyVisitor::visitObjectValueStart', '5 PSX\\Data\\Record\\SpyVisitor::visitValue', '6 PSX\\Data\\Record\\SpyVisitor::visitObjectValueEnd', '7 PSX\\Data\\Record\\SpyVisitor::visitObjectValueStart', '8 PSX\\Data\\Record\\SpyVisitor::visitValue', '9 PSX\\Data\\Record\\SpyVisitor::visitObjectValueEnd', '10 PSX\\Data\\Record\\SpyVisitor::visitObjectValueStart', '11 PSX\\Data\\Record\\SpyVisitor::visitValue', '12 PSX\\Data\\Record\\SpyVisitor::visitObjectValueEnd', '13 PSX\\Data\\Record\\SpyVisitor::visitObjectValueStart', '14 PSX\\Data\\Record\\SpyVisitor::visitValue', '15 PSX\\Data\\Record\\SpyVisitor::visitObjectValueEnd', '16 PSX\\Data\\Record\\SpyVisitor::visitObjectValueStart', '17 PSX\\Data\\Record\\SpyVisitor::visitValue', '18 PSX\\Data\\Record\\SpyVisitor::visitObjectValueEnd', '19 PSX\\Data\\Record\\SpyVisitor::visitObjectValueStart', '20 PSX\\Data\\Record\\SpyVisitor::visitValue', '21 PSX\\Data\\Record\\SpyVisitor::visitObjectValueEnd', '22 PSX\\Data\\Record\\SpyVisitor::visitObjectValueStart', '23 PSX\\Data\\Record\\SpyVisitor::visitObjectStart', '24 PSX\\Data\\Record\\SpyVisitor::visitObjectValueStart', '25 PSX\\Data\\Record\\SpyVisitor::visitValue', '26 PSX\\Data\\Record\\SpyVisitor::visitObjectValueEnd', '27 PSX\\Data\\Record\\SpyVisitor::visitObjectEnd', '28 PSX\\Data\\Record\\SpyVisitor::visitObjectValueEnd', '29 PSX\\Data\\Record\\SpyVisitor::visitObjectValueStart', '30 PSX\\Data\\Record\\SpyVisitor::visitObjectStart', '31 PSX\\Data\\Record\\SpyVisitor::visitObjectValueStart', '32 PSX\\Data\\Record\\SpyVisitor::visitObjectStart', '33 PSX\\Data\\Record\\SpyVisitor::visitObjectValueStart', '34 PSX\\Data\\Record\\SpyVisitor::visitObjectStart', '35 PSX\\Data\\Record\\SpyVisitor::visitObjectValueStart', '36 PSX\\Data\\Record\\SpyVisitor::visitValue', '37 PSX\\Data\\Record\\SpyVisitor::visitObjectValueEnd', '38 PSX\\Data\\Record\\SpyVisitor::visitObjectEnd', '39 PSX\\Data\\Record\\SpyVisitor::visitObjectValueEnd', '40 PSX\\Data\\Record\\SpyVisitor::visitObjectEnd', '41 PSX\\Data\\Record\\SpyVisitor::visitObjectValueEnd', '42 PSX\\Data\\Record\\SpyVisitor::visitObjectEnd', '43 PSX\\Data\\Record\\SpyVisitor::visitObjectValueEnd', '44 PSX\\Data\\Record\\SpyVisitor::visitObjectValueStart', '45 PSX\\Data\\Record\\SpyVisitor::visitArrayStart', '46 PSX\\Data\\Record\\SpyVisitor::visitArrayValueStart', '47 PSX\\Data\\Record\\SpyVisitor::visitValue', '48 PSX\\Data\\Record\\SpyVisitor::visitArrayValueEnd', '49 PSX\\Data\\Record\\SpyVisitor::visitArrayValueStart', '50 PSX\\Data\\Record\\SpyVisitor::visitValue', '51 PSX\\Data\\Record\\SpyVisitor::visitArrayValueEnd', '52 PSX\\Data\\Record\\SpyVisitor::visitArrayValueStart', '53 PSX\\Data\\Record\\SpyVisitor::visitValue', '54 PSX\\Data\\Record\\SpyVisitor::visitArrayValueEnd', '55 PSX\\Data\\Record\\SpyVisitor::visitArrayEnd', '56 PSX\\Data\\Record\\SpyVisitor::visitObjectValueEnd', '57 PSX\\Data\\Record\\SpyVisitor::visitObjectValueStart', '58 PSX\\Data\\Record\\SpyVisitor::visitArrayStart', '59 PSX\\Data\\Record\\SpyVisitor::visitArrayValueStart', '60 PSX\\Data\\Record\\SpyVisitor::visitObjectStart', '61 PSX\\Data\\Record\\SpyVisitor::visitObjectValueStart', '62 PSX\\Data\\Record\\SpyVisitor::visitValue', '63 PSX\\Data\\Record\\SpyVisitor::visitObjectValueEnd', '64 PSX\\Data\\Record\\SpyVisitor::visitObjectEnd', '65 PSX\\Data\\Record\\SpyVisitor::visitArrayValueEnd', '66 PSX\\Data\\Record\\SpyVisitor::visitArrayValueStart', '67 PSX\\Data\\Record\\SpyVisitor::visitObjectStart', '68 PSX\\Data\\Record\\SpyVisitor::visitObjectValueStart', '69 PSX\\Data\\Record\\SpyVisitor::visitValue', '70 PSX\\Data\\Record\\SpyVisitor::visitObjectValueEnd', '71 PSX\\Data\\Record\\SpyVisitor::visitObjectEnd', '72 PSX\\Data\\Record\\SpyVisitor::visitArrayValueEnd', '73 PSX\\Data\\Record\\SpyVisitor::visitArrayEnd', '74 PSX\\Data\\Record\\SpyVisitor::visitObjectValueEnd', '75 PSX\\Data\\Record\\SpyVisitor::visitObjectEnd');
     $this->assertEquals($expect, $visitor->getStack());
 }
Beispiel #8
0
 public function handle(Request $request, Parameters $configuration, Context $context)
 {
     $response = $this->processor->execute($configuration->get('source'), $request, $context);
     $visitor = new StdClassSerializeVisitor();
     $traverser = new GraphTraverser();
     $traverser->traverse($response->getBody(), $visitor);
     $importer = $this->importerManager->getImporterByInstance('PSX\\Data\\Record\\Importer\\Record');
     $body = $importer->import(new Record(), $visitor->getObject());
     return $this->processor->execute($configuration->get('destination'), $request->withBody($body), $context);
 }
Beispiel #9
0
 public function testTraverse()
 {
     $writer = new XMLWriter();
     $writer->openMemory();
     $writer->setIndent(true);
     $writer->startDocument('1.0', 'UTF-8');
     $graph = new GraphTraverser();
     $graph->traverse($this->getRecord(), new XmlWriterVisitor($writer));
     $this->assertXmlStringEqualsXmlString($this->getExpected(), $writer->outputMemory());
 }
Beispiel #10
0
    public function testTraverseTextLong()
    {
        $visitor = new TextWriterVisitor();
        $record = new Record('foo', array('title' => 'Lorem ipsum dolor' . "\n" . 'sit amet, consetetur sadipscin'));
        $graph = new GraphTraverser();
        $graph->traverse($record, $visitor);
        $except = <<<TEXT
Object(foo){
    title = Lorem ipsum dolor sit amet, cons (...)
}

TEXT;
        Assert::assertStringMatchIgnoreWhitespace($except, $visitor->getOutput());
    }
Beispiel #11
0
 public function write(RecordInterface $record)
 {
     $hasWriter = $this->writer !== null;
     $writer = $this->writer ?: new XMLWriter();
     if (!$hasWriter) {
         $writer->openMemory();
         $writer->setIndent(true);
         $writer->startDocument('1.0', 'UTF-8');
     }
     $graph = new GraphTraverser();
     $graph->traverse($record, $this->getVisitor($writer));
     if (!$hasWriter) {
         $writer->endDocument();
         return $writer->outputMemory();
     } else {
         return null;
     }
 }
Beispiel #12
0
    public function testTraverseNullValue()
    {
        $writer = new XMLWriter();
        $writer->openMemory();
        $writer->setIndent(true);
        $writer->startDocument('1.0', 'UTF-8');
        $data = new \stdClass();
        $data->foo = 'bar';
        $data->bar = null;
        $graph = new GraphTraverser();
        $graph->traverse($data, new JsonxWriterVisitor($writer));
        $expect = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<json:object xmlns:json="http://www.ibm.com/xmlns/prod/2009/jsonx">
 <json:string name="foo">bar</json:string>
 <json:null name="bar" />
</json:object>
XML;
        $this->assertXmlStringEqualsXmlString($expect, $writer->outputMemory());
    }
Beispiel #13
0
 protected function getValue($value)
 {
     if (GraphTraverser::isObject($value)) {
         return $this->lastObject;
     } elseif (GraphTraverser::isArray($value)) {
         return $this->lastArray;
     } else {
         return $this->newValue($value);
     }
 }
Beispiel #14
0
 protected function getDataType($value)
 {
     if (GraphTraverser::isObject($value)) {
         return 'object';
     } elseif (GraphTraverser::isArray($value)) {
         return 'array';
     } elseif (is_int($value) || is_float($value)) {
         return 'number';
     } elseif (is_bool($value)) {
         return 'boolean';
     } elseif (is_null($value)) {
         return 'null';
     } else {
         return 'string';
     }
 }