Axiom (v1.2.0)

A lightweight PHP framework
H:/Workspace/php-axiom/www/php-axiom/libraries/axiom/axFeed.class.php
Go to the documentation of this file.
00001 <?php
00018 class axFeed extends ArrayIterator {
00019     
00024     protected $_meta_inf = array();
00025     
00030     protected $_type;
00031         
00054     public function setMetaInf (array $meta_inf = array()) {
00055         $this['meta'] = $meta_inf;
00056         return $this;
00057     }
00058     
00066     public function __construct ($type, array $items = array(), array $meta_inf = array()) {
00067         parent::__construct(array(
00068             'meta'  => $meta_inf,
00069             'items' => $items,
00070         ));
00071         
00072         $this->_type = $type;
00073     }
00074     
00084     public function __get ($key) {
00085         if (method_exists($this, $method = "get" . ucfirst($key)))
00086             return $this->$method();
00087         else
00088             throw new InvalidArgumentException("$key does not exist", 4008);
00089     }
00090     
00100     public function __set ($key, $value) {
00101         if (method_exists($this, $method = "get" . ucfirst($key)))
00102             return $this->$method($value);
00103         else
00104             throw new InvalidArgumentException("$key does not exist", 4008);
00105     }
00106     
00116     public function add (axFeedEntry $entry = null) {
00117         if (!$entry)
00118             $entry = new axFeedEntry;
00119             
00120         return $this['items'][] = $entry;
00121     }
00122     
00128     public function getEntries () {
00129         return $this['items'];
00130     }
00131     
00137     public function getId () {
00138         return $this['meta']['id'];
00139     }
00140     
00148     public function setId ($id) {
00149         if (!$id = filter_var($id, FILTER_SANITIZE_ENCODED))
00150             throw new InvalidArgumentException("Invalid ID", 4009);
00151             
00152         $this['meta']['id'] = $id;
00153         return $this;
00154     }
00155     
00161     public function getTitle () {
00162         return $this['meta']['title'];
00163     }
00164     
00171     public function setTitle ($title) {
00172         $title = strip_tags($title);
00173         $this['meta']['title'] = $title;
00174         return $this;
00175     }
00176     
00182     public function getDate () {
00183         return $this['meta']['date'];
00184     }
00185     
00195     public function setDate ($date) {
00196         if ($time = strtotime($date))
00197             $date = date('r', $time);
00198         else
00199             throw new InvalidArgumentException("Invalid date format", 4010);
00200             
00201         $this['meta']['date'] = $date;
00202         return $this;
00203     }
00204     
00210     public function getAuthor () {
00211         return $this['meta']['author'];
00212     }
00213     
00222     public function setAuthor (array $author) {
00223         $author = array_intersect_key($author, array_flip(array('mail', 'name', 'uri')));
00224         
00225         if (isset($author['mail']) && !axMail::validateEmail($author['mail']))
00226             throw new InvalidArgumentException("Invalid author email", 4011);
00227             
00228         if (isset($author['name']) && !$author['name'] = filter_var($author['name'], FILTER_SANITIZE_ENCODED))
00229             throw new InvalidArgumentException("Invalid author name", 4012);
00230             
00231         if (isset($author['uri']) && !filter_var($author['uri'], FILTER_VALIDATE_URL))
00232             throw new InvalidArgumentException("Invalid URI for author", 4013);
00233             
00234         if (empty($author))
00235             throw new InvalidArgumentException("Author description must contain at least a name or email or URI", 4014);
00236             
00237         $this['meta']['author'] = $author;
00238         return $this;
00239     }
00240     
00246     public function getLang () {
00247         return $this['meta']['lang'];
00248     }
00249     
00256     public function setLang ($lang) {
00257         $this['meta']['lang'] = $lang;
00258         return $this;
00259     }
00260     
00266     public function getDescription () {
00267         return $this['meta']['description'];
00268     }
00269     
00276     public function setDescription ($description) {
00277         $description = strip_tags($description);
00278         $this['meta']['description'] = $description;
00279         return $this;
00280     }
00281     
00287     public function getCopyright () {
00288         return $this['meta']['copyright'];
00289     }
00290     
00297     public function setCopyright ($copyright) {
00298         $this['meta']['copyright'] = $copyright;
00299         return $this;
00300     }
00301     
00307     public function getLink () {
00308         return $this['meta']['link'];
00309     }
00310     
00318     public function setLink ($url) {
00319         if (!$url = filter_var($url, FILTER_VALIDATE_URL))
00320             throw new InvalidArgumentException("Invalid URL", 4015);
00321             
00322         $this['meta']['link'];
00323         return $this;
00324     }
00325     
00335     public function build ($type = null) {
00336         if (!$type)
00337             $type = ucfirst(strtolower($this->_type));
00338         
00339         if (!axAutoloader::load($class = "ax{$type}FeedWriter"))
00340             throw new RuntimeException("$type feed writer not found", 4016);
00341             
00342         $reflection = new ReflectionClass($class);
00343         if (!$reflection->isInstanciable())
00344             throw new RuntimeException("$class cannot be instanciated", 4017);
00345             
00346         if (!$reflextion->isSubclassOf("axFeedWriter"))
00347             throw new RuntimeException("$class must extends axFeedWriter", 4018);
00348         
00349         return new $class($this);
00350     }
00351 }
00352 
 All Data Structures Files Functions Variables