Subversion Repositories Applications.gtt

Compare Revisions

Ignore whitespace Rev 94 → Rev 161

/tags/v1.1-thales/bibliotheque/pear/PEAR/PackageFileManager/Perforce.php
New file
0,0 → 1,102
<?php
/*
* +------------------------------------------------------------------------+
* | PEAR :: Package File Manager :: Perforce |
* +------------------------------------------------------------------------+
* | Copyright (c) 2004 Jon Parise |
* | Email jon@php.net |
* +------------------------------------------------------------------------+
* | This source file is subject to version 3.00 of the PHP License, |
* | that is available at 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 world-wide-web, please send a note to |
* | license@php.net so we can mail you a copy immediately. |
* +------------------------------------------------------------------------+
* $Id: Perforce.php,v 1.2 2004/08/25 06:02:30 jon Exp $
*/
 
/**
* @package PEAR_PackageFileManager
*/
 
/**
* The PEAR_PackageFileManager_File class
*/
require_once 'PEAR/PackageFileManager/File.php';
 
/**
* Generate a file list from a Perforce checkout. This requires the 'p4'
* command line client, a properly-configured Perforce environment, and a
* connection to the Perforce server. Specifically, the 'p4 have' command
* is used to determine which local files are under Perforce's control.
*
* @author Jon Parise <jon@php.net>
* @package PEAR_PackageFileManager
*/
class PEAR_PackageFileManager_Perforce extends PEAR_PackageFileManager_File
{
/**
* Build a list of files based on the output of the 'p4 have' command.
*
* @param string $directory The directory in which to list the files.
*
* @return mixed An array of full filenames or a PEAR_Error value if
* $directory does not exist.
*/
function dirList($directory)
{
/* Return an error if the directory does not exist. */
if (@is_dir($directory) === false) {
return PEAR_PackageFileManager::raiseError(
PEAR_PACKAGEFILEMANAGER_DIR_DOESNT_EXIST,
$directory);
}
 
/* List the files below $directory that are under Perforce control. */
exec("p4 have $directory/...", $output);
 
/* Strip off everything except the filename from each line of output. */
$files = preg_replace('/^.* \- /', '', $output);
 
/* If we have a list of files to include, remove all other entries. */
if ($this->ignore[0]) {
$files = array_filter($files, array($this, '_includeFilter'));
}
 
/* If we have a list of files to ignore, remove them from the array. */
if ($this->ignore[1]) {
$files = array_filter($files, array($this, '_ignoreFilter'));
}
 
return $files;
}
 
/**
* Determine whether a given file should be excluded from the file list.
*
* @param string $file The full pathname of file to check.
*
* @return bool True if the specified file should be included.
*
* @access private
*/
function _includeFilter($file)
{
return ($this->_checkIgnore(basename($file), $file, 0) === 0);
}
 
/**
* Determine whether a given file should be included (i.e., not ignored)
* from the file list.
*
* @param string $file The full pathname of file to check.
*
* @return bool True if the specified file should be included.
*
* @access private
*/
function _ignoreFilter($file)
{
return ($this->_checkIgnore(basename($file), $file, 1) !== 1);
}
}
/tags/v1.1-thales/bibliotheque/pear/PEAR/PackageFileManager/Svn.php
New file
0,0 → 1,169
<?php
//
// +------------------------------------------------------------------------+
// | PEAR :: Package File Manager |
// +------------------------------------------------------------------------+
// | Copyright (c) 2003-2004 Gregory Beaver |
// | Email cellog@phpdoc.org |
// +------------------------------------------------------------------------+
// | This source file is subject to version 3.00 of the PHP License, |
// | that is available at 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 world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +------------------------------------------------------------------------+
// | Portions of this code based on phpDocumentor |
// | Web http://www.phpdoc.org |
// | Mirror http://phpdocu.sourceforge.net/ |
// +------------------------------------------------------------------------+
// $Id: Svn.php,v 1.1 2004/05/31 12:02:31 arnaud Exp $
//
/**
* @package PEAR_PackageFileManager
*/
/**
* The PEAR_PackageFileManager_File class
*/
require_once 'PEAR/PackageFileManager/File.php';
 
