Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function dump(Document $document)
 {
     $data = trim($this->processor->dump($document->getData()));
     if ('' === $data) {
         return $document->getContent();
     }
     return sprintf("%s\n%s\n%s\n%s", $this->startSep, $data, $this->endSep, $document->getContent());
 }
Ejemplo n.º 2
0
 /**
  * @param string          $targetUrl   target url to import resource into
  * @param string          $file        path to file being loaded
  * @param OutputInterface $output      output of the command
  * @param Document        $doc         document to load
  * @param string          $host        host to import into
  * @param string          $rewriteHost string to replace with value from $host during loading
  * @param string          $rewriteTo   string to replace value from $rewriteHost with during loading
  * @param boolean         $sync        send requests syncronously
  *
  * @return Promise\Promise|null
  */
 protected function importResource($targetUrl, $file, OutputInterface $output, Document $doc, $host, $rewriteHost, $rewriteTo, $sync = false)
 {
     $content = str_replace($rewriteHost, $rewriteTo, $doc->getContent());
     $successFunc = function (ResponseInterface $response) use($output) {
         $output->writeln('<comment>Wrote ' . $response->getHeader('Link')[0] . '</comment>');
     };
     $errFunc = function (RequestException $e) use($output, $file) {
         $output->writeln('<error>' . str_pad(sprintf('Failed to write <%s> from \'%s\' with message \'%s\'', $e->getRequest()->getUri(), $file, $e->getMessage()), 140, ' ') . '</error>');
         if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
             $this->dumper->dump($this->cloner->cloneVar($this->parser->parse($e->getResponse()->getBody(), false, false, true)), function ($line, $depth) use($output) {
                 if ($depth > 0) {
                     $output->writeln('<error>' . str_pad(str_repeat('  ', $depth) . $line, 140, ' ') . '</error>');
                 }
             });
         }
     };
     if ($sync === false) {
         $promise = $this->client->requestAsync('PUT', $targetUrl, ['json' => $this->parseContent($content, $file)]);
         $promise->then($successFunc, $errFunc);
     } else {
         $promise = new Promise\Promise();
         try {
             $promise->resolve($successFunc($this->client->request('PUT', $targetUrl, ['json' => $this->parseContent($content, $file)])));
         } catch (BadResponseException $e) {
             $promise->resolve($errFunc($e));
         }
     }
     return $promise;
 }
Ejemplo n.º 3
0
 public function testSetData()
 {
     $document = new Document('');
     $document->setData($data = ['foo' => 'bar']);
     $this->assertEquals($data, $document->getData());
 }