1 : <?php
2 : /**
3 : * REST-based adapter for PEAR_PackageUpdate
4 : *
5 : * PHP versions 4 and 5
6 : *
7 : * LICENSE: This source file is subject to version 3.01 of the PHP license
8 : * that is available through the world-wide-web at the following URI:
9 : * http://www.php.net/license/3_01.txt. If you did not receive a copy of
10 : * the PHP License and are unable to obtain it through the web, please
11 : * send a note to license@php.net so we can mail you a copy immediately.
12 : *
13 : * @category PEAR
14 : * @package PEAR_PackageUpdate
15 : * @author Laurent Laville <pear@laurent-laville.org>
16 : * @license http://www.php.net/license/3_01.txt PHP License 3.01
17 : * @version CVS: $Id: REST.php,v 1.1 2009/02/28 11:29:17 farell Exp $
18 : * @link http://pear.php.net/package/PEAR_PackageUpdate
19 : * @since File available since Release 1.1.0a1
20 : */
21 :
22 1 : require_once 'PEAR/PackageUpdate/Adapter.php';
23 :
24 : /**
25 : * REST-based adapter for PEAR_PackageUpdate
26 : *
27 : * @category PEAR
28 : * @package PEAR_PackageUpdate
29 : * @author Laurent Laville <pear@laurent-laville.org>
30 : * @license http://www.php.net/license/3_01.txt PHP License 3.01
31 : * @version Release: 1.1.0a1
32 : * @link http://pear.php.net/package/PEAR_PackageUpdate
33 : * @since Class available since Release 1.1.0a1
34 : */
35 :
36 1 : class PEAR_PackageUpdate_Adapter_REST extends PEAR_PackageUpdate_Adapter
37 : {
38 : var $channel;
39 : var $config;
40 : var $ppu;
41 :
42 : function PEAR_PackageUpdate_Adapter_REST(&$config, &$ppu)
43 : {
44 11 : $this->config =&$config;
45 11 : $this->ppu =&$ppu;
46 11 : $this->channel = null;
47 11 : }
48 :
49 : /**
50 : * Check if the protocol asked is supported
51 : *
52 : * Check if the protocol asked is supported by default or package channel
53 : *
54 : * @access public
55 : * @return bool
56 : * @since version 1.1.0a1 (2009-02-28)
57 : */
58 : function supports()
59 : {
60 : // Get the config's registry object
61 11 : $reg = &$this->config->getRegistry();
62 11 : if ($reg === false) {
63 0 : return false;
64 : }
65 :
66 : // Get the registry's channel object
67 11 : $chan = &$reg->getChannel($this->ppu->channel);
68 11 : if (PEAR::isError($chan)) {
69 0 : return false;
70 : }
71 11 : $this->channel = $chan;
72 :
73 11 : $mirror = $this->config->get('preferred_mirror');
74 11 : return $chan->supportsREST($mirror);
75 : }
76 :
77 : /**
78 : * Sends request to the remote server
79 : *
80 : * Sends request to the remote server and returns its response
81 : *
82 : * @param string $request Remote request id to proceed
83 : *
84 : * @access public
85 : * @return mixed
86 : * @since version 1.1.0a1 (2009-02-28)
87 : */
88 : function sendRequest($request)
89 : {
90 : switch ($request) {
91 11 : case 'package.info' :
92 11 : if (!isset($this->channel)) {
93 0 : if ($this->supports() == false) {
94 0 : return false;
95 : }
96 0 : }
97 11 : $mirror = $this->config->get('preferred_mirror');
98 11 : $base = $this->channel->getBaseURL('REST1.0', $mirror);
99 11 : $rest =& $this->config->getREST('1.0', array());
100 11 : $info = $rest->packageInfo($base, $this->ppu->packageName);
101 11 : return $info;
102 : }
103 :
104 0 : return false;
105 : }
106 : }
|