/**
* Generate a file list from a Subversion checkout
*
* Largely based on the CVS class, modified to suit
* subversion organization.
*
* Note that this will <b>NOT</b> work on a
* repository, only on a checked out Subversion module
* @package PEAR_PackageFileManager
* @author Arnaud Limbour <arnaud@limbourg.com>
*/
class PEAR_PackageFileManager_Svn extends PEAR_PackageFileManager_File
{
/**
* Return a list of all files in the CVS repository
*
* This function is like {@link parent::dirList()} except
* that instead of retrieving a regular filelist, it first
* retrieves a listing of all the .svn/entries files in
* $directory and all of the subdirectories. Then, it
* reads the entries file, and creates a listing of files
* that are a part of the Subversion checkout. No check is
* made to see if they have been modified, but removed files
* are ignored.
*
* @access protected
* @return array list of files in a directory
* @param string $directory full path to the directory you want the list of
* @uses _recurDirList()
* @uses _readSVNEntries()
*/
function dirList($directory)
{
static $in_recursion = false;
if (!$in_recursion) {
// include only .svn/entries files
// since subversion keeps its data in a hidden
// directory we must force PackageFileManager to
// consider hidden directories.
$this->_options['addhiddenfiles'] = true;
$this->_setupIgnore(array('*/.svn/entries'), 0);
$this->_setupIgnore(array(), 1);
$in_recursion = true;
$entries = parent::dirList($directory);
$in_recursion = false;
} else {
return parent::dirList($directory);
}
if (!$entries || !is_array($entries)) {
return PEAR_PackageFileManager::raiseError(PEAR_PACKAGEFILEMANAGER_NOSVNENTRIES, $directory);
}
return $this->_readSVNEntries($entries);
}
/**
* Iterate over the SVN Entries files, and retrieve every
* file in the repository
*
* @uses _getSVNEntries()
* @param array array of full paths to .svn/entries files
* @access private
*/
function _readSVNEntries($entries)
{
$ret = array();
$ignore = $this->_options['ignore'];
// implicitly ignore packagefile
$ignore[] = $this->_options['packagefile'];
$include = $this->_options['include'];
$this->ignore = array(false, false);
$this->_setupIgnore($ignore, 1);
$this->_setupIgnore($include, 0);
foreach($entries as $cvsentry) {
$directory = @dirname(@dirname($cvsentry));
if (!$directory) {
continue;
}
$d = $this->_getSVNEntries($cvsentry);
if (!is_array($d)) {
continue;
}
foreach($d as $entry) {
if ($ignore) {
if ($this->_checkIgnore($entry,
$directory . '/' . $entry, 1)) {
continue;
}
}
if ($include) {
if ($this->_checkIgnore($entry,
$directory . '/' . $entry, 0)) {
continue;
}
}
$ret[] = $directory . '/' . $entry;
}
}
return $ret;
}
/**
* Retrieve the entries in a .svn/entries file
*
* Uses XML_Tree to parse the XML subversion file
*
* It keeps only files, excluding directories. It also
* makes sure no deleted file in included.
*
* @return array an array with full paths to files
* @uses PEAR::XML_Tree
* @param string full path to a .svn/entries file
* @access private
*/
function _getSVNEntries($svnentriesfilename)
{
require_once 'XML/Tree.php';
$parser = &new XML_Tree($svnentriesfilename);
$tree = &$parser->getTreeFromFile();
 
// loop through the xml tree and keep only valid entries being files
$entries = array();
foreach ($tree->children as $entry) {
if ($entry->name == 'entry'
&& $entry->attributes['kind'] == 'file') {
if (isset($entry->attributes['deleted'])) {
continue;
}
array_push($entries, $entry->attributes['name']);
}
}
 
unset($parser, $tree);
 
if (is_array($entries)) {
return $entries;
} else {
return false;
}
}
}
?>
/tags/v1.1-thales/bibliotheque/pear/PEAR/PackageFileManager/Cvs.php
New file
0,0 → 1,175
<?php
//
// +------------------------------------------------------------------------+
// | PEAR :: Package File Manager |
// +------------------------------------------------------------------------+
// | Copyright (c) 2003-2004 Gregory Beaver |
// | Email cellog@phpdoc.org |
// +------------------------------------------------------------------------+
// | This source file is subject to version 3.00 of the PHP License, |
// | that is available at 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 world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +------------------------------------------------------------------------+
// | Portions of this code based on phpDocumentor |
// | Web http://www.phpdoc.org |
// | Mirror http://phpdocu.sourceforge.net/ |
// +------------------------------------------------------------------------+
// $Id: Cvs.php,v 1.9 2005/03/25 22:37:15 cellog Exp $
//
/**
* @package PEAR_PackageFileManager
*/
/**
* The PEAR_PackageFileManager_File class
*/
require_once 'PEAR/PackageFileManager/File.php';
 
