1: <?php
2: /**
3: * A parser for a release list response from a PEAR server.
4: *
5: * PHP version 5
6: *
7: * @category Horde
8: * @package Pear
9: * @author Gunnar Wrobel <wrobel@pardus.de>
10: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
11: * @link http://pear.horde.org/index.php?package=Pear
12: */
13:
14: /**
15: * A parser for a release list response from a PEAR server.
16: *
17: * Copyright 2011-2012 Horde LLC (http://www.horde.org/)
18: *
19: * See the enclosed file COPYING for license information (LGPL). If you
20: * did not receive this file, see http://www.horde.org/licenses/lgpl21.
21: *
22: * @category Horde
23: * @package Pear
24: * @author Gunnar Wrobel <wrobel@pardus.de>
25: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
26: * @link http://pear.horde.org/index.php?package=Pear
27: */
28: class Horde_Pear_Rest_Releases extends Horde_Xml_Element_List
29: {
30: /**
31: * The list of releases.
32: *
33: * @var array
34: */
35: private $_releases;
36:
37: /**
38: * Constructor.
39: *
40: * @param resource|string $xml The XML document received from the server.
41: */
42: public function __construct($xml)
43: {
44: if (is_resource($xml)) {
45: rewind($xml);
46: $xml = stream_get_contents($xml);
47: }
48: parent::registerNamespace('xlink', 'http://www.w3.org/1999/xlink');
49: parent::__construct($xml);
50: $this->_releases = $this->_buildReleases();
51: }
52:
53: /**
54: * Build the list of elements.
55: *
56: * @return array The list of elements.
57: */
58: protected function _buildListItemCache()
59: {
60: $entries = array();
61: foreach ($this->_element->getElementsByTagName('r') as $child) {
62: $entries[] = $child;
63: }
64: return $entries;
65: }
66:
67: /**
68: * Build the list of releases.
69: *
70: * @return array The list of releases.
71: */
72: private function _buildReleases()
73: {
74: $releases = array();
75: foreach ($this->r as $r) {
76: $releases[(string)$r->v] = (string)$r->s;
77: }
78: return $releases;
79: }
80:
81: /**
82: * Return the list of releases.
83: *
84: * @return array The releases.
85: */
86: public function listReleases()
87: {
88: return array_keys($this->_releases);
89: }
90:
91: /**
92: * Return the list of releases.
93: *
94: * @return array The releases.
95: */
96: public function getReleases()
97: {
98: return $this->_releases;
99: }
100:
101: /**
102: * Return the stability for the provided release version.
103: *
104: * @param string $version The version to query.
105: *
106: * @return string The stability of the specified release.
107: */
108: public function getReleaseStability($version)
109: {
110: if (isset($this->_releases[$version])) {
111: return $this->_releases[$version];
112: } else {
113: throw new Horde_Pear_Exception(
114: sprintf('No release with version "%s" available!', $version)
115: );
116: }
117: }
118: }