Source for file links.php

Documentation is available at links.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 links in PHP. This is
  12.  * actually a collection of links.
  13.  *
  14.  * @package  FrameworkOnFramework
  15.  * @since    2.1
  16.  */
  17. {
  18.     /**
  19.      * The collection of links, sorted by relation
  20.      *
  21.      * @var array 
  22.      */
  23.     private $_links array();
  24.  
  25.     /**
  26.      * Add a single link to the links collection
  27.      *
  28.      * @param   string      $rel        The relation of the link to the document. See RFC 5988
  29.      *                                   http://tools.ietf.org/html/rfc5988#section-6.2.2 A document
  30.      *                                   MUST always have a "self" link.
  31.      * @param   FOFHalLink  $link       The actual link object
  32.      * @param   boolean     $overwrite  When false and a link of $rel relation exists, an array of
  33.      *                                   links is created. Otherwise the existing link is overwriten
  34.      *                                   with the new one
  35.      *
  36.      * @return  boolean  True if the link was added to the collection
  37.      */
  38.     public function addLink($relFOFHalLink $link$overwrite true)
  39.     {
  40.         if (!$link->check())
  41.         {
  42.             return false;
  43.         }
  44.  
  45.         if (!array_key_exists($rel$this->_links|| !$overwrite)
  46.         {
  47.             $this->_links[$rel$link;
  48.         }
  49.         elseif (array_key_exists($rel$this->_links&& !$overwrite)
  50.         {
  51.             if (!is_array($this->_links[$rel]))
  52.             {
  53.                 $this->_links[$relarray($this->_links[$rel]);
  54.             }
  55.  
  56.             $this->_links[$rel][$link;
  57.         }
  58.         else
  59.         {
  60.             return false;
  61.         }
  62.     }
  63.  
  64.     /**
  65.      * Add multiple links to the links collection
  66.      *
  67.      * @param   string   $rel        The relation of the links to the document. See RFC 5988.
  68.      * @param   array    $links      An array of FOFHalLink objects
  69.      * @param   boolean  $overwrite  When false and a link of $rel relation exists, an array
  70.      *                                of links is created. Otherwise the existing link is
  71.      *                                overwriten with the new one
  72.      *
  73.      * @return  boolean  True if the link was added to the collection
  74.      */
  75.     public function addLinks($relarray $links$overwrite true)
  76.     {
  77.         if (empty($links))
  78.         {
  79.             return false;
  80.         }
  81.  
  82.         foreach ($links as $link)
  83.         {
  84.             if ($link instanceof FOFHalLink)
  85.             {
  86.                 $this->addLink($rel$link$overwrite);
  87.             }
  88.         }
  89.     }
  90.  
  91.     /**
  92.      * Returns the collection of links
  93.      *
  94.      * @param   string  $rel  Optional; the relation to return the links for
  95.      *
  96.      * @return  array|FOFHalLink
  97.      */
  98.     public function getLinks($rel null)
  99.     {
  100.         if (empty($rel))
  101.         {
  102.             return $this->_links;
  103.         }
  104.         elseif (isset($this->_links[$rel]))
  105.         {
  106.             return $this->_links[$rel];
  107.         }
  108.         else
  109.         {
  110.             return array();
  111.         }
  112.     }
  113. }

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