/**
* Generate a file list from a CVS checkout
*
* Note that this will <b>NOT</b> work on a
* repository, only on a checked out CVS module
* @package PEAR_PackageFileManager
*/
class PEAR_PackageFileManager_CVS extends PEAR_PackageFileManager_File {
/**
* List of CVS-specific files that may exist in CVS but should be
* ignored when building the package's file list.
* @var array
* @access private
*/
var $_cvsIgnore = array('.cvsignore');
 
/**
* Return a list of all files in the CVS repository
*
* This function is like {@link parent::dirList()} except
* that instead of retrieving a regular filelist, it first
* retrieves a listing of all the CVS/Entries files in
* $directory and all of the subdirectories. Then, it
* reads the Entries file, and creates a listing of files
* that are a part of the CVS repository. No check is
* made to see if they have been modified, but newly
* added or removed files are ignored.
* @return array list of files in a directory
* @param string $directory full path to the directory you want the list of
* @uses _recurDirList()
* @uses _readCVSEntries()
*/
function dirList($directory)
{
static $in_recursion = false;
if (!$in_recursion) {
// include only CVS/Entries files
$this->_setupIgnore(array('*/CVS/Entries'), 0);
$this->_setupIgnore(array(), 1);
$in_recursion = true;
$entries = parent::dirList($directory);
$in_recursion = false;
} else {
return parent::dirList($directory);
}
if (!$entries || !is_array($entries)) {
return PEAR_PackageFileManager::raiseError(PEAR_PACKAGEFILEMANAGER_NOCVSENTRIES, $directory);
}
return $this->_readCVSEntries($entries);
}
/**
* Iterate over the CVS Entries files, and retrieve every
* file in the repository
* @uses _getCVSEntries()
* @uses _isCVSFile()
* @param array array of full paths to CVS/Entries files
* @access private
*/
function _readCVSEntries($entries)
{
$ret = array();
$ignore = array_merge((array) $this->_options['ignore'], $this->_cvsIgnore);
// implicitly ignore packagefile
$ignore[] = $this->_options['packagefile'];
$include = $this->_options['include'];
$this->ignore = array(false, false);
$this->_setupIgnore($ignore, 1);
$this->_setupIgnore($include, 0);
foreach($entries as $cvsentry) {
$directory = @dirname(@dirname($cvsentry));
if (!$directory) {
continue;
}
$d = $this->_getCVSEntries($cvsentry);
if (!is_array($d)) {
continue;
}
foreach($d as $entry) {
if ($ignore) {
if ($this->_checkIgnore($this->_getCVSFileName($entry),
$directory . '/' . $this->_getCVSFileName($entry), 1)) {
// print 'Ignoring '.$file."<br>\n";
continue;
}
}
if ($include) {
if ($this->_checkIgnore($this->_getCVSFileName($entry),
$directory . '/' . $this->_getCVSFileName($entry), 0)) {
// print 'Including '.$file."<br\n";
continue;
}
}
if ($this->_isCVSFile($entry)) {
$ret[] = $directory . '/' . $this->_getCVSFileName($entry);
}
}
}
return $ret;
}
/**
* Retrieve the filename from an entry
*
* This method assumes that the entry is a file,
* use _isCVSFile() to verify before calling
* @param string a line in a CVS/Entries file
* @return string the filename (no path information)
* @access private
*/
function _getCVSFileName($cvsentry)
{
$stuff = explode('/', $cvsentry);
array_shift($stuff);
return array_shift($stuff);
}
/**
* Retrieve the entries in a CVS/Entries file
* @return array each line of the entries file, output of file()
* @uses function file()
* @param string full path to a CVS/Entries file
* @access private
*/
function _getCVSEntries($cvsentryfilename)
{
$cvsfile = @file($cvsentryfilename);
if (is_array($cvsfile)) {
return $cvsfile;
} else {
return false;
}
}
/**
* Check whether an entry is a file or a directory
* @return boolean
* @param string a line in a CVS/Entries file
* @access private
*/
function _isCVSFile($cvsentry)
{
// make sure we ignore entries that have either been removed or added, but not committed yet
return $cvsentry{0} == '/' && !strpos($cvsentry, 'dummy timestamp');
}
}
?>
/tags/v1.1-thales/bibliotheque/pear/PEAR/PackageFileManager/File.php
New file
0,0 → 1,421
<?php
//
// +------------------------------------------------------------------------+
// | PEAR :: Package File Manager |
// +------------------------------------------------------------------------+
// | Copyright (c) 2003-2004 Gregory Beaver |
// | Email cellog@phpdoc.org |
// +------------------------------------------------------------------------+
// | This source file is subject to version 3.00 of the PHP License, |
// | that is available at 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 world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +------------------------------------------------------------------------+
// | Portions of this code based on phpDocumentor |
// | Web http://www.phpdoc.org |
// | Mirror http://phpdocu.sourceforge.net/ |
// +------------------------------------------------------------------------+
// $Id: File.php,v 1.21 2005/03/28 06:37:35 cellog Exp $
//
/**
* Retrieve the files from a directory listing
* @package PEAR_PackageFileManager
*/
/**
* Retrieve the files from a directory listing
*
* This class is used to retrieve a raw directory
* listing. Use the {@link PEAR_PackageFileManager_CVS}
* class to only retrieve the contents of a cvs
* repository when generating the package.xml
* @package PEAR_PackageFileManager
*/
class PEAR_PackageFileManager_File {
/**
* @var array
* @access private
*/
var $_options =
array(
);
 
/**
* @access private
* @var PEAR_PackageFileManager
*/
var $_parent;
 
/**
* @access private
* @var array|false
*/
var $_ignore = false;
 
/**
* Set up the File filelist generator
*
* 'ignore' and 'include' are the only options that this class uses. See
* {@link PEAR_PackageFileManager::setOptions()} for
* more information and formatting of this option
* @param PEAR_PackageFileManager
* @param array
*/
function PEAR_PackageFileManager_File(&$parent, $options)
{
$this->_parent = &$parent;
$this->_options = array_merge($this->_options, $options);
}
/**
* Generate the <filelist></filelist> section
* of the package file.
*
* This function performs the backend generation of the array
* containing all files in this package
* @return array
*/
function getFileList()
{
$package_directory = $this->_options['packagedirectory'];
$ignore = $this->_options['ignore'];
// implicitly ignore packagefile
$ignore[] = $this->_options['packagefile'];
if ($this->_options['packagefile'] == 'package.xml') {
// ignore auto-generated package2.xml from PEAR 1.4.0
$ignore[] = 'package2.xml';
}
$include = $this->_options['include'];
$this->ignore = array(false, false);
$this->_setupIgnore($ignore, 1);
$this->_setupIgnore($include, 0);
$allfiles = $this->dirList(substr($package_directory, 0, strlen($package_directory) - 1));
if (PEAR::isError($allfiles)) {
return $allfiles;
}
if (!count($allfiles)) {
return PEAR_PackageFileManager::raiseError(PEAR_PACKAGEFILEMANAGER_NO_FILES,
substr($package_directory, 0, strlen($package_directory) - 1));
}
$struc = array();
foreach($allfiles as $file) {
$path = substr(dirname($file), strlen(str_replace(DIRECTORY_SEPARATOR,
'/',
realpath($package_directory))) + 1);
if (!$path) {
$path = '/';
}
$ext = array_pop(explode('.', $file));
if (strlen($ext) == strlen($file)) {
$ext = '';
}
$struc[$path][] = array('file' => basename($file),
'ext' => $ext,
'path' => (($path == '/') ? basename($file) : $path . '/' . basename($file)),
'fullpath' => $file);
}
if (!count($struc)) {
$newig = implode($this->_options['ignore'], ', ');
return PEAR_PackageFileManager::raiseError(PEAR_PACKAGEFILEMANAGER_IGNORED_EVERYTHING,
substr($package_directory, 0, strlen($package_directory) - 1), $newig);
}
uksort($struc,'strnatcasecmp');
foreach($struc as $key => $ind) {
usort($ind, array($this, 'sortfiles'));
$struc[$key] = $ind;
}
 
$tempstruc = $struc;
if (!isset($tempstruc['/'])) {
$tempstruc['/'] = array();
}
$struc = array('/' => $tempstruc['/']);
$bv = 0;
foreach($tempstruc as $key => $ind) {
$save = $key;
if ($key != '/')
{
$struc['/'] = $this->_setupDirs($struc['/'], explode('/',$key), $tempstruc[$key]);
}
}
uksort($struc['/'], array($this, 'mystrucsort'));
 
return $struc;
}
/**
* Retrieve a listing of every file in $directory and
* all subdirectories.
*
* The return format is an array of full paths to files
* @access protected
* @return array list of files in a directory
* @param string $directory full path to the directory you want the list of
* @throws PEAR_PACKAGEFILEMANAGER_DIR_DOESNT_EXIST
*/
function dirList($directory)
{
$ret = false;
if (@is_dir($directory)) {
$ret = array();
$d = @dir($directory); // thanks to Jason E Sweat (jsweat@users.sourceforge.net) for fix
while($d && false !== ($entry=$d->read())) {
if ($this->_testFile($directory, $entry)) {
if (is_file($directory . '/' . $entry)) {
// if include option was set, then only pass included files
if ($this->ignore[0]) {
if ($this->_checkIgnore($entry, $directory . '/' . $entry, 0)) {
continue;
}
}
// if ignore option was set, then only pass included files
if ($this->ignore[1]) {
if ($this->_checkIgnore($entry, $directory . '/' . $entry, 1)) {
continue;
}
}
$ret[] = $directory . '/' . $entry;
}
if (is_dir($directory . '/' . $entry)) {
$tmp = $this->dirList($directory . '/' . $entry);
if (is_array($tmp)) {
foreach($tmp as $ent) {
$ret[] = $ent;
}
}
}
}
}
if ($d) {
$d->close();
}
} else {
return PEAR_PackageFileManager::raiseError(PEAR_PACKAGEFILEMANAGER_DIR_DOESNT_EXIST, $directory);
}
return $ret;
}
/**
* Test whether an entry should be processed.
*
* Normally, it ignores all files and directories that begin with "." addhiddenfiles option
* instead only ignores "." and ".." entries
* @access private
* @param string directory name of entry
* @param string name
*/
function _testFile($directory, $entry)
{
if ($this->_options['addhiddenfiles']) {
return is_file($directory . '/' . $entry) || (is_dir($directory . '/' . $entry) && !in_array($entry, array('.', '..')));
} else {
return $entry{0} != '.';
}
}
 
/**
* Tell whether to ignore a file or a directory
* allows * and ? wildcards
*
* @param string $file just the file name of the file or directory,
* in the case of directories this is the last dir
* @param string $path the full path
* @param 1|0 $return value to return if regexp matches. Set this to
* false to include only matches, true to exclude
* all matches
* @return bool true if $path should be ignored, false if it should not
* @access private
*/
function _checkIgnore($file, $path, $return = 1)
{
if (file_exists($path)) {
$path = realpath($path);
}
if (is_array($this->ignore[$return])) {
foreach($this->ignore[$return] as $match) {
// match is an array if the ignore parameter was a /path/to/pattern
if (is_array($match)) {
// check to see if the path matches with a path delimiter appended
preg_match('/^' . strtoupper($match[0]).'$/', strtoupper($path) . '/',$find);
if (!count($find)) {
// check to see if it matches without an appended path delimiter
preg_match('/^' . strtoupper($match[0]).'$/', strtoupper($path), $find);
}
if (count($find)) {
// check to see if the file matches the file portion of the regex string
preg_match('/^' . strtoupper($match[1]).'$/', strtoupper($file), $find);
if (count($find)) {
return $return;
}
}
// check to see if the full path matches the regex
preg_match('/^' . strtoupper($match[0]).'$/',
strtoupper($path . DIRECTORY_SEPARATOR . $file), $find);
if (count($find)) {
return $return;
}
} else {
// ignore parameter was just a pattern with no path delimiters
// check it against the path
preg_match('/^' . strtoupper($match).'$/', strtoupper($path), $find);
if (count($find)) {
return $return;
}
// check it against the file only
preg_match('/^' . strtoupper($match).'$/', strtoupper($file), $find);
if (count($find)) {
return $return;
}
}
}
}
return !$return;
}
/**
* Construct the {@link $ignore} array
* @param array strings of files/paths/wildcards to ignore
* @param 0|1 0 = files to include, 1 = files to ignore
* @access private
*/
function _setupIgnore($ignore, $index)
{
$ig = array();
if (is_array($ignore)) {
for($i=0; $i<count($ignore);$i++) {
$ignore[$i] = strtr($ignore[$i], "\\", "/");
$ignore[$i] = str_replace('//','/',$ignore[$i]);
 
if (!empty($ignore[$i])) {
if (!is_numeric(strpos($ignore[$i], '/'))) {
$ig[] = $this->_getRegExpableSearchString($ignore[$i]);
} else {
if (basename($ignore[$i]) . '/' == $ignore[$i]) {
$ig[] = $this->_getRegExpableSearchString($ignore[$i]);
} else {
$ig[] = array($this->_getRegExpableSearchString($ignore[$i]),
$this->_getRegExpableSearchString(basename($ignore[$i])));
}
}
}
}
if (count($ig)) {
$this->ignore[$index] = $ig;
} else {
$this->ignore[$index] = false;
}
} else $this->ignore[$index] = false;
}
/**
* Converts $s into a string that can be used with preg_match
* @param string $s string with wildcards ? and *
* @return string converts * to .*, ? to ., etc.
* @access private
*/
function _getRegExpableSearchString($s)
{
$y = '\/';
if (DIRECTORY_SEPARATOR == '\\') {
$y = '\\\\';
}
$s = str_replace('/', DIRECTORY_SEPARATOR, $s);
$x = strtr($s, array('?' => '.','*' => '.*','.' => '\\.','\\' => '\\\\','/' => '\\/',
'[' => '\\[',']' => '\\]','-' => '\\-'));
if (strpos($s, DIRECTORY_SEPARATOR) !== false &&
strrpos($s, DIRECTORY_SEPARATOR) === strlen($s) - 1) {
$x = "(?:.*$y$x?.*|$x.*)";
}
return $x;
}
/**
* Recursively move contents of $struc into associative array
*
* The contents of $struc have many indexes like 'dir/subdir/subdir2'.
* This function converts them to
* array('dir' => array('subdir' => array('subdir2')))
* @param array struc is array('dir' => array of files in dir,
* 'dir/subdir' => array of files in dir/subdir,...)
* @param array array form of 'dir/subdir/subdir2' array('dir','subdir','subdir2')
* @return array same as struc but with array('dir' =>
* array(file1,file2,'subdir' => array(file1,...)))
* @access private
*/
function _setupDirs($struc, $dir, $contents)
{
if (!count($dir)) {
foreach($contents as $dir => $files) {
if (is_string($dir)) {
if (strpos($dir, '/')) {
$test = true;
$a = $contents[$dir];
unset($contents[$dir]);
$b = explode('/', $dir);
$c = array_shift($b);
if (isset($contents[$c])) {
$contents[$c] = $this->_setDir($contents[$c], $this->_setupDirs(array(), $b, $a));
} else {
$contents[$c] = $this->_setupDirs(array(), $b, $a);
}
}
}
}
return $contents;
}
$me = array_shift($dir);
if (!isset($struc[$me])) {
$struc[$me] = array();
}
$struc[$me] = $this->_setupDirs($struc[$me], $dir, $contents);
return $struc;
}
 
/**
* Recursively add all the subdirectories of $contents to $dir without erasing anything in
* $dir
* @param array
* @param array
* @return array processed $dir
* @access private
*/
function _setDir($dir, $contents)
{
while(list($one,$two) = each($contents)) {
if (isset($dir[$one])) {
$dir[$one] = $this->_setDir($dir[$one], $contents[$one]);
} else {
$dir[$one] = $two;
}
}
return $dir;
}
 
/**#@+
* Sorting functions for the file list
* @param string
* @param string
* @access private
*/
function sortfiles($a, $b)
{
return strnatcasecmp($a['file'],$b['file']);
}
function mystrucsort($a, $b)
{
if (is_numeric($a) && is_string($b)) return 1;
if (is_numeric($b) && is_string($a)) return -1;
if (is_numeric($a) && is_numeric($b))
{
if ($a > $b) return 1;
if ($a < $b) return -1;
if ($a == $b) return 0;
}
return strnatcasecmp($a,$b);
}
/**#@-*/
}
?>
/tags/v1.1-thales/bibliotheque/pear/PEAR/PackageFileManager/SimpleGenerator.php
New file
0,0 → 1,323
<?php
//
// +------------------------------------------------------------------------+
// | PEAR :: Package File Manager |
// +------------------------------------------------------------------------+
// | Copyright (c) 2004 Gregory Beaver |
// | Email cellog@phpdoc.org |
// +------------------------------------------------------------------------+
// | This source file is subject to version 3.00 of the PHP License, |
// | that is available at 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 world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +------------------------------------------------------------------------+
// | Portions of this code based on phpDocumentor |
// | Web http://www.phpdoc.org |
// | Mirror http://phpdocu.sourceforge.net/ |
// +------------------------------------------------------------------------+
// $Id: SimpleGenerator.php,v 1.4 2005/05/20 22:42:59 cellog Exp $
//
 
