Пример #1
0
 /**
  * Sets feed instance
  *
  * @param Feed $feed
  */
 public function setFeed(Feed $feed)
 {
     $author = $feed->get('author');
     if (empty($author)) {
         throw new \InvalidArgumentException('Atom formatter requires an "author" parameter in configuration.');
     }
     $this->feed = $feed;
     $this->initialize();
 }
Пример #2
0
 /**
  * Construct a formatter with given feed
  *
  * @param Feed $feed A feed instance
  */
 public function __construct(Feed $feed)
 {
     $this->fields = array(new Field('id', 'getFeedItemLink', array('cdata' => false)), new Field('title', 'getFeedItemTitle', array('cdata' => true)), new Field('summary', 'getFeedItemDescription', array('cdata' => true)), new Field('link', 'getFeedItemLink', array('attribute' => true, 'attribute_name' => 'href')), new Field('updated', 'getFeedItemPubDate', array('date_format' => \DateTime::ATOM)));
     $author = $feed->get('author');
     if (empty($author)) {
         throw new \InvalidArgumentException('Atom formatter requires an "author" parameter in configuration.');
     }
     parent::__construct($feed);
     $this->initialize();
 }
Пример #3
0
 /**
  * Construct a formatter with given feed
  *
  * @param Feed $feed A feed instance
  */
 public function __construct(Feed $feed)
 {
     $fields = $feed->getFields();
     if (!empty($fields)) {
         foreach ($fields as $field) {
             $this->fields[] = $field;
         }
     }
     $this->feed = $feed;
 }
Пример #4
0
 /**
  * Return specified Feed instance if exists.
  *
  * @param string $feedName
  *
  * @throws \InvalidArgumentException
  *
  * @return Feed
  */
 public function get($feedName)
 {
     if (!$this->has($feedName)) {
         throw new \InvalidArgumentException(sprintf("Specified feed '%s' is not defined in your configuration.", $feedName));
     }
     if (!isset($this->feeds[$feedName])) {
         $feed = new Feed($this->config['feeds'][$feedName], $this->formatters);
         $feed->setRouter($this->router);
         $this->feeds[$feedName] = $feed;
     }
     return $this->feeds[$feedName];
 }
Пример #5
0
 /**
  * Adds channel fields to given channel
  *
  * @param \DOMElement $channel
  */
 protected function addChannelFields(\DOMElement $channel)
 {
     foreach ($this->feed->getChannelFields() as $field) {
         if ($field instanceof GroupChannelField) {
             $parent = $this->dom->createElement($field->getName());
             foreach ($field->getItemFields() as $childField) {
                 $child = $this->dom->createElement($childField->getName(), $childField->getValue());
                 $this->addAttributes($child, $childField);
                 $parent->appendChild($child);
             }
         } else {
             $parent = $this->dom->createElement($field->getName(), $field->getValue());
         }
         $this->addAttributes($parent, $field);
         $channel->appendChild($parent);
     }
 }