Example #1
0
 /**
  * Generic caller
  * 
  * Returns all microformats2 items of a spefic type (or a particular index out of this list)
  * 
  * @param \string $method										Method name (lowerCamelCased microformats2 item type)
  * @param \array $arguments										List of arguments, of which the first is interpreted as list index (NULL = return the complete list)
  * @return \array|\Jkphl\Micrometa\Item							List of microformats2 items or a single microformats2 item
  * @throws \Jkphl\Micrometa\Parser\Microformats2\Exception		If it's not a valid microformats2 vocable
  * @throws \Jkphl\Micrometa\Parser\Microformats2\Exception		If the item index is out of range
  */
 public function __call($method, array $arguments)
 {
     $mf2ItemType = \Jkphl\Micrometa\Parser\Microformats2::decamelize($method);
     $mf2Items = $this->items($mf2ItemType);
     $mf2ItemIndex = count($arguments) ? intval($arguments[0]) : null;
     // If the complete item list is to be returned
     if ($mf2ItemIndex === null) {
         return $mf2Items;
         // Else: If the requested item index is out of range: Error
     } elseif ($mf2ItemIndex < 0 || $mf2ItemIndex > count($mf2Items) - 1) {
         throw new \Jkphl\Micrometa\Parser\Microformats2\Exception(sprintf(\Jkphl\Micrometa\Parser\Microformats2\Exception::INDEX_OUT_OF_RANGE_STR, $mf2ItemIndex), \Jkphl\Micrometa\Parser\Microformats2\Exception::INDEX_OUT_OF_RANGE);
         // Else: Return the requested item index
     } else {
         return $mf2Items[$mf2ItemIndex];
     }
 }
Example #2
0
 /**
  * Return a list of properties or a single property
  *
  * @param \string $key			Property (list) name
  * @return \mixed				Property (list) value(s)
  */
 public function __get($key)
 {
     $property = \Jkphl\Micrometa\Parser\Microformats2::decamelize($key);
     // If a single property value was requested
     if (isset($this->_properties->{$property})) {
         return $this->{$key}(0);
         // Else: If a property value list was requested
     } elseif (substr($property, -1) == 's' && isset($this->_properties->{substr($property, 0, -1)})) {
         return $this->{$key}(null);
         // Else: Unknown property
     } else {
         return null;
     }
 }