require_once 'PEAR/PackageFile/Generator/v1.php';
/**
* Class for XML output
*
* @author Greg Beaver <cellog@php.net>
* @since 1.2.0
* @copyright 2003
* @package PEAR_PackageFileManager
*/
class PEAR_PackageFileManager_SimpleGenerator extends PEAR_PackageFile_Generator_v1
{
var $_options;
 
/**
* remove a warning about missing parameters - don't delete this
*/
function PEAR_PackageFileManager_SimpleGenerator()
{
}
 
/**
* @param array
*/
function setPackageFileManagerOptions($opts)
{
$this->_options = $opts;
}
 
/**
* Return an XML document based on the package info (as returned
* by the PEAR_Common::infoFrom* methods).
*
* @param array $pkginfo package info
*
* @return string XML data
*
* @access public
* @deprecated use a PEAR_PackageFile_v* object's generator instead
*/
function xmlFromInfo($pkginfo)
{
include_once 'PEAR/PackageFile.php';
include_once 'PEAR/Config.php';
$config = &PEAR_Config::singleton();
$packagefile = &new PEAR_PackageFile($config);
$pf = &$packagefile->fromArray($pkginfo);
parent::PEAR_PackageFile_Generator_v1($pf);
return $this->toXml();
}
 
function getFileRoles()
{
return PEAR_Common::getFileRoles();
}
 
function getReplacementTypes()
{
return PEAR_Common::getReplacementTypes();
}
 
/**
* Validate XML package definition file.
*
* @param string $info Filename of the package archive or of the
* package definition file
* @param array $errors Array that will contain the errors
* @param array $warnings Array that will contain the warnings
* @param string $dir_prefix (optional) directory where source files
* may be found, or empty if they are not available
* @access public
* @return boolean
* @deprecated use the validation of PEAR_PackageFile objects
*/
function validatePackageInfo($info, &$errors, &$warnings, $dir_prefix = '')
{
include_once 'PEAR/PackageFile.php';
include_once 'PEAR/Config.php';
$config = &PEAR_Config::singleton();
$packagefile = &new PEAR_PackageFile($config);
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
if (is_array($info)) {
$pf = &$packagefile->fromArray($info);
if (!$pf->validate(PEAR_VALIDATE_NORMAL)) {
foreach ($pf->getValidationWarnings() as $err) {
if ($error['level'] == 'error') {
$errors[] = $error['message'];
} else {
$warnings[] = $error['message'];
}
}
return false;
}
} else {
$pf = &$packagefile->fromAnyFile($info, PEAR_VALIDATE_NORMAL);
}
PEAR::staticPopErrorHandling();
if (PEAR::isError($pf)) {
$errs = $pf->getUserinfo();
if (is_array($errs)) {
foreach ($errs as $error) {
if ($error['level'] == 'error') {
$errors[] = $error['message'];
} else {
$warnings[] = $error['message'];
}
}
}
return false;
}
return true;
}
 
/**
* @param array
* @access protected
*/
function recursiveXmlFilelist($list)
{
$this->_dirs = array();
foreach ($list as $file => $attributes) {
$this->_addDir($this->_dirs, explode('/', dirname($file)), $file, $attributes);
}
if (!isset($this->_dirs['dirs'])) {
$this->_dirs['dirs'] = array();
}
if (count($this->_dirs['dirs']) != 1 || isset($this->_dirs['files'])) {
$this->_dirs = array('dirs' => array('/' => $this->_dirs));
}
return $this->_formatDir($this->_dirs, '', '', true);
}
 
/**
* @param array
* @param array
* @param string|null
* @param array|null
* @access private
*/
function _addDir(&$dirs, $dir, $file = null, $attributes = null)
{
if ($dir == array() || $dir == array('.')) {
$dirs['files'][basename($file)] = $attributes;
return;
}
$curdir = array_shift($dir);
if (!isset($dirs['dirs'][$curdir])) {
$dirs['dirs'][$curdir] = array();
}
$this->_addDir($dirs['dirs'][$curdir], $dir, $file, $attributes);
}
 
/**
* @param array
* @param string
* @param string
* @access private
*/
function _formatDir($dirs, $indent = '', $curdir = '', $toplevel = false)
{
$ret = '';
if (!count($dirs)) {
return '';
}
if (isset($dirs['dirs'])) {
uksort($dirs['dirs'], 'strnatcasecmp');
foreach ($dirs['dirs'] as $dir => $contents) {
if ($dir == '/') {
$usedir = '/';
} else {
if ($curdir == '/') {
$curdir = '';
}
$usedir = "$curdir/$dir";
}
$ret .= "$indent <dir name=\"$dir\"";
if ($toplevel) {
$ret .= ' baseinstalldir="' . $this->_options['baseinstalldir'] . '"';
} else {
if (isset($this->_options['installexceptions'][$dir])) {
$ret .= ' baseinstalldir="' . $this->_options['installexceptions'][$dir] . '"';
}
}
$ret .= ">\n";
$ret .= $this->_formatDir($contents, "$indent ", $usedir);
$ret .= "$indent </dir> <!-- $usedir -->\n";
}
}
if (isset($dirs['files'])) {
uksort($dirs['files'], 'strnatcasecmp');
foreach ($dirs['files'] as $file => $attribs) {
$ret .= $this->_formatFile($file, $attribs, $indent);
}
}
return $ret;
}
 
/**
* @param string
* @param array
* @param string
* @access private
*/
function _formatFile($file, $attributes, $indent)
{
$ret = "$indent <file role=\"$attributes[role]\"";
if (isset($this->_options['installexceptions'][$file])) {
$ret .= ' baseinstalldir="' . $this->_options['installexceptions'][$file] . '"';
}
if (isset($attributes['md5sum'])) {
$ret .= " md5sum=\"$attributes[md5sum]\"";
}
if (isset($attributes['platform'])) {
$ret .= " platform=\"$attributes[platform]\"";
}
if (!empty($attributes['install-as'])) {
$ret .= ' install-as="' .
htmlspecialchars($attributes['install-as']) . '"';
}
$ret .= ' name="' . htmlspecialchars($file) . '"';
if (empty($attributes['replacements'])) {
$ret .= "/>\n";
} else {
$ret .= ">\n";
foreach ($attributes['replacements'] as $r) {
$ret .= "$indent <replace";
foreach ($r as $k => $v) {
$ret .= " $k=\"" . htmlspecialchars($v) .'"';
}
$ret .= "/>\n";
}
$ret .= "$indent </file>\n";
}
return $ret;
}
 
/**
* Generate the <filelist> tag
* @access private
* @return string
*/
function _doFileList($indent, $filelist, $curdir)
{
$ret = '';
foreach ($filelist as $file => $fa) {
if (isset($fa['##files'])) {
$ret .= "$indent <dir";
} else {
$ret .= "$indent <file";
}
 
if (isset($fa['role'])) {
$ret .= " role=\"$fa[role]\"";
}
if (isset($fa['baseinstalldir'])) {
$ret .= ' baseinstalldir="' .
htmlspecialchars($fa['baseinstalldir']) . '"';
}
if (isset($fa['md5sum'])) {
$ret .= " md5sum=\"$fa[md5sum]\"";
}
if (isset($fa['platform'])) {
$ret .= " platform=\"$fa[platform]\"";
}
if (!empty($fa['install-as'])) {
$ret .= ' install-as="' .
htmlspecialchars($fa['install-as']) . '"';
}
$ret .= ' name="' . htmlspecialchars($file) . '"';
if (isset($fa['##files'])) {
$ret .= ">\n";
$recurdir = $curdir;
if ($recurdir == '///') {
$recurdir = '';
}
$ret .= $this->_doFileList("$indent ", $fa['##files'], $recurdir . $file . '/');
$displaydir = $curdir;
if ($displaydir == '///' || $displaydir == '/') {
$displaydir = '';
}
$ret .= "$indent </dir> <!-- $displaydir$file -->\n";
} else {
if (empty($fa['replacements'])) {
$ret .= "/>\n";
} else {
$ret .= ">\n";
foreach ($fa['replacements'] as $r) {
$ret .= "$indent <replace";
foreach ($r as $k => $v) {
$ret .= " $k=\"" . htmlspecialchars($v) .'"';
}
$ret .= "/>\n";
}
$ret .= "$indent </file>\n";
}
}
}
return $ret;
}
}
 
