PEAR_PackageFileManager
[ class tree: PEAR_PackageFileManager ] [ index: PEAR_PackageFileManager ] [ all elements ]

Class: PEAR_PackageFileManager

Source Location: /PEAR_PackageFileManager-1.7.0/PackageFileManager.php

Class Overview


PEAR :: PackageFileManager updates the <filelist></filelist> section of a PEAR package.xml file to reflect the current files in preparation for a release.


Author(s):

Version:

  • Release: 1.7.0

Copyright:

  • 2003-2009 The PEAR Group

Methods


Inherited Variables

Inherited Methods


Class Details

[line 213]
PEAR :: PackageFileManager updates the <filelist></filelist> section of a PEAR package.xml file to reflect the current files in preparation for a release.

The PEAR_PackageFileManager class uses a plugin system to generate the list of files in a package. This allows both standard recursive directory parsing (plugin type file) and more intelligent options such as the CVS browser PEAR_PackageFileManager_Cvs, which grabs all files in a local CVS checkout to create the list, ignoring any other local files.

Other options include specifying roles for file extensions (all .php files are role="php", for example), roles for directories (all directories named "tests" are given role="tests" by default), and exceptions. Exceptions are specific pathnames with * and ? wildcards that match a default role, but should have another. For example, perhaps a debug.tpl template would normally be data, but should be included in the docs role. Along these lines, to exclude files entirely, use the ignore option.

Required options for a release include version, baseinstalldir, state, and packagedirectory (the full path to the local location of the package to create a package.xml file for)

