PEAR2_SimpleChannelFrontendPEAR2_SimpleChannelFrontend-0.2.0/php/PEAR2/Pyrus/Channel/RemoteMaintainers.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
/**
 * \PEAR2\Pyrus\Channel\RemoteMaintainers
 *
 * PHP version 5
 *
 * @category  PEAR2
 * @package   PEAR2_Pyrus
 * @author    Brett Bieber <saltybeagle@php.net>
 * @copyright 2010 The PEAR Group
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
 * @version   SVN: $Id$
 * @link      http://svn.php.net/viewvc/pear2/Pyrus/
 */

/**
 * Remote REST iteration handler for maitainer listing
 *
 * @category  PEAR2
 * @package   PEAR2_Pyrus
 * @author    Brett Bieber <saltybeagle@php.net>
 * @copyright 2010 The PEAR Group
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
 * @link      http://svn.php.net/viewvc/pear2/Pyrus/
 */
namespace PEAR2\Pyrus\Channel;
class RemoteMaintainers implements \ArrayAccess, \Iterator
{
    protected $parent;
    protected $rest;
    protected $maintainerList;

    function __construct(\PEAR2\Pyrus\ChannelFileInterface $channelinfo)
    {
        $this->parent = $channelinfo;
        if (!isset($this->parent->protocols->rest['REST1.1'])) {
            throw new Exception('Cannot access remote categories without REST1.1 protocol');
        }

        $this->rest = new \PEAR2\Pyrus\REST;
        $this->rewind();
    }

    function offsetGet($var)
    {
        $url = $this->parent->protocols->rest['REST1.1']->baseurl . 'm/' . urlencode($var) . '/info.xml';
        $info = $this->rest->retrieveCacheFirst($url);
        return $info;
    }

    function offsetSet($var, $value)
    {
        throw new Exception('remote channel info is read-only');
    }

    function offsetUnset($var)
    {
        throw new Exception('remote channel info is read-only');
    }

    function offsetExists($var)
    {
        foreach ($this->maintainerList as $maintainer) {
            if ($maintainer['_content'] == $var) {
                return true;
            }
        }
        return false;
    }

    function valid()
    {
        return current($this->maintainerList);
    }

    function current()
    {
        $handle = $this->key();
        $url = $this->parent->protocols->rest['REST1.1']->baseurl . 'm/' . urlencode($handle) . '/info.xml';
        $info = $this->rest->retrieveCacheFirst($url);
        return $info['m'];
    }

    function key()
    {
        $cur = current($this->maintainerList);
        return urldecode($cur['_content']);
    }

    function next()
    {
        return next($this->maintainerList);
    }

    function rewind()
    {
        $url = $this->parent->protocols->rest['REST1.1']->baseurl . 'm/allmaintainers.xml';
        $this->maintainerList = $this->rest->retrieveCacheFirst($url);
        $this->maintainerList = $this->maintainerList['h'];
        if (!isset($this->maintainerList[0])) {
            $this->maintainerList = array($this->maintainerList);
        }
    }
}
EOF