Source for file v1.php
Documentation is available at v1.php
* package.xml parsing class, package.xml version 1.0
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version CVS: $Id: v1.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
* package.xml abstraction class
require_once 'PEAR/PackageFile/v1.php';
* Parser for package.xml version 1.0
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: @PEAR-VER@
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
* BC hack to allow PEAR_Common::infoFromString() to sort of
* work with the version 2.0 format - there's no filelist though
* @param PEAR_PackageFile_v2
$info = $packagefile->getArray (true );
$ret->fromArray ($info['old']);
$this->_registry = &$c->getRegistry ();
* @param string contents of package.xml file, version 1.0
* @return bool success of parsing
function &parse($data, $file, $archive = false )
return PEAR::raiseError('Cannot create xml parser for parsing package.xml, no xml extension');
$a = &PEAR::raiseError('Cannot create xml parser for parsing package.xml');
$this->element_stack = array ();
$this->_packageInfo = array ('provides' => array ());
$this->current_element = false;
unset ($this->dir_install);
$this->_packageInfo['filelist'] = array ();
$this->filelist = & $this->_packageInfo['filelist'];
$this->dir_names = array ();
$this->in_changelog = false;
$pf->setConfig ($this->_config);
if (isset ($this->_logger)) {
$pf->setLogger ($this->_logger);
$pf->setPackagefile ($file, $archive);
$pf->fromArray ($this->_packageInfo);
* @param string $str The string that has to be unindented.
// remove leading newlines
// find whitespace at the beginning of the first line
$indent_len = strspn($str, " \t");
$indent = substr($str, 0 , $indent_len);
// remove the same amount of whitespace from following lines
foreach (explode("\n", $str) as $line) {
if (substr($line, 0 , $indent_len) == $indent) {
$data .= substr($line, $indent_len) . "\n";
// Support for package DTD v1.0:
// {{{ _element_start_1_0()
* XML parser callback for ending elements. Used for version 1.0
* @param resource $xp XML parser resource
* @param string $name name of ending element
function _element_start_1_0 ($xp, $name, $attribs)
$this->current_element = $name;
$spos = sizeof($this->element_stack) - 2;
$this->prev_element = ($spos >= 0 ) ? $this->element_stack[$spos] : '';
$this->current_attributes = $attribs;
if ($this->in_changelog) {
$attribs['name'] = preg_replace(array ('!\\\\+!', '!/+!'), array ('/', '/'),
if (strrpos($attribs['name'], '/') === strlen($attribs['name']) - 1 ) {
$attribs['name'] = substr($attribs['name'], 0 ,
strlen($attribs['name']) - 1 );
if (strpos($attribs['name'], '/') === 0 ) {
$attribs['name'] = substr($attribs['name'], 1 );
$this->dir_names[] = $attribs['name'];
if (isset ($attribs['baseinstalldir'])) {
$this->dir_install = $attribs['baseinstalldir'];
if (isset ($attribs['role'])) {
$this->dir_role = $attribs['role'];
if ($this->in_changelog) {
if (isset ($attribs['name'])) {
if (count($this->dir_names)) {
foreach ($this->dir_names as $dir) {
$path .= preg_replace(array ('!\\\\+!', '!/+!'), array ('/', '/'),
$this->current_path = $path;
$this->filelist[$path] = $attribs;
// Set the baseinstalldir only if the file don't have this attrib
if (!isset ($this->filelist[$path]['baseinstalldir']) &&
isset ($this->dir_install))
$this->filelist[$path]['baseinstalldir'] = $this->dir_install;
if (!isset ($this->filelist[$path]['role']) && isset ($this->dir_role)) {
$this->filelist[$path]['role'] = $this->dir_role;
if (!$this->in_changelog) {
$this->filelist[$this->current_path]['replacements'][] = $attribs;
$this->_packageInfo['maintainers'] = array ();
$this->m_i = 0; // maintainers array index
if (!isset ($this->_packageInfo['maintainers'])) {
$this->_packageInfo['maintainers'] = array ();
$this->_packageInfo['maintainers'][$this->m_i] = array ();
$this->current_maintainer = & $this->_packageInfo['maintainers'][$this->m_i];
$this->_packageInfo['changelog'] = array ();
$this->c_i = 0; // changelog array index
$this->in_changelog = true;
if ($this->in_changelog) {
$this->_packageInfo['changelog'][$this->c_i] = array ();
$this->current_release = &$this->_packageInfo['changelog'][$this->c_i];
$this->current_release = &$this->_packageInfo;
if (!$this->in_changelog) {
$this->_packageInfo['release_deps'] = array ();
// dependencies array index
if (!$this->in_changelog) {
isset ($attribs['type']) ? ($attribs['type'] = strtolower($attribs['type'])) : false;
$this->_packageInfo['release_deps'][$this->d_i] = $attribs;
if (!$this->in_changelog) {
$this->_packageInfo['configure_options'] = array ();
if (!$this->in_changelog) {
$this->_packageInfo['configure_options'][] = $attribs;
if (empty ($attribs['type']) || empty ($attribs['name'])) {
$attribs['explicit'] = true;
$this->_packageInfo['provides'][" $attribs[type];$attribs[name]" ] = $attribs;
if (isset ($attribs['version'])) {
$this->_packageInfo['xsdversion'] = trim($attribs['version']);
$this->_packageInfo['xsdversion'] = '1.0';
if (isset ($attribs['packagerversion'])) {
$this->_packageInfo['packagerversion'] = $attribs['packagerversion'];
// {{{ _element_end_1_0()
* XML parser callback for ending elements. Used for version 1.0
* @param resource $xp XML parser resource
* @param string $name name of ending element
function _element_end_1_0 ($xp, $name)
$data = trim($this->cdata);
switch ($this->prev_element) {
$this->_packageInfo['package'] = $data;
$this->current_maintainer['name'] = $data;
$this->_packageInfo['extends'] = $data;
$this->_packageInfo['summary'] = $data;
$data = $this->_unIndent ($this->cdata);
$this->_packageInfo['description'] = $data;
$this->current_maintainer['handle'] = $data;
$this->current_maintainer['email'] = $data;
$this->current_maintainer['role'] = $data;
if ($this->in_changelog) {
$this->current_release['version'] = $data;
$this->_packageInfo['version'] = $data;
if ($this->in_changelog) {
$this->current_release['release_date'] = $data;
$this->_packageInfo['release_date'] = $data;
// try to "de-indent" release notes in case someone
// has been over-indenting their xml ;-)
// Trim only on the right side
$data = rtrim($this->_unIndent ($this->cdata));
if ($this->in_changelog) {
$this->current_release['release_notes'] = $data;
$this->_packageInfo['release_notes'] = $data;
if ($this->in_changelog) {
$this->current_release['release_warnings'] = $data;
$this->_packageInfo['release_warnings'] = $data;
if ($this->in_changelog) {
$this->current_release['release_state'] = $data;
$this->_packageInfo['release_state'] = $data;
if ($this->in_changelog) {
$this->current_release['release_license'] = $data;
$this->_packageInfo['release_license'] = $data;
if ($data && !$this->in_changelog) {
$this->_packageInfo['release_deps'][$this->d_i]['name'] = $data;
if ($this->in_changelog) {
if ($this->in_changelog) {
if (count($this->dir_names)) {
foreach ($this->dir_names as $dir) {
$this->filelist[$path] = $this->current_attributes;
// Set the baseinstalldir only if the file don't have this attrib
if (!isset ($this->filelist[$path]['baseinstalldir']) &&
isset ($this->dir_install))
$this->filelist[$path]['baseinstalldir'] = $this->dir_install;
if (!isset ($this->filelist[$path]['role']) && isset ($this->dir_role)) {
$this->filelist[$path]['role'] = $this->dir_role;
if (empty ($this->_packageInfo['maintainers'][$this->m_i]['role'])) {
$this->_packageInfo['maintainers'][$this->m_i]['role'] = 'lead';
if ($this->in_changelog) {
$this->in_changelog = false;
$spos = sizeof($this->element_stack) - 1;
$this->current_element = ($spos > 0 ) ? $this->element_stack[$spos] : '';
// {{{ _pkginfo_cdata_1_0()
* XML parser callback for character data. Used for version 1.0
* @param resource $xp XML parser resource
* @param string $name character data
function _pkginfo_cdata_1_0 ($xp, $data)
if (isset ($this->cdata)) {
Documentation generated on Wed, 06 Jul 2011 23:31:32 +0000 by phpDocumentor 1.4.3. PEAR Logo Copyright © PHP Group 2004.
|