File indexing completed on 2025-05-04 05:27:54

0001 <?php
0002 
0003 /**
0004  * Zend Framework
0005  *
0006  * LICENSE
0007  *
0008  * This source file is subject to the new BSD license that is bundled
0009  * with this package in the file LICENSE.txt.
0010  * It is also available through the world-wide-web at this URL:
0011  * http://framework.zend.com/license/new-bsd
0012  * If you did not receive a copy of the license and are unable to
0013  * obtain it through the world-wide-web, please send an email
0014  * to license@zend.com so we can send you a copy immediately.
0015  *
0016  * @category   Zend
0017  * @package    Zend_Gdata
0018  * @subpackage App
0019  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0020  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0021  * @version    $Id$
0022  */
0023 
0024 /**
0025  * @see Zend_Gdata_App_Extension_Element
0026 */
0027 // require_once 'Zend/Gdata/App/Extension/Element.php';
0028 
0029 /**
0030  * @see Zend_Gdata_App_Extension_Author
0031 */
0032 // require_once 'Zend/Gdata/App/Extension/Author.php';
0033 
0034 /**
0035  * @see Zend_Gdata_App_Extension_Category
0036 */
0037 // require_once 'Zend/Gdata/App/Extension/Category.php';
0038 
0039 /**
0040  * @see Zend_Gdata_App_Extension_Contributor
0041 */
0042 // require_once 'Zend/Gdata/App/Extension/Contributor.php';
0043 
0044 /**
0045  * @see Zend_Gdata_App_Extension_Id
0046  */
0047 // require_once 'Zend/Gdata/App/Extension/Id.php';
0048 
0049 /**
0050  * @see Zend_Gdata_App_Extension_Link
0051  */
0052 // require_once 'Zend/Gdata/App/Extension/Link.php';
0053 
0054 /**
0055  * @see Zend_Gdata_App_Extension_Rights
0056  */
0057 // require_once 'Zend/Gdata/App/Extension/Rights.php';
0058 
0059 /**
0060  * @see Zend_Gdata_App_Extension_Title
0061  */
0062 // require_once 'Zend/Gdata/App/Extension/Title.php';
0063 
0064 /**
0065  * @see Zend_Gdata_App_Extension_Updated
0066  */
0067 // require_once 'Zend/Gdata/App/Extension/Updated.php';
0068 
0069 /**
0070  * Zend_Version
0071  */
0072 // require_once 'Zend/Version.php';
0073 
0074 /**
0075  * Abstract class for common functionality in entries and feeds
0076  *
0077  * @category   Zend
0078  * @package    Zend_Gdata
0079  * @subpackage App
0080  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0081  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0082  */
0083 abstract class Zend_Gdata_App_FeedEntryParent extends Zend_Gdata_App_Base
0084 {
0085     /**
0086      * Service instance used to make network requests.
0087      *
0088      * @see setService(), getService()
0089      */
0090     protected $_service = null;
0091 
0092     /**
0093      * The HTTP ETag associated with this entry. Used for optimistic
0094      * concurrency in protoco v2 or greater.
0095      *
0096      * @var string|null
0097      */
0098     protected $_etag = NULL;
0099 
0100     protected $_author = array();
0101     protected $_category = array();
0102     protected $_contributor = array();
0103     protected $_id = null;
0104     protected $_link = array();
0105     protected $_rights = null;
0106     protected $_title = null;
0107     protected $_updated = null;
0108 
0109     /**
0110       * Indicates the major protocol version that should be used.
0111       * At present, recognized values are either 1 or 2. However, any integer
0112       * value >= 1 is considered valid.
0113       *
0114       * @see setMajorProtocolVersion()
0115       * @see getMajorProtocolVersion()
0116       */
0117     protected $_majorProtocolVersion = 1;
0118 
0119     /**
0120       * Indicates the minor protocol version that should be used. Can be set
0121       * to either an integer >= 0, or NULL if no minor version should be sent
0122       * to the server.
0123       *
0124       * @see setMinorProtocolVersion()
0125       * @see getMinorProtocolVersion()
0126       */
0127     protected $_minorProtocolVersion = null;
0128 
0129     /**
0130      * Constructs a Feed or Entry
0131      */
0132     public function __construct($element = null)
0133     {
0134         if (!($element instanceof DOMElement)) {
0135             if ($element) {
0136                 $this->transferFromXML($element);
0137             }
0138         } else {
0139             $this->transferFromDOM($element);
0140         }
0141     }
0142 
0143     /**
0144      * Set the HTTP client instance
0145      *
0146      * Sets the HTTP client object to use for retrieving the feed.
0147      *
0148      * @deprecated Deprecated as of Zend Framework 1.7. Use
0149      *             setService() instead.
0150      * @param  Zend_Http_Client $httpClient
0151      * @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface
0152      */
0153     public function setHttpClient(Zend_Http_Client $httpClient)
0154     {
0155         if (!$this->_service) {
0156             $this->_service = new Zend_Gdata_App();
0157         }
0158         $this->_service->setHttpClient($httpClient);
0159         return $this;
0160     }
0161 
0162     /**
0163      * Gets the HTTP client object. If none is set, a new Zend_Http_Client
0164      * will be used.
0165      *
0166      * @deprecated Deprecated as of Zend Framework 1.7. Use
0167      *             getService() instead.
0168      * @return Zend_Http_Client_Abstract
0169      */
0170     public function getHttpClient()
0171     {
0172         if (!$this->_service) {
0173             $this->_service = new Zend_Gdata_App();
0174         }
0175         $client = $this->_service->getHttpClient();
0176         return $client;
0177     }
0178 
0179     /**
0180      * Set the active service instance for this object. This will be used to
0181      * perform network requests, such as when calling save() and delete().
0182      *
0183      * @param Zend_Gdata_App $instance The new service instance.
0184      * @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface.
0185      */
0186     public function setService($instance)
0187     {
0188         $this->_service = $instance;
0189         return $this;
0190     }
0191 
0192     /**
0193      * Get the active service instance for this object. This will be used to
0194      * perform network requests, such as when calling save() and delete().
0195      *
0196      * @return Zend_Gdata_App|null The current service instance, or null if
0197      *         not set.
0198      */
0199     public function getService()
0200     {
0201         return $this->_service;
0202     }
0203 
0204     public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
0205     {
0206         $element = parent::getDOM($doc, $majorVersion, $minorVersion);
0207         foreach ($this->_author as $author) {
0208             $element->appendChild($author->getDOM($element->ownerDocument));
0209         }
0210         foreach ($this->_category as $category) {
0211             $element->appendChild($category->getDOM($element->ownerDocument));
0212         }
0213         foreach ($this->_contributor as $contributor) {
0214             $element->appendChild($contributor->getDOM($element->ownerDocument));
0215         }
0216         if ($this->_id != null) {
0217             $element->appendChild($this->_id->getDOM($element->ownerDocument));
0218         }
0219         foreach ($this->_link as $link) {
0220             $element->appendChild($link->getDOM($element->ownerDocument));
0221         }
0222         if ($this->_rights != null) {
0223             $element->appendChild($this->_rights->getDOM($element->ownerDocument));
0224         }
0225         if ($this->_title != null) {
0226             $element->appendChild($this->_title->getDOM($element->ownerDocument));
0227         }
0228         if ($this->_updated != null) {
0229             $element->appendChild($this->_updated->getDOM($element->ownerDocument));
0230         }
0231         return $element;
0232     }
0233 
0234     protected function takeChildFromDOM($child)
0235     {
0236         $absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
0237         switch ($absoluteNodeName) {
0238         case $this->lookupNamespace('atom') . ':' . 'author':
0239             $author = new Zend_Gdata_App_Extension_Author();
0240             $author->transferFromDOM($child);
0241             $this->_author[] = $author;
0242             break;
0243         case $this->lookupNamespace('atom') . ':' . 'category':
0244             $category = new Zend_Gdata_App_Extension_Category();
0245             $category->transferFromDOM($child);
0246             $this->_category[] = $category;
0247             break;
0248         case $this->lookupNamespace('atom') . ':' . 'contributor':
0249             $contributor = new Zend_Gdata_App_Extension_Contributor();
0250             $contributor->transferFromDOM($child);
0251             $this->_contributor[] = $contributor;
0252             break;
0253         case $this->lookupNamespace('atom') . ':' . 'id':
0254             $id = new Zend_Gdata_App_Extension_Id();
0255             $id->transferFromDOM($child);
0256             $this->_id = $id;
0257             break;
0258         case $this->lookupNamespace('atom') . ':' . 'link':
0259             $link = new Zend_Gdata_App_Extension_Link();
0260             $link->transferFromDOM($child);
0261             $this->_link[] = $link;
0262             break;
0263         case $this->lookupNamespace('atom') . ':' . 'rights':
0264             $rights = new Zend_Gdata_App_Extension_Rights();
0265             $rights->transferFromDOM($child);
0266             $this->_rights = $rights;
0267             break;
0268         case $this->lookupNamespace('atom') . ':' . 'title':
0269             $title = new Zend_Gdata_App_Extension_Title();
0270             $title->transferFromDOM($child);
0271             $this->_title = $title;
0272             break;
0273         case $this->lookupNamespace('atom') . ':' . 'updated':
0274             $updated = new Zend_Gdata_App_Extension_Updated();
0275             $updated->transferFromDOM($child);
0276             $this->_updated = $updated;
0277             break;
0278         default:
0279             parent::takeChildFromDOM($child);
0280             break;
0281         }
0282     }
0283 
0284     /**
0285      * @return Zend_Gdata_App_Extension_Author
0286      */
0287     public function getAuthor()
0288     {
0289         return $this->_author;
0290     }
0291 
0292     /**
0293      * Sets the list of the authors of this feed/entry.  In an atom feed, each
0294      * author is represented by an atom:author element
0295      *
0296      * @param array $value
0297      * @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface
0298      */
0299     public function setAuthor($value)
0300     {
0301         $this->_author = $value;
0302         return $this;
0303     }
0304 
0305     /**
0306      * Returns the array of categories that classify this feed/entry.  Each
0307      * category is represented in an atom feed by an atom:category element.
0308      *
0309      * @return array Array of Zend_Gdata_App_Extension_Category
0310      */
0311     public function getCategory()
0312     {
0313         return $this->_category;
0314     }
0315 
0316     /**
0317      * Sets the array of categories that classify this feed/entry.  Each
0318      * category is represented in an atom feed by an atom:category element.
0319      *
0320      * @param array $value Array of Zend_Gdata_App_Extension_Category
0321      * @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface
0322      */
0323     public function setCategory($value)
0324     {
0325         $this->_category = $value;
0326         return $this;
0327     }
0328 
0329     /**
0330      * Returns the array of contributors to this feed/entry.  Each contributor
0331      * is represented in an atom feed by an atom:contributor XML element
0332      *
0333      * @return array An array of Zend_Gdata_App_Extension_Contributor
0334      */
0335     public function getContributor()
0336     {
0337         return $this->_contributor;
0338     }
0339 
0340     /**
0341      * Sets the array of contributors to this feed/entry.  Each contributor
0342      * is represented in an atom feed by an atom:contributor XML element
0343      *
0344      * @param array $value
0345      * @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface
0346      */
0347     public function setContributor($value)
0348     {
0349         $this->_contributor = $value;
0350         return $this;
0351     }
0352 
0353     /**
0354      * @return Zend_Gdata_App_Extension_Id
0355      */
0356     public function getId()
0357     {
0358         return $this->_id;
0359     }
0360 
0361     /**
0362      * @param Zend_Gdata_App_Extension_Id $value
0363      * @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface
0364      */
0365     public function setId($value)
0366     {
0367         $this->_id = $value;
0368         return $this;
0369     }
0370 
0371     /**
0372      * Given a particular 'rel' value, this method returns a matching
0373      * Zend_Gdata_App_Extension_Link element.  If the 'rel' value
0374      * is not provided, the full array of Zend_Gdata_App_Extension_Link
0375      * elements is returned.  In an atom feed, each link is represented
0376      * by an atom:link element.  The 'rel' value passed to this function
0377      * is the atom:link/@rel attribute.  Example rel values include 'self',
0378      * 'edit', and 'alternate'.
0379      *
0380      * @param string $rel The rel value of the link to be found.  If null,
0381      *     the array of Zend_Gdata_App_Extension_link elements is returned
0382      * @return mixed Either a single Zend_Gdata_App_Extension_link element,
0383      *     an array of the same or null is returned depending on the rel value
0384      *     supplied as the argument to this function
0385      */
0386     public function getLink($rel = null)
0387     {
0388         if ($rel == null) {
0389             return $this->_link;
0390         } else {
0391             foreach ($this->_link as $link) {
0392                 if ($link->rel == $rel) {
0393                     return $link;
0394                 }
0395             }
0396             return null;
0397         }
0398     }
0399 
0400     /**
0401      * Returns the Zend_Gdata_App_Extension_Link element which represents
0402      * the URL used to edit this resource.  This link is in the atom feed/entry
0403      * as an atom:link with a rel attribute value of 'edit'.
0404      *
0405      * @return Zend_Gdata_App_Extension_Link The link, or null if not found
0406      */
0407     public function getEditLink()
0408     {
0409         return $this->getLink('edit');
0410     }
0411 
0412     /**
0413      * Returns the Zend_Gdata_App_Extension_Link element which represents
0414      * the URL used to retrieve the next chunk of results when paging through
0415      * a feed.  This link is in the atom feed as an atom:link with a
0416      * rel attribute value of 'next'.
0417      *
0418      * @return Zend_Gdata_App_Extension_Link The link, or null if not found
0419      */
0420     public function getNextLink()
0421     {
0422         return $this->getLink('next');
0423     }
0424 
0425     /**
0426      * Returns the Zend_Gdata_App_Extension_Link element which represents
0427      * the URL used to retrieve the previous chunk of results when paging
0428      * through a feed.  This link is in the atom feed as an atom:link with a
0429      * rel attribute value of 'previous'.
0430      *
0431      * @return Zend_Gdata_App_Extension_Link The link, or null if not found
0432      */
0433     public function getPreviousLink()
0434     {
0435         return $this->getLink('previous');
0436     }
0437 
0438     /**
0439      * @return Zend_Gdata_App_Extension_Link
0440      */
0441     public function getLicenseLink()
0442     {
0443         return $this->getLink('license');
0444     }
0445 
0446     /**
0447      * Returns the Zend_Gdata_App_Extension_Link element which represents
0448      * the URL used to retrieve the entry or feed represented by this object
0449      * This link is in the atom feed/entry as an atom:link with a
0450      * rel attribute value of 'self'.
0451      *
0452      * @return Zend_Gdata_App_Extension_Link The link, or null if not found
0453      */
0454     public function getSelfLink()
0455     {
0456         return $this->getLink('self');
0457     }
0458 
0459     /**
0460      * Returns the Zend_Gdata_App_Extension_Link element which represents
0461      * the URL for an alternate view of the data represented by this feed or
0462      * entry.  This alternate view is commonly a user-facing webpage, blog
0463      * post, etc.  The MIME type for the data at the URL is available from the
0464      * returned Zend_Gdata_App_Extension_Link element.
0465      * This link is in the atom feed/entry as an atom:link with a
0466      * rel attribute value of 'self'.
0467      *
0468      * @return Zend_Gdata_App_Extension_Link The link, or null if not found
0469      */
0470     public function getAlternateLink()
0471     {
0472         return $this->getLink('alternate');
0473     }
0474 
0475     /**
0476      * @param array $value The array of Zend_Gdata_App_Extension_Link elements
0477      * @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface
0478      */
0479     public function setLink($value)
0480     {
0481         $this->_link = $value;
0482         return $this;
0483     }
0484 
0485     /**
0486      * @return Zend_Gdata_AppExtension_Rights
0487      */
0488     public function getRights()
0489     {
0490         return $this->_rights;
0491     }
0492 
0493     /**
0494      * @param Zend_Gdata_App_Extension_Rights $value
0495      * @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface
0496      */
0497     public function setRights($value)
0498     {
0499         $this->_rights = $value;
0500         return $this;
0501     }
0502 
0503     /**
0504      * Returns the title of this feed or entry.  The title is an extremely
0505      * short textual representation of this resource and is found as
0506      * an atom:title element in a feed or entry
0507      *
0508      * @return Zend_Gdata_App_Extension_Title
0509      */
0510     public function getTitle()
0511     {
0512         return $this->_title;
0513     }
0514 
0515     /**
0516      * Returns a string representation of the title of this feed or entry.
0517      * The title is an extremely short textual representation of this
0518      * resource and is found as an atom:title element in a feed or entry
0519      *
0520      * @return string
0521      */
0522     public function getTitleValue()
0523     {
0524         if (($titleObj = $this->getTitle()) != null) {
0525             return $titleObj->getText();
0526         } else {
0527             return null;
0528         }
0529     }
0530 
0531     /**
0532      * Returns the title of this feed or entry.  The title is an extremely
0533      * short textual representation of this resource and is found as
0534      * an atom:title element in a feed or entry
0535      *
0536      * @param Zend_Gdata_App_Extension_Title $value
0537      * @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface
0538      */
0539     public function setTitle($value)
0540     {
0541         $this->_title = $value;
0542         return $this;
0543     }
0544 
0545     /**
0546      * @return Zend_Gdata_App_Extension_Updated
0547      */
0548     public function getUpdated()
0549     {
0550         return $this->_updated;
0551     }
0552 
0553     /**
0554      * @param Zend_Gdata_App_Extension_Updated $value
0555      * @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface
0556      */
0557     public function setUpdated($value)
0558     {
0559         $this->_updated = $value;
0560         return $this;
0561     }
0562 
0563     /**
0564      * Set the Etag for the current entry to $value. Setting $value to null
0565      * unsets the Etag.
0566      *
0567      * @param string|null $value
0568      * @return Zend_Gdata_App_Entry Provides a fluent interface
0569      */
0570     public function setEtag($value) {
0571         $this->_etag = $value;
0572         return $this;
0573     }
0574 
0575     /**
0576      * Return the Etag for the current entry, or null if not set.
0577      *
0578      * @return string|null
0579      */
0580     public function getEtag() {
0581         return $this->_etag;
0582     }
0583 
0584     /**
0585      * Set the major protocol version that should be used. Values < 1
0586      * (excluding NULL) will cause a Zend_Gdata_App_InvalidArgumentException
0587      * to be thrown.
0588      *
0589      * @see _majorProtocolVersion
0590      * @param (int|NULL) $value The major protocol version to use.
0591      * @throws Zend_Gdata_App_InvalidArgumentException
0592      */
0593     public function setMajorProtocolVersion($value)
0594     {
0595         if (!($value >= 1) && ($value !== null)) {
0596             // require_once('Zend/Gdata/App/InvalidArgumentException.php');
0597             throw new Zend_Gdata_App_InvalidArgumentException(
0598                     'Major protocol version must be >= 1');
0599         }
0600         $this->_majorProtocolVersion = $value;
0601     }
0602 
0603     /**
0604      * Get the major protocol version that is in use.
0605      *
0606      * @see _majorProtocolVersion
0607      * @return (int|NULL) The major protocol version in use.
0608      */
0609     public function getMajorProtocolVersion()
0610     {
0611         return $this->_majorProtocolVersion;
0612     }
0613 
0614     /**
0615      * Set the minor protocol version that should be used. If set to NULL, no
0616      * minor protocol version will be sent to the server. Values < 0 will
0617      * cause a Zend_Gdata_App_InvalidArgumentException to be thrown.
0618      *
0619      * @see _minorProtocolVersion
0620      * @param (int|NULL) $value The minor protocol version to use.
0621      * @throws Zend_Gdata_App_InvalidArgumentException
0622      */
0623     public function setMinorProtocolVersion($value)
0624     {
0625         if (!($value >= 0)) {
0626             // require_once('Zend/Gdata/App/InvalidArgumentException.php');
0627             throw new Zend_Gdata_App_InvalidArgumentException(
0628                     'Minor protocol version must be >= 0 or null');
0629         }
0630         $this->_minorProtocolVersion = $value;
0631     }
0632 
0633     /**
0634      * Get the minor protocol version that is in use.
0635      *
0636      * @see _minorProtocolVersion
0637      * @return (int|NULL) The major protocol version in use, or NULL if no
0638      *         minor version is specified.
0639      */
0640     public function getMinorProtocolVersion()
0641     {
0642         return $this->_minorProtocolVersion;
0643     }
0644 
0645     /**
0646      * Get the full version of a namespace prefix
0647      *
0648      * Looks up a prefix (atom:, etc.) in the list of registered
0649      * namespaces and returns the full namespace URI if
0650      * available. Returns the prefix, unmodified, if it's not
0651      * registered.
0652      *
0653      * The current entry or feed's version will be used when performing the
0654      * namespace lookup unless overridden using $majorVersion and
0655      * $minorVersion. If the entry/fee has a null version, then the latest
0656      * protocol version will be used by default.
0657      *
0658      * @param string $prefix The namespace prefix to lookup.
0659      * @param integer $majorVersion The major protocol version in effect.
0660      *        Defaults to null (auto-select).
0661      * @param integer $minorVersion The minor protocol version in effect.
0662      *        Defaults to null (auto-select).
0663      * @return string
0664      */
0665     public function lookupNamespace($prefix,
0666                                     $majorVersion = null,
0667                                     $minorVersion = null)
0668     {
0669         // Auto-select current version
0670         if ($majorVersion === null) {
0671             $majorVersion = $this->getMajorProtocolVersion();
0672         }
0673         if ($minorVersion === null) {
0674             $minorVersion = $this->getMinorProtocolVersion();
0675         }
0676 
0677         // Perform lookup
0678         return parent::lookupNamespace($prefix, $majorVersion, $minorVersion);
0679     }
0680 
0681 }