8 * This source file is subject to the new BSD license that is bundled
9 * with this package in the file LICENSE.txt.
10 * It is also available through the world-wide-web at this URL:
11 * http://framework.zend.com/license/new-bsd
12 * If you did not receive a copy of the license and are unable to
13 * obtain it through the world-wide-web, please send an email
14 * to license@zend.com so we can send you a copy immediately.
19 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
20 * @license http://framework.zend.com/license/new-bsd New BSD License
21 * @version $Id: FeedEntryParent.php 16971 2009-07-22 18:05:45Z mikaelkael $
25 * @see Zend_Gdata_App_Extension_Element
27 require_once 'Zend/Gdata/App/Extension/Element.php';
30 * @see Zend_Gdata_App_Extension_Author
32 require_once 'Zend/Gdata/App/Extension/Author.php';
35 * @see Zend_Gdata_App_Extension_Category
37 require_once 'Zend/Gdata/App/Extension/Category.php';
40 * @see Zend_Gdata_App_Extension_Contributor
42 require_once 'Zend/Gdata/App/Extension/Contributor.php';
45 * @see Zend_Gdata_App_Extension_Id
47 require_once 'Zend/Gdata/App/Extension/Id.php';
50 * @see Zend_Gdata_App_Extension_Link
52 require_once 'Zend/Gdata/App/Extension/Link.php';
55 * @see Zend_Gdata_App_Extension_Rights
57 require_once 'Zend/Gdata/App/Extension/Rights.php';
60 * @see Zend_Gdata_App_Extension_Title
62 require_once 'Zend/Gdata/App/Extension/Title.php';
65 * @see Zend_Gdata_App_Extension_Updated
67 require_once 'Zend/Gdata/App/Extension/Updated.php';
72 require_once 'Zend/Version.php';
75 * Abstract class for common functionality in entries and feeds
80 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
81 * @license http://framework.zend.com/license/new-bsd New BSD License
83 abstract class Zend_Gdata_App_FeedEntryParent
extends Zend_Gdata_App_Base
86 * Service instance used to make network requests.
88 * @see setService(), getService()
90 protected $_service = null;
93 * The HTTP ETag associated with this entry. Used for optimistic
94 * concurrency in protoco v2 or greater.
98 protected $_etag = NULL;
100 protected $_author = array();
101 protected $_category = array();
102 protected $_contributor = array();
103 protected $_id = null;
104 protected $_link = array();
105 protected $_rights = null;
106 protected $_title = null;
107 protected $_updated = null;
110 * Indicates the major protocol version that should be used.
111 * At present, recognized values are either 1 or 2. However, any integer
112 * value >= 1 is considered valid.
114 * @see setMajorProtocolVersion()
115 * @see getMajorProtocolVersion()
117 protected $_majorProtocolVersion = 1;
120 * Indicates the minor protocol version that should be used. Can be set
121 * to either an integer >= 0, or NULL if no minor version should be sent
124 * @see setMinorProtocolVersion()
125 * @see getMinorProtocolVersion()
127 protected $_minorProtocolVersion = null;
130 * Constructs a Feed or Entry
132 public function __construct($element = null)
134 if (!($element instanceof DOMElement
)) {
136 $this->transferFromXML($element);
139 $this->transferFromDOM($element);
144 * Set the HTTP client instance
146 * Sets the HTTP client object to use for retrieving the feed.
148 * @deprecated Deprecated as of Zend Framework 1.7. Use
149 * setService() instead.
150 * @param Zend_Http_Client $httpClient
151 * @return Zend_Gdata_App_Feed Provides a fluent interface
153 public function setHttpClient(Zend_Http_Client
$httpClient)
155 if (!$this->_service
) {
156 $this->_service
= new Zend_Gdata_App();
158 $this->_service
->setHttpClient($httpClient);
163 * Gets the HTTP client object. If none is set, a new Zend_Http_Client
166 * @deprecated Deprecated as of Zend Framework 1.7. Use
167 * getService() instead.
168 * @return Zend_Http_Client_Abstract
170 public function getHttpClient()
172 if (!$this->_service
) {
173 $this->_service
= new Zend_Gdata_App();
175 $client = $this->_service
->getHttpClient();
180 * Set the active service instance for this object. This will be used to
181 * perform network requests, such as when calling save() and delete().
183 * @param Zend_Gdata_App $instance The new service instance.
184 * @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface.
186 public function setService($instance)
188 $this->_service
= $instance;
193 * Get the active service instance for this object. This will be used to
194 * perform network requests, such as when calling save() and delete().
196 * @return Zend_Gdata_App|null The current service instance, or null if
199 public function getService()
201 return $this->_service
;
204 public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
206 $element = parent
::getDOM($doc, $majorVersion, $minorVersion);
207 foreach ($this->_author
as $author) {
208 $element->appendChild($author->getDOM($element->ownerDocument
));
210 foreach ($this->_category
as $category) {
211 $element->appendChild($category->getDOM($element->ownerDocument
));
213 foreach ($this->_contributor
as $contributor) {
214 $element->appendChild($contributor->getDOM($element->ownerDocument
));
216 if ($this->_id
!= null) {
217 $element->appendChild($this->_id
->getDOM($element->ownerDocument
));
219 foreach ($this->_link
as $link) {
220 $element->appendChild($link->getDOM($element->ownerDocument
));
222 if ($this->_rights
!= null) {
223 $element->appendChild($this->_rights
->getDOM($element->ownerDocument
));
225 if ($this->_title
!= null) {
226 $element->appendChild($this->_title
->getDOM($element->ownerDocument
));
228 if ($this->_updated
!= null) {
229 $element->appendChild($this->_updated
->getDOM($element->ownerDocument
));
234 protected function takeChildFromDOM($child)
236 $absoluteNodeName = $child->namespaceURI
. ':' . $child->localName
;
237 switch ($absoluteNodeName) {
238 case $this->lookupNamespace('atom') . ':' . 'author':
239 $author = new Zend_Gdata_App_Extension_Author();
240 $author->transferFromDOM($child);
241 $this->_author
[] = $author;
243 case $this->lookupNamespace('atom') . ':' . 'category':
244 $category = new Zend_Gdata_App_Extension_Category();
245 $category->transferFromDOM($child);
246 $this->_category
[] = $category;
248 case $this->lookupNamespace('atom') . ':' . 'contributor':
249 $contributor = new Zend_Gdata_App_Extension_Contributor();
250 $contributor->transferFromDOM($child);
251 $this->_contributor
[] = $contributor;
253 case $this->lookupNamespace('atom') . ':' . 'id':
254 $id = new Zend_Gdata_App_Extension_Id();
255 $id->transferFromDOM($child);
258 case $this->lookupNamespace('atom') . ':' . 'link':
259 $link = new Zend_Gdata_App_Extension_Link();
260 $link->transferFromDOM($child);
261 $this->_link
[] = $link;
263 case $this->lookupNamespace('atom') . ':' . 'rights':
264 $rights = new Zend_Gdata_App_Extension_Rights();
265 $rights->transferFromDOM($child);
266 $this->_rights
= $rights;
268 case $this->lookupNamespace('atom') . ':' . 'title':
269 $title = new Zend_Gdata_App_Extension_Title();
270 $title->transferFromDOM($child);
271 $this->_title
= $title;
273 case $this->lookupNamespace('atom') . ':' . 'updated':
274 $updated = new Zend_Gdata_App_Extension_Updated();
275 $updated->transferFromDOM($child);
276 $this->_updated
= $updated;
279 parent
::takeChildFromDOM($child);
285 * @return Zend_Gdata_App_Extension_Author
287 public function getAuthor()
289 return $this->_author
;
293 * Sets the list of the authors of this feed/entry. In an atom feed, each
294 * author is represented by an atom:author element
296 * @param array $value
297 * @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface
299 public function setAuthor($value)
301 $this->_author
= $value;
306 * Returns the array of categories that classify this feed/entry. Each
307 * category is represented in an atom feed by an atom:category element.
309 * @return array Array of Zend_Gdata_App_Extension_Category
311 public function getCategory()
313 return $this->_category
;
317 * Sets the array of categories that classify this feed/entry. Each
318 * category is represented in an atom feed by an atom:category element.
320 * @param array $value Array of Zend_Gdata_App_Extension_Category
321 * @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface
323 public function setCategory($value)
325 $this->_category
= $value;
330 * Returns the array of contributors to this feed/entry. Each contributor
331 * is represented in an atom feed by an atom:contributor XML element
333 * @return array An array of Zend_Gdata_App_Extension_Contributor
335 public function getContributor()
337 return $this->_contributor
;
341 * Sets the array of contributors to this feed/entry. Each contributor
342 * is represented in an atom feed by an atom:contributor XML element
344 * @param array $value
345 * @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface
347 public function setContributor($value)
349 $this->_contributor
= $value;
354 * @return Zend_Gdata_App_Extension_Id
356 public function getId()
362 * @param Zend_Gdata_App_Extension_Id $value
363 * @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface
365 public function setId($value)
372 * Given a particular 'rel' value, this method returns a matching
373 * Zend_Gdata_App_Extension_Link element. If the 'rel' value
374 * is not provided, the full array of Zend_Gdata_App_Extension_Link
375 * elements is returned. In an atom feed, each link is represented
376 * by an atom:link element. The 'rel' value passed to this function
377 * is the atom:link/@rel attribute. Example rel values include 'self',
378 * 'edit', and 'alternate'.
380 * @param string $rel The rel value of the link to be found. If null,
381 * the array of Zend_Gdata_App_Extension_link elements is returned
382 * @return mixed Either a single Zend_Gdata_App_Extension_link element,
383 * an array of the same or null is returned depending on the rel value
384 * supplied as the argument to this function
386 public function getLink($rel = null)
391 foreach ($this->_link
as $link) {
392 if ($link->rel
== $rel) {
401 * Returns the Zend_Gdata_App_Extension_Link element which represents
402 * the URL used to edit this resource. This link is in the atom feed/entry
403 * as an atom:link with a rel attribute value of 'edit'.
405 * @return Zend_Gdata_App_Extension_Link The link, or null if not found
407 public function getEditLink()
409 return $this->getLink('edit');
413 * Returns the Zend_Gdata_App_Extension_Link element which represents
414 * the URL used to retrieve the next chunk of results when paging through
415 * a feed. This link is in the atom feed as an atom:link with a
416 * rel attribute value of 'next'.
418 * @return Zend_Gdata_App_Extension_Link The link, or null if not found
420 public function getNextLink()
422 return $this->getLink('next');
426 * Returns the Zend_Gdata_App_Extension_Link element which represents
427 * the URL used to retrieve the previous chunk of results when paging
428 * through a feed. This link is in the atom feed as an atom:link with a
429 * rel attribute value of 'previous'.
431 * @return Zend_Gdata_App_Extension_Link The link, or null if not found
433 public function getPreviousLink()
435 return $this->getLink('previous');
439 * @return Zend_Gdata_App_Extension_Link
441 public function getLicenseLink()
443 return $this->getLink('license');
447 * Returns the Zend_Gdata_App_Extension_Link element which represents
448 * the URL used to retrieve the entry or feed represented by this object
449 * This link is in the atom feed/entry as an atom:link with a
450 * rel attribute value of 'self'.
452 * @return Zend_Gdata_App_Extension_Link The link, or null if not found
454 public function getSelfLink()
456 return $this->getLink('self');
460 * Returns the Zend_Gdata_App_Extension_Link element which represents
461 * the URL for an alternate view of the data represented by this feed or
462 * entry. This alternate view is commonly a user-facing webpage, blog
463 * post, etc. The MIME type for the data at the URL is available from the
464 * returned Zend_Gdata_App_Extension_Link element.
465 * This link is in the atom feed/entry as an atom:link with a
466 * rel attribute value of 'self'.
468 * @return Zend_Gdata_App_Extension_Link The link, or null if not found
470 public function getAlternateLink()
472 return $this->getLink('alternate');
476 * @param array $value The array of Zend_Gdata_App_Extension_Link elements
477 * @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface
479 public function setLink($value)
481 $this->_link
= $value;
486 * @return Zend_Gdata_AppExtension_Rights
488 public function getRights()
490 return $this->_rights
;
494 * @param Zend_Gdata_App_Extension_Rights $value
495 * @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface
497 public function setRights($value)
499 $this->_rights
= $value;
504 * Returns the title of this feed or entry. The title is an extremely
505 * short textual representation of this resource and is found as
506 * an atom:title element in a feed or entry
508 * @return Zend_Gdata_App_Extension_Title
510 public function getTitle()
512 return $this->_title
;
516 * Returns a string representation of the title of this feed or entry.
517 * The title is an extremely short textual representation of this
518 * resource and is found as an atom:title element in a feed or entry
522 public function getTitleValue()
524 if (($titleObj = $this->getTitle()) != null) {
525 return $titleObj->getText();
532 * Returns the title of this feed or entry. The title is an extremely
533 * short textual representation of this resource and is found as
534 * an atom:title element in a feed or entry
536 * @param Zend_Gdata_App_Extension_Title $value
537 * @return Zend_Gdata_App_Feed_Entry_Parent Provides a fluent interface
539 public function setTitle($value)
541 $this->_title
= $value;
546 * @return Zend_Gdata_App_Extension_Updated
548 public function getUpdated()
550 return $this->_updated
;
554 * @param Zend_Gdata_App_Extension_Updated $value
555 * @return Zend_Gdata_App_Feed_Entry_Parent Provides a fluent interface
557 public function setUpdated($value)
559 $this->_updated
= $value;
564 * Set the Etag for the current entry to $value. Setting $value to null
567 * @param string|null $value
568 * @return Zend_Gdata_App_Entry Provides a fluent interface
570 public function setEtag($value) {
571 $this->_etag
= $value;
576 * Return the Etag for the current entry, or null if not set.
578 * @return string|null
580 public function getEtag() {
585 * Set the major protocol version that should be used. Values < 1
586 * (excluding NULL) will cause a Zend_Gdata_App_InvalidArgumentException
589 * @see _majorProtocolVersion
590 * @param (int|NULL) $value The major protocol version to use.
591 * @throws Zend_Gdata_App_InvalidArgumentException
593 public function setMajorProtocolVersion($value)
595 if (!($value >= 1) && ($value !== null)) {
596 require_once('Zend/Gdata/App/InvalidArgumentException.php');
597 throw new Zend_Gdata_App_InvalidArgumentException(
598 'Major protocol version must be >= 1');
600 $this->_majorProtocolVersion
= $value;
604 * Get the major protocol version that is in use.
606 * @see _majorProtocolVersion
607 * @return (int|NULL) The major protocol version in use.
609 public function getMajorProtocolVersion()
611 return $this->_majorProtocolVersion
;
615 * Set the minor protocol version that should be used. If set to NULL, no
616 * minor protocol version will be sent to the server. Values < 0 will
617 * cause a Zend_Gdata_App_InvalidArgumentException to be thrown.
619 * @see _minorProtocolVersion
620 * @param (int|NULL) $value The minor protocol version to use.
621 * @throws Zend_Gdata_App_InvalidArgumentException
623 public function setMinorProtocolVersion($value)
625 if (!($value >= 0)) {
626 require_once('Zend/Gdata/App/InvalidArgumentException.php');
627 throw new Zend_Gdata_App_InvalidArgumentException(
628 'Minor protocol version must be >= 0 or null');
630 $this->_minorProtocolVersion
= $value;
634 * Get the minor protocol version that is in use.
636 * @see _minorProtocolVersion
637 * @return (int|NULL) The major protocol version in use, or NULL if no
638 * minor version is specified.
640 public function getMinorProtocolVersion()
642 return $this->_minorProtocolVersion
;
646 * Get the full version of a namespace prefix
648 * Looks up a prefix (atom:, etc.) in the list of registered
649 * namespaces and returns the full namespace URI if
650 * available. Returns the prefix, unmodified, if it's not
653 * The current entry or feed's version will be used when performing the
654 * namespace lookup unless overridden using $majorVersion and
655 * $minorVersion. If the entry/fee has a null version, then the latest
656 * protocol version will be used by default.
658 * @param string $prefix The namespace prefix to lookup.
659 * @param integer $majorVersion The major protocol version in effect.
660 * Defaults to null (auto-select).
661 * @param integer $minorVersion The minor protocol version in effect.
662 * Defaults to null (auto-select).
665 public function lookupNamespace($prefix,
666 $majorVersion = null,
667 $minorVersion = null)
669 // Auto-select current version
670 if ($majorVersion === null) {
671 $majorVersion = $this->getMajorProtocolVersion();
673 if ($minorVersion === null) {
674 $minorVersion = $this->getMinorProtocolVersion();
678 return parent
::lookupNamespace($prefix, $majorVersion, $minorVersion);