From 658782f53124ee932bb442be5fc05b3f126e686a Mon Sep 17 00:00:00 2001 From: Daniele Alessandri Date: Sun, 27 Mar 2011 15:01:51 +0200 Subject: [PATCH] Add a script to generate a Phar archive of Predis from the repository. --- README.markdown | 10 ++++++--- bin/createPhar.php | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 3 deletions(-) create mode 100755 bin/createPhar.php diff --git a/README.markdown b/README.markdown index 4f2ea88a..089d20d5 100644 --- a/README.markdown +++ b/README.markdown @@ -40,9 +40,13 @@ When used in simple projects or scripts you might need to define an autoloader f } }); -Optionally, you can generate a single PHP file that holds every class (just like older versions of Predis) -by launching the _createSingleFile.php_ script from the _bin_ directory of the repository. In this way -you can load Predis in your scripts simply by using functions such as _require_ and _include_. +You can also create a single Phar archive from the repository just by launching the _createPhar.php_ +script located in the _bin_ directory. The generated Phar ships with a stub that defines an autoloader +function for Predis, so you just need to require the Phar archive in order to be able to use the library. + +Alternatively you can generate a single PHP file that holds every class, just like older versions of Predis, +using the _createSingleFile.php_ script located in the _bin_ directory. In this way you can load Predis in +your scripts simply by using functions such as _require_ and _include_, but this practice is not encouraged. ### Connecting to a local instance of Redis ### diff --git a/bin/createPhar.php b/bin/createPhar.php new file mode 100755 index 00000000..4178a090 --- /dev/null +++ b/bin/createPhar.php @@ -0,0 +1,53 @@ +#!/usr/bin/php + 'predis', + 'project_path' => __DIR__ . '/../lib/', + 'compression' => Phar::NONE, + 'append_version' => true, +); + +function getPharFilename($options) { + $filename = $options['name']; + // NOTE: do not consider "append_version" with Phar compression do to a bug in + // Phar::compress() when renaming phar archives containing dots in their name. + if ($options['append_version'] && $options['compression'] === Phar::NONE) { + $versionFile = @fopen(__DIR__ . '/../VERSION', 'r'); + if ($versionFile === false) { + throw new Exception("Could not locate the VERSION file."); + } + $version = trim(fgets($versionFile)); + fclose($versionFile); + $filename .= "_$version"; + } + return "$filename.phar"; +} + +function getPharStub($options) { + return <<compress($options['compression']); +$phar->setStub(getPharStub($options)); +$phar->buildFromDirectory($options['project_path']);