?>
/tags/v1.1-thales/bibliotheque/pear/PEAR/PackageFileManager/XMLOutput.php
New file
0,0 → 1,180
<?php
//
// +------------------------------------------------------------------------+
// | PEAR :: Package File Manager |
// +------------------------------------------------------------------------+
// | Copyright (c) 2004 Gregory Beaver |
// | Email cellog@phpdoc.org |
// +------------------------------------------------------------------------+
// | This source file is subject to version 3.00 of the PHP License, |
// | that is available at 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 world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +------------------------------------------------------------------------+
// | Portions of this code based on phpDocumentor |
// | Web http://www.phpdoc.org |
// | Mirror http://phpdocu.sourceforge.net/ |
// +------------------------------------------------------------------------+
// $Id: XMLOutput.php,v 1.4 2004/02/07 18:04:00 cellog Exp $
//
 
/**
* Class for XML output
*
* @author Greg Beaver <cellog@php.net>
* @since 1.2.0
* @copyright 2003
* @package PEAR_PackageFileManager
*/
class PEAR_PackageFileManager_XMLOutput extends PEAR_Common {
 
/**
* Generate part of an XML description with release information.
*
* @param array $pkginfo array with release information
* @param bool $changelog whether the result will be in a changelog element
*
* @return string XML data
*
* @access private
*/
function _makeReleaseXml($pkginfo, $changelog = false)
{
$indent = $changelog ? " " : "";
$ret = "$indent <release>\n";
if (!empty($pkginfo['version'])) {
$ret .= "$indent <version>$pkginfo[version]</version>\n";
}
if (!empty($pkginfo['release_date'])) {
$ret .= "$indent <date>$pkginfo[release_date]</date>\n";
}
if (!empty($pkginfo['release_license'])) {
$ret .= "$indent <license>$pkginfo[release_license]</license>\n";
}
if (!empty($pkginfo['release_state'])) {
$ret .= "$indent <state>$pkginfo[release_state]</state>\n";
}
if (!empty($pkginfo['release_notes'])) {
$ret .= "$indent <notes>".htmlspecialchars($pkginfo['release_notes'])."</notes>\n";
}
if (!empty($pkginfo['release_warnings'])) {
$ret .= "$indent <warnings>".htmlspecialchars($pkginfo['release_warnings'])."</warnings>\n";
}
if (isset($pkginfo['release_deps']) && sizeof($pkginfo['release_deps']) > 0) {
$ret .= "$indent <deps>\n";
foreach ($pkginfo['release_deps'] as $dep) {
$ret .= "$indent <dep type=\"$dep[type]\" rel=\"$dep[rel]\"";
if (isset($dep['version'])) {
$ret .= " version=\"$dep[version]\"";
}
if (isset($dep['optional'])) {
$ret .= " optional=\"$dep[optional]\"";
}
if (isset($dep['name'])) {
$ret .= ">$dep[name]</dep>\n";
} else {
$ret .= "/>\n";
}
}
$ret .= "$indent </deps>\n";
}
if (isset($pkginfo['configure_options'])) {
$ret .= "$indent <configureoptions>\n";
foreach ($pkginfo['configure_options'] as $c) {
$ret .= "$indent <configureoption name=\"".
htmlspecialchars($c['name']) . "\"";
if (isset($c['default'])) {
$ret .= " default=\"" . htmlspecialchars($c['default']) . "\"";
}
$ret .= " prompt=\"" . htmlspecialchars($c['prompt']) . "\"";
$ret .= "/>\n";
}
$ret .= "$indent </configureoptions>\n";
}
if (isset($pkginfo['provides'])) {
foreach ($pkginfo['provides'] as $key => $what) {
$ret .= "$indent <provides type=\"$what[type]\" ";
$ret .= "name=\"$what[name]\" ";
if (isset($what['extends'])) {
$ret .= "extends=\"$what[extends]\" ";
}
$ret .= "/>\n";
}
}
if (isset($pkginfo['filelist'])) {
$ret .= "$indent <filelist>\n";
$ret .= $this->_doFileList($indent, $pkginfo['filelist'], '/');
$ret .= "$indent </filelist>\n";
}
$ret .= "$indent </release>\n";
return $ret;
}
 
/**
* Generate the <filelist> tag
* @access private
* @return string
*/
function _doFileList($indent, $filelist, $curdir)
{
$ret = '';
foreach ($filelist as $file => $fa) {
if (isset($fa['##files'])) {
$ret .= "$indent <dir";
} else {
$ret .= "$indent <file";
}
 
if (isset($fa['role'])) {
$ret .= " role=\"$fa[role]\"";
}
if (isset($fa['baseinstalldir'])) {
$ret .= ' baseinstalldir="' .
htmlspecialchars($fa['baseinstalldir']) . '"';
}
if (isset($fa['md5sum'])) {
$ret .= " md5sum=\"$fa[md5sum]\"";
}
if (isset($fa['platform'])) {
$ret .= " platform=\"$fa[platform]\"";
}
if (!empty($fa['install-as'])) {
$ret .= ' install-as="' .
htmlspecialchars($fa['install-as']) . '"';
}
$ret .= ' name="' . htmlspecialchars($file) . '"';
if (isset($fa['##files'])) {
$ret .= ">\n";
$recurdir = $curdir;
if ($recurdir == '///') {
$recurdir = '';
}
$ret .= $this->_doFileList("$indent ", $fa['##files'], $recurdir . $file . '/');
$displaydir = $curdir;
if ($displaydir == '///' || $displaydir == '/') {
$displaydir = '';
}
$ret .= "$indent </dir> <!-- $displaydir$file -->\n";
} else {
if (empty($fa['replacements'])) {
$ret .= "/>\n";
} else {
$ret .= ">\n";
foreach ($fa['replacements'] as $r) {
$ret .= "$indent <replace";
foreach ($r as $k => $v) {
$ret .= " $k=\"" . htmlspecialchars($v) .'"';
}
$ret .= "/>\n";
}
$ret .= "$indent </file>\n";
}
}
}
return $ret;
}
}
 
?>