Example usage:

  1.  <?php
  2.  require_once('PEAR/PackageFileManager.php');
  3.  $packagexml = new PEAR_PackageFileManager;
  4.  $e $packagexml->setOptions(
  5.  array('baseinstalldir' => 'PhpDocumentor',
  6.   'version' => '1.2.1',
  7.   'packagedirectory' => 'C:/Web Pages/chiara/phpdoc2/',
  8.   'state' => 'stable',
  9.   'filelistgenerator' => 'cvs'// generate from cvs, use file for directory
  10.   'notes' => 'We\'ve implemented many new and exciting features',
  11.   'ignore' => array('TODO''tests/')// ignore TODO, all files in tests/
  12.   'installexceptions' => array('phpdoc' => '/*')// baseinstalldir ="/" for phpdoc
  13.   'dir_roles' => array('tutorials' => 'doc'),
  14.   'exceptions' => array('README' => 'doc'// README would be data, now is doc
  15.                         'PHPLICENSE.txt' => 'doc')))// same for the license
  16.  if (PEAR::isError($e)) {
  17.      echo $e->getMessage();
  18.      die();
  19.  }
  20.  $e $test->addPlatformException('pear-phpdoc.bat''windows');
  21.  if (PEAR::isError($e)) {
  22.      echo $e->getMessage();
  23.      exit;
  24.  }
  25.  $packagexml->addRole('pkg''doc')// add a new role mapping
  26.  if (PEAR::isError($e)) {
  27.      echo $e->getMessage();
  28.      exit;
  29.  }
  30.  // replace @PHP-BIN@ in this file with the path to php executable!  pretty neat
  31.  $e $test->addReplacement('pear-phpdoc''pear-config''@PHP-BIN@''php_bin');
  32.  if (PEAR::isError($e)) {
  33.      echo $e->getMessage();
  34.      exit;
  35.  }
  36.  $e $test->addReplacement('pear-phpdoc.bat''pear-config''@PHP-BIN@''php_bin');
  37.  if (PEAR::isError($e)) {
  38.      echo $e->getMessage();
  39.      exit;
  40.  }
  41.  // note use of <a href="../PEAR_PackageFileManager/PEAR_PackageFileManager.html#methoddebugPackageFile">debugPackageFile()</a> - this is VERY important
  42.  if (isset($_GET['make']|| (isset($_SERVER['argv'][2]&&
  43.        $_SERVER['argv'][2== 'make')) {
  44.      $e $packagexml->writePackageFile();
  45.  else {
  46.      $e $packagexml->debugPackageFile();
  47.  }
  48.  if (PEAR::isError($e)) {
  49.      echo $e->getMessage();
  50.      die();
  51.  }
  52.  ?>

In addition, a package.xml file can now be generated from scratch, with the usage of new options package, summary, description, and the use of the addMaintainer() method



[ Top ]


Method Detail

PEAR_PackageFileManager (Constructor)   [line 324]

PEAR_PackageFileManager PEAR_PackageFileManager( )

Does nothing, use setOptions

The constructor is not used in order to be able to return a PEAR_Error from setOptions


[ Top ]

addConfigureOption   [line 858]

void|PEAR_Error addConfigureOption( string $name, string $prompt, [string $default = null])

Add an install-time configuration option for building of source

This option is only useful to PECL projects that are built upon installation

  • Throws: PEAR_PACKAGEFILEMANAGER_RUN_SETOPTIONS
  • Since: 0.9
  • Access: public

Parameters:

string   $name   —  name of the option
string   $prompt   —  prompt to display to the user
string   $default   —  (optional) default value

[ Top ]

addDependency   [line 951]

void|PEAR_Error addDependency( string $name, [string $version = false], [string $operator = 'ge'], [string $type = 'pkg'], [boolean $optional = false])

Add a dependency on another package, or an extension/php

This will overwrite an existing dependency if it is found. In other words, if a dependency on PHP 4.1.0 exists, and addDependency('php', '4.3.0', 'ge', 'php') is called, the existing dependency on PHP 4.1.0 will be overwritten with the new one on PHP 4.3.0

  • Since: 0.1
  • Throws: PEAR_PACKAGEFILEMANAGER_RUN_SETOPTIONS
  • Throws: PEAR_PACKAGEFILEMANAGER_PHP_NOT_PACKAGE
  • Access: public

Parameters:

string   $name   —  Dependency element name
string   $version   —  (optional) Dependency version
string   $operator   —  A specific operator for the version, this can be one of: 'has', 'not', 'lt', 'le', 'eq', 'ne', 'ge', or 'gt'
string   $type   —  (optional) Dependency type. This can be one of: 'pkg', 'ext', 'php', 'prog', 'os', 'sapi', or 'zend'
boolean   $optional   —  (optional) true if dependency is optional

[ Top ]

addGlobalReplacement   [line 730]

void|PEAR_Error addGlobalReplacement( string $type, string $from, string $to)

Add a replacement option for all files, or files matching the glob pattern

This sets an install-time complex search-and-replace function allowing the setting of platform-specific variables in all installed files.

if $type is php-const, then $to must be the name of a PHP Constant. If $type is pear-config, then $to must be the name of a PEAR config variable accessible through a PEAR_Config::get() method. If type is package-info, then $to must be the name of a section from the package.xml file used to install this file.

  • Throws: PEAR_PACKAGEFILEMANAGER_INVALID_REPLACETYPE
  • Since: 1.4.0
  • Access: public

Parameters:

string   $type   —  variable type, either php-const, pear-config or package-info
string   $from   —  text to replace in the source file
string   $to   —  variable name to use for replacement

[ Top ]

addMaintainer   [line 811]

void|PEAR_Error addMaintainer( string $handle, string $role, string $name, string $email)

Add a maintainer to the list of maintainers.

Every maintainer must have a valid account at pear.php.net. The first parameter is the account name (for instance, cellog is the handle for Greg Beaver at pear.php.net). Every maintainer has one of four possible roles:

  • lead: the primary maintainer
  • developer: an important developer on the project
  • contributor: self-explanatory
  • helper: ditto
Finally, specify the name and email of the maintainer

  • Since: 0.9
  • Access: public

Parameters:

string   $handle   —  username on pear.php.net of maintainer
string   $role   —  lead|developer|contributor|helper role of maintainer
string   $name   —  full name of maintainer
string   $email   —  email address of maintainer

[ Top ]

addPlatformException   [line 700]

void addPlatformException( string $path, string $platform)

Add an install-time platform conditional install for a file

The format of the platform string must be OS-version-cpu-extra if any more specific information is needed, and the OS must be in lower case as in "windows." The match is performed using a regular expression, but uses * and ? wildcards instead of .* and .?. Note that hpux/aix/irix/linux are all exclusive. To select non-windows, use (*ix|*ux)

This information is based on eyeing the source for OS/Guess.php, so if you are unsure of what to do, read that file.

  • Since: 0.10
  • Access: public

Parameters:

string   $path   —  relative path of file (relative to packagedirectory option)
string   $platform   —  platform descriptor string

[ Top ]

addReplacement   [line 775]

void|PEAR_Error addReplacement( string $path, string $type, string $from, string $to)

Add a replacement option for a file

This sets an install-time complex search-and-replace function allowing the setting of platform-specific variables in an installed file.

if $type is php-const, then $to must be the name of a PHP Constant. If $type is pear-config, then $to must be the name of a PEAR config variable accessible through a PEAR_Config::get() method. If type is package-info, then $to must be the name of a section from the package.xml file used to install this file.

  • Throws: PEAR_PACKAGEFILEMANAGER_INVALID_REPLACETYPE
  • Since: 0.10
  • Access: public

Parameters:

string   $path   —  relative path of file (relative to packagedirectory option)
string   $type   —  variable type, either php-const, pear-config or package-info
string   $from   —  text to replace in the source file
string   $to   —  variable name to use for replacement

[ Top ]

addRole   [line 671]

void|PEAR_Error addRole( string $extension, string $role)

Add an extension/role mapping to the role mapping option

Roles influence both where a file is installed and how it is installed. Files with role="data" are in a completely different directory hierarchy from the program files of role="php"

In PEAR 1.3b2, these roles are

  • php (most common)
  • data
  • doc
  • test
  • script (gives the file an executable attribute)
  • src

  • Throws: PEAR_PACKAGEFILEMANAGER_INVALID_ROLE
  • Since: 0.1
  • Access: public

Parameters:

string   $extension   —  file extension
string   $role   —  role

[ Top ]

debugPackageFile   [line 1172]

true|PEAR_Error debugPackageFile( )

ALWAYS use this to test output before overwriting your package.xml!!

This method instructs writePackageFile() to simply print the package.xml to output, either command-line or web-friendly (this is automatic based on the value of php_sapi_name())


[ Top ]

detectDependencies   [line 893]

void|PEAR_Error detectDependencies( )

Uses PEAR::PHP_CompatInfo package to detect dependencies (extensions, php version)
  • Since: 1.3.0
  • Throws: PEAR_PACKAGEFILEMANAGER_RUN_SETOPTIONS
  • Throws: PEAR_PACKAGEFILEMANAGER_NO_PHPCOMPATINFO
  • Access: public

[ Top ]

getOptions   [line 643]

array getOptions( )

Get the existing options
  • Since: 1.5.0
  • Access: public

[ Top ]

getWarnings   [line 1201]

array getWarnings( )

Retrieve the list of warnings
  • Since: 1.1.0
  • Access: public

[ Top ]

importOptions   [line 608]

true|PEAR_Error importOptions( string $packagefile, [array $options = array()])

Import options from an existing package.xml
  • Since: 1.5.0
  • Access: public

Parameters:

string   $packagefile   —  name of package file
array   $options   —  (optional) list of generation options

[ Top ]

isIncludeable   [line 915]

boolean isIncludeable( string $file)

Returns whether or not a file is in the include path.
  • Return: true if the file is in the include path, false otherwise
  • Since: 1.3.0
  • Access: public

Parameters:

string   $file   —  path to filename

[ Top ]

pushWarning   [line 1188]

void pushWarning( integer $code, array $info)

Store a warning on the warning stack
  • Since: 1.1.0
  • Access: public

Parameters:

integer   $code   —  error code
array   $info   —  additional specific error info

[ Top ]

raiseError   [line 1241]

PEAR_Error raiseError( integer $code, [string $i1 = ''], [string $i2 = ''])

Utility function to shorten error generation code

  1. function raiseError($code$i1 ''$i2 '')
  2.     {
  3.         return PEAR::raiseError('PEAR_PackageFileManager Error: ' .
  4.                     sprintf($GLOBALS['_PEAR_PACKAGEFILEMANAGER_ERRORS'][$this->_options['lang']][$code],
  5.                     $i1$i2)$code);
  6.     }

  • Since: 0.9
  • Access: public

Parameters:

integer   $code   —  error code
string   $i1   —  (optional) additional specific error info #1
string   $i2   —  (optional) additional specific error info #2

[ Top ]

setOptions   [line 489]

void|PEAR_Error setOptions( [array $options = array()], [boolean $internal = false])

Set package.xml generation options

The options array is indexed as follows:

  1.  $options = array('option_name' => <optionvalue>);

The documentation below simplifies this description through the use of option_name without quotes

Configuration options:

  • lang: lang controls the language in which error messages are displayed. There are currently only English error messages, but any contributed will be added over time.
    Possible values: en (default)
  • packagefile: the name of the packagefile, defaults to package.xml
  • pathtopackagefile: the path to an existing package file to read in, if different from the packagedirectory
  • packagedirectory: the path to the base directory of the package. For package PEAR_PackageFileManager, this path is /path/to/pearcvs/pear/PEAR_PackageFileManager where /path/to/pearcvs is a local path on your hard drive
  • outputdirectory: the path in which to place the generated package.xml by default, this is ignored, and the package.xml is created in the packagedirectory
  • filelistgenerator: the <filelist> section plugin which will be used. In this release, there are two generator plugins, file and cvs. For details, see the docs for these plugins
  • usergeneratordir: For advanced users. If you write your own filelist generator plugin, use this option to tell PEAR_PackageFileManager where to find the file that contains it. If the plugin is named foo, the class must be named PEAR_PackageFileManager_Foo no matter where it is located. By default, the Foo plugin is located in PEAR/PackageFileManager/Foo.php. If you pass /path/to/foo in this option, setOptions will look for PEAR_PackageFileManager_Foo in /path/to/foo/Foo.php
  • doctype: Specifies the DTD of the package.xml file. Default is http://pear.php.net/dtd/package-1.0
  • pearcommonclass: Specifies the name of the class to instantiate, default is PEAR_PackageFileManager_ComplexGenerator or PEAR_Common, but users can override this with a custom class that implements PEAR_Common's method interface
  • changelogoldtonew: True if the ChangeLog should list from oldest entry to newest. Set to false if you would like new entries first
  • simpleoutput: True if the package.xml should not contain md5sum or <provides /> for readability
  • addhiddenfiles: True if you wish to add hidden files/directories that begin with . like .bashrc. This is only used by the File generator. The CVS generator will use all files in CVS regardless of format
package.xml simple options:
  • baseinstalldir: The base directory to install this package in. For package PEAR_PackageFileManager, this is "PEAR", for package PEAR, this is "/"
  • license: The license this release is released under. Default is PHP License if left unspecified
  • notes: Release notes, any text describing what makes this release unique
  • changelognotes: notes for the changelog, this should be more detailed than the release notes. By default, PEAR_PackageFileManager uses the notes option for the changelog as well
  • version: The version number for this release. Remember the convention for numbering: initial alpha is between 0 and 1, add b<beta number> for beta as in 1.0b1, the integer portion of the version should specify backwards compatibility, as in 1.1 is backwards compatible with 1.0, but 2.0 is not backwards compatible with 1.10. Also note that 1.10 is a greater release version than 1.1 (think of it as "one point ten" and "one point one"). Bugfix releases should be a third decimal as in 1.0.1, 1.0.2
  • package: [optional] Package name. Use this to create a new package.xml, or overwrite an existing one from another package used as a template
  • summary: [optional] Summary of package purpose
  • description: [optional] Description of package purpose. Note that the above three options are not optional when creating a new package.xml from scratch
WARNING: all complex options that require a file path are case-sensitive

package.xml complex options:

  • cleardependencies: since version 1.3.0, this option will erase any existing dependencies in the package.xml if set to true
  • ignore: an array of filenames, directory names, or wildcard expressions specifying files to exclude entirely from the package.xml. Wildcards are operating system wildcards * and ?. file*foo.php will exclude filefoo.php, fileabrfoo.php and filewho_is_thisfoo.php. file?foo.php will exclude fileafoo.php and will not exclude fileaafoo.php. test/ will exclude all directories and subdirectories of ANY directory named test encountered in directory parsing. *test* will exclude all files and directories that contain test in their name
  • include: an array of filenames, directory names, or wildcard expressions specifying files to include in the listing. All other files will be ignored. Wildcards are in the same format as ignore
  • roles: this is an array mapping file extension to install role. This specifies default behavior that can be overridden by the exceptions option and dir_roles option. use addRole() to add a new role to the pre-existing array
  • dir_roles: this is an array mapping directory name to install role. All files in a directory whose name matches the directory will be given the install role specified. Single files can be excluded from this using the exceptions option. The directory should be a relative path from the baseinstalldir, or "/" for the baseinstalldir
  • exceptions: specify file role for specific files. This array maps all files matching the exact name of a file to a role as in "file.ext" => "role"
  • deps: dependency array. Pass in an empty array to clear all dependencies, and use addDependency() to add new ones/replace existing ones
  • maintainers: maintainers array. Pass in an empty array to clear all maintainers, and use addMaintainer() to add a new maintainer/replace existing maintainer
  • installexceptions: array mapping of specific filenames to baseinstalldir values. Use this to force the installation of a file into another directory, such as forcing a script to be in the root scripts directory so that it will be in the path. The filename must be a relative path to the packagedirectory
  • platformexceptions: array mapping of specific filenames to the platform they should be installed on. Use this to specify unix-only files or windows-only files. The format of the platform string must be OS-version-cpu-extra if any more specific information is needed, and the OS must be in lower case as in "windows." The match is performed using a regular expression, but uses * and ? wildcards instead of .* and .?. Note that hpux/aix/irix/linux are all exclusive. To select non-windows, use (*ix|*ux)
  • scriptphaseexceptions: array mapping of scripts to their install phase. This can be one of: pre-install, post-install, pre-uninstall, post-uninstall, pre-build, post-build, pre-setup, or post-setup
  • installas: array mapping of specific filenames to the filename they should be installed as. Use this to specify new filenames for files that should be installed. This will often be used in conjunction with platformexceptions if there are two files for different OSes that must have the same name when installed.
  • replacements: array mapping of specific filenames to complex text search-and-replace that should be performed upon install. The format is:
       filename => array('type' => php-const|pear-config|package-info
                         'from' => text in file
                         'to' => name of variable)
    if type is php-const, then 'to' must be the name of a PHP Constant. If type is pear-config, then 'to' must be the name of a PEAR config variable accessible through a PEAR_Config class->get() method. If type is package-info, then 'to' must be the name of a section from the package.xml file used to install this file.
  • globalreplacements: a list of replacements that should be performed on every single file. The format is the same as replacements (since 1.4.0)
  • configure_options: array specifies build options for PECL packages (you should probably use PECL_Gen instead, but it's here for completeness)

  • See: PEAR_PackageFileManager_File
  • See: PEAR_PackageFileManager_CVS
  • Throws: PEAR_PACKAGEFILEMANAGER_NOSTATE
  • Since: 0.1
  • Throws: PEAR_PACKAGEFILEMANAGER_NOVERSION
  • Throws: PEAR_PACKAGEFILEMANAGER_NOBASEDIR
  • Throws: PEAR_PACKAGEFILEMANAGER_GENERATOR_NOTFOUND
  • Throws: PEAR_PACKAGEFILEMANAGER_GENERATOR_NOTFOUND_ANYWHERE
  • Throws: PEAR_PACKAGEFILEMANAGER_NOPKGDIR
  • Access: public

Parameters:

array   $options   —  (optional) list of generation options
boolean   $internal   —  (optional) private function call

[ Top ]

writePackageFile   [line 1024]

true|PEAR_Error writePackageFile( [boolean $debuginterface = null])

Writes the package.xml file out with the newly created <release></release> tag

ALWAYS use debugPackageFile to verify that output is correct before overwriting your package.xml

  • Throws: PEAR_PACKAGEFILEMANAGER_NONOTES
  • Throws: PEAR_PACKAGEFILEMANAGER_ADD_MAINTAINERS
  • Throws: PEAR_PACKAGEFILEMANAGER_RUN_SETOPTIONS
  • Since: 0.1
  • Throws: PEAR_PACKAGEFILEMANAGER_DEST_UNWRITABLE
  • Throws: PEAR_PACKAGEFILEMANAGER_NOLICENSE
  • Throws: PEAR_PACKAGEFILEMANAGER_CANTOPEN_TMPPKGFILE
  • Throws: PEAR_PACKAGEFILEMANAGER_INVALID_PACKAGE
  • Throws: PEAR_PACKAGEFILEMANAGER_CANTCOPY_PKGFILE
  • Throws: PEAR_PACKAGEFILEMANAGER_CANTWRITE_PKGFILE
  • Access: public
  • Usedby: PEAR_PackageFileManager::debugPackageFile() - calls with the debug parameter set based on whether it is called from the command-line or web interface

Parameters:

boolean   $debuginterface   —  (optional) null if no debugging, true if web interface, false if command-line

[ Top ]


Documentation generated on Mon, 11 Mar 2019 15:31:02 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.