summaryrefslogtreecommitdiffstats
path: root/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'README.md')
-rw-r--r--README.md144
1 files changed, 138 insertions, 6 deletions
diff --git a/README.md b/README.md
index 9461c22..6efd10c 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,8 @@
Retrieve RPM information from PHP code using librpm.
-**Notice**: this is a experimental extension, a work in progress, so don't expect a stable API yet.
+This extension can be considered as stable, and be used on production environement.
+
----
@@ -13,7 +14,7 @@ Retrieve RPM information from PHP code using librpm.
# Build
-You need the rpm development files (rpm-devel) version >= 4.11.3.
+You need the rpm development files (rpm-devel) version >= 4.13.
From the sources tree
@@ -22,6 +23,15 @@ From the sources tree
$ make
$ make test
+From https://pecl.php.net/ using pecl command
+
+ $ pecl install rpminfo
+
+From https://packagist.org/ using PHP Installer for Extensions
+
+ $ pie install remi/rpminfo
+
+
----
# Usage
@@ -41,7 +51,7 @@ Allow to compare 2 EVR (epoch:version-release) strings. The return value is < 0
## rpminfo
- array rpminfo(string path [, bool full [, string &error]]);
+ rpminfo(string path [, bool full [, string &error]]): array;
Retrieve information from a rpm file, reading its metadata.
If given `error` will be used to store error message instead of raising a warning.
@@ -85,7 +95,7 @@ The return value is a hash table, or false if it fails.
## rpmdbinfo
- array rpmdbinfo(string path [, bool full ]);
+ rpmdbinfo(string path [, bool full ]): array;
Retrieve information from rpm database about an installed package.
The return value is an array of hash tables, or false if it fails.
@@ -97,12 +107,134 @@ The return value is an array of hash tables, or false if it fails.
[0] => Array
(
[Name] => php
- [Version] => 7.2.2
- [Release] => 1.fc27.remi
+ [Version] => 7.3.5
+ [Release] => 1.fc31.remi
+ [Summary] => PHP scripting language for creating dynamic web sites
+ [Arch] => x86_64
+ )
+ )
+
+Retrieve information from rpm database about installed packages using glob or regex.
+The return value is an array of hash tables, or false if it fails.
+
+ $ php -a
+ php > print_r(rpmdbsearch("php-pecl-r*", RPMTAG_NAME, RPMMIRE_GLOB));
+ Array
+ (
+ [0] => Array
+ (
+ [Name] => php-pecl-radius
+ [Version] => 1.4.0
+ [Release] => 0.10.b1.fc31
+ [Summary] => Radius client library
+ [Arch] => x86_64
+ )
+ [1] => Array
+ (
+ [Name] => php-pecl-redis5
+ [Version] => 5.2.0
+ [Release] => 1.fc31.remi.7.3
+ [Summary] => Extension for communicating with the Redis key-value store
+ [Arch] => x86_64
+ )
+ [2] => Array
+ (
+ [Name] => php-pecl-rpminfo
+ [Version] => 0.2.3
+ [Release] => 1.fc31.remi.7.3
+ [Summary] => RPM information
[Arch] => x86_64
)
)
+ $ php -a
+ php > print_r(rpmdbsearch("^php-pecl-r", RPMTAG_NAME, RPMMIRE_REGEX));
+ Array
+ (
+ [0] => Array
+ (
+ [Name] => php-pecl-radius
+ [Version] => 1.4.0
+ [Release] => 0.10.b1.fc31
+ [Summary] => Radius client library
+ [Arch] => x86_64
+ )
+ [1] => Array
+ (
+ [Name] => php-pecl-redis5
+ [Version] => 5.2.0
+ [Release] => 1.fc31.remi.7.3
+ [Summary] => Extension for communicating with the Redis key-value store
+ [Arch] => x86_64
+ )
+ [2] => Array
+ (
+ [Name] => php-pecl-rpminfo
+ [Version] => 0.2.3
+ [Release] => 1.fc31.remi.7.3
+ [Summary] => RPM information
+ [Arch] => x86_64
+ )
+ )
+
+ $ php -a
+ php > print_r(rpmdbsearch(PHP_BINARY, RPMTAG_INSTFILENAMES));
+ Array
+ (
+ [0] => Array
+ (
+ [Name] => php-cli
+ [Version] => 7.3.15
+ [Release] => 1.fc31.remi
+ [Summary] => Command-line interface for PHP
+ [Arch] => x86_64
+ )
+ )
+
+## rpmexpand
+
+ rpmexpand($text): string
+
+Retrieve expanded value of a RPM macro
+
+ $ php -a
+ php > var_dump(rpmexpand("%{?fedora:Fedora %{fedora}}%{?rhel:Enterprise Linux %{rhel}}"));
+ string(9) "Fedora 41"
+
+## rpmexpandnumeric
+
+ rpmexpandnumeric($text): int
+
+Retrieve numerical value of a RPM macro
+
+ $ php -a
+ php > var_dump(rpmexpandnumeric("%__isa_bits"));
+ int(64)
+
+## rpmdefine
+
+ rpmdefine($text): bool
+
+Define or change a RPM macro value.
+
+For example, can be used to set the Database path and backend
+
+ $ mock -r almalinux-8-x86_64 init
+ ...
+ $ mock -r fedora-41-x86_64 init
+ ...
+ $ php -a
+ php > // use an old database (bdb) from an EL-8 chroot
+ php > rpmdefine("_dbpath /var/lib/mock/almalinux-8-x86_64/root/var/lib/rpm");
+ php > rpmdefine("_db_backend bdb_ro");
+ php > var_dump(rpmdbinfo("almalinux-release")[0]["Summary"]);
+ string(22) "AlmaLinux release file"
+ php > // use a new database (sqlite) from a Fedora-41 chroot
+ php > rpmdefine("_dbpath /var/lib/mock/fedora-41-x86_64/root/usr/lib/sysimage/rpm");
+ php > rpmdefine("_db_backend sqlite");
+ php > var_dump(rpmdbinfo("fedora-release")[0]["Summary"]);
+ string(20) "Fedora release files"
+
----
# LICENSE