예제 #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
파일: Response.php 프로젝트: seytar/psx
 /**
  * @param integer $code
  * @param array $headers
  * @param string $body
  */
 public function __construct($code = null, array $headers = array(), $body = null)
 {
     parent::__construct($headers, $body);
     $this->code = $code;
 }
예제 #3
0
 /**
  * Parses an raw http header string into an Message object
  *
  * @param \PSX\Http\Message $message
  * @param string $header
  * @return array
  */
 protected function headerToArray(Message $message, $header)
 {
     $lines = explode(Http::$newLine, $header);
     foreach ($lines as $line) {
         $parts = explode(':', $line, 2);
         if (isset($parts[0]) && isset($parts[1])) {
             $key = $parts[0];
             $value = substr($parts[1], 1);
             $message->addHeader($key, $value);
         }
     }
 }
예제 #4
0
파일: Request.php 프로젝트: seytar/psx
 /**
  * @param \PSX\Uri $uri
  * @param string $method
  * @param array $headers
  * @param string $body
  */
 public function __construct(Uri $uri, $method, array $headers = array(), $body = null)
 {
     parent::__construct($headers, $body);
     $this->uri = $uri;
     $this->method = $method;
 }
예제 #5
0
파일: MessageTest.php 프로젝트: seytar/psx
 public function testSetBodyResource()
 {
     $handle = fopen('php://memory', 'r+');
     fwrite($handle, 'foobar');
     $message = new Message(array(), $handle);
     $this->assertEquals('foobar', (string) $message->getBody());
 }
예제 #6
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);
 }
예제 #7
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);
    }