Subversion Repositories Applications.gtt

Compare Revisions

Ignore whitespace Rev 186 → Rev 187

/trunk/bibliotheque/pear/PEAR/PackageFile.php
4,18 → 4,11
*
* PHP versions 4 and 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
*
* @category pear
* @package PEAR
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2006 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id: PackageFile.php,v 1.40 2006/09/25 05:12:21 cellog Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
39,9 → 32,9
* @category pear
* @package PEAR
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2006 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: 1.5.1
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
52,11 → 45,7
*/
var $_config;
var $_debug;
/**
* Temp directory for uncompressing tgz files.
* @var string|false
*/
var $_tmpdir;
 
var $_logger = false;
/**
* @var boolean
64,6 → 53,13
var $_rawReturn = false;
 
/**
* helper for extracting Archive_Tar errors
* @var array
* @access private
*/
var $_extractErrors = array();
 
/**
*
* @param PEAR_Config $config
* @param ? $debug
70,11 → 66,10
* @param string @tmpdir Optional temporary directory for uncompressing
* files
*/
function PEAR_PackageFile(&$config, $debug = false, $tmpdir = false)
function __construct(&$config, $debug = false)
{
$this->_config = $config;
$this->_debug = $debug;
$this->_tmpdir = $tmpdir;
}
 
