PEAR logo

PEAR_PackageFileManager : The Definitive Guide



Chapter 7. Creating a new package

Table of Contents

From scratch
Add a new release
Resume

This lesson :

From scratch

While in reality, we could find the same generator script to build a package.xml on first time, and update it later, both classes PEAR_PackageFileManager and PEAR_PackageFileManager2 provides two distinct ways of generation, using : setOptions() and importOptions(). We will focus only, in this chapter, on the first method. Later we will see usage of second method when we will talk how to update an existing package.

Lets see step by step how to define a new package with the two versions of PEAR_PackageFileManager.

To define a new package we will need to know some informations, such as : its name, a little summary, and a longer description. But we need also to know where package sources resides, and where it should be installed (on PEAR infrastructure).

With package.xml version 1.0, almost all properties were set with the setOptions() method. With package.xml version 2.0, there are new functions to get/set property individually. Among these ones, there is :

name

getPackage(), setPackage()

extends

getExtends(), setExtends()

channel

getChannel(), setChannel()

uri

getUri(), setUri()

summary

getSummary(), setSummary()

description

getDescription(), setDescription()

To produce a package.xml version 1.0, here is the basic sheme

  1. <?php
  2. require_once 'PEAR/PackageFileManager.php';
  3.  
  4. PEAR::setErrorHandling(PEAR_ERROR_DIE);
  5.  
  6. $p1 = new PEAR_PackageFileManager();
  7.  
  8. $name        = 'MDB2';
  9. $summary     = 'database abstraction layer';
  10. $description = 'PEAR MDB2 is a merge of the PEAR DB and ...';
  11.  
  12. $p1->setOptions(array(
  13.     'package'           => $name,
  14.     'summary'           => $summary,
  15.     'description'       => $description,
  16.     'packagedirectory'  => 'C:/php/pear/MDB2',
  17.     'baseinstalldir'    => '/'
  18. ));
  19. //...
  20.  
  21. if (isset($_GET['make'])) {
  22.     $p1->writePackageFile();
  23. } else {
  24.     $p1->debugPackageFile();
  25. }
  26. ?>

To produce a package.xml version 2.0

  1. <?php
  2. require_once 'PEAR/PackageFileManager2.php';
  3.  
  4. PEAR::setErrorHandling(PEAR_ERROR_DIE);
  5.  
  6. $p2 = new PEAR_PackageFileManager2();
  7.  
  8. $name        = 'MDB2';
  9. $summary     = 'database abstraction layer';
  10. $description = 'PEAR MDB2 is a merge of the PEAR DB and ...';
  11. $extend      = 'MDB';
  12. $channel     = 'pear.php.net';
  13.  
  14. $p2->setOptions(array(
  15.     'packagedirectory'  => 'C:/php/pear/MDB2',
  16.     'baseinstalldir'    => '/'
  17. ));
  18.  
  19. $p2->setPackage($name);
  20.  
  21. // only necessary when a new major version supperceed to a package
  22. // examples are : MDB -> MDB2, HTML_Progress -> HTML_Progress2, ...
  23. $p2->setExtends($extend);
  24.  
  25. $p2->setChannel($channel);
  26. $p2->setSummary($summary);
  27. $p2->setDescription($description);
  28.  
  29. //...
  30.  
  31. if (isset($_GET['make']) || (isset($_SERVER['argv']) && @$_SERVER['argv'][1] == 'make')) {
  32.     $p2->writePackageFile();
  33. } else {
  34.     $p2->debugPackageFile();
  35. }
  36. ?>
PEAR_PackageFileManager : The Definitive Guide v 1.6.0 : November 17, 2006