summaryrefslogtreecommitdiffstats
path: root/examples/librpm.php
diff options
context:
space:
mode:
Diffstat (limited to 'examples/librpm.php')
-rw-r--r--examples/librpm.php68
1 files changed, 66 insertions, 2 deletions
diff --git a/examples/librpm.php b/examples/librpm.php
index 7d36f2d..6ae8b81 100644
--- a/examples/librpm.php
+++ b/examples/librpm.php
@@ -59,22 +59,47 @@ abstract class Common {
if (isset($this->info['Requirename'])) {
return $this->_dep($this->info['Requirename'], $this->info['Requireflags'], $this->info['Requireversion']);
}
+ return NULL;
case 'Conflicts':
if (isset($this->info['Conflictname'])) {
return $this->_dep($this->info['Conflictname'], $this->info['Conflictflags'], $this->info['Conflictversion']);
}
+ return NULL;
case 'Obsoletes':
if (isset($this->info['Obsoletename'])) {
return $this->_dep($this->info['Obsoletename'], $this->info['Obsoleteflags'], $this->info['Obsoleteversion']);
}
+ return NULL;
case 'Provides':
if (isset($this->info['Providename'])) {
return $this->_dep($this->info['Providename'], $this->info['Provideflags'], $this->info['Provideversion']);
}
+ return NULL;
+ case 'Recommends':
+ if (isset($this->info['Recommendname'])) {
+ return $this->_dep($this->info['Recommendname'], $this->info['Recommendflags'], $this->info['Recommendversion']);
+ }
+ return NULL;
+ case 'Suggests':
+ if (isset($this->info['Suggestname'])) {
+ return $this->_dep($this->info['Suggestname'], $this->info['Suggestflags'], $this->info['Suggestversion']);
+ }
+ return NULL;
+ case 'Supplements':
+ if (isset($this->info['Supplementname'])) {
+ return $this->_dep($this->info['Supplementname'], $this->info['Supplementflags'], $this->info['Supplementversion']);
+ }
+ return NULL;
+ case 'Enhances':
+ if (isset($this->info['Enhancename'])) {
+ return $this->_dep($this->info['Enhancename'], $this->info['Enhanceflags'], $this->info['Enhanceversion']);
+ }
+ return NULL;
case 'Files':
if (isset($this->info['Basenames'])) {
return $this->_files();
}
+ return NULL;
default:
if (isset($this->info[$name])) {
return $this->info[$name];
@@ -94,7 +119,7 @@ abstract class Common {
class File extends Common {
public function __construct($path) {
- $info = rpminfo($path, true, $error);
+ $info = \rpminfo($path, true, $error);
if ($error) {
throw new \RuntimeException($error);
@@ -114,7 +139,7 @@ class File extends Common {
class Package extends Common {
public function __construct($name, $index=0) {
- $info = rpmdbinfo($name, true);
+ $info = \rpmdbinfo($name, true);
if (!$info) {
throw new \RuntimeException("$name not found");
@@ -126,8 +151,47 @@ class Package extends Common {
}
}
+/**
+ * Find packages which provides something or own a file
+ *
+ * $a = \Remi\RPM\WhatProvides("php-redis");
+ * print_r($a[0]->NEVR);
+ *
+ * $a = \Remi\RPM\WhatProvides("/usr/bin/php");
+ * print_r($a[0]->NEVR);
+ **/
+function WhatProvides($crit) {
+ if (file_exists($crit)) {
+ $a = \rpmdbsearch($crit, RPMTAG_INSTFILENAMES);
+ } else {
+ $a = \rpmdbsearch($crit, RPMTAG_PROVIDES);
+ }
+ $r = [];
+ if (is_array($a)) {
+ foreach($a as $i) {
+ $r[] = new Package($i['Name']);
+ }
+ }
+ return $r;
+}
+/**
+ * Find packages which requires something
+ *
+ * $a = \Remi\RPM\WhatRequires("php-common");
+ * print_r($a[0]->NEVRA);
+ **/
+function WhatRequires($crit) {
+ $a = \rpmdbsearch($crit, RPMTAG_REQUIRES);
+ $r = [];
+ if (is_array($a)) {
+ foreach($a as $i) {
+ $r[] = new Package($i['Name']);
+ }
+ }
+ return $r;
+}
/*
$a = new File(dirname(__DIR__).'/tests/bidon.rpm');
$a = new Package('phpunit7');