예제 #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $table = $this->tableManager->getTable('Phpsx\\Website\\Table\\Blog');
     $atom = new Atom();
     $message = new Message(['Content-Type' => 'application/atom+xml']);
     $message->setBody(new TempStream(fopen($this->feedFile, 'r')));
     $postCount = $putCount = 0;
     $atom = $this->importer->import($atom, $message);
     foreach ($atom as $entry) {
         $row = $table->getOneById($entry->getId());
         $author = $this->getFirstAuthor($entry);
         if (!$author instanceof Atom\Person) {
             throw new \RuntimeException(sprintf('No author provided for entry %s', $entry->getId()));
         }
         if (!$row instanceof RecordInterface) {
             // the blog entry does not exist create it
             $table->create(['id' => $entry->getId(), 'title' => $entry->getTitle(), 'titleSlug' => $this->slugify->slugify($entry->getTitle()), 'authorName' => $author->getName(), 'authorUri' => $author->getUri(), 'updated' => $entry->getUpdated(), 'summary' => $entry->getSummary(), 'category' => $this->getCategories($entry), 'content' => $entry->getContent()->getContent()]);
             $postCount++;
         } else {
             if ($entry->getUpdated() > $row->getUpdated()) {
                 // if the update date has change update the entry
                 $table->update(['id' => $entry->getId(), 'title' => $entry->getTitle(), 'titleSlug' => $this->slugify->slugify($entry->getTitle()), 'authorName' => $author->getName(), 'authorUri' => $author->getUri(), 'updated' => $entry->getUpdated(), 'summary' => $entry->getSummary(), 'category' => $this->getCategories($entry), 'content' => $entry->getContent()->getContent()]);
                 $putCount++;
             }
         }
     }
     $output->writeln(sprintf('Created %s and updated %s entries', $postCount, $putCount));
 }
예제 #2
0
파일: MessageTest.php 프로젝트: seytar/psx
 public function testSetBody()
 {
     $message = new Message();
     $message->setBody(new StringStream('foobar'));
     $this->assertEquals('foobar', (string) $message->getBody());
 }
예제 #3
0
파일: ImporterTest.php 프로젝트: seytar/psx
 /**
  * @expectedException \RuntimeException
  */
 public function testImportEmptyBody()
 {
     $message = new Message();
     $message->addHeader('Content-Type', 'application/json');
     $message->setBody(new StringStream(''));
     $importer = new Importer(Environment::getService('extractor'), Environment::getService('importer_manager'));
     $importer->import(new Page(), $message);
 }
예제 #4
0
    public function testExtractJsonExplicitReader()
    {
        $data = <<<TEXT
{"foo": "bar"}
TEXT;
        $message = new Message();
        $message->addHeader('Content-Type', 'text/plain');
        $message->setBody(new StringStream($data));
        $extractor = new Extractor(Environment::getService('reader_factory'), Environment::getService('transformer_manager'));
        $data = $extractor->extract($message, null, ReaderInterface::JSON);
        $expect = new \stdClass();
        $expect->foo = 'bar';
        $this->assertEquals($expect, $data);
    }