summaryrefslogtreecommitdiffstats
path: root/class
diff options
context:
space:
mode:
Diffstat (limited to 'class')
-rw-r--r--class/FedoraClient.php25
-rw-r--r--class/FedoraPkgdb.php147
2 files changed, 116 insertions, 56 deletions
diff --git a/class/FedoraClient.php b/class/FedoraClient.php
index 62f8eac..7aa2bbb 100644
--- a/class/FedoraClient.php
+++ b/class/FedoraClient.php
@@ -42,7 +42,7 @@ require_once 'Cache/Lite.php';
abstract class FedoraClient
{
- const VERSION='0.1.0-dev';
+ const VERSION='0.2.0-dev';
protected $url;
private $_agent;
private $_debug = 0;
@@ -60,18 +60,30 @@ abstract class FedoraClient
)
);
- $this->url = $url;
+ if (isset($options['debug']) && intval($options['debug'])>0) {
+ $this->_debug = intval($options['debug']);
+ }
+
+ $this->setUrl($url);
+
if (isset($options['agent']) && !empty($options['agent'])) {
$this->_agent = $options['agent'];
} else {
$this->_agent = 'Fedora PHPClient/'.self::VERSION;
}
- if (isset($options['debug']) && intval($options['debug'])>0) {
- $this->_debug = intval($options['debug']);
- }
+
+ $this->logDebug(
+ 3,
+ __CLASS__."::".__FUNCTION__.": agent='".$this->_agent."'"
+ );
+ }
+
+ function setUrl($url)
+ {
+ $this->url = $url;
$this->logDebug(
3,
- __CLASS__."::".__FUNCTION__.": url='$url', agent='".$this->_agent."'"
+ __CLASS__."::".__FUNCTION__.": url='$url'"
);
}
@@ -161,4 +173,3 @@ abstract class FedoraClient
}
}
-?> \ No newline at end of file
diff --git a/class/FedoraPkgdb.php b/class/FedoraPkgdb.php
index 15ddf50..da43986 100644
--- a/class/FedoraPkgdb.php
+++ b/class/FedoraPkgdb.php
@@ -7,7 +7,7 @@
*
* PHP version 5
*
- * Copyright (C) 2010 Remi Collet
+ * Copyright (C) 2010-2013 Remi Collet
* http://github.com/remicollet/rpmphp.
*
* Inspired from python-fedora
@@ -29,7 +29,7 @@
*
* @author Remi Collet <unknown@unknwown.com>
* @author Johan Cwiklinski <johan@x-tnd.be>
- * @copyright 2010 Remi Collet
+ * @copyright 2010-2013 Remi Collet
* @license http://www.gnu.org/licenses/lgpl-2.1.txt LGPL License 2.1 or (at your option) any later version
* @link http://github.com/remicollet/rpmphp/
* @since The begining of times.
@@ -37,41 +37,65 @@
class FedoraPkgdb extends FedoraClient
{
- private $_suburl;
+ private $_version = 0;
function __construct (array $options=array())
{
- parent::__construct('https://admin.fedoraproject.org/pkgdb/', $options);
- $this->_suburl = 'acls/name/';
+ if (isset($options['server']) && ($options['server'])) {
+ $server = $options['server'];
+ } else {
+ $server = 'admin.fedoraproject.org';
+ }
+ parent::__construct("http://$server/api/", $options);
+
+ $rep = $this->cache->get(__METHOD__, $this->url);
+ if ($rep!==false) {
+ $this->logDebug(2, __METHOD__."() get from cache");
+ } else {
+ $rep =$this->sendRequest('version');
+ $this->cache->save($rep, __METHOD__, $this->url);
+ $this->logDebug(2, __METHOD__."() save to cache"
+ );
+ }
+
+ if (isset($rep['version'])) {
+ /* Pkgdb2 */
+ $this->_version = $rep['version'];
+ } else {
+ /* Pkgdb */
+ $this->setUrl("https://$server/pkgdb/");
+ }
+ }
- $this->logDebug(
- 3,
- __CLASS__."::".__FUNCTION__
- );
+ function getVersion()
+ {
+ return $this->_version;
}
function getBranches($refresh=false)
{
- $rep = ($refresh ? false : $this->cache->get(__FUNCTION__, __CLASS__));
+ $rep = ($refresh ? false : $this->cache->get(__METHOD__, $this->url));
if ($rep) {
- $this->logDebug(
- 2,
- __CLASS__."::".__FUNCTION__."() get from cache"
- );
+ $this->logDebug(2, __METHOD__."() get from cache");
} else {
$rep =$this->sendRequest('collections');
- $this->cache->save($rep, __FUNCTION__, __CLASS__);
- $this->logDebug(
- 2,
- __CLASS__."::".__FUNCTION__."() save to cache"
- );
+ $this->cache->save($rep, __METHOD__, $this->url);
+ $this->logDebug(2, __METHOD__."() save to cache");
}
$branches = array();
if (isset($rep['collections'])) {
- foreach ($rep['collections'] as $coll) {
- if (isset($coll[0]['branchname'])) {
- $branches[$coll[0]['branchname']] = $coll[0];
+ if ($this->_version > 0) {
+ foreach ($rep['collections'] as $coll) {
+ if (isset($coll['branchname'])) { /* pkgdb version 2 */
+ $branches[$coll['branchname']] = $coll;
+ }
+ }
+ } else {
+ foreach ($rep['collections'] as $coll) {
+ if (isset($coll[0]['branchname'])) { /* pkgdb version 1 */
+ $branches[$coll[0]['branchname']] = $coll[0];
+ }
}
}
}
@@ -80,32 +104,37 @@ class FedoraPkgdb extends FedoraClient
function getPackageURL($name)
{
- return $this->url.$this->_suburl.$name;
+ return $this->url.'acls/name/'.$name;
}
function getPackageInfo($name, $refresh=false)
{
- $url=$this->_suburl.urlencode($name);
- $rep = ($refresh ? false : $this->cache->get($url, __CLASS__));
+ if ($this->_version > 0) {
+ $url='package/acl/get/'.urlencode($name);
+ $rep = ($refresh ? false : $this->cache->get(__METHOD__, $this->url.$url));
+ if ($rep) {
+ $this->logDebug(2, __METHOD__."($name) get from cache");
+ } else {
+ $rep =$this->sendRequest($url);
+ $this->cache->save($rep, __METHOD__, $this->url.$url);
+ $this->logDebug(2, __METHOD__."($name) save to cache");
+ }
+ $this->logDebug(8, print_r($rep, true));
+ return false;
+ }
+
+ $url='acls/name/'.urlencode($name);
+ $rep = ($refresh ? false : $this->cache->get(__METHOD__, $this->url.$url));
if ($rep) {
- $this->logDebug(
- 2,
- __CLASS__."::".__FUNCTION__."($name) get from cache"
- );
+ $this->logDebug(2, __METHOD__."($name) get from cache");
} else {
$rep =$this->sendRequest($url);
- $this->cache->save($rep, $url, __CLASS__);
- $this->logDebug(
- 2,
- __CLASS__."::".__FUNCTION__."($name) save to cache"
- );
+ $this->cache->save($rep, __METHOD__, $this->url.$url);
+ $this->logDebug(2, __METHOD__."($name) save to cache");
}
if (isset($rep['status']) && !$rep['status']) {
- $this->logDebug(
- 1,
- __CLASS__."::".__FUNCTION__."($name) ".$rep['message']
- );
+ $this->logDebug(1, __METHOD__."($name) ".$rep['message']);
return false;
}
$this->logDebug(8, print_r($rep, true));
@@ -119,6 +148,18 @@ class FedoraPkgdb extends FedoraClient
function getBranch($name, $refresh=false)
{
+ if ($this->_version > 0) {
+ $url='collections/'.urlencode($name).'/';
+ $rep = ($refresh ? false : $this->cache->get(__METHOD__, $this->url.$url));
+ if ($rep) {
+ $this->logDebug(2, __METHOD__."($name) get from cache");
+ } else {
+ $rep =$this->sendRequest($url);
+ $this->cache->save($rep, __METHOD__, $this->url.$url);
+ $this->logDebug(2, __METHOD__."($name) save to cache");
+ }
+ return (isset($rep['collections'][0]) ? $rep['collections'][0] : array());
+ }
$branches = $this->getBranches($refresh);
if (isset($branches[$name])) {
@@ -129,22 +170,30 @@ class FedoraPkgdb extends FedoraClient
function getCritPath($refresh=false)
{
+ if ($this->_version > 0) {
+ $url="critpath";
+ $rep = ($refresh ? false : $this->cache->get(__METHOD__, $this->url));
+ if ($rep) {
+ $this->logDebug(2, __METHOD__."() get from cache");
+ } else {
+ $rep =$this->sendRequest($url);
+ $this->cache->save($rep, __METHOD__, $this->url);
+ $this->logDebug(2, __METHOD__."() save to cache");
+ }
+ return (isset($rep['pkgs']) ? $rep['pkgs'] : NULL);
+ }
+
$url="lists/critpath";
- $rep = ($refresh ? false : $this->cache->get($url, __CLASS__));
+ $rep = ($refresh ? false : $this->cache->get(__METHOD__, $this->url));
if ($rep) {
- $this->logDebug(
- 2,
- __CLASS__."::".__FUNCTION__." get from cache"
- );
+ $this->logDebug(2, __METHOD__."() get from cache");
} else {
$rep =$this->sendRequest($url);
- $this->cache->save($rep, $url, __CLASS__);
- $this->logDebug(
- 2,
- __CLASS__."::".__FUNCTION__." save to cache"
+ $this->cache->save($rep, __METHOD__, $this->url);
+ $this->logDebug(2, __METHOD__."() save to cache"
);
}
- return $rep['pkgs'];
+ return (isset($rep['pkgs']) ? $rep['pkgs'] : NULL);
}
}
-?> \ No newline at end of file
+