diff options
author | Remi Collet <remi@remirepo.net> | 2018-02-12 14:44:22 +0100 |
---|---|---|
committer | Remi Collet <remi@remirepo.net> | 2018-02-12 14:44:22 +0100 |
commit | 702d21b778b6e3a0d962b64a86735f824e9252c5 (patch) | |
tree | 07fdc63eef195bdaa8187d5a8c29fc951f94fe48 /examples/librpm.php | |
parent | ded7f74551635f1e6fb68974416f5fc406ca909f (diff) |
retrieve array of int from metadata, allow dependency retrieval
Diffstat (limited to 'examples/librpm.php')
-rw-r--r-- | examples/librpm.php | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/examples/librpm.php b/examples/librpm.php index 90082e0..b012e54 100644 --- a/examples/librpm.php +++ b/examples/librpm.php @@ -7,6 +7,28 @@ namespace Remi\RPM; abstract class Common { protected $info = NULL; + protected function _dep(Array $names, Array $flags, Array $vers) { + $ret = []; + $signs = [ + RPMSENSE_EQUAL => ' = ', + RPMSENSE_LESS => ' < ', + RPMSENSE_GREATER => ' > ', + RPMSENSE_LESS | RPMSENSE_EQUAL => ' <= ', + RPMSENSE_GREATER | RPMSENSE_EQUAL => ' >= ', + ]; + + if (count($names) == count($vers) && count($vers) == count($flags)) { + for ($i=0 ; $i<count($names) ; $i++) { + if (isset($signs[$flags[$i] & 15])) { + $ret[] = $names[$i] . $signs[$flags[$i] & 15] . $vers[$i]; + } else { + $ret[] = $names[$i] . '('. ($flags[$i] & 15) .')' . $vers[$i]; + } + } + } + return $ret; + } + public function __get($name) { switch ($name) { case 'EVR': @@ -25,6 +47,22 @@ abstract class Common { $ret .= '.' . $this->info['Arch']; } return $ret; + case 'Requires': + if (isset($this->info['Requirename'])) { + return $this->_dep($this->info['Requirename'], $this->info['Requireflags'], $this->info['Requireversion']); + } + case 'Conflicts': + if (isset($this->info['Conflictname'])) { + return $this->_dep($this->info['Conflictname'], $this->info['Conflictflags'], $this->info['Conflictversion']); + } + case 'Obsoletes': + if (isset($this->info['Obsoletename'])) { + return $this->_dep($this->info['Obsoletename'], $this->info['Obsoleteflags'], $this->info['Obsoleteversion']); + } + case 'Provides': + if (isset($this->info['Providename'])) { + return $this->_dep($this->info['Providename'], $this->info['Provideflags'], $this->info['Provideversion']); + } default: if (isset($this->info[$name])) { return $this->info[$name]; @@ -76,3 +114,12 @@ class Package extends Common { } } + +/* +$a = new File(dirname(__DIR__).'/tests/bidon.rpm'); +echo "Requires: "; print_r($a->Requires); +echo "Provides: "; print_r($a->Provides); +echo "Conflicts: "; print_r($a->Conflicts); +echo "Obsoletes: "; print_r($a->Obsoletes); +*/ + |