From bc796fd68e1faae3260c186ac446c3a75ac1ecf5 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Sun, 23 May 2010 17:12:20 +0200 Subject: Add FedoraPkgdb->getBranch(), improves fedcli.php --- FedoraClient.php | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'FedoraClient.php') diff --git a/FedoraClient.php b/FedoraClient.php index 891b7f3..1a33ac9 100644 --- a/FedoraClient.php +++ b/FedoraClient.php @@ -41,7 +41,7 @@ abstract class FedoraClient { if (isset($options['agent']) && !empty($options['agent'])) { $this->agent = $options['agent']; } else { - $this->agent = 'PHP FedoraClient/'.FEDORACLIENT_VERSION; + $this->agent = 'Fedora PHPClient/'.FEDORACLIENT_VERSION; } if (isset($options['debug']) && intval($options['debug'])>0) { $this->debug = intval($options['debug']); @@ -74,7 +74,7 @@ abstract class FedoraClient { curl_setopt($curl, CURLOPT_HTTPHEADER, array('User-agent: '.$this->agent, 'Accept: application/json')); # run the request - $this->logDebug(1,__CLASS__."::".__FUNCTION__.": call '$url'"); + $this->logDebug(2,__CLASS__."::".__FUNCTION__.": call '$url'"); curl_exec($curl); @@ -93,7 +93,7 @@ abstract class FedoraClient { $this->logDebug(2,__CLASS__."::".__FUNCTION__.": http_status '$http_status'"); } - $this->logDebug(1,__CLASS__."::".__FUNCTION__.": close connexion"); + $this->logDebug(2,__CLASS__."::".__FUNCTION__.": close connexion"); curl_close($curl); return json_decode($this->data, true); @@ -116,7 +116,7 @@ class FedoraPkgdb extends FedoraClient { } function getBranches($refresh=false) { - $rep = $this->cache->get(__FUNCTION__,__CLASS__); + $rep = ($refresh ? false : $this->cache->get(__FUNCTION__,__CLASS__)); if ($rep) { $this->logDebug(2,__CLASS__."::".__FUNCTION__." get from cache"); } else { @@ -125,13 +125,22 @@ class FedoraPkgdb extends FedoraClient { $this->logDebug(2,__CLASS__."::".__FUNCTION__." save to cache"); } - $this->branches = array(); + $branches = array(); if (isset($rep['collections'])) { foreach ($rep['collections'] as $coll) if (isset($coll[0]['branchname'])) { - $this->branches[$coll[0]['branchname']] = $coll[0]; + $branches[$coll[0]['branchname']] = $coll[0]; } } - return $this->branches; + return $branches; + } + + function getBranch($name, $refresh=false) { + $branches = $this->getBranches($refresh); + + if (isset($branches[$name])) { + return $branches[$name]; + } + return false; } } ?> -- cgit