Source for file link.php

Documentation is available at link.php

  1. <?php
  2. /**
  3.  * @package     FrameworkOnFramework
  4.  * @subpackage  hal
  5.  * @copyright   Copyright (C) 2010 - 2012 Akeeba Ltd. All rights reserved.
  6.  * @license     GNU General Public License version 2 or later; see LICENSE.txt
  7.  */
  8. defined('_JEXEC'or die;
  9.  
  10. /**
  11.  * Implementation of the Hypertext Application Language link in PHP.
  12.  *
  13.  * @package  FrameworkOnFramework
  14.  * @since    2.1
  15.  */
  16. class FOFHalLink
  17. {
  18.     /**
  19.      * For indicating the target URI. Corresponds with the ’Target IRI’ as
  20.      * defined in Web Linking (RFC 5988). This attribute MAY contain a URI
  21.      * Template (RFC6570) and in which case, SHOULD be complemented by an
  22.      * additional templated attribtue on the link with a boolean value true.
  23.      *
  24.      * @var string 
  25.      */
  26.     protected $_href = '';
  27.  
  28.     /**
  29.      * This attribute SHOULD be present with a boolean value of true when the
  30.      * href of the link contains a URI Template (RFC6570).
  31.      *
  32.      * @var  boolean 
  33.      */
  34.     protected $_templated = false;
  35.  
  36.     /**
  37.      * For distinguishing between Resource and Link elements that share the
  38.      * same relation
  39.      *
  40.      * @var  string 
  41.      */
  42.     protected $_name = null;
  43.  
  44.     /**
  45.      * For indicating what the language of the result of dereferencing the link should be.
  46.      *
  47.      * @var  string 
  48.      */
  49.     protected $_hreflang = null;
  50.  
  51.     /**
  52.      * For labeling the destination of a link with a human-readable identifier.
  53.      *
  54.      * @var  string 
  55.      */
  56.     protected $_title = null;
  57.  
  58.     /**
  59.      * Public constructor of a FOFHalLink object
  60.      *
  61.      * @param   string   $href       See $this->_href
  62.      * @param   boolean  $templated  See $this->_templated
  63.      * @param   string   $name       See $this->_name
  64.      * @param   string   $hreflang   See $this->_hreflang
  65.      * @param   string   $title      See $this->_title
  66.      *
  67.      * @throws  RuntimeException  If $href is empty
  68.      */
  69.     public function __construct($href$templated false$name null$hreflang null$title null)
  70.     {
  71.         if (empty($href))
  72.         {
  73.             throw new RuntimeException('A HAL link must always have a non-empty href');
  74.         }
  75.  
  76.         $this->_href = $href;
  77.         $this->_templated = $templated;
  78.         $this->_name = $name;
  79.         $this->_hreflang = $hreflang;
  80.         $this->_title = $title;
  81.     }
  82.  
  83.     /**
  84.      * Is this a valid link? Checks the existence of required fields, not their
  85.      * values.
  86.      *
  87.      * @return  boolean 
  88.      */
  89.     public function check()
  90.     {
  91.         return !empty($this->_href);
  92.     }
  93.  
  94.     /**
  95.      * Magic getter for the protected properties
  96.      *
  97.      * @param   string  $name  The name of the property to retrieve, sans the underscore
  98.      *
  99.      * @return  mixed  Null will always be returned if the property doesn't exist
  100.      */
  101.     public function __get($name)
  102.     {
  103.         $property '_' $name;
  104.  
  105.         if (property_exists($this$property))
  106.         {
  107.             return $this->$property;
  108.         }
  109.         else
  110.         {
  111.             return null;
  112.         }
  113.     }
  114.  
  115.     /**
  116.      * Magic setter for the protected properties
  117.      *
  118.      * @param   string  $name   The name of the property to set, sans the underscore
  119.      * @param   mixed   $value  The value of the property to set
  120.      *
  121.      * @return  void 
  122.      */
  123.     public function __set($name$value)
  124.     {
  125.         if (($name == 'href'&& empty($value))
  126.         {
  127.             return;
  128.         }
  129.  
  130.         $property '_' $name;
  131.  
  132.         if (property_exists($this$property))
  133.         {
  134.             $this->$property $value;
  135.         }
  136.     }
  137. }

Documentation generated on Tue, 19 Nov 2013 15:07:06 +0100 by phpDocumentor 1.4.3