/**
103,6 → 98,7
$a = false;
return $a;
}
 
include_once 'PEAR/PackageFile/Parser/v' . $version{0} . '.php';
$version = $version{0};
$class = "PEAR_PackageFile_Parser_v$version";
130,6 → 126,7
$a = false;
return $a;
}
 
include_once 'PEAR/PackageFile/v' . $version{0} . '.php';
$version = $version{0};
$class = $this->getClassPrefix() . $version;
153,22 → 150,25
if ($this->_logger) {
$obj->setLogger($this->_logger);
}
 
$obj->setConfig($this->_config);
$obj->fromArray($arr);
return $obj;
}
 
if (isset($arr['package']['attribs']['version'])) {
$obj = &$this->factory($arr['package']['attribs']['version']);
} else {
if (isset($arr['package']['attribs']['version'])) {
$obj = &$this->factory($arr['package']['attribs']['version']);
} else {
$obj = &$this->factory('1.0');
}
if ($this->_logger) {
$obj->setLogger($this->_logger);
}
$obj->setConfig($this->_config);
$obj->fromArray($arr);
return $obj;
$obj = &$this->factory('1.0');
}
 
if ($this->_logger) {
$obj->setLogger($this->_logger);
}
 
$obj->setConfig($this->_config);
$obj->fromArray($arr);
return $obj;
}
 
/**
185,50 → 185,53
*/
function &fromXmlString($data, $state, $file, $archive = false)
{
if (preg_match('/<package[^>]+version="([0-9]+\.[0-9]+)"/', $data, $packageversion)) {
if (preg_match('/<package[^>]+version=[\'"]([0-9]+\.[0-9]+)[\'"]/', $data, $packageversion)) {
if (!in_array($packageversion[1], array('1.0', '2.0', '2.1'))) {
return PEAR::raiseError('package.xml version "' . $packageversion[1] .
'" is not supported, only 1.0, 2.0, and 2.1 are supported.');
}
 
$object = &$this->parserFactory($packageversion[1]);
if ($this->_logger) {
$object->setLogger($this->_logger);
}
 
$object->setConfig($this->_config);
$pf = $object->parse($data, $file, $archive);
if (PEAR::isError($pf)) {
return $pf;
}
 
if ($this->_rawReturn) {
return $pf;
}
if ($pf->validate($state)) {
if ($this->_logger) {
if ($pf->getValidationWarnings(false)) {
foreach ($pf->getValidationWarnings() as $warning) {
$this->_logger->log(0, 'WARNING: ' . $warning['message']);
}
 
if (!$pf->validate($state)) {;
if ($this->_config->get('verbose') > 0
&& $this->_logger && $pf->getValidationWarnings(false)
) {
foreach ($pf->getValidationWarnings(false) as $warning) {
$this->_logger->log(0, 'ERROR: ' . $warning['message']);
}
}
if (method_exists($pf, 'flattenFilelist')) {
$pf->flattenFilelist(); // for v2
}
return $pf;
} else {
if ($this->_config->get('verbose') > 0) {
if ($this->_logger) {
if ($pf->getValidationWarnings(false)) {
foreach ($pf->getValidationWarnings(false) as $warning) {
$this->_logger->log(0, 'ERROR: ' . $warning['message']);
}
}
}
}
 
$a = PEAR::raiseError('Parsing of package.xml from file "' . $file . '" failed',
2, null, null, $pf->getValidationWarnings());
return $a;
}
} elseif (preg_match('/<package[^>]+version="([^"]+)"/', $data, $packageversion)) {
 
if ($this->_logger && $pf->getValidationWarnings(false)) {
foreach ($pf->getValidationWarnings() as $warning) {
$this->_logger->log(0, 'WARNING: ' . $warning['message']);
}
}
 
if (method_exists($pf, 'flattenFilelist')) {
$pf->flattenFilelist(); // for v2
}
 
return $pf;
} elseif (preg_match('/<package[^>]+version=[\'"]([^"\']+)[\'"]/', $data, $packageversion)) {
$a = PEAR::raiseError('package.xml file "' . $file .
'" has unsupported package.xml <package> version "' . $packageversion[1] . '"');
return $a;
236,6 → 239,7
if (!class_exists('PEAR_ErrorStack')) {
require_once 'PEAR/ErrorStack.php';
}
 
PEAR_ErrorStack::staticPush('PEAR_PackageFile',
PEAR_PACKAGEFILE_ERROR_NO_PACKAGEVERSION,
'warning', array('xml' => $data), 'package.xml "' . $file .
246,26 → 250,28
if (PEAR::isError($pf)) {
return $pf;
}
 
if ($this->_rawReturn) {
return $pf;
}
if ($pf->validate($state)) {
if ($this->_logger) {
if ($pf->getValidationWarnings(false)) {
foreach ($pf->getValidationWarnings() as $warning) {
$this->_logger->log(0, 'WARNING: ' . $warning['message']);
}
}
}
if (method_exists($pf, 'flattenFilelist')) {
$pf->flattenFilelist(); // for v2
}
return $pf;
} else {
 
if (!$pf->validate($state)) {
$a = PEAR::raiseError('Parsing of package.xml from file "' . $file . '" failed',
2, null, null, $pf->getValidationWarnings());
return $a;
}
 
if ($this->_logger && $pf->getValidationWarnings(false)) {
foreach ($pf->getValidationWarnings() as $warning) {
$this->_logger->log(0, 'WARNING: ' . $warning['message']);
}
}
 
if (method_exists($pf, 'flattenFilelist')) {
$pf->flattenFilelist(); // for v2
}
 
return $pf;
}
}
 
297,14 → 303,17
if (!class_exists('Archive_Tar')) {
require_once 'Archive/Tar.php';
}
 
$tar = new Archive_Tar($file);
if ($this->_debug <= 1) {
$tar->pushErrorHandling(PEAR_ERROR_RETURN);
}
 
$content = $tar->listContent();
if ($this->_debug <= 1) {
$tar->popErrorHandling();
}
 
if (!is_array($content)) {
if (is_string($file) && strlen($file < 255) &&
(!file_exists($file) || !@is_file($file))) {
311,17 → 320,19
$ret = PEAR::raiseError("could not open file \"$file\"");
return $ret;
}
 
$file = realpath($file);
$ret = PEAR::raiseError("Could not get contents of package \"$file\"".
'. Invalid tgz file.');
return $ret;
} else {
if (!count($content) && !@is_file($file)) {
$ret = PEAR::raiseError("could not open file \"$file\"");
return $ret;
}
}
$xml = null;
 
if (!count($content) && !@is_file($file)) {
$ret = PEAR::raiseError("could not open file \"$file\"");
return $ret;
}
 
$xml = null;
$origfile = $file;
foreach ($content as $file) {
$name = $file['filename'];
329,32 → 340,39
$xml = $name;
break;
}
 
if ($name == 'package.xml') {
$xml = $name;
break;
} elseif (ereg('package.xml$', $name, $match)) {
} elseif (preg_match('/package.xml$/', $name, $match)) {
$xml = $name;
break;
}
}
if ($this->_tmpdir) {
$tmpdir = $this->_tmpdir;
} else {
$tmpdir = System::mkTemp(array('-d', 'pear'));
PEAR_PackageFile::addTempFile($tmpdir);
 
$tmpdir = System::mktemp('-t "' . $this->_config->get('temp_dir') . '" -d pear');
if ($tmpdir === false) {
$ret = PEAR::raiseError("there was a problem with getting the configured temp directory");
return $ret;
}
 
PEAR_PackageFile::addTempFile($tmpdir);
 
$this->_extractErrors();
PEAR::staticPushErrorHandling(PEAR_ERROR_CALLBACK, array($this, '_extractErrors'));
 
if (!$xml || !$tar->extractList(array($xml), $tmpdir)) {
$extra = implode("\n", $this->_extractErrors());
if ($extra) {
$extra = ' ' . $extra;
}
 
PEAR::staticPopErrorHandling();
$ret = PEAR::raiseError('could not extract the package.xml file from "' .
$origfile . '"' . $extra);
return $ret;
}
 
PEAR::staticPopErrorHandling();
$ret = &PEAR_PackageFile::fromPackageFile("$tmpdir/$xml", $state, $origfile);
return $ret;
361,13 → 379,6
}
 
/**
* helper for extracting Archive_Tar errors
* @var array
* @access private
*/
var $_extractErrors = array();
 
/**
* helper callback for extracting Archive_Tar errors
*
* @param PEAR_Error|null $err
399,9 → 410,13
*/
function &fromPackageFile($descfile, $state, $archive = false)
{
$fp = false;
if (is_string($descfile) && strlen($descfile) < 255 &&
(!file_exists($descfile) || !is_file($descfile) || !is_readable($descfile) ||
(!$fp = @fopen($descfile, 'r')))) {
(
!file_exists($descfile) || !is_file($descfile) || !is_readable($descfile)
|| (!$fp = @fopen($descfile, 'r'))
)
) {
$a = PEAR::raiseError("Unable to open $descfile");
return $a;
}
414,7 → 429,6
return $ret;
}
 
 
/**
* Create a PEAR_PackageFile_v* from a .tgz archive or package.xml file.
*
439,15 → 453,19
} else {
$info = PEAR::raiseError("No package definition found in '$info' directory");
}
 
return $info;
}
 
$fp = false;
if (is_string($info) && strlen($info) < 255 &&
(file_exists($info) || ($fp = @fopen($info, 'r')))) {
(file_exists($info) || ($fp = @fopen($info, 'r')))
) {
 
if ($fp) {
fclose($fp);
}
 
$tmp = substr($info, -4);
if ($tmp == '.xml') {
$info = &PEAR_PackageFile::fromPackageFile($info, $state);
454,21 → 472,20
} elseif ($tmp == '.tar' || $tmp == '.tgz') {
$info = &PEAR_PackageFile::fromTgzFile($info, $state);
} else {
$fp = fopen($info, "r");
$fp = fopen($info, 'r');
$test = fread($fp, 5);
fclose($fp);
if ($test == "<?xml") {
if ($test == '<?xml') {
$info = &PEAR_PackageFile::fromPackageFile($info, $state);
} else {
$info = &PEAR_PackageFile::fromTgzFile($info, $state);
}
}
} else {
$info = PEAR::raiseError("Cannot open '$info' for parsing");
 
return $info;
}
 
$info = PEAR::raiseError("Cannot open '$info' for parsing");
return $info;
}
}
 
?>