mirror of
https://github.com/bdnugget/php-src.git
synced 2026-11-26 10:25:41 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
faa91c5568 |
No files matched your search
@@ -1,2 +0,0 @@
|
||||
PHP Data Objects
|
||||
Wez Furlong, Marcus Boerger, Sterling Hughes, George Schlossnagle
|
||||
@@ -1,39 +0,0 @@
|
||||
phpincludedir=$(prefix)/include/php
|
||||
|
||||
PDO_HEADER_FILES= \
|
||||
php_pdo.h \
|
||||
php_pdo_driver.h
|
||||
|
||||
install-pdo-headers:
|
||||
@echo "Installing PDO headers: $(INSTALL_ROOT)$(phpincludedir)/ext/pdo/"
|
||||
@$(mkinstalldirs) $(INSTALL_ROOT)$(phpincludedir)/ext/pdo
|
||||
@for f in $(PDO_HEADER_FILES); do \
|
||||
if test -f "$(top_srcdir)/$$f"; then \
|
||||
$(INSTALL_DATA) $(top_srcdir)/$$f $(INSTALL_ROOT)$(phpincludedir)/ext/pdo; \
|
||||
elif test -f "$(top_builddir)/$$f"; then \
|
||||
$(INSTALL_DATA) $(top_builddir)/$$f $(INSTALL_ROOT)$(phpincludedir)/ext/pdo; \
|
||||
elif test -f "$(top_srcdir)/ext/pdo/$$f"; then \
|
||||
$(INSTALL_DATA) $(top_srcdir)/ext/pdo/$$f $(INSTALL_ROOT)$(phpincludedir)/ext/pdo; \
|
||||
elif test -f "$(top_builddir)/ext/pdo/$$f"; then \
|
||||
$(INSTALL_DATA) $(top_builddir)/ext/pdo/$$f $(INSTALL_ROOT)$(phpincludedir)/ext/pdo; \
|
||||
else \
|
||||
echo "hmmm"; \
|
||||
fi \
|
||||
done;
|
||||
@echo ""
|
||||
@echo ""
|
||||
@echo "You're now ready to install PDO drivers for your database"
|
||||
@echo "If you'd like to have PDO show up in the list of installed"
|
||||
@echo "packages when you run \"pear list\", you may now run"
|
||||
@echo "\"sudo pear install package.xml\""
|
||||
@echo "this time, when prompted to press enter, you should type"
|
||||
@echo "\"no\" and press enter instead."
|
||||
|
||||
# mini hack
|
||||
install: $(all_targets) $(install_targets) install-pdo-headers
|
||||
|
||||
$(top_srcdir)/ext/pdo/pdo_sql_parser.c: $(top_srcdir)/ext/pdo/pdo_sql_parser.re
|
||||
exit 0; re2c -b $(top_srcdir)/ext/pdo/pdo_sql_parser.re > $@
|
||||
|
||||
$(srcdir)/pdo_sql_parser.c: $(srcdir)/pdo_sql_parser.re
|
||||
exit 0; re2c -b $(srcdir)/pdo_sql_parser.re > $@
|
||||
@@ -1,56 +0,0 @@
|
||||
$Id$
|
||||
|
||||
PHP Data Objects
|
||||
================
|
||||
|
||||
Concept: Data Access Abstraction
|
||||
|
||||
Goals:
|
||||
|
||||
1/ Be light-weight
|
||||
2/ Provide common API for common database operations
|
||||
3/ Be performant
|
||||
4/ Keep majority of PHP specific stuff in the PDO core (such as persistent
|
||||
resource management); drivers should only have to worry about getting the
|
||||
data and not about PHP internals.
|
||||
|
||||
|
||||
Transactions and autocommit
|
||||
===========================
|
||||
|
||||
When you create a database handle, you *should* specify the autocommit
|
||||
behaviour that you require. PDO will default to autocommit on.
|
||||
|
||||
$dbh = new PDO("...", $user, $pass, array(PDO_ATTR_AUTOCOMMIT => true));
|
||||
|
||||
When auto-commit is on, the driver will implicitly commit each query as it is
|
||||
executed. This works fine for most simple tasks but can be significantly
|
||||
slower when you are making a large number of udpates.
|
||||
|
||||
$dbh = new PDO("...", $user, $pass, array(PDO_ATTR_AUTOCOMMIT => false));
|
||||
|
||||
When auto-commit is off, you must then use $dbh->beginTransaction() to
|
||||
initiate a transaction. When your work is done, you then call $dbh->commit()
|
||||
or $dbh->rollBack() to persist or abort your changes respectively. Not all
|
||||
databases support transactions.
|
||||
|
||||
You can change the auto-commit mode at run-time:
|
||||
|
||||
$dbh->setAttribute(PDO_ATTR_AUTOCOMMIT, false);
|
||||
|
||||
Regardless of the error handling mode set on the database handle, if the
|
||||
autocommit mode cannot be changed, an exception will be thrown.
|
||||
|
||||
Some drivers will allow you to temporarily disable autocommit if you call
|
||||
$dbh->beginTransaction(). When you commit() or rollBack() such a transaction,
|
||||
the handle will switch back to autocommit mode again. If the mode could not
|
||||
be changed, an exception will be raised, as noted above.
|
||||
|
||||
When the database handle is closed or destroyed (or at request end for
|
||||
persistent handles), the driver will implicitly rollBack(). It is your
|
||||
responsibility to call commit() when you are done making changes and
|
||||
autocommit is turned off.
|
||||
|
||||
vim:tw=78:et
|
||||
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
$Id$
|
||||
|
||||
In no particular order:
|
||||
|
||||
Probable Bugs:
|
||||
- persistent connections with bound parameters might segv on subsequent
|
||||
requests
|
||||
|
||||
Low-level:
|
||||
|
||||
- $dbh->quote()
|
||||
- LOB support via Streams API
|
||||
- make errors generated at the pdo level (as opposed to driver level) use the
|
||||
selected error mode.
|
||||
|
||||
Not-so-low-level:
|
||||
- fetchAll(), single row, single column fetches etc.
|
||||
|
||||
Could be more...
|
||||
|
||||
vim:tw=78:et
|
||||
@@ -1,67 +0,0 @@
|
||||
dnl $Id$
|
||||
dnl config.m4 for extension pdo
|
||||
dnl vim:se ts=2 sw=2 et:
|
||||
|
||||
AC_ARG_WITH(broken-pear-install,
|
||||
[],[
|
||||
if test "x$withval" = "xyes"; then
|
||||
case $host_alias in
|
||||
*darwin*)
|
||||
AC_MSG_ERROR([
|
||||
Due to the way that loadable modules work on OSX/Darwin, you need to
|
||||
compile the PDO package statically into the PHP core.
|
||||
|
||||
Please follow the instructions at: http://netevil.org/node.php?nid=202
|
||||
for more detail on this issue.
|
||||
])
|
||||
;;
|
||||
*)
|
||||
AC_MSG_ERROR([
|
||||
Due to a bug in the pear installer you should install the PDO package manually
|
||||
using the following steps:
|
||||
|
||||
1. Download the PDO package to your local machine:
|
||||
|
||||
% wget http://pecl.php.net/get/PDO
|
||||
|
||||
2. Determine your PHP bin dir.
|
||||
If your php5 cli binary lives at /usr/local/php5/bin/php
|
||||
the bin dir is /usr/local/php5/bin
|
||||
|
||||
3. Set your path so that your PHP bin dir is at the front:
|
||||
export PATH="/usr/local/php5/bin:\$PATH"
|
||||
|
||||
4. Manually build:
|
||||
|
||||
% tar xzf PDO-0.2.tgz
|
||||
% cd PDO-0.2
|
||||
% phpize
|
||||
% ./configure
|
||||
% make
|
||||
% sudo -s
|
||||
# make install
|
||||
# echo extension=pdo.so >> /usr/local/php5/lib/php.ini
|
||||
|
||||
We apologize for the inconvenience, and hope to resolve this problem
|
||||
in a future PHP/PEAR release.
|
||||
|
||||
])
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
])
|
||||
|
||||
PHP_ARG_ENABLE(pdo, whether to disable PDO support,
|
||||
[ --disable-pdo Disable PHP Data Objects support], yes)
|
||||
|
||||
if test "$PHP_PDO" != "no"; then
|
||||
if test "$ext_shared" = "yes" ; then
|
||||
case $host_alias in
|
||||
*darwin*)
|
||||
ext_shared=no
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
PHP_NEW_EXTENSION(pdo, pdo.c pdo_dbh.c pdo_stmt.c pdo_sql_parser.c pdo_sqlstate.c, $ext_shared)
|
||||
PHP_ADD_MAKEFILE_FRAGMENT
|
||||
fi
|
||||
@@ -1,9 +0,0 @@
|
||||
// $Id$
|
||||
// vim:ft=javascript
|
||||
|
||||
ARG_ENABLE("pdo", "Enable PHP Data Objects support", "no");
|
||||
|
||||
if (PHP_PDO != "no") {
|
||||
EXTENSION('pdo', 'pdo.c pdo_dbh.c pdo_stmt.c pdo_sql_parser.c pdo_sqlstate.c');
|
||||
}
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!DOCTYPE package SYSTEM "../pear/package.dtd">
|
||||
<package version="1.0">
|
||||
<name>PDO</name>
|
||||
<summary>PHP Data Objects Interface</summary>
|
||||
<maintainers>
|
||||
<maintainer>
|
||||
<user>wez</user>
|
||||
<name>Wez Furlong</name>
|
||||
<email>wez@php.net</email>
|
||||
<role>lead</role>
|
||||
</maintainer>
|
||||
<maintainer>
|
||||
<user>helly</user>
|
||||
<name>Marcus Boerger</name>
|
||||
<email>helly@php.net</email>
|
||||
<role>lead</role>
|
||||
</maintainer>
|
||||
<maintainer>
|
||||
<user>iliaa</user>
|
||||
<name>Ilia Alshanetsky</name>
|
||||
<email>iliaa@php.net</email>
|
||||
<role>lead</role>
|
||||
</maintainer>
|
||||
<maintainer>
|
||||
<user>gschlossnagle</user>
|
||||
<name>George Schlossnagle</name>
|
||||
<email>george@omniti.com</email>
|
||||
<role>lead</role>
|
||||
</maintainer>
|
||||
</maintainers>
|
||||
|
||||
<!-- pear is still broken -->
|
||||
<configureoptions>
|
||||
<configureoption name="with-broken-pear-install" default="yes" prompt="the pear installer has a bug; press enter to find out more"/>
|
||||
</configureoptions>
|
||||
|
||||
|
||||
<description>
|
||||
PDO provides a uniform data access interface, sporting advanced features such
|
||||
as prepared statements and bound parameters. PDO drivers are dynamically
|
||||
loadable and may be developed independently from the core, but still accessed
|
||||
using the same API.
|
||||
|
||||
Read the documentation at http://www.php.net/pdo for more information.
|
||||
</description>
|
||||
<license>PHP</license>
|
||||
<release>
|
||||
<state>beta</state>
|
||||
<version>0.2.3</version>
|
||||
<date>2005-02-13</date>
|
||||
|
||||
<notes>
|
||||
Note that PDO on its own is useless.
|
||||
You need to install a PDO database driver to make use of it,
|
||||
check http://pecl.php.net for a list of available PDO drivers.
|
||||
|
||||
It is highly recommended that you update to the latest stable PHP 5 snapshot
|
||||
before using PDO.
|
||||
You can obtain it from http://snaps.php.net.
|
||||
|
||||
If you are running on Windows, you should download:
|
||||
http://snaps.php.net/win32/php5.0-win32-latest.zip
|
||||
http://snaps.php.net/win32/PECL_5_0/php_pdo.dll
|
||||
|
||||
You can find additional PDO drivers at:
|
||||
http://snaps.php.net/win32/PECL_5_0/
|
||||
|
||||
- Added PDO::quote($string). Closes PECL Bug #3393
|
||||
- Fixed PDO::query() for drivers using bound parameter emulation.
|
||||
- Fixed PECL Bug #3434, crash when using odbc with named parameters.
|
||||
|
||||
* Note: this release bumps the API number; you will need to rebuild
|
||||
your PDO drivers
|
||||
|
||||
</notes>
|
||||
|
||||
<filelist>
|
||||
<file role="src" name="config.m4"/>
|
||||
<file role="src" name="config.w32"/>
|
||||
<file role="src" name="pdo.c"/>
|
||||
<file role="src" name="pdo_dbh.c"/>
|
||||
<file role="src" name="pdo_stmt.c"/>
|
||||
<file role="src" name="php_pdo.h"/>
|
||||
<file role="src" name="php_pdo_driver.h"/>
|
||||
<file role="src" name="php_pdo_int.h"/>
|
||||
<file role="src" name="pdo_sql_parser.re"/>
|
||||
<file role="src" name="pdo_sql_parser.c"/>
|
||||
<file role="src" name="pdo_sqlstate.c"/>
|
||||
<file role="src" name="Makefile.frag"/>
|
||||
|
||||
<file role="doc" name="README"/>
|
||||
<file role="doc" name="TODO"/>
|
||||
<file role="doc" name="pdo.php"/>
|
||||
<file role="doc" name="CREDITS"/>
|
||||
</filelist>
|
||||
<deps>
|
||||
<dep type="php" rel="ge" version="5.0.3"/>
|
||||
</deps>
|
||||
</release>
|
||||
</package>
|
||||
-351
@@ -1,351 +0,0 @@
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| PHP Version 5 |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 1997-2005 The PHP Group |
|
||||
+----------------------------------------------------------------------+
|
||||
| This source file is subject to version 3.0 of the PHP license, |
|
||||
| that is bundled with this package in the file LICENSE, and is |
|
||||
| available through the world-wide-web at the following url: |
|
||||
| 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. |
|
||||
+----------------------------------------------------------------------+
|
||||
| Author: Wez Furlong <wez@php.net> |
|
||||
| Marcus Boerger <helly@php.net> |
|
||||
| Sterling Hughes <sterling@php.net> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <ctype.h>
|
||||
#include "php.h"
|
||||
#include "php_ini.h"
|
||||
#include "ext/standard/info.h"
|
||||
#include "php_pdo.h"
|
||||
#include "php_pdo_driver.h"
|
||||
#include "php_pdo_int.h"
|
||||
#include "zend_exceptions.h"
|
||||
|
||||
ZEND_DECLARE_MODULE_GLOBALS(pdo)
|
||||
|
||||
/* True global resources - no need for thread safety here */
|
||||
|
||||
/* the registry of PDO drivers */
|
||||
static HashTable pdo_driver_hash;
|
||||
|
||||
/* we use persistent resources for the driver connection stuff */
|
||||
static int le_ppdo;
|
||||
|
||||
int php_pdo_list_entry(void)
|
||||
{
|
||||
return le_ppdo;
|
||||
}
|
||||
|
||||
/* for exceptional circumstances */
|
||||
zend_class_entry *pdo_exception_ce;
|
||||
|
||||
PDO_API zend_class_entry *php_pdo_get_exception(void)
|
||||
{
|
||||
return pdo_exception_ce;
|
||||
}
|
||||
|
||||
zend_class_entry *pdo_dbh_ce, *pdo_dbstmt_ce, *pdo_row_ce;
|
||||
|
||||
/* {{{ pdo_functions[] */
|
||||
function_entry pdo_functions[] = {
|
||||
{NULL, NULL, NULL}
|
||||
};
|
||||
/* }}} */
|
||||
|
||||
/* {{{ pdo_module_entry */
|
||||
zend_module_entry pdo_module_entry = {
|
||||
STANDARD_MODULE_HEADER,
|
||||
"PDO",
|
||||
pdo_functions,
|
||||
PHP_MINIT(pdo),
|
||||
PHP_MSHUTDOWN(pdo),
|
||||
PHP_RINIT(pdo),
|
||||
PHP_RSHUTDOWN(pdo),
|
||||
PHP_MINFO(pdo),
|
||||
"0.2.3",
|
||||
STANDARD_MODULE_PROPERTIES
|
||||
};
|
||||
/* }}} */
|
||||
|
||||
#ifdef COMPILE_DL_PDO
|
||||
ZEND_GET_MODULE(pdo)
|
||||
#endif
|
||||
|
||||
/* {{{ PHP_INI */
|
||||
PHP_INI_BEGIN()
|
||||
STD_PHP_INI_ENTRY("pdo.global_value", "42", PHP_INI_ALL, OnUpdateLong, global_value, zend_pdo_globals, pdo_globals)
|
||||
PHP_INI_END()
|
||||
/* }}} */
|
||||
|
||||
/* {{{ php_pdo_init_globals */
|
||||
static void php_pdo_init_globals(zend_pdo_globals *pdo_globals)
|
||||
{
|
||||
pdo_globals->global_value = 0;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
PDO_API int php_pdo_register_driver(pdo_driver_t *driver)
|
||||
{
|
||||
if (driver->api_version != PDO_DRIVER_API) {
|
||||
zend_error(E_ERROR, "PDO: driver %s requires PDO API version %ld; this is PDO version %d",
|
||||
driver->driver_name, driver->api_version, PDO_DRIVER_API);
|
||||
return FAILURE;
|
||||
}
|
||||
if (!zend_hash_exists(&module_registry, "pdo", sizeof("pdo"))) {
|
||||
zend_error(E_ERROR, "You MUST load PDO before loading any PDO drivers");
|
||||
return FAILURE; /* NOTREACHED */
|
||||
}
|
||||
|
||||
return zend_hash_add(&pdo_driver_hash, (char*)driver->driver_name, driver->driver_name_len,
|
||||
(void**)&driver, sizeof(driver), NULL);
|
||||
}
|
||||
|
||||
PDO_API void php_pdo_unregister_driver(pdo_driver_t *driver)
|
||||
{
|
||||
if (!zend_hash_exists(&module_registry, "pdo", sizeof("pdo"))) {
|
||||
return;
|
||||
}
|
||||
|
||||
zend_hash_del(&pdo_driver_hash, (char*)driver->driver_name, driver->driver_name_len);
|
||||
}
|
||||
|
||||
pdo_driver_t *pdo_find_driver(const char *name, int namelen)
|
||||
{
|
||||
pdo_driver_t **driver = NULL;
|
||||
|
||||
zend_hash_find(&pdo_driver_hash, (char*)name, namelen, (void**)&driver);
|
||||
|
||||
return driver ? *driver : NULL;
|
||||
}
|
||||
|
||||
PDO_API int php_pdo_parse_data_source(const char *data_source,
|
||||
unsigned long data_source_len, struct pdo_data_src_parser *parsed,
|
||||
int nparams)
|
||||
{
|
||||
int i, j;
|
||||
int valstart = -1;
|
||||
int semi = -1;
|
||||
int optstart = 0;
|
||||
int nlen;
|
||||
int n_matches = 0;
|
||||
|
||||
i = 0;
|
||||
while (i < data_source_len) {
|
||||
/* looking for NAME= */
|
||||
|
||||
if (data_source[i] == '\0') {
|
||||
break;
|
||||
}
|
||||
|
||||
if (data_source[i] != '=') {
|
||||
++i;
|
||||
continue;
|
||||
}
|
||||
|
||||
valstart = ++i;
|
||||
|
||||
/* now we're looking for VALUE; or just VALUE<NUL> */
|
||||
semi = -1;
|
||||
while (i < data_source_len) {
|
||||
if (data_source[i] == '\0') {
|
||||
semi = i++;
|
||||
break;
|
||||
}
|
||||
if (data_source[i] == ';') {
|
||||
semi = i++;
|
||||
break;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
|
||||
if (semi == -1) {
|
||||
semi = i;
|
||||
}
|
||||
|
||||
/* find the entry in the array */
|
||||
nlen = valstart - optstart - 1;
|
||||
for (j = 0; j < nparams; j++) {
|
||||
if (0 == strncmp(data_source + optstart, parsed[j].optname, nlen) && parsed[j].optname[nlen] == '\0') {
|
||||
/* got a match */
|
||||
if (parsed[j].freeme) {
|
||||
efree(parsed[j].optval);
|
||||
}
|
||||
parsed[j].optval = estrndup(data_source + valstart, semi - valstart);
|
||||
parsed[j].freeme = 1;
|
||||
++n_matches;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
while (i < data_source_len && isspace(data_source[i])) {
|
||||
i++;
|
||||
}
|
||||
|
||||
optstart = i;
|
||||
}
|
||||
|
||||
return n_matches;
|
||||
}
|
||||
|
||||
|
||||
/* {{{ PHP_MINIT_FUNCTION */
|
||||
PHP_MINIT_FUNCTION(pdo)
|
||||
{
|
||||
zend_class_entry ce;
|
||||
|
||||
ZEND_INIT_MODULE_GLOBALS(pdo, php_pdo_init_globals, NULL);
|
||||
REGISTER_INI_ENTRIES();
|
||||
|
||||
if (FAILURE == pdo_sqlstate_init_error_table()) {
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
zend_hash_init(&pdo_driver_hash, 0, NULL, NULL, 1);
|
||||
|
||||
le_ppdo = zend_register_list_destructors_ex(NULL, php_pdo_pdbh_dtor,
|
||||
"PDO persistent database", module_number);
|
||||
|
||||
REGISTER_LONG_CONSTANT("PDO_PARAM_NULL", (long)PDO_PARAM_NULL, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PDO_PARAM_INT", (long)PDO_PARAM_INT, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PDO_PARAM_STR", (long)PDO_PARAM_STR, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PDO_PARAM_LOB", (long)PDO_PARAM_LOB, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PDO_PARAM_STMT", (long)PDO_PARAM_STMT, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PDO_PARAM_INPUT_OUTPUT", (long)PDO_PARAM_INPUT_OUTPUT, CONST_CS|CONST_PERSISTENT);
|
||||
|
||||
REGISTER_LONG_CONSTANT("PDO_FETCH_LAZY", (long)PDO_FETCH_LAZY, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PDO_FETCH_ASSOC",(long)PDO_FETCH_ASSOC, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PDO_FETCH_NUM", (long)PDO_FETCH_NUM, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PDO_FETCH_BOTH", (long)PDO_FETCH_BOTH, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PDO_FETCH_OBJ", (long)PDO_FETCH_OBJ, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PDO_FETCH_BOUND",(long)PDO_FETCH_BOUND, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PDO_FETCH_COLUMN",(long)PDO_FETCH_COLUMN, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PDO_FETCH_CLASS",(long)PDO_FETCH_CLASS, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PDO_FETCH_INTO", (long)PDO_FETCH_INTO, CONST_CS|CONST_PERSISTENT);
|
||||
|
||||
REGISTER_LONG_CONSTANT("PDO_ATTR_AUTOCOMMIT", (long)PDO_ATTR_AUTOCOMMIT, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PDO_ATTR_PREFETCH", (long)PDO_ATTR_PREFETCH, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PDO_ATTR_TIMEOUT", (long)PDO_ATTR_TIMEOUT, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PDO_ATTR_ERRMODE", (long)PDO_ATTR_ERRMODE, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PDO_ATTR_SERVER_VERSION", (long)PDO_ATTR_SERVER_VERSION, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PDO_ATTR_CLIENT_VERSION", (long)PDO_ATTR_CLIENT_VERSION, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PDO_ATTR_SERVER_INFO", (long)PDO_ATTR_SERVER_INFO, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PDO_ATTR_CONNECTION_STATUS", (long)PDO_ATTR_CONNECTION_STATUS, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PDO_ATTR_CASE", (long)PDO_ATTR_CASE, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PDO_ATTR_CURSOR_NAME", (long)PDO_ATTR_CURSOR_NAME, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PDO_ATTR_CURSOR", (long)PDO_ATTR_CURSOR, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PDO_ATTR_ORACLE_NULLS", (long)PDO_ATTR_ORACLE_NULLS, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PDO_ATTR_PERSISTENT", (long)PDO_ATTR_PERSISTENT, CONST_CS|CONST_PERSISTENT);
|
||||
|
||||
REGISTER_LONG_CONSTANT("PDO_ERRMODE_SILENT", (long)PDO_ERRMODE_SILENT, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PDO_ERRMODE_WARNING", (long)PDO_ERRMODE_WARNING, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PDO_ERRMODE_EXCEPTION", (long)PDO_ERRMODE_EXCEPTION, CONST_CS|CONST_PERSISTENT);
|
||||
|
||||
REGISTER_LONG_CONSTANT("PDO_CASE_NATURAL", (long)PDO_CASE_NATURAL, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PDO_CASE_LOWER", (long)PDO_CASE_LOWER, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PDO_CASE_UPPER", (long)PDO_CASE_UPPER, CONST_CS|CONST_PERSISTENT);
|
||||
|
||||
REGISTER_STRING_CONSTANT("PDO_ERR_NONE", PDO_ERR_NONE, CONST_CS|CONST_PERSISTENT);
|
||||
|
||||
REGISTER_LONG_CONSTANT("PDO_FETCH_ORI_NEXT", (long)PDO_FETCH_ORI_NEXT, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PDO_FETCH_ORI_PRIOR", (long)PDO_FETCH_ORI_PRIOR, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PDO_FETCH_ORI_FIRST", (long)PDO_FETCH_ORI_FIRST, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PDO_FETCH_ORI_LAST", (long)PDO_FETCH_ORI_LAST, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PDO_FETCH_ORI_ABS", (long)PDO_FETCH_ORI_ABS, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PDO_FETCH_ORI_REL", (long)PDO_FETCH_ORI_REL, CONST_CS|CONST_PERSISTENT);
|
||||
|
||||
REGISTER_LONG_CONSTANT("PDO_CURSOR_FWDONLY", (long)PDO_CURSOR_FWDONLY,CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PDO_CURSOR_SCROLL", (long)PDO_CURSOR_SCROLL,CONST_CS|CONST_PERSISTENT);
|
||||
|
||||
#if 0
|
||||
REGISTER_LONG_CONSTANT("PDO_ERR_CANT_MAP", (long)PDO_ERR_CANT_MAP, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PDO_ERR_SYNTAX", (long)PDO_ERR_SYNTAX, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PDO_ERR_CONSTRAINT", (long)PDO_ERR_CONSTRAINT, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PDO_ERR_NOT_FOUND", (long)PDO_ERR_NOT_FOUND, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PDO_ERR_ALREADY_EXISTS", (long)PDO_ERR_ALREADY_EXISTS, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PDO_ERR_NOT_IMPLEMENTED", (long)PDO_ERR_NOT_IMPLEMENTED, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PDO_ERR_MISMATCH", (long)PDO_ERR_MISMATCH, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PDO_ERR_TRUNCATED", (long)PDO_ERR_TRUNCATED, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PDO_ERR_DISCONNECTED", (long)PDO_ERR_DISCONNECTED, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PDO_ERR_NO_PERM", (long)PDO_ERR_NO_PERM, CONST_CS|CONST_PERSISTENT);
|
||||
#endif
|
||||
|
||||
INIT_CLASS_ENTRY(ce, "PDOException", NULL);
|
||||
pdo_exception_ce = zend_register_internal_class_ex(&ce, zend_exception_get_default(), NULL TSRMLS_CC);
|
||||
zend_declare_property_null(pdo_exception_ce, "errorInfo", sizeof("errorInfo")-1, ZEND_ACC_PUBLIC TSRMLS_CC);
|
||||
|
||||
INIT_CLASS_ENTRY(ce, "PDO", pdo_dbh_functions);
|
||||
ce.create_object = pdo_dbh_new;
|
||||
pdo_dbh_ce = zend_register_internal_class(&ce TSRMLS_CC);
|
||||
|
||||
INIT_CLASS_ENTRY(ce, "PDOStatement", pdo_dbstmt_functions);
|
||||
ce.create_object = pdo_dbstmt_new;
|
||||
pdo_dbstmt_ce = zend_register_internal_class(&ce TSRMLS_CC);
|
||||
pdo_dbstmt_ce->get_iterator = pdo_stmt_iter_get;
|
||||
|
||||
INIT_CLASS_ENTRY(ce, "PDORow", pdo_row_functions);
|
||||
ce.create_object = pdo_row_new;
|
||||
pdo_row_ce = zend_register_internal_class(&ce TSRMLS_CC);
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ PHP_MSHUTDOWN_FUNCTION */
|
||||
PHP_MSHUTDOWN_FUNCTION(pdo)
|
||||
{
|
||||
UNREGISTER_INI_ENTRIES();
|
||||
zend_hash_destroy(&pdo_driver_hash);
|
||||
pdo_sqlstate_fini_error_table();
|
||||
return SUCCESS;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ PHP_RINIT_FUNCTION */
|
||||
PHP_RINIT_FUNCTION(pdo)
|
||||
{
|
||||
return SUCCESS;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ PHP_RSHUTDOWN_FUNCTION */
|
||||
PHP_RSHUTDOWN_FUNCTION(pdo)
|
||||
{
|
||||
/* TODO: visit persistent handles: for each persistent statement handle,
|
||||
* remove bound parameter associations */
|
||||
return SUCCESS;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ PHP_MINFO_FUNCTION */
|
||||
PHP_MINFO_FUNCTION(pdo)
|
||||
{
|
||||
php_info_print_table_start();
|
||||
php_info_print_table_header(2, "pdo support", "enabled");
|
||||
php_info_print_table_end();
|
||||
|
||||
#if 0
|
||||
DISPLAY_INI_ENTRIES();
|
||||
#endif
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
* vim600: noet sw=4 ts=4 fdm=marker
|
||||
* vim<600: noet sw=4 ts=4
|
||||
*/
|
||||
@@ -1,62 +0,0 @@
|
||||
<?php
|
||||
dl('pdo.so');
|
||||
dl('pdo_sqlite.so');
|
||||
|
||||
//$x = new PDO("oci:dbname=hostname", 'php', 'php');
|
||||
$x = new PDO("sqlite::memory:");
|
||||
|
||||
$x->query("create table test(name string, value string)");
|
||||
debug_zval_dump($x);
|
||||
|
||||
$stmt = $x->prepare("INSERT INTO test (NAME, VALUE) VALUES (:name, :value)");
|
||||
|
||||
$stmt->bindParam(":name", $the_name, PDO_PARAM_STR, 32);
|
||||
$stmt->bindParam(":value", $the_value, PDO_PARAM_STR, 32);
|
||||
|
||||
for ($i = 0; $i < 4; $i++) {
|
||||
$the_name = "foo" . rand();
|
||||
$the_value = "bar" . rand();
|
||||
|
||||
if (!$stmt->execute()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$stmt = null;
|
||||
|
||||
echo "DEFAULT:\n";
|
||||
foreach ($x->query("select NAME, VALUE from test") as $row) {
|
||||
print_r($row);
|
||||
}
|
||||
|
||||
echo "OBJ:\n";
|
||||
|
||||
class Foo {
|
||||
public $NAME = "Don't change me";
|
||||
}
|
||||
|
||||
$foo = new foo;
|
||||
|
||||
foreach ($x->query("select NAME, VALUE from test", PDO_FETCH_COLUMN, 1) as $row) {
|
||||
debug_zval_dump($row);
|
||||
}
|
||||
|
||||
echo "Done\n";
|
||||
exit;
|
||||
|
||||
$stmt = $x->prepare("select NAME, VALUE from test where value like ?");
|
||||
$the_name = 'bar%';
|
||||
$stmt->execute(array($the_name)) or die("failed to execute!");
|
||||
$stmt->bindColumn('VALUE', $value);
|
||||
|
||||
while ($row = $stmt->fetch()) {
|
||||
echo "name=$row[NAME] value=$row[VALUE]\n";
|
||||
echo "value is $value\n";
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
echo "Let's try an update\n";
|
||||
|
||||
echo "All done\n";
|
||||
|
||||
?>
|
||||
-1120
File diff suppressed because it is too large.
Load diff
@@ -1,572 +0,0 @@
|
||||
/* Generated by re2c 0.9.3 on Sun Feb 13 00:25:51 2005 */
|
||||
#line 1 "pdo_sql_parser.re"
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| PHP Version 5 |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 1997-2004 The PHP Group |
|
||||
+----------------------------------------------------------------------+
|
||||
| This source file is subject to version 3.0 of the PHP license, |
|
||||
| that is bundled with this package in the file LICENSE, and is |
|
||||
| available through the world-wide-web at the following url: |
|
||||
| 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. |
|
||||
+----------------------------------------------------------------------+
|
||||
| Author: George Schlossnagle <george@omniti.com> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
#include "php.h"
|
||||
#include "php_pdo_driver.h"
|
||||
|
||||
#define PDO_PARSER_TEXT 1
|
||||
#define PDO_PARSER_BIND 2
|
||||
#define PDO_PARSER_BIND_POS 3
|
||||
#define PDO_PARSER_EOI 4
|
||||
|
||||
#define RET(i) {s->cur = cursor; return i; }
|
||||
|
||||
#define YYCTYPE char
|
||||
#define YYCURSOR cursor
|
||||
#define YYLIMIT s->lim
|
||||
#define YYMARKER s->ptr
|
||||
#define YYFILL(n)
|
||||
|
||||
typedef struct Scanner {
|
||||
char *lim, *ptr, *cur, *tok;
|
||||
} Scanner;
|
||||
|
||||
static int scan(Scanner *s)
|
||||
{
|
||||
char *cursor = s->cur;
|
||||
std:
|
||||
s->tok = cursor;
|
||||
#line 54 "pdo_sql_parser.re"
|
||||
|
||||
|
||||
|
||||
#line 7 "<stdout>"
|
||||
{
|
||||
YYCTYPE yych;
|
||||
unsigned int yyaccept;
|
||||
static unsigned char yybm[] = {
|
||||
0, 168, 168, 168, 168, 168, 168, 168,
|
||||
168, 168, 168, 168, 168, 168, 168, 168,
|
||||
168, 168, 168, 168, 168, 168, 168, 168,
|
||||
168, 168, 168, 168, 168, 168, 168, 168,
|
||||
168, 168, 0, 168, 168, 168, 168, 192,
|
||||
168, 168, 168, 168, 168, 168, 168, 168,
|
||||
184, 184, 184, 184, 184, 184, 184, 184,
|
||||
184, 184, 160, 168, 168, 168, 168, 160,
|
||||
168, 184, 184, 184, 184, 184, 184, 184,
|
||||
184, 184, 184, 184, 184, 184, 184, 184,
|
||||
184, 184, 184, 184, 184, 184, 184, 184,
|
||||
184, 184, 184, 168, 8, 168, 168, 184,
|
||||
168, 184, 184, 184, 184, 184, 184, 184,
|
||||
184, 184, 184, 184, 184, 184, 184, 184,
|
||||
184, 184, 184, 184, 184, 184, 184, 184,
|
||||
184, 184, 184, 168, 168, 168, 168, 168,
|
||||
168, 168, 168, 168, 168, 168, 168, 168,
|
||||
168, 168, 168, 168, 168, 168, 168, 168,
|
||||
168, 168, 168, 168, 168, 168, 168, 168,
|
||||
168, 168, 168, 168, 168, 168, 168, 168,
|
||||
168, 168, 168, 168, 168, 168, 168, 168,
|
||||
168, 168, 168, 168, 168, 168, 168, 168,
|
||||
168, 168, 168, 168, 168, 168, 168, 168,
|
||||
168, 168, 168, 168, 168, 168, 168, 168,
|
||||
168, 168, 168, 168, 168, 168, 168, 168,
|
||||
168, 168, 168, 168, 168, 168, 168, 168,
|
||||
168, 168, 168, 168, 168, 168, 168, 168,
|
||||
168, 168, 168, 168, 168, 168, 168, 168,
|
||||
168, 168, 168, 168, 168, 168, 168, 168,
|
||||
168, 168, 168, 168, 168, 168, 168, 168,
|
||||
168, 168, 168, 168, 168, 168, 168, 168,
|
||||
168, 168, 168, 168, 168, 168, 168, 168,
|
||||
};
|
||||
goto yy0;
|
||||
yy1: ++YYCURSOR;
|
||||
yy0:
|
||||
if((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
|
||||
yych = *YYCURSOR;
|
||||
if(yybm[0+yych] & 8) goto yy8;
|
||||
if(yych <= '\000') goto yy11;
|
||||
if(yych <= '&') goto yy2;
|
||||
if(yych <= '\'') goto yy4;
|
||||
if(yych <= '>') goto yy5;
|
||||
goto yy6;
|
||||
yy2: yyaccept = 0;
|
||||
yych = *(YYMARKER = ++YYCURSOR);
|
||||
if(yych >= '\001') goto yy24;
|
||||
goto yy3;
|
||||
yy3:
|
||||
#line 61 "pdo_sql_parser.re"
|
||||
{ RET(PDO_PARSER_TEXT); }
|
||||
#line 63 "<stdout>"
|
||||
yy4: yyaccept = 0;
|
||||
yych = *(YYMARKER = ++YYCURSOR);
|
||||
if(yych <= '\000') goto yy3;
|
||||
if(yych == '"') goto yy3;
|
||||
goto yy17;
|
||||
yy5: yych = *++YYCURSOR;
|
||||
if(yybm[0+yych] & 16) goto yy13;
|
||||
goto yy3;
|
||||
yy6: ++YYCURSOR;
|
||||
goto yy7;
|
||||
yy7:
|
||||
#line 60 "pdo_sql_parser.re"
|
||||
{ RET(PDO_PARSER_BIND_POS); }
|
||||
#line 77 "<stdout>"
|
||||
yy8: ++YYCURSOR;
|
||||
if(YYLIMIT == YYCURSOR) YYFILL(1);
|
||||
yych = *YYCURSOR;
|
||||
goto yy9;
|
||||
yy9: if(yybm[0+yych] & 8) goto yy8;
|
||||
goto yy10;
|
||||
yy10:
|
||||
#line 62 "pdo_sql_parser.re"
|
||||
{ RET(PDO_PARSER_TEXT); }
|
||||
#line 88 "<stdout>"
|
||||
yy11: ++YYCURSOR;
|
||||
goto yy12;
|
||||
yy12:
|
||||
#line 63 "pdo_sql_parser.re"
|
||||
{ RET(PDO_PARSER_EOI); }
|
||||
#line 94 "<stdout>"
|
||||
yy13: ++YYCURSOR;
|
||||
if(YYLIMIT == YYCURSOR) YYFILL(1);
|
||||
yych = *YYCURSOR;
|
||||
goto yy14;
|
||||
yy14: if(yybm[0+yych] & 16) goto yy13;
|
||||
goto yy15;
|
||||
yy15:
|
||||
#line 59 "pdo_sql_parser.re"
|
||||
{ RET(PDO_PARSER_BIND); }
|
||||
#line 105 "<stdout>"
|
||||
yy16: ++YYCURSOR;
|
||||
if(YYLIMIT == YYCURSOR) YYFILL(1);
|
||||
yych = *YYCURSOR;
|
||||
goto yy17;
|
||||
yy17: if(yybm[0+yych] & 32) goto yy16;
|
||||
if(yych <= '&') goto yy18;
|
||||
if(yych <= '\'') goto yy19;
|
||||
goto yy22;
|
||||
yy18: YYCURSOR = YYMARKER;
|
||||
switch(yyaccept){
|
||||
case 1: goto yy21;
|
||||
case 0: goto yy3;
|
||||
}
|
||||
yy19: yyaccept = 1;
|
||||
YYMARKER = ++YYCURSOR;
|
||||
if(YYLIMIT == YYCURSOR) YYFILL(1);
|
||||
yych = *YYCURSOR;
|
||||
goto yy20;
|
||||
yy20: if(yybm[0+yych] & 32) goto yy16;
|
||||
if(yych <= '&') goto yy21;
|
||||
if(yych <= '\'') goto yy19;
|
||||
goto yy22;
|
||||
yy21:
|
||||
#line 58 "pdo_sql_parser.re"
|
||||
{ RET(PDO_PARSER_TEXT); }
|
||||
#line 132 "<stdout>"
|
||||
yy22: ++YYCURSOR;
|
||||
if(YYLIMIT == YYCURSOR) YYFILL(1);
|
||||
yych = *YYCURSOR;
|
||||
if(yych == '\'') goto yy16;
|
||||
goto yy18;
|
||||
yy23: ++YYCURSOR;
|
||||
if(YYLIMIT == YYCURSOR) YYFILL(1);
|
||||
yych = *YYCURSOR;
|
||||
goto yy24;
|
||||
yy24: if(yybm[0+yych] & 128) goto yy23;
|
||||
if(yych <= '\000') goto yy18;
|
||||
if(yych <= '[') goto yy26;
|
||||
goto yy25;
|
||||
yy25: ++YYCURSOR;
|
||||
if(YYLIMIT == YYCURSOR) YYFILL(1);
|
||||
yych = *YYCURSOR;
|
||||
if(yych == '"') goto yy23;
|
||||
goto yy18;
|
||||
yy26: ++YYCURSOR;
|
||||
goto yy27;
|
||||
yy27:
|
||||
#line 57 "pdo_sql_parser.re"
|
||||
{ RET(PDO_PARSER_TEXT); }
|
||||
#line 159 "<stdout>"
|
||||
}
|
||||
#line 64 "pdo_sql_parser.re"
|
||||
|
||||
}
|
||||
|
||||
struct placeholder {
|
||||
char *pos;
|
||||
int len;
|
||||
int bindno;
|
||||
int qlen; /* quoted length of value */
|
||||
char *quoted; /* quoted value */
|
||||
int freeq;
|
||||
struct placeholder *next;
|
||||
};
|
||||
|
||||
PDO_API int pdo_parse_params(pdo_stmt_t *stmt, char *inquery, int inquery_len,
|
||||
char **outquery, int *outquery_len TSRMLS_DC)
|
||||
{
|
||||
Scanner s;
|
||||
char *ptr, *newbuffer;
|
||||
int t;
|
||||
int bindno = 0;
|
||||
int ret = 0;
|
||||
int newbuffer_len;
|
||||
HashTable *params;
|
||||
struct pdo_bound_param_data *param;
|
||||
int query_type = PDO_PLACEHOLDER_NONE;
|
||||
struct placeholder *placeholders = NULL, *placetail = NULL, *plc = NULL;
|
||||
|
||||
ptr = *outquery;
|
||||
s.cur = inquery;
|
||||
s.lim = inquery + inquery_len;
|
||||
|
||||
/* phase 1: look for args */
|
||||
while((t = scan(&s)) != PDO_PARSER_EOI) {
|
||||
if (t == PDO_PARSER_BIND || t == PDO_PARSER_BIND_POS) {
|
||||
if (t == PDO_PARSER_BIND) {
|
||||
query_type |= PDO_PLACEHOLDER_NAMED;
|
||||
} else {
|
||||
query_type |= PDO_PLACEHOLDER_POSITIONAL;
|
||||
}
|
||||
|
||||
plc = emalloc(sizeof(*plc));
|
||||
memset(plc, 0, sizeof(*plc));
|
||||
plc->next = NULL;
|
||||
plc->pos = s.tok;
|
||||
plc->len = s.cur - s.tok;
|
||||
plc->bindno = bindno++;
|
||||
|
||||
if (placetail) {
|
||||
placetail->next = plc;
|
||||
} else {
|
||||
placeholders = plc;
|
||||
}
|
||||
placetail = plc;
|
||||
}
|
||||
}
|
||||
|
||||
if (bindno == 0) {
|
||||
/* nothing to do; good! */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* did the query make sense to me? */
|
||||
if (query_type == (PDO_PLACEHOLDER_NAMED|PDO_PLACEHOLDER_POSITIONAL)) {
|
||||
/* they mixed both types; punt */
|
||||
pdo_raise_impl_error(stmt->dbh, stmt, "HY093", "mixed named and positional parameters" TSRMLS_CC);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (stmt->supports_placeholders == query_type) {
|
||||
/* query matches native syntax */
|
||||
ret = 0;
|
||||
goto clean_up;
|
||||
}
|
||||
|
||||
params = stmt->bound_params;
|
||||
|
||||
/* Do we have placeholders but no bound params */
|
||||
if (bindno && !params && stmt->supports_placeholders == PDO_PLACEHOLDER_NONE) {
|
||||
pdo_raise_impl_error(stmt->dbh, stmt, "HY093", "no parameters were bound" TSRMLS_CC);
|
||||
ret = -1;
|
||||
goto clean_up;
|
||||
}
|
||||
|
||||
/* what are we going to do ? */
|
||||
|
||||
if (stmt->supports_placeholders == PDO_PLACEHOLDER_NONE) {
|
||||
/* query generation */
|
||||
|
||||
newbuffer_len = inquery_len;
|
||||
|
||||
/* let's quote all the values */
|
||||
for (plc = placeholders; plc; plc = plc->next) {
|
||||
if (query_type == PDO_PLACEHOLDER_POSITIONAL) {
|
||||
ret = zend_hash_index_find(params, plc->bindno, (void**) ¶m);
|
||||
} else {
|
||||
ret = zend_hash_find(params, plc->pos, plc->len, (void**) ¶m);
|
||||
}
|
||||
if (ret == FAILURE) {
|
||||
/* parameter was not defined */
|
||||
ret = -1;
|
||||
pdo_raise_impl_error(stmt->dbh, stmt, "HY093", "parameter was not defined" TSRMLS_CC);
|
||||
goto clean_up;
|
||||
}
|
||||
if (stmt->dbh->methods->quoter) {
|
||||
if (param->param_type == PDO_PARAM_LOB && Z_TYPE_P(param->parameter) == IS_RESOURCE) {
|
||||
php_stream *stm;
|
||||
|
||||
php_stream_from_zval_no_verify(stm, ¶m->parameter);
|
||||
if (stm) {
|
||||
size_t len;
|
||||
char *buf = NULL;
|
||||
|
||||
len = php_stream_copy_to_mem(stm, &buf, PHP_STREAM_COPY_ALL, 0);
|
||||
if (!stmt->dbh->methods->quoter(stmt->dbh, buf, len, &plc->quoted, &plc->qlen,
|
||||
param->param_type TSRMLS_CC)) {
|
||||
/* bork */
|
||||
ret = -1;
|
||||
strcpy(stmt->error_code, stmt->dbh->error_code);
|
||||
efree(buf);
|
||||
goto clean_up;
|
||||
}
|
||||
efree(buf);
|
||||
|
||||
} else {
|
||||
pdo_raise_impl_error(stmt->dbh, stmt, "HY105", "Expected a stream resource" TSRMLS_CC);
|
||||
ret = -1;
|
||||
goto clean_up;
|
||||
}
|
||||
} else {
|
||||
convert_to_string(param->parameter);
|
||||
if (!stmt->dbh->methods->quoter(stmt->dbh, Z_STRVAL_P(param->parameter),
|
||||
Z_STRLEN_P(param->parameter), &plc->quoted, &plc->qlen,
|
||||
param->param_type TSRMLS_CC)) {
|
||||
/* bork */
|
||||
ret = -1;
|
||||
strcpy(stmt->error_code, stmt->dbh->error_code);
|
||||
goto clean_up;
|
||||
}
|
||||
}
|
||||
plc->freeq = 1;
|
||||
} else {
|
||||
plc->quoted = Z_STRVAL_P(param->parameter);
|
||||
plc->qlen = Z_STRLEN_P(param->parameter);
|
||||
}
|
||||
newbuffer_len += plc->qlen;
|
||||
}
|
||||
|
||||
rewrite:
|
||||
/* allocate output buffer */
|
||||
newbuffer = emalloc(newbuffer_len + 1);
|
||||
*outquery = newbuffer;
|
||||
|
||||
/* and build the query */
|
||||
plc = placeholders;
|
||||
ptr = inquery;
|
||||
|
||||
do {
|
||||
t = plc->pos - ptr;
|
||||
if (t) {
|
||||
memcpy(newbuffer, ptr, t);
|
||||
newbuffer += t;
|
||||
}
|
||||
memcpy(newbuffer, plc->quoted, plc->qlen);
|
||||
newbuffer += plc->qlen;
|
||||
ptr = plc->pos + plc->len;
|
||||
|
||||
plc = plc->next;
|
||||
} while (plc);
|
||||
|
||||
t = (inquery + inquery_len) - ptr;
|
||||
if (t) {
|
||||
memcpy(newbuffer, ptr, t);
|
||||
newbuffer += t;
|
||||
}
|
||||
*newbuffer = '\0';
|
||||
*outquery_len = newbuffer - *outquery;
|
||||
|
||||
ret = 1;
|
||||
goto clean_up;
|
||||
|
||||
} else if (query_type == PDO_PLACEHOLDER_POSITIONAL) {
|
||||
/* rewrite ? to :pdoX */
|
||||
char idxbuf[32];
|
||||
|
||||
newbuffer_len = inquery_len;
|
||||
|
||||
for (plc = placeholders; plc; plc = plc->next) {
|
||||
snprintf(idxbuf, sizeof(idxbuf), ":pdo%d", plc->bindno);
|
||||
plc->quoted = estrdup(idxbuf);
|
||||
plc->qlen = strlen(plc->quoted);
|
||||
plc->freeq = 1;
|
||||
newbuffer_len += plc->qlen;
|
||||
}
|
||||
|
||||
goto rewrite;
|
||||
|
||||
} else {
|
||||
/* rewrite :name to ? */
|
||||
|
||||
newbuffer_len = inquery_len;
|
||||
|
||||
if (stmt->bound_param_map == NULL) {
|
||||
ALLOC_HASHTABLE(stmt->bound_param_map);
|
||||
zend_hash_init(stmt->bound_param_map, 13, NULL, NULL, 0);
|
||||
}
|
||||
|
||||
for (plc = placeholders; plc; plc = plc->next) {
|
||||
char *name;
|
||||
|
||||
name = estrndup(plc->pos, plc->len);
|
||||
zend_hash_index_update(stmt->bound_param_map, plc->bindno, name, plc->len + 1, NULL);
|
||||
efree(name);
|
||||
plc->quoted = "?";
|
||||
plc->qlen = 1;
|
||||
}
|
||||
|
||||
goto rewrite;
|
||||
}
|
||||
|
||||
clean_up:
|
||||
|
||||
while (placeholders) {
|
||||
plc = placeholders;
|
||||
placeholders = plc->next;
|
||||
|
||||
if (plc->freeq) {
|
||||
efree(plc->quoted);
|
||||
}
|
||||
|
||||
efree(plc);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if 0
|
||||
int old_pdo_parse_params(pdo_stmt_t *stmt, char *inquery, int inquery_len, char **outquery,
|
||||
int *outquery_len TSRMLS_DC)
|
||||
{
|
||||
Scanner s;
|
||||
char *ptr;
|
||||
int t;
|
||||
int bindno = 0;
|
||||
int newbuffer_len;
|
||||
int padding;
|
||||
HashTable *params = stmt->bound_params;
|
||||
struct pdo_bound_param_data *param;
|
||||
/* allocate buffer for query with expanded binds, ptr is our writing pointer */
|
||||
newbuffer_len = inquery_len;
|
||||
|
||||
/* calculate the possible padding factor due to quoting */
|
||||
if(stmt->dbh->max_escaped_char_length) {
|
||||
padding = stmt->dbh->max_escaped_char_length;
|
||||
} else {
|
||||
padding = 3;
|
||||
}
|
||||
if(params) {
|
||||
zend_hash_internal_pointer_reset(params);
|
||||
while (SUCCESS == zend_hash_get_current_data(params, (void**)¶m)) {
|
||||
if(param->parameter) {
|
||||
convert_to_string(param->parameter);
|
||||
/* accomodate a string that needs to be fully quoted
|
||||
bind placeholders are at least 2 characters, so
|
||||
the accomodate their own "'s
|
||||
*/
|
||||
newbuffer_len += padding * Z_STRLEN_P(param->parameter);
|
||||
}
|
||||
zend_hash_move_forward(params);
|
||||
}
|
||||
}
|
||||
*outquery = (char *) emalloc(newbuffer_len + 1);
|
||||
*outquery_len = 0;
|
||||
|
||||
ptr = *outquery;
|
||||
s.cur = inquery;
|
||||
s.lim = inquery + inquery_len;
|
||||
while((t = scan(&s)) != PDO_PARSER_EOI) {
|
||||
if(t == PDO_PARSER_TEXT) {
|
||||
memcpy(ptr, s.tok, s.cur - s.tok);
|
||||
ptr += (s.cur - s.tok);
|
||||
*outquery_len += (s.cur - s.tok);
|
||||
}
|
||||
else if(t == PDO_PARSER_BIND) {
|
||||
if(!params) {
|
||||
/* error */
|
||||
efree(*outquery);
|
||||
*outquery = NULL;
|
||||
return (int) (s.cur - inquery);
|
||||
}
|
||||
/* lookup bind first via hash and then index */
|
||||
/* stupid keys need to be null-terminated, even though we know their length */
|
||||
if((SUCCESS == zend_hash_find(params, s.tok, s.cur-s.tok,(void **)¶m))
|
||||
||
|
||||
(SUCCESS == zend_hash_index_find(params, bindno, (void **)¶m)))
|
||||
{
|
||||
char *quotedstr;
|
||||
int quotedstrlen;
|
||||
/* restore the in-string key, doesn't need null-termination here */
|
||||
/* currently everything is a string here */
|
||||
|
||||
/* quote the bind value if necessary */
|
||||
if(stmt->dbh->methods->quoter(stmt->dbh, Z_STRVAL_P(param->parameter),
|
||||
Z_STRLEN_P(param->parameter), "edstr, "edstrlen TSRMLS_CC))
|
||||
{
|
||||
memcpy(ptr, quotedstr, quotedstrlen);
|
||||
ptr += quotedstrlen;
|
||||
*outquery_len += quotedstrlen;
|
||||
efree(quotedstr);
|
||||
} else {
|
||||
memcpy(ptr, Z_STRVAL_P(param->parameter), Z_STRLEN_P(param->parameter));
|
||||
ptr += Z_STRLEN_P(param->parameter);
|
||||
*outquery_len += (Z_STRLEN_P(param->parameter));
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* error and cleanup */
|
||||
efree(*outquery);
|
||||
*outquery = NULL;
|
||||
return (int) (s.cur - inquery);
|
||||
}
|
||||
bindno++;
|
||||
}
|
||||
else if(t == PDO_PARSER_BIND_POS) {
|
||||
if(!params) {
|
||||
/* error */
|
||||
efree(*outquery);
|
||||
*outquery = NULL;
|
||||
return (int) (s.cur - inquery);
|
||||
}
|
||||
/* lookup bind by index */
|
||||
if(SUCCESS == zend_hash_index_find(params, bindno, (void **)¶m))
|
||||
{
|
||||
char *quotedstr;
|
||||
int quotedstrlen;
|
||||
/* currently everything is a string here */
|
||||
|
||||
/* quote the bind value if necessary */
|
||||
if(stmt->dbh->methods->quoter(stmt->dbh, Z_STRVAL_P(param->parameter),
|
||||
Z_STRLEN_P(param->parameter), "edstr, "edstrlen TSRMLS_CC))
|
||||
{
|
||||
memcpy(ptr, quotedstr, quotedstrlen);
|
||||
ptr += quotedstrlen;
|
||||
*outquery_len += quotedstrlen;
|
||||
efree(quotedstr);
|
||||
} else {
|
||||
memcpy(ptr, Z_STRVAL_P(param->parameter), Z_STRLEN_P(param->parameter));
|
||||
ptr += Z_STRLEN_P(param->parameter);
|
||||
*outquery_len += (Z_STRLEN_P(param->parameter));
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* error and cleanup */
|
||||
efree(*outquery);
|
||||
*outquery = NULL;
|
||||
return (int) (s.cur - inquery);
|
||||
}
|
||||
bindno++;
|
||||
}
|
||||
}
|
||||
*ptr = '\0';
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
* vim600: noet sw=4 ts=4 fdm=marker ft=c
|
||||
* vim<600: noet sw=4 ts=4
|
||||
*/
|
||||
@@ -1,435 +0,0 @@
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| PHP Version 5 |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 1997-2004 The PHP Group |
|
||||
+----------------------------------------------------------------------+
|
||||
| This source file is subject to version 3.0 of the PHP license, |
|
||||
| that is bundled with this package in the file LICENSE, and is |
|
||||
| available through the world-wide-web at the following url: |
|
||||
| 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. |
|
||||
+----------------------------------------------------------------------+
|
||||
| Author: George Schlossnagle <george@omniti.com> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
#include "php.h"
|
||||
#include "php_pdo_driver.h"
|
||||
|
||||
#define PDO_PARSER_TEXT 1
|
||||
#define PDO_PARSER_BIND 2
|
||||
#define PDO_PARSER_BIND_POS 3
|
||||
#define PDO_PARSER_EOI 4
|
||||
|
||||
#define RET(i) {s->cur = cursor; return i; }
|
||||
|
||||
#define YYCTYPE char
|
||||
#define YYCURSOR cursor
|
||||
#define YYLIMIT s->lim
|
||||
#define YYMARKER s->ptr
|
||||
#define YYFILL(n)
|
||||
|
||||
typedef struct Scanner {
|
||||
char *lim, *ptr, *cur, *tok;
|
||||
} Scanner;
|
||||
|
||||
static int scan(Scanner *s)
|
||||
{
|
||||
char *cursor = s->cur;
|
||||
std:
|
||||
s->tok = cursor;
|
||||
/*!re2c
|
||||
BINDCHR = [:][a-zA-Z0-9_]+;
|
||||
QUESTION = [?];
|
||||
SPECIALS = [:?"'];
|
||||
ESCQQ = [\\]["];
|
||||
ESCQ = [\\]['];
|
||||
EOF = [\000];
|
||||
ANYNOEOF = [\001-\377];
|
||||
*/
|
||||
|
||||
/*!re2c
|
||||
(["] (ESCQQ|ANYNOEOF\[\\"])* ["]) { RET(PDO_PARSER_TEXT); }
|
||||
(['] (ESCQ|ANYNOEOF\[\\"])* [']) { RET(PDO_PARSER_TEXT); }
|
||||
BINDCHR { RET(PDO_PARSER_BIND); }
|
||||
QUESTION { RET(PDO_PARSER_BIND_POS); }
|
||||
SPECIALS { RET(PDO_PARSER_TEXT); }
|
||||
(ANYNOEOF\SPECIALS)+ { RET(PDO_PARSER_TEXT); }
|
||||
EOF { RET(PDO_PARSER_EOI); }
|
||||
*/
|
||||
}
|
||||
|
||||
struct placeholder {
|
||||
char *pos;
|
||||
int len;
|
||||
int bindno;
|
||||
int qlen; /* quoted length of value */
|
||||
char *quoted; /* quoted value */
|
||||
int freeq;
|
||||
struct placeholder *next;
|
||||
};
|
||||
|
||||
PDO_API int pdo_parse_params(pdo_stmt_t *stmt, char *inquery, int inquery_len,
|
||||
char **outquery, int *outquery_len TSRMLS_DC)
|
||||
{
|
||||
Scanner s;
|
||||
char *ptr, *newbuffer;
|
||||
int t;
|
||||
int bindno = 0;
|
||||
int ret = 0;
|
||||
int newbuffer_len;
|
||||
HashTable *params;
|
||||
struct pdo_bound_param_data *param;
|
||||
int query_type = PDO_PLACEHOLDER_NONE;
|
||||
struct placeholder *placeholders = NULL, *placetail = NULL, *plc = NULL;
|
||||
|
||||
ptr = *outquery;
|
||||
s.cur = inquery;
|
||||
s.lim = inquery + inquery_len;
|
||||
|
||||
/* phase 1: look for args */
|
||||
while((t = scan(&s)) != PDO_PARSER_EOI) {
|
||||
if (t == PDO_PARSER_BIND || t == PDO_PARSER_BIND_POS) {
|
||||
if (t == PDO_PARSER_BIND) {
|
||||
query_type |= PDO_PLACEHOLDER_NAMED;
|
||||
} else {
|
||||
query_type |= PDO_PLACEHOLDER_POSITIONAL;
|
||||
}
|
||||
|
||||
plc = emalloc(sizeof(*plc));
|
||||
memset(plc, 0, sizeof(*plc));
|
||||
plc->next = NULL;
|
||||
plc->pos = s.tok;
|
||||
plc->len = s.cur - s.tok;
|
||||
plc->bindno = bindno++;
|
||||
|
||||
if (placetail) {
|
||||
placetail->next = plc;
|
||||
} else {
|
||||
placeholders = plc;
|
||||
}
|
||||
placetail = plc;
|
||||
}
|
||||
}
|
||||
|
||||
if (bindno == 0) {
|
||||
/* nothing to do; good! */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* did the query make sense to me? */
|
||||
if (query_type == (PDO_PLACEHOLDER_NAMED|PDO_PLACEHOLDER_POSITIONAL)) {
|
||||
/* they mixed both types; punt */
|
||||
pdo_raise_impl_error(stmt->dbh, stmt, "HY093", "mixed named and positional parameters" TSRMLS_CC);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (stmt->supports_placeholders == query_type) {
|
||||
/* query matches native syntax */
|
||||
ret = 0;
|
||||
goto clean_up;
|
||||
}
|
||||
|
||||
params = stmt->bound_params;
|
||||
|
||||
/* Do we have placeholders but no bound params */
|
||||
if (bindno && !params && stmt->supports_placeholders == PDO_PLACEHOLDER_NONE) {
|
||||
pdo_raise_impl_error(stmt->dbh, stmt, "HY093", "no parameters were bound" TSRMLS_CC);
|
||||
ret = -1;
|
||||
goto clean_up;
|
||||
}
|
||||
|
||||
/* what are we going to do ? */
|
||||
|
||||
if (stmt->supports_placeholders == PDO_PLACEHOLDER_NONE) {
|
||||
/* query generation */
|
||||
|
||||
newbuffer_len = inquery_len;
|
||||
|
||||
/* let's quote all the values */
|
||||
for (plc = placeholders; plc; plc = plc->next) {
|
||||
if (query_type == PDO_PLACEHOLDER_POSITIONAL) {
|
||||
ret = zend_hash_index_find(params, plc->bindno, (void**) ¶m);
|
||||
} else {
|
||||
ret = zend_hash_find(params, plc->pos, plc->len, (void**) ¶m);
|
||||
}
|
||||
if (ret == FAILURE) {
|
||||
/* parameter was not defined */
|
||||
ret = -1;
|
||||
pdo_raise_impl_error(stmt->dbh, stmt, "HY093", "parameter was not defined" TSRMLS_CC);
|
||||
goto clean_up;
|
||||
}
|
||||
if (stmt->dbh->methods->quoter) {
|
||||
if (param->param_type == PDO_PARAM_LOB && Z_TYPE_P(param->parameter) == IS_RESOURCE) {
|
||||
php_stream *stm;
|
||||
|
||||
php_stream_from_zval_no_verify(stm, ¶m->parameter);
|
||||
if (stm) {
|
||||
size_t len;
|
||||
char *buf = NULL;
|
||||
|
||||
len = php_stream_copy_to_mem(stm, &buf, PHP_STREAM_COPY_ALL, 0);
|
||||
if (!stmt->dbh->methods->quoter(stmt->dbh, buf, len, &plc->quoted, &plc->qlen,
|
||||
param->param_type TSRMLS_CC)) {
|
||||
/* bork */
|
||||
ret = -1;
|
||||
strcpy(stmt->error_code, stmt->dbh->error_code);
|
||||
efree(buf);
|
||||
goto clean_up;
|
||||
}
|
||||
efree(buf);
|
||||
|
||||
} else {
|
||||
pdo_raise_impl_error(stmt->dbh, stmt, "HY105", "Expected a stream resource" TSRMLS_CC);
|
||||
ret = -1;
|
||||
goto clean_up;
|
||||
}
|
||||
} else {
|
||||
convert_to_string(param->parameter);
|
||||
if (!stmt->dbh->methods->quoter(stmt->dbh, Z_STRVAL_P(param->parameter),
|
||||
Z_STRLEN_P(param->parameter), &plc->quoted, &plc->qlen,
|
||||
param->param_type TSRMLS_CC)) {
|
||||
/* bork */
|
||||
ret = -1;
|
||||
strcpy(stmt->error_code, stmt->dbh->error_code);
|
||||
goto clean_up;
|
||||
}
|
||||
}
|
||||
plc->freeq = 1;
|
||||
} else {
|
||||
plc->quoted = Z_STRVAL_P(param->parameter);
|
||||
plc->qlen = Z_STRLEN_P(param->parameter);
|
||||
}
|
||||
newbuffer_len += plc->qlen;
|
||||
}
|
||||
|
||||
rewrite:
|
||||
/* allocate output buffer */
|
||||
newbuffer = emalloc(newbuffer_len + 1);
|
||||
*outquery = newbuffer;
|
||||
|
||||
/* and build the query */
|
||||
plc = placeholders;
|
||||
ptr = inquery;
|
||||
|
||||
do {
|
||||
t = plc->pos - ptr;
|
||||
if (t) {
|
||||
memcpy(newbuffer, ptr, t);
|
||||
newbuffer += t;
|
||||
}
|
||||
memcpy(newbuffer, plc->quoted, plc->qlen);
|
||||
newbuffer += plc->qlen;
|
||||
ptr = plc->pos + plc->len;
|
||||
|
||||
plc = plc->next;
|
||||
} while (plc);
|
||||
|
||||
t = (inquery + inquery_len) - ptr;
|
||||
if (t) {
|
||||
memcpy(newbuffer, ptr, t);
|
||||
newbuffer += t;
|
||||
}
|
||||
*newbuffer = '\0';
|
||||
*outquery_len = newbuffer - *outquery;
|
||||
|
||||
ret = 1;
|
||||
goto clean_up;
|
||||
|
||||
} else if (query_type == PDO_PLACEHOLDER_POSITIONAL) {
|
||||
/* rewrite ? to :pdoX */
|
||||
char idxbuf[32];
|
||||
|
||||
newbuffer_len = inquery_len;
|
||||
|
||||
for (plc = placeholders; plc; plc = plc->next) {
|
||||
snprintf(idxbuf, sizeof(idxbuf), ":pdo%d", plc->bindno);
|
||||
plc->quoted = estrdup(idxbuf);
|
||||
plc->qlen = strlen(plc->quoted);
|
||||
plc->freeq = 1;
|
||||
newbuffer_len += plc->qlen;
|
||||
}
|
||||
|
||||
goto rewrite;
|
||||
|
||||
} else {
|
||||
/* rewrite :name to ? */
|
||||
|
||||
newbuffer_len = inquery_len;
|
||||
|
||||
if (stmt->bound_param_map == NULL) {
|
||||
ALLOC_HASHTABLE(stmt->bound_param_map);
|
||||
zend_hash_init(stmt->bound_param_map, 13, NULL, NULL, 0);
|
||||
}
|
||||
|
||||
for (plc = placeholders; plc; plc = plc->next) {
|
||||
char *name;
|
||||
|
||||
name = estrndup(plc->pos, plc->len);
|
||||
zend_hash_index_update(stmt->bound_param_map, plc->bindno, name, plc->len + 1, NULL);
|
||||
efree(name);
|
||||
plc->quoted = "?";
|
||||
plc->qlen = 1;
|
||||
}
|
||||
|
||||
goto rewrite;
|
||||
}
|
||||
|
||||
clean_up:
|
||||
|
||||
while (placeholders) {
|
||||
plc = placeholders;
|
||||
placeholders = plc->next;
|
||||
|
||||
if (plc->freeq) {
|
||||
efree(plc->quoted);
|
||||
}
|
||||
|
||||
efree(plc);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if 0
|
||||
int old_pdo_parse_params(pdo_stmt_t *stmt, char *inquery, int inquery_len, char **outquery,
|
||||
int *outquery_len TSRMLS_DC)
|
||||
{
|
||||
Scanner s;
|
||||
char *ptr;
|
||||
int t;
|
||||
int bindno = 0;
|
||||
int newbuffer_len;
|
||||
int padding;
|
||||
HashTable *params = stmt->bound_params;
|
||||
struct pdo_bound_param_data *param;
|
||||
/* allocate buffer for query with expanded binds, ptr is our writing pointer */
|
||||
newbuffer_len = inquery_len;
|
||||
|
||||
/* calculate the possible padding factor due to quoting */
|
||||
if(stmt->dbh->max_escaped_char_length) {
|
||||
padding = stmt->dbh->max_escaped_char_length;
|
||||
} else {
|
||||
padding = 3;
|
||||
}
|
||||
if(params) {
|
||||
zend_hash_internal_pointer_reset(params);
|
||||
while (SUCCESS == zend_hash_get_current_data(params, (void**)¶m)) {
|
||||
if(param->parameter) {
|
||||
convert_to_string(param->parameter);
|
||||
/* accomodate a string that needs to be fully quoted
|
||||
bind placeholders are at least 2 characters, so
|
||||
the accomodate their own "'s
|
||||
*/
|
||||
newbuffer_len += padding * Z_STRLEN_P(param->parameter);
|
||||
}
|
||||
zend_hash_move_forward(params);
|
||||
}
|
||||
}
|
||||
*outquery = (char *) emalloc(newbuffer_len + 1);
|
||||
*outquery_len = 0;
|
||||
|
||||
ptr = *outquery;
|
||||
s.cur = inquery;
|
||||
s.lim = inquery + inquery_len;
|
||||
while((t = scan(&s)) != PDO_PARSER_EOI) {
|
||||
if(t == PDO_PARSER_TEXT) {
|
||||
memcpy(ptr, s.tok, s.cur - s.tok);
|
||||
ptr += (s.cur - s.tok);
|
||||
*outquery_len += (s.cur - s.tok);
|
||||
}
|
||||
else if(t == PDO_PARSER_BIND) {
|
||||
if(!params) {
|
||||
/* error */
|
||||
efree(*outquery);
|
||||
*outquery = NULL;
|
||||
return (int) (s.cur - inquery);
|
||||
}
|
||||
/* lookup bind first via hash and then index */
|
||||
/* stupid keys need to be null-terminated, even though we know their length */
|
||||
if((SUCCESS == zend_hash_find(params, s.tok, s.cur-s.tok,(void **)¶m))
|
||||
||
|
||||
(SUCCESS == zend_hash_index_find(params, bindno, (void **)¶m)))
|
||||
{
|
||||
char *quotedstr;
|
||||
int quotedstrlen;
|
||||
/* restore the in-string key, doesn't need null-termination here */
|
||||
/* currently everything is a string here */
|
||||
|
||||
/* quote the bind value if necessary */
|
||||
if(stmt->dbh->methods->quoter(stmt->dbh, Z_STRVAL_P(param->parameter),
|
||||
Z_STRLEN_P(param->parameter), "edstr, "edstrlen TSRMLS_CC))
|
||||
{
|
||||
memcpy(ptr, quotedstr, quotedstrlen);
|
||||
ptr += quotedstrlen;
|
||||
*outquery_len += quotedstrlen;
|
||||
efree(quotedstr);
|
||||
} else {
|
||||
memcpy(ptr, Z_STRVAL_P(param->parameter), Z_STRLEN_P(param->parameter));
|
||||
ptr += Z_STRLEN_P(param->parameter);
|
||||
*outquery_len += (Z_STRLEN_P(param->parameter));
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* error and cleanup */
|
||||
efree(*outquery);
|
||||
*outquery = NULL;
|
||||
return (int) (s.cur - inquery);
|
||||
}
|
||||
bindno++;
|
||||
}
|
||||
else if(t == PDO_PARSER_BIND_POS) {
|
||||
if(!params) {
|
||||
/* error */
|
||||
efree(*outquery);
|
||||
*outquery = NULL;
|
||||
return (int) (s.cur - inquery);
|
||||
}
|
||||
/* lookup bind by index */
|
||||
if(SUCCESS == zend_hash_index_find(params, bindno, (void **)¶m))
|
||||
{
|
||||
char *quotedstr;
|
||||
int quotedstrlen;
|
||||
/* currently everything is a string here */
|
||||
|
||||
/* quote the bind value if necessary */
|
||||
if(stmt->dbh->methods->quoter(stmt->dbh, Z_STRVAL_P(param->parameter),
|
||||
Z_STRLEN_P(param->parameter), "edstr, "edstrlen TSRMLS_CC))
|
||||
{
|
||||
memcpy(ptr, quotedstr, quotedstrlen);
|
||||
ptr += quotedstrlen;
|
||||
*outquery_len += quotedstrlen;
|
||||
efree(quotedstr);
|
||||
} else {
|
||||
memcpy(ptr, Z_STRVAL_P(param->parameter), Z_STRLEN_P(param->parameter));
|
||||
ptr += Z_STRLEN_P(param->parameter);
|
||||
*outquery_len += (Z_STRLEN_P(param->parameter));
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* error and cleanup */
|
||||
efree(*outquery);
|
||||
*outquery = NULL;
|
||||
return (int) (s.cur - inquery);
|
||||
}
|
||||
bindno++;
|
||||
}
|
||||
}
|
||||
*ptr = '\0';
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
* vim600: noet sw=4 ts=4 fdm=marker ft=c
|
||||
* vim<600: noet sw=4 ts=4
|
||||
*/
|
||||
@@ -1,190 +0,0 @@
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| PHP Version 5 |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 1997-2005 The PHP Group |
|
||||
+----------------------------------------------------------------------+
|
||||
| This source file is subject to version 3.0 of the PHP license, |
|
||||
| that is bundled with this package in the file LICENSE, and is |
|
||||
| available through the world-wide-web at the following url: |
|
||||
| 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. |
|
||||
+----------------------------------------------------------------------+
|
||||
| Author: Wez Furlong <wez@php.net> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "php.h"
|
||||
#include "php_ini.h"
|
||||
#include "ext/standard/info.h"
|
||||
#include "php_pdo.h"
|
||||
#include "php_pdo_driver.h"
|
||||
|
||||
struct pdo_sqlstate_info {
|
||||
char state[6];
|
||||
const char *desc;
|
||||
};
|
||||
|
||||
static HashTable err_hash;
|
||||
|
||||
static struct pdo_sqlstate_info err_initializer[] = {
|
||||
{ "00000", "No error" },
|
||||
{ "01001", "Cursor operation conflict" },
|
||||
{ "01002", "Disconnect error" },
|
||||
{ "01003", "NULL value eliminated in set function" },
|
||||
{ "01004", "String data, right truncated" },
|
||||
{ "01006", "Privilege not revoked" },
|
||||
{ "01007", "Privilege not granted" },
|
||||
{ "01S00", "Invalid connection string attribute" },
|
||||
{ "01S01", "Error in row" },
|
||||
{ "01S02", "Option value changed" },
|
||||
{ "01S06", "Attempt to fetch before the result set returned the first rowset" },
|
||||
{ "01S07", "Fractional truncation" },
|
||||
{ "01S08", "Error saving File DSN" },
|
||||
{ "01S09", "Invalid keyword" },
|
||||
{ "07002", "COUNT field incorrect" },
|
||||
{ "07005", "Prepared statement not a cursor-specification" },
|
||||
{ "07006", "Restricted data type attribute violation" },
|
||||
{ "07009", "Invalid descriptor index" },
|
||||
{ "07S01", "Invalid use of default parameter" },
|
||||
{ "08001", "Client unable to establish connection" },
|
||||
{ "08002", "Connection name in use" },
|
||||
{ "08003", "Connection does not exist" },
|
||||
{ "08004", "Server rejected the connection" },
|
||||
{ "08007", "Connection failure during transaction" },
|
||||
{ "08S01", "Communication link failure" },
|
||||
{ "21S01", "Insert value list does not match column list" },
|
||||
{ "21S02", "Degree of derived table does not match column list" },
|
||||
{ "22001", "String data, right truncated" },
|
||||
{ "22002", "Indicator variable required but not supplied" },
|
||||
{ "22003", "Numeric value out of range" },
|
||||
{ "22007", "Invalid datetime format" },
|
||||
{ "22008", "Datetime field overflow" },
|
||||
{ "22012", "Division by zero" },
|
||||
{ "22015", "Interval field overflow" },
|
||||
{ "22018", "Invalid character value for cast specification" },
|
||||
{ "22019", "Invalid escape character" },
|
||||
{ "22025", "Invalid escape sequence" },
|
||||
{ "22026", "String data, length mismatch" },
|
||||
{ "23000", "Integrity constraint violation" },
|
||||
{ "24000", "Invalid cursor state" },
|
||||
{ "25000", "Invalid transaction state" },
|
||||
{ "25S01", "Transaction state" },
|
||||
{ "25S02", "Transaction is still active" },
|
||||
{ "25S03", "Transaction is rolled back" },
|
||||
{ "28000", "Invalid authorization specification" },
|
||||
{ "34000", "Invalid cursor name" },
|
||||
{ "3C000", "Duplicate cursor name" },
|
||||
{ "3D000", "Invalid catalog name" },
|
||||
{ "3F000", "Invalid schema name" },
|
||||
{ "40001", "Serialization failure" },
|
||||
{ "40003", "Statement completion unknown" },
|
||||
{ "42000", "Syntax error or access violation" },
|
||||
{ "42S01", "Base table or view already exists" },
|
||||
{ "42S02", "Base table or view not found" },
|
||||
{ "42S11", "Index already exists" },
|
||||
{ "42S12", "Index not found" },
|
||||
{ "42S21", "Column already exists" },
|
||||
{ "42S22", "Column not found" },
|
||||
{ "44000", "WITH CHECK OPTION violation" },
|
||||
{ "HY000", "General error" },
|
||||
{ "HY001", "Memory allocation error" },
|
||||
{ "HY003", "Invalid application buffer type" },
|
||||
{ "HY004", "Invalid SQL data type" },
|
||||
{ "HY007", "Associated statement is not prepared" },
|
||||
{ "HY008", "Operation canceled" },
|
||||
{ "HY009", "Invalid use of null pointer" },
|
||||
{ "HY010", "Function sequence error" },
|
||||
{ "HY011", "Attribute cannot be set now" },
|
||||
{ "HY012", "Invalid transaction operation code" },
|
||||
{ "HY013", "Memory management error" },
|
||||
{ "HY014", "Limit on the number of handles exceeded" },
|
||||
{ "HY015", "No cursor name available" },
|
||||
{ "HY016", "Cannot modify an implementation row descriptor" },
|
||||
{ "HY017", "Invalid use of an automatically allocated descriptor handle" },
|
||||
{ "HY018", "Server declined cancel request" },
|
||||
{ "HY019", "Non-character and non-binary data sent in pieces" },
|
||||
{ "HY020", "Attempt to concatenate a null value" },
|
||||
{ "HY021", "Inconsistent descriptor information" },
|
||||
{ "HY024", "Invalid attribute value" },
|
||||
{ "HY090", "Invalid string or buffer length" },
|
||||
{ "HY091", "Invalid descriptor field identifier" },
|
||||
{ "HY092", "Invalid attribute/option identifier" },
|
||||
{ "HY093", "Invalid parameter number" },
|
||||
{ "HY095", "Function type out of range" },
|
||||
{ "HY096", "Invalid information type" },
|
||||
{ "HY097", "Column type out of range" },
|
||||
{ "HY098", "Scope type out of range" },
|
||||
{ "HY099", "Nullable type out of range" },
|
||||
{ "HY100", "Uniqueness option type out of range" },
|
||||
{ "HY101", "Accuracy option type out of range" },
|
||||
{ "HY103", "Invalid retrieval code" },
|
||||
{ "HY104", "Invalid precision or scale value" },
|
||||
{ "HY105", "Invalid parameter type" },
|
||||
{ "HY106", "Fetch type out of range" },
|
||||
{ "HY107", "Row value out of range" },
|
||||
{ "HY109", "Invalid cursor position" },
|
||||
{ "HY110", "Invalid driver completion" },
|
||||
{ "HY111", "Invalid bookmark value" },
|
||||
{ "HYC00", "Optional feature not implemented" },
|
||||
{ "HYT00", "Timeout expired" },
|
||||
{ "HYT01", "Connection timeout expired" },
|
||||
{ "IM001", "Driver does not support this function" },
|
||||
{ "IM002", "Data source name not found and no default driver specified" },
|
||||
{ "IM003", "Specified driver could not be loaded" },
|
||||
{ "IM004", "Driver's SQLAllocHandle on SQL_HANDLE_ENV failed" },
|
||||
{ "IM005", "Driver's SQLAllocHandle on SQL_HANDLE_DBC failed" },
|
||||
{ "IM006", "Driver's SQLSetConnectAttr failed" },
|
||||
{ "IM007", "No data source or driver specified; dialog prohibited" },
|
||||
{ "IM008", "Dialog failed" },
|
||||
{ "IM009", "Unable to load translation DLL" },
|
||||
{ "IM010", "Data source name too long" },
|
||||
{ "IM011", "Driver name too long" },
|
||||
{ "IM012", "DRIVER keyword syntax error" },
|
||||
{ "IM013", "Trace file error" },
|
||||
{ "IM014", "Invalid name of File DSN" },
|
||||
{ "IM015", "Corrupt file data source" }
|
||||
};
|
||||
|
||||
void pdo_sqlstate_fini_error_table(void)
|
||||
{
|
||||
zend_hash_destroy(&err_hash);
|
||||
}
|
||||
|
||||
int pdo_sqlstate_init_error_table(void)
|
||||
{
|
||||
int i;
|
||||
struct pdo_sqlstate_info *info;
|
||||
|
||||
if (FAILURE == zend_hash_init(&err_hash,
|
||||
sizeof(err_initializer)/sizeof(err_initializer[0]), NULL, NULL, 1)) {
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
for (i = 0; i < sizeof(err_initializer)/sizeof(err_initializer[0]); i++) {
|
||||
info = &err_initializer[i];
|
||||
|
||||
zend_hash_add(&err_hash, info->state, sizeof(info->state), &info, sizeof(info), NULL);
|
||||
}
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
const char *pdo_sqlstate_state_to_description(char *state)
|
||||
{
|
||||
struct pdo_sqlstate_info **info;
|
||||
if (SUCCESS == zend_hash_find(&err_hash, state, sizeof(err_initializer[0].state),
|
||||
(void**)&info)) {
|
||||
return (*info)->desc;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
-1626
File diff suppressed because it is too large.
Load diff
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| PHP Version 5 |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 1997-2005 The PHP Group |
|
||||
+----------------------------------------------------------------------+
|
||||
| This source file is subject to version 3.0 of the PHP license, |
|
||||
| that is bundled with this package in the file LICENSE, and is |
|
||||
| available through the world-wide-web at the following url: |
|
||||
| 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. |
|
||||
+----------------------------------------------------------------------+
|
||||
| Author: Wez Furlong <wez@php.net> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
#ifndef PHP_PDO_H
|
||||
#define PHP_PDO_H
|
||||
|
||||
#include "zend.h"
|
||||
|
||||
extern zend_module_entry pdo_module_entry;
|
||||
#define phpext_pdo_ptr &pdo_module_entry
|
||||
|
||||
#ifdef PHP_WIN32
|
||||
# ifdef PDO_EXPORTS
|
||||
# define PDO_API __declspec(dllexport)
|
||||
# elif defined(COMPILE_DL_PDO)
|
||||
# define PDO_API __declspec(dllimport)
|
||||
# else
|
||||
# define PDO_API /* nothing special */
|
||||
# endif
|
||||
#else
|
||||
# define PDO_API /* nothing special */
|
||||
#endif
|
||||
|
||||
#ifdef ZTS
|
||||
# include "TSRM.h"
|
||||
#endif
|
||||
|
||||
PHP_MINIT_FUNCTION(pdo);
|
||||
PHP_MSHUTDOWN_FUNCTION(pdo);
|
||||
PHP_RINIT_FUNCTION(pdo);
|
||||
PHP_RSHUTDOWN_FUNCTION(pdo);
|
||||
PHP_MINFO_FUNCTION(pdo);
|
||||
|
||||
ZEND_BEGIN_MODULE_GLOBALS(pdo)
|
||||
long global_value;
|
||||
ZEND_END_MODULE_GLOBALS(pdo)
|
||||
|
||||
#ifdef ZTS
|
||||
# define PDOG(v) TSRMG(pdo_globals_id, zend_pdo_globals *, v)
|
||||
#else
|
||||
# define PDOG(v) (pdo_globals.v)
|
||||
#endif
|
||||
|
||||
#endif /* PHP_PDO_H */
|
||||
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
* vim600: noet sw=4 ts=4 fdm=marker
|
||||
* vim<600: noet sw=4 ts=4
|
||||
*/
|
||||
@@ -1,573 +0,0 @@
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| PHP Version 5 |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 1997-2005 The PHP Group |
|
||||
+----------------------------------------------------------------------+
|
||||
| This source file is subject to version 3.0 of the PHP license, |
|
||||
| that is bundled with this package in the file LICENSE, and is |
|
||||
| available through the world-wide-web at the following url: |
|
||||
| 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. |
|
||||
+----------------------------------------------------------------------+
|
||||
| Author: Wez Furlong <wez@php.net> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
#ifndef PHP_PDO_DRIVER_H
|
||||
#define PHP_PDO_DRIVER_H
|
||||
|
||||
#include "php_pdo.h"
|
||||
|
||||
/* forward declarations */
|
||||
typedef struct _pdo_dbh_t pdo_dbh_t;
|
||||
typedef struct _pdo_stmt_t pdo_stmt_t;
|
||||
struct pdo_bound_param_data;
|
||||
|
||||
#ifndef TRUE
|
||||
# define TRUE 1
|
||||
#endif
|
||||
#ifndef FALSE
|
||||
# define FALSE 0
|
||||
#endif
|
||||
|
||||
#define PDO_DRIVER_API 20050213
|
||||
|
||||
enum pdo_param_type {
|
||||
PDO_PARAM_NULL,
|
||||
|
||||
/* int as in long (the php native int type).
|
||||
* If you mark a column as an int, PDO expects get_col to return
|
||||
* a pointer to a long */
|
||||
PDO_PARAM_INT,
|
||||
|
||||
/* get_col ptr should point to start of the string buffer */
|
||||
PDO_PARAM_STR,
|
||||
|
||||
/* get_col: when len is 0 ptr should point to a php_stream *,
|
||||
* otherwise it should behave like a string. Indicate a NULL field
|
||||
* value by setting the ptr to NULL */
|
||||
PDO_PARAM_LOB,
|
||||
|
||||
/* get_col: will expect the ptr to point to a new PDOStatement object handle,
|
||||
* but this isn't wired up yet */
|
||||
PDO_PARAM_STMT, /* hierarchical result set */
|
||||
|
||||
/* get_col ptr should point to a zend_bool */
|
||||
PDO_PARAM_BOOL,
|
||||
|
||||
|
||||
/* magic flag to denote a parameter as being input/output */
|
||||
PDO_PARAM_INPUT_OUTPUT = 0x80000000
|
||||
};
|
||||
|
||||
#define PDO_PARAM_TYPE(x) ((x) & ~PDO_PARAM_INPUT_OUTPUT)
|
||||
|
||||
enum pdo_fetch_type {
|
||||
PDO_FETCH_USE_DEFAULT,
|
||||
PDO_FETCH_LAZY,
|
||||
PDO_FETCH_ASSOC,
|
||||
PDO_FETCH_NUM,
|
||||
PDO_FETCH_BOTH,
|
||||
PDO_FETCH_OBJ,
|
||||
PDO_FETCH_BOUND, /* return true/false only; rely on bound columns */
|
||||
PDO_FETCH_COLUMN, /* fetch a numbered column only */
|
||||
PDO_FETCH_CLASS, /* create an instance of named class, call ctor and set properties */
|
||||
PDO_FETCH_INTO, /* fetch row into an existing object */
|
||||
PDO_FETCH__MAX /* must be last */
|
||||
};
|
||||
|
||||
/* fetch orientation for scrollable cursors */
|
||||
enum pdo_fetch_orientation {
|
||||
PDO_FETCH_ORI_NEXT, /* default: fetch the next available row */
|
||||
PDO_FETCH_ORI_PRIOR, /* scroll back to prior row and fetch that */
|
||||
PDO_FETCH_ORI_FIRST, /* scroll to the first row and fetch that */
|
||||
PDO_FETCH_ORI_LAST, /* scroll to the last row and fetch that */
|
||||
PDO_FETCH_ORI_ABS, /* scroll to an absolute numbered row and fetch that */
|
||||
PDO_FETCH_ORI_REL, /* scroll relative to the current row, and fetch that */
|
||||
};
|
||||
|
||||
enum pdo_attribute_type {
|
||||
PDO_ATTR_AUTOCOMMIT, /* use to turn on or off auto-commit mode */
|
||||
PDO_ATTR_PREFETCH, /* configure the prefetch size for drivers that support it. Size is in KB */
|
||||
PDO_ATTR_TIMEOUT, /* connection timeout in seconds */
|
||||
PDO_ATTR_ERRMODE, /* control how errors are handled */
|
||||
PDO_ATTR_SERVER_VERSION, /* database server version */
|
||||
PDO_ATTR_CLIENT_VERSION, /* client library version */
|
||||
PDO_ATTR_SERVER_INFO, /* server information */
|
||||
PDO_ATTR_CONNECTION_STATUS, /* connection status */
|
||||
PDO_ATTR_CASE, /* control case folding for portability */
|
||||
PDO_ATTR_CURSOR_NAME, /* name a cursor for use in "WHERE CURRENT OF <name>" */
|
||||
PDO_ATTR_CURSOR, /* cursor type */
|
||||
PDO_ATTR_ORACLE_NULLS, /* convert empty strings to NULL */
|
||||
PDO_ATTR_PERSISTENT, /* pconnect style connection */
|
||||
|
||||
/* this defines the start of the range for driver specific options.
|
||||
* Drivers should define their own attribute constants beginning with this
|
||||
* value. */
|
||||
PDO_ATTR_DRIVER_SPECIFIC = 1000
|
||||
};
|
||||
|
||||
enum pdo_cursor_type {
|
||||
PDO_CURSOR_FWDONLY, /* forward only cursor (default) */
|
||||
PDO_CURSOR_SCROLL, /* scrollable cursor */
|
||||
};
|
||||
|
||||
/* SQL-92 SQLSTATE error codes.
|
||||
|
||||
The character string value returned for an SQLSTATE consists of a two-character
|
||||
class value followed by a three-character subclass value. A class value of 01
|
||||
indicates a warning and is accompanied by a return code of
|
||||
SQL_SUCCESS_WITH_INFO.
|
||||
|
||||
Class values other than '01', except for the class 'IM',
|
||||
indicate an error and are accompanied by a return code of SQL_ERROR. The class
|
||||
'IM' is specific to warnings and errors that derive from the implementation of
|
||||
ODBC itself.
|
||||
|
||||
The subclass value '000' in any class indicates that there is no
|
||||
subclass for that SQLSTATE. The assignment of class and subclass values is
|
||||
defined by SQL-92.
|
||||
*/
|
||||
|
||||
typedef char pdo_error_type[6]; /* SQLSTATE */
|
||||
|
||||
|
||||
#define PDO_ERR_NONE "00000"
|
||||
#if 0
|
||||
/* generic error code values.
|
||||
* Don't want to go overboard with these.
|
||||
* */
|
||||
#define PDO_ERR_SYNTAX "42000"
|
||||
#define PDO_ERR_CONSTRAINT "23000"
|
||||
#define PDO_ERR_NOT_FOUND ""
|
||||
#define PDO_ERR_ALREADY_EXISTS,
|
||||
#define PDO_ERR_NOT_IMPLEMENTED,
|
||||
#define PDO_ERR_MISMATCH,
|
||||
#define PDO_ERR_TRUNCATED,
|
||||
#define PDO_ERR_DISCONNECTED,
|
||||
#define PDO_ERR_NO_PERM,
|
||||
|
||||
PDO_ERR_CANT_MAP, /* no way to map native error to the generic
|
||||
* codes; consult the native error for more info */
|
||||
};
|
||||
#endif
|
||||
|
||||
enum pdo_error_mode {
|
||||
PDO_ERRMODE_SILENT, /* just set error codes */
|
||||
PDO_ERRMODE_WARNING, /* raise E_WARNING */
|
||||
PDO_ERRMODE_EXCEPTION, /* throw exceptions */
|
||||
};
|
||||
|
||||
enum pdo_case_conversion {
|
||||
PDO_CASE_NATURAL,
|
||||
PDO_CASE_UPPER,
|
||||
PDO_CASE_LOWER
|
||||
};
|
||||
|
||||
/* {{{ utils for reading attributes set as driver_options */
|
||||
static inline long pdo_attr_lval(zval *options, enum pdo_fetch_type option_name, long defval TSRMLS_DC)
|
||||
{
|
||||
zval **v;
|
||||
|
||||
if (options && SUCCESS == zend_hash_index_find(Z_ARRVAL_P(options), option_name, (void**)&v)) {
|
||||
convert_to_long_ex(v);
|
||||
return Z_LVAL_PP(v);
|
||||
}
|
||||
return defval;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* This structure is registered with PDO when a PDO driver extension is
|
||||
* initialized */
|
||||
typedef struct {
|
||||
const char *driver_name;
|
||||
unsigned long driver_name_len;
|
||||
unsigned long api_version; /* needs to be compatible with PDO */
|
||||
|
||||
#define PDO_DRIVER_HEADER(name) \
|
||||
#name, sizeof(#name)-1, \
|
||||
PDO_DRIVER_API
|
||||
|
||||
/* create driver specific portion of the database handle and stash it into
|
||||
* the dbh. dbh contains the data source string and flags for this
|
||||
* instance. You MUST respect dbh->is_persistent and pass that flag to
|
||||
* pemalloc() for all allocations that are stored in the dbh or your instance
|
||||
* data in the db, otherwise you will crash PHP when persistent connections
|
||||
* are used.
|
||||
*/
|
||||
int (*db_handle_factory)(pdo_dbh_t *dbh, zval *driver_options TSRMLS_DC);
|
||||
|
||||
} pdo_driver_t;
|
||||
|
||||
/* {{{ methods for a database handle */
|
||||
|
||||
/* close or otherwise disconnect the database */
|
||||
typedef int (*pdo_dbh_close_func)(pdo_dbh_t *dbh TSRMLS_DC);
|
||||
|
||||
/* prepare a statement and stash driver specific portion into stmt */
|
||||
typedef int (*pdo_dbh_prepare_func)(pdo_dbh_t *dbh, const char *sql, long sql_len, pdo_stmt_t *stmt, zval *driver_options TSRMLS_DC);
|
||||
|
||||
/* execute a statement (that does not return a result set) */
|
||||
typedef long (*pdo_dbh_do_func)(pdo_dbh_t *dbh, const char *sql, long sql_len TSRMLS_DC);
|
||||
|
||||
/* quote a string */
|
||||
typedef int (*pdo_dbh_quote_func)(pdo_dbh_t *dbh, const char *unquoted, int unquotedlen, char **quoted, int *quotedlen, enum pdo_param_type paramtype TSRMLS_DC);
|
||||
|
||||
/* transaction related */
|
||||
typedef int (*pdo_dbh_txn_func)(pdo_dbh_t *dbh TSRMLS_DC);
|
||||
|
||||
/* setting of attributes */
|
||||
typedef int (*pdo_dbh_set_attr_func)(pdo_dbh_t *dbh, long attr, zval *val TSRMLS_DC);
|
||||
|
||||
/* return last insert id */
|
||||
typedef long (*pdo_dbh_last_id_func)(pdo_dbh_t *dbh TSRMLS_DC);
|
||||
|
||||
/* fetch error information. if stmt is not null, fetch information pertaining
|
||||
* to the statement, otherwise fetch global error information. The driver
|
||||
* should add the following information to the array "info" in this order:
|
||||
* - native error code
|
||||
* - string representation of the error code ... any other optional driver
|
||||
* specific data ... */
|
||||
typedef int (*pdo_dbh_fetch_error_func)(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info TSRMLS_DC);
|
||||
|
||||
/* fetching of attributes */
|
||||
typedef int (*pdo_dbh_get_attr_func)(pdo_dbh_t *dbh, long attr, zval *val TSRMLS_DC);
|
||||
|
||||
/* checking/pinging persistent connections; return SUCCESS if the connection
|
||||
* is still alive and ready to be used, FAILURE otherwise.
|
||||
* You may set this handler to NULL, which is equivalent to returning SUCCESS. */
|
||||
typedef int (*pdo_dbh_check_liveness_func)(pdo_dbh_t *dbh TSRMLS_DC);
|
||||
|
||||
/* for adding methods to the dbh or stmt objects
|
||||
pointer to a list of driver specific functions. The convention is
|
||||
to prefix the function names using the PDO driver name; this will
|
||||
reduce the chance of collisions with future functionality in the
|
||||
PDO class or in user code (they can extend the PDO object).
|
||||
*/
|
||||
enum {
|
||||
PDO_DBH_DRIVER_METHOD_KIND_DBH = 0,
|
||||
PDO_DBH_DRIVER_METHOD_KIND_STMT,
|
||||
PDO_DBH_DRIVER_METHOD_KIND__MAX
|
||||
};
|
||||
|
||||
typedef function_entry *(*pdo_dbh_get_driver_methods_func)(pdo_dbh_t *dbh, int kind TSRMLS_DC);
|
||||
|
||||
struct pdo_dbh_methods {
|
||||
pdo_dbh_close_func closer;
|
||||
pdo_dbh_prepare_func preparer;
|
||||
pdo_dbh_do_func doer;
|
||||
pdo_dbh_quote_func quoter;
|
||||
pdo_dbh_txn_func begin;
|
||||
pdo_dbh_txn_func commit;
|
||||
pdo_dbh_txn_func rollback;
|
||||
pdo_dbh_set_attr_func set_attribute;
|
||||
pdo_dbh_last_id_func last_id;
|
||||
pdo_dbh_fetch_error_func fetch_err;
|
||||
pdo_dbh_get_attr_func get_attribute;
|
||||
pdo_dbh_check_liveness_func check_liveness;
|
||||
pdo_dbh_get_driver_methods_func get_driver_methods;
|
||||
};
|
||||
|
||||
/* }}} */
|
||||
|
||||
/* {{{ methods for a statement handle */
|
||||
|
||||
/* free the statement handle */
|
||||
typedef int (*pdo_stmt_dtor_func)(pdo_stmt_t *stmt TSRMLS_DC);
|
||||
|
||||
/* start the query */
|
||||
typedef int (*pdo_stmt_execute_func)(pdo_stmt_t *stmt TSRMLS_DC);
|
||||
|
||||
/* causes the next row in the set to be fetched; indicates if there are no
|
||||
* more rows. The ori and offset params modify which row should be returned,
|
||||
* if the stmt represents a scrollable cursor */
|
||||
typedef int (*pdo_stmt_fetch_func)(pdo_stmt_t *stmt,
|
||||
enum pdo_fetch_orientation ori, long offset TSRMLS_DC);
|
||||
|
||||
/* queries information about the type of a column, by index (0 based).
|
||||
* Driver should populate stmt->columns[colno] with appropriate info */
|
||||
typedef int (*pdo_stmt_describe_col_func)(pdo_stmt_t *stmt, int colno TSRMLS_DC);
|
||||
|
||||
/* retrieves pointer and size of the value for a column.
|
||||
* Note that PDO expects the driver to manage the lifetime of this data;
|
||||
* it will copy the value into a zval on behalf of the script.
|
||||
* If the driver sets caller_frees, ptr should point to emalloc'd memory
|
||||
* and PDO will free it as soon as it is done using it.
|
||||
*/
|
||||
typedef int (*pdo_stmt_get_col_data_func)(pdo_stmt_t *stmt, int colno, char **ptr, unsigned long *len, int *caller_frees TSRMLS_DC);
|
||||
|
||||
/* hook for bound params */
|
||||
enum pdo_param_event {
|
||||
PDO_PARAM_EVT_ALLOC,
|
||||
PDO_PARAM_EVT_FREE,
|
||||
PDO_PARAM_EVT_EXEC_PRE,
|
||||
PDO_PARAM_EVT_EXEC_POST,
|
||||
PDO_PARAM_EVT_FETCH_PRE,
|
||||
PDO_PARAM_EVT_FETCH_POST,
|
||||
};
|
||||
|
||||
typedef int (*pdo_stmt_param_hook_func)(pdo_stmt_t *stmt, struct pdo_bound_param_data *param, enum pdo_param_event event_type TSRMLS_DC);
|
||||
|
||||
/* setting of attributes */
|
||||
typedef int (*pdo_stmt_set_attr_func)(pdo_stmt_t *stmt, long attr, zval *val TSRMLS_DC);
|
||||
|
||||
/* fetching of attributes */
|
||||
typedef int (*pdo_stmt_get_attr_func)(pdo_stmt_t *stmt, long attr, zval *val TSRMLS_DC);
|
||||
|
||||
/* retrieves meta data for a numbered column.
|
||||
* Returns SUCCESS/FAILURE.
|
||||
* On SUCCESS, fill in return_value with an array with the following fields.
|
||||
* If a particular field is not supported, then the driver simply does not add it to
|
||||
* the array, so that scripts can use isset() to check for it.
|
||||
*
|
||||
* ### this is just a rough first cut, and subject to change ###
|
||||
*
|
||||
* these are added by PDO itself, based on data from the describe handler:
|
||||
* name => the column name
|
||||
* len => the length/size of the column
|
||||
* precision => precision of the column
|
||||
* pdo_type => an integer, one of the PDO_PARAM_XXX values
|
||||
*
|
||||
* scale => the floating point scale
|
||||
* table => the table for that column
|
||||
* type => a string representation of the type, mapped to the PHP equivalent type name
|
||||
* native_type => a string representation of the type, native style, if different from
|
||||
* the mapped name.
|
||||
* flags => an array of flags including zero or more of the following:
|
||||
* primary_key, not_null, unique_key, multiple_key, unsigned, auto_increment, blob
|
||||
*
|
||||
* Any driver specific data should be returned using a prefixed key or value.
|
||||
* Eg: custom data for the mysql driver would use either
|
||||
* 'mysql:foobar' => 'some data' // to add a new key to the array
|
||||
* or
|
||||
* 'flags' => array('not_null', 'mysql:some_flag'); // to add data to an existing key
|
||||
*/
|
||||
typedef int (*pdo_stmt_get_column_meta_func)(pdo_stmt_t *stmt, long colno, zval *return_value TSRMLS_DC);
|
||||
|
||||
/* advances the statement to the next rowset of the batch.
|
||||
* If it returns 1, PDO will tear down its idea of columns
|
||||
* and meta data. If it returns 0, PDO will indicate an error
|
||||
* to the caller. */
|
||||
typedef int (*pdo_stmt_next_rowset_func)(pdo_stmt_t *stmt TSRMLS_DC);
|
||||
|
||||
struct pdo_stmt_methods {
|
||||
pdo_stmt_dtor_func dtor;
|
||||
pdo_stmt_execute_func executer;
|
||||
pdo_stmt_fetch_func fetcher;
|
||||
pdo_stmt_describe_col_func describer;
|
||||
pdo_stmt_get_col_data_func get_col;
|
||||
pdo_stmt_param_hook_func param_hook;
|
||||
pdo_stmt_set_attr_func set_attribute;
|
||||
pdo_stmt_get_attr_func get_attribute;
|
||||
pdo_stmt_get_column_meta_func get_column_meta;
|
||||
pdo_stmt_next_rowset_func next_rowset;
|
||||
};
|
||||
|
||||
/* }}} */
|
||||
|
||||
enum pdo_placeholder_support {
|
||||
PDO_PLACEHOLDER_NONE=0,
|
||||
PDO_PLACEHOLDER_NAMED=1,
|
||||
PDO_PLACEHOLDER_POSITIONAL=2
|
||||
};
|
||||
|
||||
/* represents a connection to a database */
|
||||
struct _pdo_dbh_t {
|
||||
/* these items must appear in this order at the beginning of the
|
||||
struct so that this can be cast as a zend_object. we need this
|
||||
to allow the extending class to escape all the custom handlers
|
||||
that PDO declares.
|
||||
*/
|
||||
zend_class_entry *ce;
|
||||
HashTable *properties;
|
||||
unsigned int in_get:1;
|
||||
unsigned int in_set:1;
|
||||
|
||||
/* driver specific methods */
|
||||
struct pdo_dbh_methods *methods;
|
||||
/* driver specific data */
|
||||
void *driver_data;
|
||||
|
||||
/* credentials */
|
||||
char *username, *password;
|
||||
|
||||
/* if true, then data stored and pointed at by this handle must all be
|
||||
* persistently allocated */
|
||||
unsigned is_persistent:1;
|
||||
|
||||
/* if true, driver should act as though a COMMIT were executed between
|
||||
* each executed statement; otherwise, COMMIT must be carried out manually
|
||||
* */
|
||||
unsigned auto_commit:1;
|
||||
|
||||
/* if true, the handle has been closed and will not function anymore */
|
||||
unsigned is_closed:1;
|
||||
|
||||
/* if true, the driver requires that memory be allocated explicitly for
|
||||
* the columns that are returned */
|
||||
unsigned alloc_own_columns:1;
|
||||
|
||||
/* if true, commit or rollBack is allowed to be called */
|
||||
unsigned in_txn:1;
|
||||
|
||||
/* max length a single character can become after correct quoting */
|
||||
unsigned max_escaped_char_length:3;
|
||||
|
||||
/* when set, convert empty strings to NULL */
|
||||
unsigned oracle_nulls:1;
|
||||
|
||||
/* the sum of the number of bits here and the bit fields preceeding should
|
||||
* equal 32 */
|
||||
unsigned _reserved_flags:23;
|
||||
|
||||
/* data source string used to open this handle */
|
||||
const char *data_source;
|
||||
unsigned long data_source_len;
|
||||
|
||||
/* the global error code. */
|
||||
pdo_error_type error_code;
|
||||
|
||||
enum pdo_error_mode error_mode;
|
||||
|
||||
enum pdo_case_conversion native_case, desired_case;
|
||||
|
||||
/* persistent hash key associated with this handle */
|
||||
const char *persistent_id;
|
||||
int persistent_id_len;
|
||||
unsigned int refcount;
|
||||
|
||||
/* driver specific "class" methods for the dbh and stmt */
|
||||
HashTable *cls_methods[PDO_DBH_DRIVER_METHOD_KIND__MAX];
|
||||
};
|
||||
|
||||
/* describes a column */
|
||||
struct pdo_column_data {
|
||||
char *name;
|
||||
long namelen;
|
||||
unsigned long maxlen;
|
||||
enum pdo_param_type param_type;
|
||||
unsigned long precision;
|
||||
};
|
||||
|
||||
/* describes a bound parameter */
|
||||
struct pdo_bound_param_data {
|
||||
long paramno; /* if -1, then it has a name, and we don't know the index *yet* */
|
||||
char *name;
|
||||
long namelen;
|
||||
|
||||
long max_value_len; /* as a hint for pre-allocation */
|
||||
|
||||
zval *parameter; /* the variable itself */
|
||||
enum pdo_param_type param_type; /* desired or suggested type */
|
||||
|
||||
zval *driver_params; /* optional parameter(s) for the driver */
|
||||
void *driver_data;
|
||||
|
||||
pdo_stmt_t *stmt; /* for convenience in dtor */
|
||||
int is_param; /* parameter or column ? */
|
||||
};
|
||||
|
||||
/* represents a prepared statement */
|
||||
struct _pdo_stmt_t {
|
||||
/* driver specifics */
|
||||
struct pdo_stmt_methods *methods;
|
||||
void *driver_data;
|
||||
|
||||
/* if true, we've already successfully executed this statement at least
|
||||
* once */
|
||||
unsigned executed:1;
|
||||
/* if true, the statement supports placeholders and can implement
|
||||
* bindParam() for its prepared statements, if false, PDO should
|
||||
* emulate prepare and bind on its behalf */
|
||||
unsigned supports_placeholders:2;
|
||||
|
||||
unsigned _reserved:29;
|
||||
|
||||
/* the number of columns in the result set; not valid until after
|
||||
* the statement has been executed at least once. In some cases, might
|
||||
* not be valid until fetch (at the driver level) has been called at least once.
|
||||
* */
|
||||
int column_count;
|
||||
struct pdo_column_data *columns;
|
||||
|
||||
/* we want to keep the dbh alive while we live, so we own a reference */
|
||||
zval database_object_handle;
|
||||
pdo_dbh_t *dbh;
|
||||
|
||||
/* keep track of bound input parameters. Some drivers support
|
||||
* input/output parameters, but you can't rely on that working */
|
||||
HashTable *bound_params;
|
||||
/* When rewriting from named to positional, this maps positions to names */
|
||||
HashTable *bound_param_map;
|
||||
/* keep track of PHP variables bound to named (or positional) columns
|
||||
* in the result set */
|
||||
HashTable *bound_columns;
|
||||
|
||||
/* not always meaningful */
|
||||
long row_count;
|
||||
|
||||
/* used to hold the statement's current query */
|
||||
char *query_string;
|
||||
int query_stringlen;
|
||||
|
||||
/* the copy of the query with expanded binds ONLY for emulated-prepare drivers */
|
||||
char *active_query_string;
|
||||
int active_query_stringlen;
|
||||
|
||||
/* the cursor specific error code. */
|
||||
pdo_error_type error_code;
|
||||
|
||||
/* for lazy fetches, we always return the same lazy object handle.
|
||||
* Let's keep it here. */
|
||||
zval lazy_object_ref;
|
||||
unsigned long refcount;
|
||||
|
||||
/* defaults for fetches */
|
||||
enum pdo_fetch_type default_fetch_type;
|
||||
union {
|
||||
int column;
|
||||
struct {
|
||||
zend_class_entry *ce;
|
||||
zval *ctor_args;
|
||||
} cls;
|
||||
zval *into;
|
||||
} fetch;
|
||||
};
|
||||
|
||||
/* call this in MINIT to register your PDO driver */
|
||||
PDO_API int php_pdo_register_driver(pdo_driver_t *driver);
|
||||
/* call this in MSHUTDOWN to unregister your PDO driver */
|
||||
PDO_API void php_pdo_unregister_driver(pdo_driver_t *driver);
|
||||
|
||||
/* For the convenience of drivers, this function will parse a data source
|
||||
* string, of the form "name=value; name2=value2" and populate variables
|
||||
* according to the data you pass in and array of pdo_data_src_parser structures */
|
||||
struct pdo_data_src_parser {
|
||||
const char *optname;
|
||||
char *optval;
|
||||
int freeme;
|
||||
};
|
||||
|
||||
PDO_API int php_pdo_parse_data_source(const char *data_source,
|
||||
unsigned long data_source_len, struct pdo_data_src_parser *parsed,
|
||||
int nparams);
|
||||
|
||||
PDO_API zend_class_entry *php_pdo_get_exception(void);
|
||||
|
||||
PDO_API int pdo_parse_params(pdo_stmt_t *stmt, char *inquery, int inquery_len,
|
||||
char **outquery, int *outquery_len TSRMLS_DC);
|
||||
|
||||
#endif /* PHP_PDO_DRIVER_H */
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
* vim600: noet sw=4 ts=4 fdm=marker
|
||||
* vim<600: noet sw=4 ts=4
|
||||
*/
|
||||
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| PHP Version 5 |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 1997-2005 The PHP Group |
|
||||
+----------------------------------------------------------------------+
|
||||
| This source file is subject to version 3.0 of the PHP license, |
|
||||
| that is bundled with this package in the file LICENSE, and is |
|
||||
| available through the world-wide-web at the following url: |
|
||||
| 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. |
|
||||
+----------------------------------------------------------------------+
|
||||
| Author: Wez Furlong <wez@php.net> |
|
||||
| Marcus Boerger <helly@php.net> |
|
||||
| Sterling Hughes <sterling@php.net> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Stuff private to the PDO extension and not for consumption by PDO drivers
|
||||
* */
|
||||
extern zend_class_entry *pdo_exception_ce;
|
||||
int php_pdo_list_entry(void);
|
||||
|
||||
extern zend_object_value pdo_dbh_new(zend_class_entry *ce TSRMLS_DC);
|
||||
extern function_entry pdo_dbh_functions[];
|
||||
extern zend_class_entry *pdo_dbh_ce;
|
||||
extern ZEND_RSRC_DTOR_FUNC(php_pdo_pdbh_dtor);
|
||||
|
||||
extern zend_object_value pdo_dbstmt_new(zend_class_entry *ce TSRMLS_DC);
|
||||
extern function_entry pdo_dbstmt_functions[];
|
||||
extern zend_class_entry *pdo_dbstmt_ce;
|
||||
void pdo_dbstmt_free_storage(zend_object *object TSRMLS_DC);
|
||||
zend_object_iterator *pdo_stmt_iter_get(zend_class_entry *ce, zval *object TSRMLS_DC);
|
||||
extern zend_object_handlers pdo_dbstmt_object_handlers;
|
||||
int pdo_stmt_describe_columns(pdo_stmt_t *stmt TSRMLS_DC);
|
||||
int pdo_stmt_setup_fetch_mode(INTERNAL_FUNCTION_PARAMETERS, pdo_stmt_t *stmt, int skip_first_arg);
|
||||
|
||||
extern zend_object_value pdo_row_new(zend_class_entry *ce TSRMLS_DC);
|
||||
extern function_entry pdo_row_functions[];
|
||||
extern zend_class_entry *pdo_row_ce;
|
||||
void pdo_row_free_storage(zend_object *object TSRMLS_DC);
|
||||
extern zend_object_handlers pdo_row_object_handlers;
|
||||
|
||||
zend_object_iterator *php_pdo_dbstmt_iter_get(zend_class_entry *ce, zval *object TSRMLS_DC);
|
||||
|
||||
extern pdo_driver_t *pdo_find_driver(const char *name, int namelen);
|
||||
|
||||
extern void pdo_handle_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt TSRMLS_DC);
|
||||
extern void pdo_raise_impl_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *sqlstate, const char *supp TSRMLS_DC);
|
||||
|
||||
#define PDO_DBH_CLEAR_ERR() strcpy(dbh->error_code, PDO_ERR_NONE)
|
||||
#define PDO_STMT_CLEAR_ERR() strcpy(stmt->error_code, PDO_ERR_NONE)
|
||||
#define PDO_HANDLE_DBH_ERR() if (strcmp(dbh->error_code, PDO_ERR_NONE)) { pdo_handle_error(dbh, NULL TSRMLS_CC); }
|
||||
#define PDO_HANDLE_STMT_ERR() if (strcmp(stmt->error_code, PDO_ERR_NONE)) { pdo_handle_error(stmt->dbh, stmt TSRMLS_CC); }
|
||||
|
||||
int pdo_sqlstate_init_error_table(void);
|
||||
void pdo_sqlstate_fini_error_table(void);
|
||||
const char *pdo_sqlstate_state_to_description(char *state);
|
||||
int pdo_hash_methods(pdo_dbh_t *dbh, int kind TSRMLS_DC);
|
||||
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
* vim600: noet sw=4 ts=4 fdm=marker
|
||||
* vim<600: noet sw=4 ts=4
|
||||
*/
|
||||
@@ -0,0 +1,198 @@
|
||||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.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. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Stig Bakken <ssb@fast.no> |
|
||||
// | |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id$
|
||||
|
||||
// {{{ uname examples
|
||||
|
||||
// php_uname() without args returns the same as 'uname -a', or a PHP-custom
|
||||
// string for Windows.
|
||||
// PHP versions prior to 4.3 return the uname of the host where PHP was built,
|
||||
// as of 4.3 it returns the uname of the host running the PHP code.
|
||||
//
|
||||
// PC RedHat Linux 7.1:
|
||||
// Linux host.example.com 2.4.2-2 #1 Sun Apr 8 20:41:30 EDT 2001 i686 unknown
|
||||
//
|
||||
// PC Debian Potato:
|
||||
// Linux host 2.4.17 #2 SMP Tue Feb 12 15:10:04 CET 2002 i686 unknown
|
||||
//
|
||||
// PC FreeBSD 3.3:
|
||||
// FreeBSD host.example.com 3.3-STABLE FreeBSD 3.3-STABLE #0: Mon Feb 21 00:42:31 CET 2000 root@example.com:/usr/src/sys/compile/CONFIG i386
|
||||
//
|
||||
// PC FreeBSD 4.3:
|
||||
// FreeBSD host.example.com 4.3-RELEASE FreeBSD 4.3-RELEASE #1: Mon Jun 25 11:19:43 EDT 2001 root@example.com:/usr/src/sys/compile/CONFIG i386
|
||||
//
|
||||
// PC FreeBSD 4.5:
|
||||
// FreeBSD host.example.com 4.5-STABLE FreeBSD 4.5-STABLE #0: Wed Feb 6 23:59:23 CET 2002 root@example.com:/usr/src/sys/compile/CONFIG i386
|
||||
//
|
||||
// PC FreeBSD 4.5 w/uname from GNU shellutils:
|
||||
// FreeBSD host.example.com 4.5-STABLE FreeBSD 4.5-STABLE #0: Wed Feb i386 unknown
|
||||
//
|
||||
// HP 9000/712 HP-UX 10:
|
||||
// HP-UX iq B.10.10 A 9000/712 2008429113 two-user license
|
||||
//
|
||||
// HP 9000/712 HP-UX 10 w/uname from GNU shellutils:
|
||||
// HP-UX host B.10.10 A 9000/712 unknown
|
||||
//
|
||||
// IBM RS6000/550 AIX 4.3:
|
||||
// AIX host 3 4 000003531C00
|
||||
//
|
||||
// AIX 4.3 w/uname from GNU shellutils:
|
||||
// AIX host 3 4 000003531C00 unknown
|
||||
//
|
||||
// SGI Onyx IRIX 6.5 w/uname from GNU shellutils:
|
||||
// IRIX64 host 6.5 01091820 IP19 mips
|
||||
//
|
||||
// SGI Onyx IRIX 6.5:
|
||||
// IRIX64 host 6.5 01091820 IP19
|
||||
//
|
||||
// SparcStation 20 Solaris 8 w/uname from GNU shellutils:
|
||||
// SunOS host.example.com 5.8 Generic_108528-12 sun4m sparc
|
||||
//
|
||||
// SparcStation 20 Solaris 8:
|
||||
// SunOS host.example.com 5.8 Generic_108528-12 sun4m sparc SUNW,SPARCstation-20
|
||||
//
|
||||
|
||||
// }}}
|
||||
|
||||
class OS_Guess
|
||||
{
|
||||
var $sysname;
|
||||
var $nodename;
|
||||
var $cpu;
|
||||
var $release;
|
||||
var $extra;
|
||||
|
||||
function OS_Guess($uname = null)
|
||||
{
|
||||
static $sysmap = array(
|
||||
'HP-UX' => 'hpux',
|
||||
'IRIX64' => 'irix',
|
||||
// Darwin?
|
||||
);
|
||||
static $cpumap = array(
|
||||
'i586' => 'i386',
|
||||
'i686' => 'i386',
|
||||
);
|
||||
if ($uname === null) {
|
||||
$uname = php_uname();
|
||||
}
|
||||
$parts = preg_split('/\s+/', trim($uname));
|
||||
$n = count($parts);
|
||||
|
||||
$this->release = $this->machine = $this->cpu = '';
|
||||
|
||||
$this->sysname = $parts[0];
|
||||
$nodename = $parts[1];
|
||||
$this->cpu = $parts[$n-1];
|
||||
if ($this->cpu == 'unknown') {
|
||||
$this->cpu = $parts[$n-2];
|
||||
}
|
||||
|
||||
switch ($this->sysname) {
|
||||
case 'AIX':
|
||||
$this->release = "$parts[3].$parts[2]";
|
||||
break;
|
||||
case 'Windows':
|
||||
$this->release = $parts[3];
|
||||
break;
|
||||
default:
|
||||
$this->release = preg_replace('/-.*/', '', $parts[2]);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (isset($sysmap[$this->sysname])) {
|
||||
$this->sysname = $sysmap[$this->sysname];
|
||||
} else {
|
||||
$this->sysname = strtolower($this->sysname);
|
||||
}
|
||||
if (isset($cpumap[$this->cpu])) {
|
||||
$this->cpu = $cpumap[$this->cpu];
|
||||
}
|
||||
}
|
||||
|
||||
function getSignature()
|
||||
{
|
||||
return "{$this->sysname}-{$this->release}-{$this->cpu}";
|
||||
}
|
||||
|
||||
function getSysname()
|
||||
{
|
||||
return $this->sysname;
|
||||
}
|
||||
|
||||
function getNodename()
|
||||
{
|
||||
return $this->nodename;
|
||||
}
|
||||
|
||||
function getCpu()
|
||||
{
|
||||
return $this->cpu;
|
||||
}
|
||||
|
||||
function getRelease()
|
||||
{
|
||||
return $this->release;
|
||||
}
|
||||
|
||||
function getExtra()
|
||||
{
|
||||
return $this->extra;
|
||||
}
|
||||
|
||||
function matchSignature($match)
|
||||
{
|
||||
$fragments = explode('-', $match);
|
||||
$n = count($fragments);
|
||||
$matches = 0;
|
||||
if ($n > 0) {
|
||||
$matches += $this->_matchFragment($fragments[0], $this->sysname);
|
||||
}
|
||||
if ($n > 1) {
|
||||
$matches += $this->_matchFragment($fragments[1], $this->release);
|
||||
}
|
||||
if ($n > 2) {
|
||||
$matches += $this->_matchFragment($fragments[2], $this->cpu);
|
||||
}
|
||||
if ($n > 3) {
|
||||
$matches += $this->_matchFragment($fragments[3], $this->extra);
|
||||
}
|
||||
return ($matches == $n);
|
||||
}
|
||||
|
||||
function _matchFragment($fragment, $value)
|
||||
{
|
||||
if (strcspn($fragment, '*?') < strlen($fragment)) {
|
||||
$preg = '/^' . str_replace(array('*', '?', '/'), array('.*', '.', '\\/'), $fragment) . '$/i';
|
||||
return preg_match($preg, $value);
|
||||
}
|
||||
return ($fragment == '*' || !strcasecmp($fragment, $value));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Local Variables:
|
||||
* indent-tabs-mode: nil
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
*/
|
||||
?>
|
||||
+927
@@ -0,0 +1,927 @@
|
||||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.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. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Sterling Hughes <sterling@php.net> |
|
||||
// | Stig Bakken <ssb@fast.no> |
|
||||
// | Tomas V.V.Cox <cox@idecnet.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
|
||||
define('PEAR_ERROR_RETURN', 1);
|
||||
define('PEAR_ERROR_PRINT', 2);
|
||||
define('PEAR_ERROR_TRIGGER', 4);
|
||||
define('PEAR_ERROR_DIE', 8);
|
||||
define('PEAR_ERROR_CALLBACK', 16);
|
||||
define('PEAR_ZE2', (function_exists('version_compare') &&
|
||||
version_compare(zend_version(), "2-dev", "ge")));
|
||||
|
||||
if (substr(PHP_OS, 0, 3) == 'WIN') {
|
||||
define('OS_WINDOWS', true);
|
||||
define('OS_UNIX', false);
|
||||
define('PEAR_OS', 'Windows');
|
||||
} else {
|
||||
define('OS_WINDOWS', false);
|
||||
define('OS_UNIX', true);
|
||||
define('PEAR_OS', 'Unix'); // blatant assumption
|
||||
}
|
||||
|
||||
$GLOBALS['_PEAR_default_error_mode'] = PEAR_ERROR_RETURN;
|
||||
$GLOBALS['_PEAR_default_error_options'] = E_USER_NOTICE;
|
||||
$GLOBALS['_PEAR_destructor_object_list'] = array();
|
||||
$GLOBALS['_PEAR_shutdown_funcs'] = array();
|
||||
$GLOBALS['_PEAR_error_handler_stack'] = array();
|
||||
|
||||
ini_set('track_errors', true);
|
||||
|
||||
/**
|
||||
* Base class for other PEAR classes. Provides rudimentary
|
||||
* emulation of destructors.
|
||||
*
|
||||
* If you want a destructor in your class, inherit PEAR and make a
|
||||
* destructor method called _yourclassname (same name as the
|
||||
* constructor, but with a "_" prefix). Also, in your constructor you
|
||||
* have to call the PEAR constructor: $this->PEAR();.
|
||||
* The destructor method will be called without parameters. Note that
|
||||
* at in some SAPI implementations (such as Apache), any output during
|
||||
* the request shutdown (in which destructors are called) seems to be
|
||||
* discarded. If you need to get any debug information from your
|
||||
* destructor, use error_log(), syslog() or something similar.
|
||||
*
|
||||
* IMPORTANT! To use the emulated destructors you need to create the
|
||||
* objects by reference, ej: $obj =& new PEAR_child;
|
||||
*
|
||||
* @since PHP 4.0.2
|
||||
* @author Stig Bakken <ssb@fast.no>
|
||||
* @see http://pear.php.net/manual/
|
||||
*/
|
||||
class PEAR
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* Whether to enable internal debug messages.
|
||||
*
|
||||
* @var bool
|
||||
* @access private
|
||||
*/
|
||||
var $_debug = false;
|
||||
|
||||
/**
|
||||
* Default error mode for this object.
|
||||
*
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $_default_error_mode = null;
|
||||
|
||||
/**
|
||||
* Default error options used for this object when error mode
|
||||
* is PEAR_ERROR_TRIGGER.
|
||||
*
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $_default_error_options = null;
|
||||
|
||||
/**
|
||||
* Default error handler (callback) for this object, if error mode is
|
||||
* PEAR_ERROR_CALLBACK.
|
||||
*
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_default_error_handler = '';
|
||||
|
||||
/**
|
||||
* Which class to use for error objects.
|
||||
*
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_error_class = 'PEAR_Error';
|
||||
|
||||
/**
|
||||
* An array of expected errors.
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_expected_errors = array();
|
||||
|
||||
// }}}
|
||||
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Constructor. Registers this object in
|
||||
* $_PEAR_destructor_object_list for destructor emulation if a
|
||||
* destructor object exists.
|
||||
*
|
||||
* @param string $error_class (optional) which class to use for
|
||||
* error objects, defaults to PEAR_Error.
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function PEAR($error_class = null)
|
||||
{
|
||||
$classname = get_class($this);
|
||||
if ($this->_debug) {
|
||||
print "PEAR constructor called, class=$classname\n";
|
||||
}
|
||||
if ($error_class !== null) {
|
||||
$this->_error_class = $error_class;
|
||||
}
|
||||
while ($classname) {
|
||||
$destructor = "_$classname";
|
||||
if (method_exists($this, $destructor)) {
|
||||
global $_PEAR_destructor_object_list;
|
||||
$_PEAR_destructor_object_list[] = &$this;
|
||||
break;
|
||||
} else {
|
||||
$classname = get_parent_class($classname);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ destructor
|
||||
|
||||
/**
|
||||
* Destructor (the emulated type of...). Does nothing right now,
|
||||
* but is included for forward compatibility, so subclass
|
||||
* destructors should always call it.
|
||||
*
|
||||
* See the note in the class desciption about output from
|
||||
* destructors.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function _PEAR() {
|
||||
if ($this->_debug) {
|
||||
printf("PEAR destructor called, class=%s\n", get_class($this));
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getStaticProperty()
|
||||
|
||||
/**
|
||||
* If you have a class that's mostly/entirely static, and you need static
|
||||
* properties, you can use this method to simulate them. Eg. in your method(s)
|
||||
* do this: $myVar = &PEAR::getStaticProperty('myVar');
|
||||
* You MUST use a reference, or they will not persist!
|
||||
*
|
||||
* @access public
|
||||
* @param string $class The calling classname, to prevent clashes
|
||||
* @param string $var The variable to retrieve.
|
||||
* @return mixed A reference to the variable. If not set it will be
|
||||
* auto initialised to NULL.
|
||||
*/
|
||||
function &getStaticProperty($class, $var)
|
||||
{
|
||||
static $properties;
|
||||
return $properties[$class][$var];
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ registerShutdownFunc()
|
||||
|
||||
/**
|
||||
* Use this function to register a shutdown method for static
|
||||
* classes.
|
||||
*
|
||||
* @access public
|
||||
* @param mixed $func The function name (or array of class/method) to call
|
||||
* @param mixed $args The arguments to pass to the function
|
||||
* @return void
|
||||
*/
|
||||
function registerShutdownFunc($func, $args = array())
|
||||
{
|
||||
$GLOBALS['_PEAR_shutdown_funcs'][] = array($func, $args);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ isError()
|
||||
|
||||
/**
|
||||
* Tell whether a value is a PEAR error.
|
||||
*
|
||||
* @param mixed $data the value to test
|
||||
* @access public
|
||||
* @return bool true if parameter is an error
|
||||
*/
|
||||
function isError($data) {
|
||||
return (bool)(is_object($data) &&
|
||||
(get_class($data) == 'pear_error' ||
|
||||
is_subclass_of($data, 'pear_error')));
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ setErrorHandling()
|
||||
|
||||
/**
|
||||
* Sets how errors generated by this DB object should be handled.
|
||||
* Can be invoked both in objects and statically. If called
|
||||
* statically, setErrorHandling sets the default behaviour for all
|
||||
* PEAR objects. If called in an object, setErrorHandling sets
|
||||
* the default behaviour for that object.
|
||||
*
|
||||
* @param int $mode
|
||||
* One of PEAR_ERROR_RETURN, PEAR_ERROR_PRINT,
|
||||
* PEAR_ERROR_TRIGGER, PEAR_ERROR_DIE or
|
||||
* PEAR_ERROR_CALLBACK.
|
||||
*
|
||||
* @param mixed $options
|
||||
* When $mode is PEAR_ERROR_TRIGGER, this is the error level (one
|
||||
* of E_USER_NOTICE, E_USER_WARNING or E_USER_ERROR).
|
||||
*
|
||||
* When $mode is PEAR_ERROR_CALLBACK, this parameter is expected
|
||||
* to be the callback function or method. A callback
|
||||
* function is a string with the name of the function, a
|
||||
* callback method is an array of two elements: the element
|
||||
* at index 0 is the object, and the element at index 1 is
|
||||
* the name of the method to call in the object.
|
||||
*
|
||||
* When $mode is PEAR_ERROR_PRINT or PEAR_ERROR_DIE, this is
|
||||
* a printf format string used when printing the error
|
||||
* message.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @see PEAR_ERROR_RETURN
|
||||
* @see PEAR_ERROR_PRINT
|
||||
* @see PEAR_ERROR_TRIGGER
|
||||
* @see PEAR_ERROR_DIE
|
||||
* @see PEAR_ERROR_CALLBACK
|
||||
*
|
||||
* @since PHP 4.0.5
|
||||
*/
|
||||
|
||||
function setErrorHandling($mode = null, $options = null)
|
||||
{
|
||||
if (isset($this)) {
|
||||
$setmode = &$this->_default_error_mode;
|
||||
$setoptions = &$this->_default_error_options;
|
||||
} else {
|
||||
$setmode = &$GLOBALS['_PEAR_default_error_mode'];
|
||||
$setoptions = &$GLOBALS['_PEAR_default_error_options'];
|
||||
}
|
||||
|
||||
switch ($mode) {
|
||||
case PEAR_ERROR_RETURN:
|
||||
case PEAR_ERROR_PRINT:
|
||||
case PEAR_ERROR_TRIGGER:
|
||||
case PEAR_ERROR_DIE:
|
||||
case null:
|
||||
$setmode = $mode;
|
||||
$setoptions = $options;
|
||||
break;
|
||||
|
||||
case PEAR_ERROR_CALLBACK:
|
||||
$setmode = $mode;
|
||||
if ((is_string($options) && function_exists($options)) ||
|
||||
(is_array($options) && method_exists(@$options[0], @$options[1])))
|
||||
{
|
||||
$setoptions = $options;
|
||||
} else {
|
||||
trigger_error("invalid error callback", E_USER_WARNING);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
trigger_error("invalid error mode", E_USER_WARNING);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ expectError()
|
||||
|
||||
/**
|
||||
* This method is used to tell which errors you expect to get.
|
||||
* Expected errors are always returned with error mode
|
||||
* PEAR_ERROR_RETURN. Expected error codes are stored in a stack,
|
||||
* and this method pushes a new element onto it. The list of
|
||||
* expected errors are in effect until they are popped off the
|
||||
* stack with the popExpect() method.
|
||||
*
|
||||
* Note that this method can not be called statically
|
||||
*
|
||||
* @param mixed $code a single error code or an array of error codes to expect
|
||||
*
|
||||
* @return int the new depth of the "expected errors" stack
|
||||
* @access public
|
||||
*/
|
||||
function expectError($code = '*')
|
||||
{
|
||||
if (is_array($code)) {
|
||||
array_push($this->_expected_errors, $code);
|
||||
} else {
|
||||
array_push($this->_expected_errors, array($code));
|
||||
}
|
||||
return sizeof($this->_expected_errors);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ popExpect()
|
||||
|
||||
/**
|
||||
* This method pops one element off the expected error codes
|
||||
* stack.
|
||||
*
|
||||
* @return array the list of error codes that were popped
|
||||
*/
|
||||
function popExpect()
|
||||
{
|
||||
return array_pop($this->_expected_errors);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ _checkDelExpect()
|
||||
|
||||
/**
|
||||
* This method checks unsets an error code if available
|
||||
*
|
||||
* @param mixed error code
|
||||
* @return bool true if the error code was unset, false otherwise
|
||||
* @access private
|
||||
* @since PHP 4.3.0
|
||||
*/
|
||||
function _checkDelExpect($error_code)
|
||||
{
|
||||
$deleted = false;
|
||||
|
||||
foreach ($this->_expected_errors AS $key => $error_array) {
|
||||
if (in_array($error_code, $error_array)) {
|
||||
unset($this->_expected_errors[$key][array_search($error_code, $error_array)]);
|
||||
$deleted = true;
|
||||
}
|
||||
|
||||
// clean up empty arrays
|
||||
if (0 == count($this->_expected_errors[$key])) {
|
||||
unset($this->_expected_errors[$key]);
|
||||
}
|
||||
}
|
||||
return $deleted;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ delExpect()
|
||||
|
||||
/**
|
||||
* This method deletes all occurences of the specified element from
|
||||
* the expected error codes stack.
|
||||
*
|
||||
* @param mixed $error_code error code that should be deleted
|
||||
* @return mixed list of error codes that were deleted or error
|
||||
* @access public
|
||||
* @since PHP 4.3.0
|
||||
*/
|
||||
function delExpect($error_code)
|
||||
{
|
||||
$deleted = false;
|
||||
|
||||
if ((is_array($error_code) && (0 != count($error_code)))) {
|
||||
// $error_code is a non-empty array here;
|
||||
// we walk through it trying to unset all
|
||||
// values
|
||||
foreach($error_code AS $key => $error) {
|
||||
if ($this->_checkDelExpect($error)) {
|
||||
$deleted = true;
|
||||
} else {
|
||||
$deleted = false;
|
||||
}
|
||||
}
|
||||
return $deleted ? true : PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME
|
||||
} elseif (!empty($error_code)) {
|
||||
// $error_code comes alone, trying to unset it
|
||||
if ($this->_checkDelExpect($error_code)) {
|
||||
return true;
|
||||
} else {
|
||||
return PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME
|
||||
}
|
||||
} else {
|
||||
// $error_code is empty
|
||||
return PEAR::raiseError("The expected error you submitted is empty"); // IMPROVE ME
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ raiseError()
|
||||
|
||||
/**
|
||||
* This method is a wrapper that returns an instance of the
|
||||
* configured error class with this object's default error
|
||||
* handling applied. If the $mode and $options parameters are not
|
||||
* specified, the object's defaults are used.
|
||||
*
|
||||
* @param mixed $message a text error message or a PEAR error object
|
||||
*
|
||||
* @param int $code a numeric error code (it is up to your class
|
||||
* to define these if you want to use codes)
|
||||
*
|
||||
* @param int $mode One of PEAR_ERROR_RETURN, PEAR_ERROR_PRINT,
|
||||
* PEAR_ERROR_TRIGGER, PEAR_ERROR_DIE or
|
||||
* PEAR_ERROR_CALLBACK.
|
||||
*
|
||||
* @param mixed $options If $mode is PEAR_ERROR_TRIGGER, this parameter
|
||||
* specifies the PHP-internal error level (one of
|
||||
* E_USER_NOTICE, E_USER_WARNING or E_USER_ERROR).
|
||||
* If $mode is PEAR_ERROR_CALLBACK, this
|
||||
* parameter specifies the callback function or
|
||||
* method. In other error modes this parameter
|
||||
* is ignored.
|
||||
*
|
||||
* @param string $userinfo If you need to pass along for example debug
|
||||
* information, this parameter is meant for that.
|
||||
*
|
||||
* @param string $error_class The returned error object will be
|
||||
* instantiated from this class, if specified.
|
||||
*
|
||||
* @param bool $skipmsg If true, raiseError will only pass error codes,
|
||||
* the error message parameter will be dropped.
|
||||
*
|
||||
* @access public
|
||||
* @return object a PEAR error object
|
||||
* @see PEAR::setErrorHandling
|
||||
* @since PHP 4.0.5
|
||||
*/
|
||||
function &raiseError($message = null,
|
||||
$code = null,
|
||||
$mode = null,
|
||||
$options = null,
|
||||
$userinfo = null,
|
||||
$error_class = null,
|
||||
$skipmsg = false)
|
||||
{
|
||||
// The error is yet a PEAR error object
|
||||
if (is_object($message)) {
|
||||
$code = $message->getCode();
|
||||
$userinfo = $message->getUserInfo();
|
||||
$error_class = $message->getType();
|
||||
$message = $message->getMessage();
|
||||
}
|
||||
|
||||
if (isset($this) && isset($this->_expected_errors) && sizeof($this->_expected_errors) > 0 && sizeof($exp = end($this->_expected_errors))) {
|
||||
if ($exp[0] == "*" ||
|
||||
(is_int(reset($exp)) && in_array($code, $exp)) ||
|
||||
(is_string(reset($exp)) && in_array($message, $exp))) {
|
||||
$mode = PEAR_ERROR_RETURN;
|
||||
}
|
||||
}
|
||||
// No mode given, try global ones
|
||||
if ($mode === null) {
|
||||
// Class error handler
|
||||
if (isset($this) && isset($this->_default_error_mode)) {
|
||||
$mode = $this->_default_error_mode;
|
||||
$options = $this->_default_error_options;
|
||||
// Global error handler
|
||||
} elseif (isset($GLOBALS['_PEAR_default_error_mode'])) {
|
||||
$mode = $GLOBALS['_PEAR_default_error_mode'];
|
||||
$options = $GLOBALS['_PEAR_default_error_options'];
|
||||
}
|
||||
}
|
||||
|
||||
if ($error_class !== null) {
|
||||
$ec = $error_class;
|
||||
} elseif (isset($this) && isset($this->_error_class)) {
|
||||
$ec = $this->_error_class;
|
||||
} else {
|
||||
$ec = 'PEAR_Error';
|
||||
}
|
||||
if ($skipmsg) {
|
||||
return new $ec($code, $mode, $options, $userinfo);
|
||||
} else {
|
||||
return new $ec($message, $code, $mode, $options, $userinfo);
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ throwError()
|
||||
|
||||
/**
|
||||
* Simpler form of raiseError with fewer options. In most cases
|
||||
* message, code and userinfo are enough.
|
||||
*
|
||||
* @param string $message
|
||||
*
|
||||
*/
|
||||
function &throwError($message = null,
|
||||
$code = null,
|
||||
$userinfo = null)
|
||||
{
|
||||
if (isset($this)) {
|
||||
return $this->raiseError($message, $code, null, null, $userinfo);
|
||||
} else {
|
||||
return PEAR::raiseError($message, $code, null, null, $userinfo);
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ pushErrorHandling()
|
||||
|
||||
/**
|
||||
* Push a new error handler on top of the error handler options stack. With this
|
||||
* you can easily override the actual error handler for some code and restore
|
||||
* it later with popErrorHandling.
|
||||
*
|
||||
* @param mixed $mode (same as setErrorHandling)
|
||||
* @param mixed $options (same as setErrorHandling)
|
||||
*
|
||||
* @return bool Always true
|
||||
*
|
||||
* @see PEAR::setErrorHandling
|
||||
*/
|
||||
function pushErrorHandling($mode, $options = null)
|
||||
{
|
||||
$stack = &$GLOBALS['_PEAR_error_handler_stack'];
|
||||
if (isset($this)) {
|
||||
$def_mode = &$this->_default_error_mode;
|
||||
$def_options = &$this->_default_error_options;
|
||||
} else {
|
||||
$def_mode = &$GLOBALS['_PEAR_default_error_mode'];
|
||||
$def_options = &$GLOBALS['_PEAR_default_error_options'];
|
||||
}
|
||||
$stack[] = array($def_mode, $def_options);
|
||||
|
||||
if (isset($this)) {
|
||||
$this->setErrorHandling($mode, $options);
|
||||
} else {
|
||||
PEAR::setErrorHandling($mode, $options);
|
||||
}
|
||||
$stack[] = array($mode, $options);
|
||||
return true;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ popErrorHandling()
|
||||
|
||||
/**
|
||||
* Pop the last error handler used
|
||||
*
|
||||
* @return bool Always true
|
||||
*
|
||||
* @see PEAR::pushErrorHandling
|
||||
*/
|
||||
function popErrorHandling()
|
||||
{
|
||||
$stack = &$GLOBALS['_PEAR_error_handler_stack'];
|
||||
array_pop($stack);
|
||||
list($mode, $options) = $stack[sizeof($stack) - 1];
|
||||
array_pop($stack);
|
||||
if (isset($this)) {
|
||||
$this->setErrorHandling($mode, $options);
|
||||
} else {
|
||||
PEAR::setErrorHandling($mode, $options);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ loadExtension()
|
||||
|
||||
/**
|
||||
* OS independant PHP extension load. Remember to take care
|
||||
* on the correct extension name for case sensitive OSes.
|
||||
*
|
||||
* @param string $ext The extension name
|
||||
* @return bool Success or not on the dl() call
|
||||
*/
|
||||
function loadExtension($ext)
|
||||
{
|
||||
if (!extension_loaded($ext)) {
|
||||
if (OS_WINDOWS) {
|
||||
$suffix = '.dll';
|
||||
} elseif (PHP_OS == 'HP-UX') {
|
||||
$suffix = '.sl';
|
||||
} elseif (PHP_OS == 'AIX') {
|
||||
$suffix = '.a';
|
||||
} elseif (PHP_OS == 'OSX') {
|
||||
$suffix = '.bundle';
|
||||
} else {
|
||||
$suffix = '.so';
|
||||
}
|
||||
return @dl('php_'.$ext.$suffix) || @dl($ext.$suffix);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// }}}
|
||||
}
|
||||
|
||||
// {{{ _PEAR_call_destructors()
|
||||
|
||||
function _PEAR_call_destructors()
|
||||
{
|
||||
global $_PEAR_destructor_object_list;
|
||||
if (is_array($_PEAR_destructor_object_list) &&
|
||||
sizeof($_PEAR_destructor_object_list))
|
||||
{
|
||||
reset($_PEAR_destructor_object_list);
|
||||
while (list($k, $objref) = each($_PEAR_destructor_object_list)) {
|
||||
$classname = get_class($objref);
|
||||
while ($classname) {
|
||||
$destructor = "_$classname";
|
||||
if (method_exists($objref, $destructor)) {
|
||||
$objref->$destructor();
|
||||
break;
|
||||
} else {
|
||||
$classname = get_parent_class($classname);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Empty the object list to ensure that destructors are
|
||||
// not called more than once.
|
||||
$_PEAR_destructor_object_list = array();
|
||||
}
|
||||
|
||||
// Now call the shutdown functions
|
||||
if (is_array($GLOBALS['_PEAR_shutdown_funcs']) AND !empty($GLOBALS['_PEAR_shutdown_funcs'])) {
|
||||
foreach ($GLOBALS['_PEAR_shutdown_funcs'] as $value) {
|
||||
call_user_func_array($value[0], $value[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
class PEAR_Error
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
var $error_message_prefix = '';
|
||||
var $mode = PEAR_ERROR_RETURN;
|
||||
var $level = E_USER_NOTICE;
|
||||
var $code = -1;
|
||||
var $message = '';
|
||||
var $userinfo = '';
|
||||
|
||||
// Wait until we have a stack-groping function in PHP.
|
||||
//var $file = '';
|
||||
//var $line = 0;
|
||||
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* PEAR_Error constructor
|
||||
*
|
||||
* @param string $message message
|
||||
*
|
||||
* @param int $code (optional) error code
|
||||
*
|
||||
* @param int $mode (optional) error mode, one of: PEAR_ERROR_RETURN,
|
||||
* PEAR_ERROR_PRINT, PEAR_ERROR_DIE, PEAR_ERROR_TRIGGER or
|
||||
* PEAR_ERROR_CALLBACK
|
||||
*
|
||||
* @param mixed $options (optional) error level, _OR_ in the case of
|
||||
* PEAR_ERROR_CALLBACK, the callback function or object/method
|
||||
* tuple.
|
||||
*
|
||||
* @param string $userinfo (optional) additional user/debug info
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
*/
|
||||
function PEAR_Error($message = 'unknown error', $code = null,
|
||||
$mode = null, $options = null, $userinfo = null)
|
||||
{
|
||||
if ($mode === null) {
|
||||
$mode = PEAR_ERROR_RETURN;
|
||||
}
|
||||
$this->message = $message;
|
||||
$this->code = $code;
|
||||
$this->mode = $mode;
|
||||
$this->userinfo = $userinfo;
|
||||
if ($mode & PEAR_ERROR_CALLBACK) {
|
||||
$this->level = E_USER_NOTICE;
|
||||
$this->callback = $options;
|
||||
} else {
|
||||
if ($options === null) {
|
||||
$options = E_USER_NOTICE;
|
||||
}
|
||||
$this->level = $options;
|
||||
$this->callback = null;
|
||||
}
|
||||
if ($this->mode & PEAR_ERROR_PRINT) {
|
||||
if (is_null($options) || is_int($options)) {
|
||||
$format = "%s";
|
||||
} else {
|
||||
$format = $options;
|
||||
}
|
||||
printf($format, $this->getMessage());
|
||||
}
|
||||
if ($this->mode & PEAR_ERROR_TRIGGER) {
|
||||
trigger_error($this->getMessage(), $this->level);
|
||||
}
|
||||
if ($this->mode & PEAR_ERROR_DIE) {
|
||||
$msg = $this->getMessage();
|
||||
if (is_null($options) || is_int($options)) {
|
||||
$format = "%s";
|
||||
if (substr($msg, -1) != "\n") {
|
||||
$msg .= "\n";
|
||||
}
|
||||
} else {
|
||||
$format = $options;
|
||||
}
|
||||
die(sprintf($format, $msg));
|
||||
}
|
||||
if ($this->mode & PEAR_ERROR_CALLBACK) {
|
||||
if (is_string($this->callback) && strlen($this->callback)) {
|
||||
call_user_func($this->callback, $this);
|
||||
} elseif (is_array($this->callback) &&
|
||||
sizeof($this->callback) == 2 &&
|
||||
is_object($this->callback[0]) &&
|
||||
is_string($this->callback[1]) &&
|
||||
strlen($this->callback[1])) {
|
||||
@call_user_func($this->callback, $this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getMode()
|
||||
|
||||
/**
|
||||
* Get the error mode from an error object.
|
||||
*
|
||||
* @return int error mode
|
||||
* @access public
|
||||
*/
|
||||
function getMode() {
|
||||
return $this->mode;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getCallback()
|
||||
|
||||
/**
|
||||
* Get the callback function/method from an error object.
|
||||
*
|
||||
* @return mixed callback function or object/method array
|
||||
* @access public
|
||||
*/
|
||||
function getCallback() {
|
||||
return $this->callback;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getMessage()
|
||||
|
||||
|
||||
/**
|
||||
* Get the error message from an error object.
|
||||
*
|
||||
* @return string full error message
|
||||
* @access public
|
||||
*/
|
||||
function getMessage()
|
||||
{
|
||||
return ($this->error_message_prefix . $this->message);
|
||||
}
|
||||
|
||||
|
||||
// }}}
|
||||
// {{{ getCode()
|
||||
|
||||
/**
|
||||
* Get error code from an error object
|
||||
*
|
||||
* @return int error code
|
||||
* @access public
|
||||
*/
|
||||
function getCode()
|
||||
{
|
||||
return $this->code;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getType()
|
||||
|
||||
/**
|
||||
* Get the name of this error/exception.
|
||||
*
|
||||
* @return string error/exception name (type)
|
||||
* @access public
|
||||
*/
|
||||
function getType()
|
||||
{
|
||||
return get_class($this);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getUserInfo()
|
||||
|
||||
/**
|
||||
* Get additional user-supplied information.
|
||||
*
|
||||
* @return string user-supplied information
|
||||
* @access public
|
||||
*/
|
||||
function getUserInfo()
|
||||
{
|
||||
return $this->userinfo;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getDebugInfo()
|
||||
|
||||
/**
|
||||
* Get additional debug information supplied by the application.
|
||||
*
|
||||
* @return string debug information
|
||||
* @access public
|
||||
*/
|
||||
function getDebugInfo()
|
||||
{
|
||||
return $this->getUserInfo();
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ addUserInfo()
|
||||
|
||||
function addUserInfo($info)
|
||||
{
|
||||
if (empty($this->userinfo)) {
|
||||
$this->userinfo = $info;
|
||||
} else {
|
||||
$this->userinfo .= " ** $info";
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ toString()
|
||||
|
||||
/**
|
||||
* Make a string representation of this object.
|
||||
*
|
||||
* @return string a string with an object summary
|
||||
* @access public
|
||||
*/
|
||||
function toString() {
|
||||
$modes = array();
|
||||
$levels = array(E_USER_NOTICE => 'notice',
|
||||
E_USER_WARNING => 'warning',
|
||||
E_USER_ERROR => 'error');
|
||||
if ($this->mode & PEAR_ERROR_CALLBACK) {
|
||||
if (is_array($this->callback)) {
|
||||
$callback = get_class($this->callback[0]) . '::' .
|
||||
$this->callback[1];
|
||||
} else {
|
||||
$callback = $this->callback;
|
||||
}
|
||||
return sprintf('[%s: message="%s" code=%d mode=callback '.
|
||||
'callback=%s prefix="%s" info="%s"]',
|
||||
get_class($this), $this->message, $this->code,
|
||||
$callback, $this->error_message_prefix,
|
||||
$this->userinfo);
|
||||
}
|
||||
if ($this->mode & PEAR_ERROR_PRINT) {
|
||||
$modes[] = 'print';
|
||||
}
|
||||
if ($this->mode & PEAR_ERROR_TRIGGER) {
|
||||
$modes[] = 'trigger';
|
||||
}
|
||||
if ($this->mode & PEAR_ERROR_DIE) {
|
||||
$modes[] = 'die';
|
||||
}
|
||||
if ($this->mode & PEAR_ERROR_RETURN) {
|
||||
$modes[] = 'return';
|
||||
}
|
||||
return sprintf('[%s: message="%s" code=%d mode=%s level=%s '.
|
||||
'prefix="%s" info="%s"]',
|
||||
get_class($this), $this->message, $this->code,
|
||||
implode("|", $modes), $levels[$this->level],
|
||||
$this->error_message_prefix,
|
||||
$this->userinfo);
|
||||
}
|
||||
|
||||
// }}}
|
||||
}
|
||||
|
||||
register_shutdown_function("_PEAR_call_destructors");
|
||||
|
||||
/*
|
||||
* Local Variables:
|
||||
* mode: php
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
*/
|
||||
?>
|
||||
@@ -0,0 +1,186 @@
|
||||
<?php
|
||||
// /* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.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. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Stig Bakken <ssb@fast.no> |
|
||||
// | |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id$
|
||||
|
||||
if (!extension_loaded("overload")) {
|
||||
// die hard without ext/overload
|
||||
die("Rebuild PHP with the `overload' extension to use PEAR_Autoloader");
|
||||
}
|
||||
|
||||
require_once "PEAR.php";
|
||||
|
||||
/**
|
||||
* This class is for objects where you want to separate the code for
|
||||
* some methods into separate classes. This is useful if you have a
|
||||
* class with not-frequently-used methods that contain lots of code
|
||||
* that you would like to avoid always parsing.
|
||||
*
|
||||
* The PEAR_Autoloader class provides autoloading and aggregation.
|
||||
* The autoloading lets you set up in which classes the separated
|
||||
* methods are found. Aggregation is the technique used to import new
|
||||
* methods, an instance of each class providing separated methods is
|
||||
* stored and called every time the aggregated method is called.
|
||||
*
|
||||
* @author Stig Sæther Bakken <ssb@fast.no>
|
||||
*/
|
||||
class PEAR_Autoloader extends PEAR
|
||||
{
|
||||
/**
|
||||
* Map of methods and classes where they are defined
|
||||
*
|
||||
* @var array
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
var $_autoload_map = array();
|
||||
|
||||
/**
|
||||
* Map of methods and aggregate objects
|
||||
*
|
||||
* @var array
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
var $_method_map = array();
|
||||
|
||||
/**
|
||||
* Add one or more autoload entries.
|
||||
*
|
||||
* @param string $method which method to autoload
|
||||
*
|
||||
* @param string $classname (optional) which class to find the method in.
|
||||
* If the $method parameter is an array, this
|
||||
* parameter may be omitted (and will be ignored
|
||||
* if not), and the $method parameter will be
|
||||
* treated as an associative array with method
|
||||
* names as keys and class names as values.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function addAutoload($method, $classname = null)
|
||||
{
|
||||
if (is_array($method)) {
|
||||
$this->_autoload_map = array_merge($this->_autoload_map, $method);
|
||||
} else {
|
||||
$this->_autoload_map[$method] = $classname;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an autoload entry.
|
||||
*
|
||||
* @param string $method which method to remove the autoload entry for
|
||||
*
|
||||
* @return bool TRUE if an entry was removed, FALSE if not
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function removeAutoload($method)
|
||||
{
|
||||
$ok = isset($this->_autoload_map[$method]);
|
||||
unset($this->_autoload_map[$method]);
|
||||
return $ok;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an aggregate object to this object. If the specified class
|
||||
* is not defined, loading it will be attempted following PEAR's
|
||||
* file naming scheme. All the methods in the class will be
|
||||
* aggregated, except private ones (name starting with an
|
||||
* underscore) and constructors.
|
||||
*
|
||||
* @param string $classname what class to instantiate for the object.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function addAggregateObject($classname)
|
||||
{
|
||||
$classname = strtolower($classname);
|
||||
if (!class_exists($classname)) {
|
||||
$include_file = preg_replace('/[^a-z0-9]/i', '_', $classname);
|
||||
include_once $include_file;
|
||||
}
|
||||
$obj =& new $classname;
|
||||
$methods = get_class_methods($classname);
|
||||
foreach ($methods as $method) {
|
||||
// don't import priviate methods and constructors
|
||||
if ($method{0} != '_' && $method != $classname) {
|
||||
$this->_method_map[$method] = $obj;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an aggregate object.
|
||||
*
|
||||
* @param string $classname the class of the object to remove
|
||||
*
|
||||
* @return bool TRUE if an object was removed, FALSE if not
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function removeAggregateObject($classname)
|
||||
{
|
||||
$ok = false;
|
||||
$classname = strtolower($classname);
|
||||
reset($this->_method_map);
|
||||
while (list($method, $obj) = each($this->_method_map)) {
|
||||
if (get_class($obj) == $classname) {
|
||||
unset($this->_method_map[$method]);
|
||||
$ok = true;
|
||||
}
|
||||
}
|
||||
return $ok;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overloaded object call handler, called each time an
|
||||
* undefined/aggregated method is invoked. This method repeats
|
||||
* the call in the right aggregate object and passes on the return
|
||||
* value.
|
||||
*
|
||||
* @param string $method which method that was called
|
||||
*
|
||||
* @param string $args An array of the parameters passed in the
|
||||
* original call
|
||||
*
|
||||
* @return mixed The return value from the aggregated method, or a PEAR
|
||||
* error if the called method was unknown.
|
||||
*/
|
||||
function __call($method, $args, &$retval)
|
||||
{
|
||||
if (empty($this->_method_map[$method]) && isset($this->_autoload_map[$method])) {
|
||||
$this->addAggregateObject($this->_autoload_map[$method]);
|
||||
}
|
||||
if (isset($this->_method_map[$method])) {
|
||||
$retval = call_user_func_array(array($this->_method_map[$method], $method), $args);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
overload("PEAR_Autoloader");
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,379 @@
|
||||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.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. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Stig Sæther Bakken <ssb@fast.no> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id$
|
||||
|
||||
require_once 'PEAR/Common.php';
|
||||
|
||||
/**
|
||||
* Class to handle building (compiling) extensions.
|
||||
*
|
||||
* @author Stig Sæther Bakken <ssb@fast.no>
|
||||
*/
|
||||
class PEAR_Builder extends PEAR_Common
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
var $php_api_version = 0;
|
||||
var $zend_module_api_no = 0;
|
||||
var $zend_extension_api_no = 0;
|
||||
|
||||
var $extensions_built = array();
|
||||
|
||||
var $current_callback = null;
|
||||
|
||||
// used for msdev builds
|
||||
var $_lastline = null;
|
||||
var $_firstline = null;
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* PEAR_Builder constructor.
|
||||
*
|
||||
* @param object $ui user interface object (instance of PEAR_Frontend_*)
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PEAR_Builder(&$ui)
|
||||
{
|
||||
parent::PEAR_Common();
|
||||
$this->setFrontendObject($ui);
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
// {{{ _build_win32()
|
||||
|
||||
/**
|
||||
* Build an extension from source on windows.
|
||||
* requires msdev
|
||||
*/
|
||||
function _build_win32($descfile, $callback = null)
|
||||
{
|
||||
if (PEAR::isError($info = $this->infoFromDescriptionFile($descfile))) {
|
||||
return $info;
|
||||
}
|
||||
$dir = dirname($descfile);
|
||||
$old_cwd = getcwd();
|
||||
|
||||
if (!@chdir($dir)) {
|
||||
return $this->raiseError("could not chdir to $dir");
|
||||
}
|
||||
$this->log(2, "building in $dir");
|
||||
|
||||
$dsp = $info['package'].'.dsp';
|
||||
if (!@is_file("$dir/$dsp")) {
|
||||
return $this->raiseError("The DSP $dsp does not exist.");
|
||||
}
|
||||
// XXX TODO: make release build type configurable
|
||||
$command = 'msdev '.$dsp.' /MAKE "'.$info['package']. ' - Release"';
|
||||
|
||||
$this->current_callback = $callback;
|
||||
$err = $this->_runCommand($command, array(&$this, 'msdevCallback'));
|
||||
if (PEAR::isError($err)) {
|
||||
return $err;
|
||||
}
|
||||
|
||||
// figure out the build platform and type
|
||||
$platform = 'Win32';
|
||||
$buildtype = 'Release';
|
||||
if (preg_match('/.*?'.$info['package'].'\s-\s(\w+)\s(.*?)-+/i',$this->_firstline,$matches)) {
|
||||
$platform = $matches[1];
|
||||
$buildtype = $matches[2];
|
||||
}
|
||||
|
||||
if (preg_match('/(.*)?\s-\s(\d+).*?(\d+)/',$this->_lastline,$matches)) {
|
||||
if ($matches[2]) {
|
||||
// there were errors in the build
|
||||
return $this->raiseError("There were errors during compilation.");
|
||||
}
|
||||
$out = $matches[1];
|
||||
} else {
|
||||
return $this->raiseError("Did not understand the completion status returned from msdev.exe.");
|
||||
}
|
||||
|
||||
// msdev doesn't tell us the output directory :/
|
||||
// open the dsp, find /out and use that directory
|
||||
$dsptext = join(file($dsp),'');
|
||||
|
||||
// this regex depends on the build platform and type having been
|
||||
// correctly identified above.
|
||||
$regex ='/.*?!IF\s+"\$\(CFG\)"\s+==\s+("'.
|
||||
$info['package'].'\s-\s'.
|
||||
$platform.'\s'.
|
||||
$buildtype.'").*?'.
|
||||
'\/out:"(.*?)"/is';
|
||||
|
||||
if ($dsptext && preg_match($regex,$dsptext,$matches)) {
|
||||
// what we get back is a relative path to the output file itself.
|
||||
$outfile = realpath($matches[2]);
|
||||
} else {
|
||||
return $this->raiseError("Could not retrieve output information from $dsp.");
|
||||
}
|
||||
if (@copy($outfile, "$dir/$out")) {
|
||||
$outfile = "$dir/$out";
|
||||
}
|
||||
|
||||
$built_files[] = array(
|
||||
'file' => "$outfile",
|
||||
'php_api' => $this->php_api_version,
|
||||
'zend_mod_api' => $this->zend_module_api_no,
|
||||
'zend_ext_api' => $this->zend_extension_api_no,
|
||||
);
|
||||
|
||||
return $built_files;
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ msdevCallback()
|
||||
function msdevCallback($what, $data)
|
||||
{
|
||||
if (!$this->_firstline)
|
||||
$this->_firstline = $data;
|
||||
$this->_lastline = $data;
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ build()
|
||||
|
||||
/**
|
||||
* Build an extension from source. Runs "phpize" in the source
|
||||
* directory, but compiles in a temporary directory
|
||||
* (/var/tmp/pear-build-USER/PACKAGE-VERSION).
|
||||
*
|
||||
* @param string $descfile path to XML package description file
|
||||
*
|
||||
* @param mixed $callback callback function used to report output,
|
||||
* see PEAR_Builder::_runCommand for details
|
||||
*
|
||||
* @return array an array of associative arrays with built files,
|
||||
* format:
|
||||
* array( array( 'file' => '/path/to/ext.so',
|
||||
* 'php_api' => YYYYMMDD,
|
||||
* 'zend_mod_api' => YYYYMMDD,
|
||||
* 'zend_ext_api' => YYYYMMDD ),
|
||||
* ... )
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @see PEAR_Builder::_runCommand
|
||||
* @see PEAR_Common::infoFromDescriptionFile
|
||||
*/
|
||||
function build($descfile, $callback = null)
|
||||
{
|
||||
if (PEAR_OS == "Windows") {
|
||||
return $this->_build_win32($descfile,$callback);
|
||||
}
|
||||
if (PEAR_OS != 'Unix') {
|
||||
return $this->raiseError("building extensions not supported on this platform");
|
||||
}
|
||||
if (PEAR::isError($info = $this->infoFromDescriptionFile($descfile))) {
|
||||
return $info;
|
||||
}
|
||||
$dir = dirname($descfile);
|
||||
$old_cwd = getcwd();
|
||||
if (!@chdir($dir)) {
|
||||
return $this->raiseError("could not chdir to $dir");
|
||||
}
|
||||
$vdir = "$info[package]-$info[version]";
|
||||
if (is_dir($vdir)) {
|
||||
chdir($vdir);
|
||||
}
|
||||
$dir = getcwd();
|
||||
$this->log(2, "building in $dir");
|
||||
$this->current_callback = $callback;
|
||||
$err = $this->_runCommand("phpize", array(&$this, 'phpizeCallback'));
|
||||
if (PEAR::isError($err)) {
|
||||
return $err;
|
||||
}
|
||||
if (!$err) {
|
||||
return $this->raiseError("`phpize' failed");
|
||||
}
|
||||
|
||||
// start of interactive part
|
||||
$configure_command = "$dir/configure";
|
||||
if (isset($info['configure_options'])) {
|
||||
foreach ($info['configure_options'] as $o) {
|
||||
list($r) = $this->ui->userDialog('build',
|
||||
array($o['prompt']),
|
||||
array('text'),
|
||||
array(@$o['default']));
|
||||
if (substr($o['name'], 0, 5) == 'with-' &&
|
||||
($r == 'yes' || $r == 'autodetect')) {
|
||||
$configure_command .= " --$o[name]";
|
||||
} else {
|
||||
$configure_command .= " --$o[name]=$r";
|
||||
}
|
||||
}
|
||||
}
|
||||
// end of interactive part
|
||||
|
||||
// make configurable
|
||||
if(!$user=getenv('USER')){
|
||||
$user='defaultuser';
|
||||
}
|
||||
$build_basedir = "/var/tmp/pear-build-$user";
|
||||
$build_dir = "$build_basedir/$info[package]-$info[version]";
|
||||
$this->log(1, "building in $build_dir");
|
||||
if (is_dir($build_dir)) {
|
||||
System::rm("-rf $build_dir");
|
||||
}
|
||||
if (!System::mkDir("-p $build_dir")) {
|
||||
return $this->raiseError("could not create build dir: $build_dir");
|
||||
}
|
||||
$this->addTempFile($build_dir);
|
||||
if (getenv('MAKE')) {
|
||||
$make_command = getenv('MAKE');
|
||||
} else {
|
||||
$make_command = 'make';
|
||||
}
|
||||
$to_run = array(
|
||||
$configure_command,
|
||||
$make_command,
|
||||
);
|
||||
if (!@chdir($build_dir)) {
|
||||
return $this->raiseError("could not chdir to $build_dir");
|
||||
}
|
||||
foreach ($to_run as $cmd) {
|
||||
$err = $this->_runCommand($cmd, $callback);
|
||||
if (PEAR::isError($err) && !$err) {
|
||||
chdir($old_cwd);
|
||||
return $err;
|
||||
}
|
||||
}
|
||||
if (!($dp = opendir("modules"))) {
|
||||
chdir($old_cwd);
|
||||
return $this->raiseError("no `modules' directory found");
|
||||
}
|
||||
$built_files = array();
|
||||
while ($ent = readdir($dp)) {
|
||||
if ($ent{0} == '.' || substr($ent, -3) == '.la') {
|
||||
continue;
|
||||
}
|
||||
// harvest!
|
||||
if (@copy("modules/$ent", "$dir/$ent")) {
|
||||
$built_files[] = array(
|
||||
'file' => "$dir/$ent",
|
||||
'php_api' => $this->php_api_version,
|
||||
'zend_mod_api' => $this->zend_module_api_no,
|
||||
'zend_ext_api' => $this->zend_extension_api_no,
|
||||
);
|
||||
|
||||
$this->log(1, "$ent copied to $dir/$ent");
|
||||
} else {
|
||||
chdir($old_cwd);
|
||||
return $this->raiseError("failed copying $ent to $dir");
|
||||
}
|
||||
}
|
||||
closedir($dp);
|
||||
chdir($old_cwd);
|
||||
return $built_files;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ phpizeCallback()
|
||||
|
||||
/**
|
||||
* Message callback function used when running the "phpize"
|
||||
* program. Extracts the API numbers used. Ignores other message
|
||||
* types than "cmdoutput".
|
||||
*
|
||||
* @param string $what the type of message
|
||||
* @param mixed $data the message
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function phpizeCallback($what, $data)
|
||||
{
|
||||
if ($what != 'cmdoutput') {
|
||||
return;
|
||||
}
|
||||
$this->log(3, rtrim($data));
|
||||
if (preg_match('/You should update your .aclocal.m4/', $data)) {
|
||||
return;
|
||||
}
|
||||
$matches = array();
|
||||
if (preg_match('/^\s+(\S[^:]+):\s+(\d{8})/', $data, $matches)) {
|
||||
$member = preg_replace('/[^a-z]/', '_', strtolower($matches[1]));
|
||||
$apino = (int)$matches[2];
|
||||
if (isset($this->$member)) {
|
||||
$this->$member = $apino;
|
||||
$msg = sprintf("%-22s : %d", $matches[1], $apino);
|
||||
$this->log(1, $msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ _runCommand()
|
||||
|
||||
/**
|
||||
* Run an external command, using a message callback to report
|
||||
* output. The command will be run through popen and output is
|
||||
* reported for every line with a "cmdoutput" message with the
|
||||
* line string, including newlines, as payload.
|
||||
*
|
||||
* @param string $command the command to run
|
||||
*
|
||||
* @param mixed $callback (optional) function to use as message
|
||||
* callback
|
||||
*
|
||||
* @return bool whether the command was successful (exit code 0
|
||||
* means success, any other means failure)
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
function _runCommand($command, $callback = null)
|
||||
{
|
||||
$this->log(1, "running: $command");
|
||||
$pp = @popen("$command 2>&1", "r");
|
||||
if (!$pp) {
|
||||
return $this->raiseError("failed to run `$command'");
|
||||
}
|
||||
while ($line = fgets($pp, 1024)) {
|
||||
if ($callback) {
|
||||
call_user_func($callback, 'cmdoutput', $line);
|
||||
} else {
|
||||
$this->log(2, rtrim($line));
|
||||
}
|
||||
}
|
||||
$exitcode = @pclose($pp);
|
||||
return ($exitcode == 0);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ log()
|
||||
|
||||
function log($level, $msg)
|
||||
{
|
||||
if ($this->current_callback) {
|
||||
if ($this->debug >= $level) {
|
||||
call_user_func($this->current_callback, 'output', $msg);
|
||||
}
|
||||
return;
|
||||
}
|
||||
return PEAR_Common::log($level, $msg);
|
||||
}
|
||||
|
||||
// }}}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,322 @@
|
||||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.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. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Stig Bakken <ssb@fast.no> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id$
|
||||
|
||||
|
||||
require_once "PEAR.php";
|
||||
|
||||
/**
|
||||
* List of commands and what classes they are implemented in.
|
||||
* @var array command => implementing class
|
||||
*/
|
||||
$GLOBALS['_PEAR_Command_commandlist'] = array();
|
||||
|
||||
/**
|
||||
* List of shortcuts to common commands.
|
||||
* @var array shortcut => command
|
||||
*/
|
||||
$GLOBALS['_PEAR_Command_shortcuts'] = array();
|
||||
|
||||
/**
|
||||
* Array of command objects
|
||||
* @var array class => object
|
||||
*/
|
||||
$GLOBALS['_PEAR_Command_objects'] = array();
|
||||
|
||||
/**
|
||||
* Which user interface class is being used.
|
||||
* @var string class name
|
||||
*/
|
||||
$GLOBALS['_PEAR_Command_uiclass'] = 'PEAR_Frontend_CLI';
|
||||
|
||||
/**
|
||||
* Instance of $_PEAR_Command_uiclass.
|
||||
* @var object
|
||||
*/
|
||||
$GLOBALS['_PEAR_Command_uiobject'] = null;
|
||||
|
||||
/**
|
||||
* PEAR command class, a simple factory class for administrative
|
||||
* commands.
|
||||
*
|
||||
* How to implement command classes:
|
||||
*
|
||||
* - The class must be called PEAR_Command_Nnn, installed in the
|
||||
* "PEAR/Common" subdir, with a method called getCommands() that
|
||||
* returns an array of the commands implemented by the class (see
|
||||
* PEAR/Command/Install.php for an example).
|
||||
*
|
||||
* - The class must implement a run() function that is called with three
|
||||
* params:
|
||||
*
|
||||
* (string) command name
|
||||
* (array) assoc array with options, freely defined by each
|
||||
* command, for example:
|
||||
* array('force' => true)
|
||||
* (array) list of the other parameters
|
||||
*
|
||||
* The run() function returns a PEAR_CommandResponse object. Use
|
||||
* these methods to get information:
|
||||
*
|
||||
* int getStatus() Returns PEAR_COMMAND_(SUCCESS|FAILURE|PARTIAL)
|
||||
* *_PARTIAL means that you need to issue at least
|
||||
* one more command to complete the operation
|
||||
* (used for example for validation steps).
|
||||
*
|
||||
* string getMessage() Returns a message for the user. Remember,
|
||||
* no HTML or other interface-specific markup.
|
||||
*
|
||||
* If something unexpected happens, run() returns a PEAR error.
|
||||
*
|
||||
* - DON'T OUTPUT ANYTHING! Return text for output instead.
|
||||
*
|
||||
* - DON'T USE HTML! The text you return will be used from both Gtk,
|
||||
* web and command-line interfaces, so for now, keep everything to
|
||||
* plain text.
|
||||
*
|
||||
* - DON'T USE EXIT OR DIE! Always use pear errors. From static
|
||||
* classes do PEAR::raiseError(), from other classes do
|
||||
* $this->raiseError().
|
||||
*/
|
||||
class PEAR_Command
|
||||
{
|
||||
/**
|
||||
* Get the right object for executing a command.
|
||||
*
|
||||
* @param string $command The name of the command
|
||||
* @param object $config Instance of PEAR_Config object
|
||||
*
|
||||
* @return object the command object or a PEAR error
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function factory($command, &$config)
|
||||
{
|
||||
if (empty($GLOBALS['_PEAR_Command_commandlist'])) {
|
||||
PEAR_Command::registerCommands();
|
||||
}
|
||||
if (isset($GLOBALS['_PEAR_Command_shortcuts'][$command])) {
|
||||
$command = $GLOBALS['_PEAR_Command_shortcuts'][$command];
|
||||
}
|
||||
$class = @$GLOBALS['_PEAR_Command_commandlist'][$command];
|
||||
if (empty($class)) {
|
||||
return PEAR::raiseError("unknown command `$command'");
|
||||
}
|
||||
$ui = PEAR_Command::getFrontendObject();
|
||||
$obj = &new $class($ui, $config);
|
||||
return $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get instance of frontend object.
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
function &getFrontendObject()
|
||||
{
|
||||
if (empty($GLOBALS['_PEAR_Command_uiobject'])) {
|
||||
$GLOBALS['_PEAR_Command_uiobject'] = &new $GLOBALS['_PEAR_Command_uiclass'];
|
||||
}
|
||||
return $GLOBALS['_PEAR_Command_uiobject'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Load current frontend class.
|
||||
*
|
||||
* @param string $uiclass Name of class implementing the frontend
|
||||
*
|
||||
* @return object the frontend object, or a PEAR error
|
||||
*/
|
||||
function &setFrontendClass($uiclass)
|
||||
{
|
||||
if (is_object($GLOBALS['_PEAR_Command_uiobject']) &&
|
||||
strtolower($uiclass) == get_class($GLOBALS['_PEAR_Command_uiobject'])) {
|
||||
return;
|
||||
}
|
||||
$file = str_replace('_', '/', $uiclass) . '.php';
|
||||
@include_once $file;
|
||||
if (class_exists(strtolower($uiclass))) {
|
||||
$obj = &new $uiclass;
|
||||
// quick test to see if this class implements a few of the most
|
||||
// important frontend methods
|
||||
if (method_exists($obj, 'userConfirm')) {
|
||||
$GLOBALS['_PEAR_Command_uiobject'] = &$obj;
|
||||
$GLOBALS['_PEAR_Command_uiclass'] = $uiclass;
|
||||
return $obj;
|
||||
} else {
|
||||
return PEAR::raiseError("not a frontend class: $uiclass");
|
||||
}
|
||||
}
|
||||
return PEAR::raiseError("no such class: $uiclass");
|
||||
}
|
||||
|
||||
/**
|
||||
* Set current frontend.
|
||||
*
|
||||
* @param string $uitype Name of the frontend type (for example "CLI")
|
||||
*
|
||||
* @return object the frontend object, or a PEAR error
|
||||
*/
|
||||
function setFrontendType($uitype)
|
||||
{
|
||||
$uiclass = 'PEAR_Frontend_' . $uitype;
|
||||
return PEAR_Command::setFrontendClass($uiclass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scan through the Command directory looking for classes
|
||||
* and see what commands they implement.
|
||||
*
|
||||
* @param bool (optional) if FALSE (default), the new list of
|
||||
* commands should replace the current one. If TRUE,
|
||||
* new entries will be merged with old.
|
||||
*
|
||||
* @param string (optional) where (what directory) to look for
|
||||
* classes, defaults to the Command subdirectory of
|
||||
* the directory from where this file (__FILE__) is
|
||||
* included.
|
||||
*
|
||||
* @return bool TRUE on success, a PEAR error on failure
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function registerCommands($merge = false, $dir = null)
|
||||
{
|
||||
if ($dir === null) {
|
||||
$dir = dirname(__FILE__) . '/Command';
|
||||
}
|
||||
$dp = @opendir($dir);
|
||||
if (empty($dp)) {
|
||||
return PEAR::raiseError("registerCommands: opendir($dir) failed");
|
||||
}
|
||||
if (!$merge) {
|
||||
$GLOBALS['_PEAR_Command_commandlist'] = array();
|
||||
}
|
||||
while ($entry = readdir($dp)) {
|
||||
if ($entry{0} == '.' || substr($entry, -4) != '.php' || $entry == 'Common.php') {
|
||||
continue;
|
||||
}
|
||||
$class = "PEAR_Command_".substr($entry, 0, -4);
|
||||
$file = "$dir/$entry";
|
||||
include_once $file;
|
||||
// List of commands
|
||||
if (empty($GLOBALS['_PEAR_Command_objects'][$class])) {
|
||||
$GLOBALS['_PEAR_Command_objects'][$class] = &new $class($ui, $config);
|
||||
}
|
||||
$implements = $GLOBALS['_PEAR_Command_objects'][$class]->getCommands();
|
||||
foreach ($implements as $command => $desc) {
|
||||
$GLOBALS['_PEAR_Command_commandlist'][$command] = $class;
|
||||
$GLOBALS['_PEAR_Command_commanddesc'][$command] = $desc;
|
||||
}
|
||||
$shortcuts = $GLOBALS['_PEAR_Command_objects'][$class]->getShortcuts();
|
||||
foreach ($shortcuts as $shortcut => $command) {
|
||||
$GLOBALS['_PEAR_Command_shortcuts'][$shortcut] = $command;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of currently supported commands, and what
|
||||
* classes implement them.
|
||||
*
|
||||
* @return array command => implementing class
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function getCommands()
|
||||
{
|
||||
if (empty($GLOBALS['_PEAR_Command_commandlist'])) {
|
||||
PEAR_Command::registerCommands();
|
||||
}
|
||||
return $GLOBALS['_PEAR_Command_commandlist'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of command shortcuts.
|
||||
*
|
||||
* @return array shortcut => command
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function getShortcuts()
|
||||
{
|
||||
if (empty($GLOBALS['_PEAR_Command_shortcuts'])) {
|
||||
PEAR_Command::registerCommands();
|
||||
}
|
||||
return $GLOBALS['_PEAR_Command_shortcuts'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Compiles arguments for getopt.
|
||||
*
|
||||
* @param string $command command to get optstring for
|
||||
* @param string $short_args (reference) short getopt format
|
||||
* @param array $long_args (reference) long getopt format
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function getGetoptArgs($command, &$short_args, &$long_args)
|
||||
{
|
||||
if (empty($GLOBALS['_PEAR_Command_commandlist'])) {
|
||||
PEAR_Command::registerCommands();
|
||||
}
|
||||
$class = @$GLOBALS['_PEAR_Command_commandlist'][$command];
|
||||
if (empty($class)) {
|
||||
return null;
|
||||
}
|
||||
$obj = &$GLOBALS['_PEAR_Command_objects'][$class];
|
||||
return $obj->getGetoptArgs($command, $short_args, $long_args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get description for a command.
|
||||
*
|
||||
* @param string $command Name of the command
|
||||
*
|
||||
* @return string command description
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function getDescription($command)
|
||||
{
|
||||
return @$GLOBALS['_PEAR_Command_commanddesc'][$command];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get help for command.
|
||||
*
|
||||
* @param string $command Name of the command to return help for
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function getHelp($command)
|
||||
{
|
||||
$cmds = PEAR_Command::getCommands();
|
||||
if (isset($cmds[$command])) {
|
||||
$class = $cmds[$command];
|
||||
return $GLOBALS['_PEAR_Command_objects'][$class]->getHelp($command);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.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. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Stig Bakken <ssb@fast.no> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id$
|
||||
|
||||
require_once "PEAR/Command/Common.php";
|
||||
require_once "PEAR/Remote.php";
|
||||
require_once "PEAR/Config.php";
|
||||
|
||||
/**
|
||||
* PEAR commands for managing configuration data.
|
||||
*
|
||||
*/
|
||||
class PEAR_Command_Auth extends PEAR_Command_Common
|
||||
{
|
||||
var $commands = array(
|
||||
'login' => array(
|
||||
'summary' => 'Connects and authenticates to remote server',
|
||||
'shortcut' => 'li',
|
||||
'function' => 'doLogin',
|
||||
'options' => array(),
|
||||
'doc' => '
|
||||
Log in to the remote server. To use remote functions in the installer
|
||||
that require any kind of privileges, you need to log in first. The
|
||||
username and password you enter here will be stored in your per-user
|
||||
PEAR configuration (~/.pearrc on Unix-like systems). After logging
|
||||
in, your username and password will be sent along in subsequent
|
||||
operations on the remote server.',
|
||||
),
|
||||
'logout' => array(
|
||||
'summary' => 'Logs out from the remote server',
|
||||
'shortcut' => 'lo',
|
||||
'function' => 'doLogout',
|
||||
'options' => array(),
|
||||
'doc' => '
|
||||
Logs out from the remote server. This command does not actually
|
||||
connect to the remote server, it only deletes the stored username and
|
||||
password from your user configuration.',
|
||||
)
|
||||
|
||||
);
|
||||
|
||||
/**
|
||||
* PEAR_Command_Auth constructor.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PEAR_Command_Auth(&$ui, &$config)
|
||||
{
|
||||
parent::PEAR_Command_Common($ui, $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the 'login' command.
|
||||
*
|
||||
* @param string $command command name
|
||||
*
|
||||
* @param array $options option_name => value
|
||||
*
|
||||
* @param array $params list of additional parameters
|
||||
*
|
||||
* @return bool TRUE on success, FALSE for unknown commands, or
|
||||
* a PEAR error on failure
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function doLogin($command, $options, $params)
|
||||
{
|
||||
$server = $this->config->get('master_server');
|
||||
$remote = new PEAR_Remote($this->config);
|
||||
$username = $this->config->get('username');
|
||||
if (empty($username)) {
|
||||
$username = @$_ENV['USER'];
|
||||
}
|
||||
$this->ui->outputData("Logging in to $server.", $command);
|
||||
|
||||
list($username, $password) = $this->ui->userDialog(
|
||||
$command,
|
||||
array('Username', 'Password'),
|
||||
array('text', 'password'),
|
||||
array($username, '')
|
||||
);
|
||||
$username = trim($username);
|
||||
$password = trim($password);
|
||||
|
||||
$this->config->set('username', $username);
|
||||
$this->config->set('password', $password);
|
||||
|
||||
$remote->expectError(401);
|
||||
$ok = $remote->call('logintest');
|
||||
$remote->popExpect();
|
||||
if ($ok === true) {
|
||||
$this->ui->outputData("Logged in.", $command);
|
||||
$this->config->store();
|
||||
} else {
|
||||
return $this->raiseError("Login failed!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the 'logout' command.
|
||||
*
|
||||
* @param string $command command name
|
||||
*
|
||||
* @param array $options option_name => value
|
||||
*
|
||||
* @param array $params list of additional parameters
|
||||
*
|
||||
* @return bool TRUE on success, FALSE for unknown commands, or
|
||||
* a PEAR error on failure
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function doLogout($command, $options, $params)
|
||||
{
|
||||
$server = $this->config->get('master_server');
|
||||
$this->ui->outputData("Logging out from $server.", $command);
|
||||
$this->config->remove('username');
|
||||
$this->config->remove('password');
|
||||
$this->config->store();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.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. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Stig Bakken <ssb@fast.no> |
|
||||
// | Tomas V.V.Cox <cox@idecnet.com> |
|
||||
// | |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id$
|
||||
|
||||
require_once "PEAR/Command/Common.php";
|
||||
require_once "PEAR/Builder.php";
|
||||
|
||||
/**
|
||||
* PEAR commands for building extensions.
|
||||
*
|
||||
*/
|
||||
class PEAR_Command_Build extends PEAR_Command_Common
|
||||
{
|
||||
var $commands = array(
|
||||
'build' => array(
|
||||
'summary' => 'Build an Extension From C Source',
|
||||
'function' => 'doBuild',
|
||||
'shortcut' => 'b',
|
||||
'options' => array(),
|
||||
'doc' => '[package.xml]
|
||||
Builds one or more extensions contained in a package.'
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* PEAR_Command_Build constructor.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PEAR_Command_Build(&$ui, &$config)
|
||||
{
|
||||
parent::PEAR_Command_Common($ui, $config);
|
||||
}
|
||||
|
||||
function doBuild($command, $options, $params)
|
||||
{
|
||||
if (sizeof($params) < 1) {
|
||||
$params[0] = 'package.xml';
|
||||
}
|
||||
$builder = &new PEAR_Builder($this->ui);
|
||||
$this->verbose = $this->config->get('verbose');
|
||||
$err = $builder->build($params[0], array(&$this, 'buildCallback'));
|
||||
if (PEAR::isError($err)) {
|
||||
return $err;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function buildCallback($what, $data)
|
||||
{
|
||||
if (($what == 'cmdoutput' && $this->verbose > 1) ||
|
||||
($what == 'output' && $this->verbose > 0)) {
|
||||
$this->ui->outputData(rtrim($data), 'build');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,247 @@
|
||||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.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. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Stig Sæther Bakken <ssb@fast.no> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id$
|
||||
|
||||
require_once "PEAR.php";
|
||||
|
||||
class PEAR_Command_Common extends PEAR
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* PEAR_Config object used to pass user system and configuration
|
||||
* on when executing commands
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
var $config;
|
||||
|
||||
/**
|
||||
* User Interface object, for all interaction with the user.
|
||||
* @var object
|
||||
*/
|
||||
var $ui;
|
||||
|
||||
var $_deps_rel_trans = array(
|
||||
'lt' => '<',
|
||||
'le' => '<=',
|
||||
'eq' => '=',
|
||||
'ne' => '!=',
|
||||
'gt' => '>',
|
||||
'ge' => '>=',
|
||||
'has' => '=='
|
||||
);
|
||||
|
||||
var $_deps_type_trans = array(
|
||||
'pkg' => 'package',
|
||||
'extension' => 'extension',
|
||||
'php' => 'PHP',
|
||||
'prog' => 'external program',
|
||||
'ldlib' => 'external library for linking',
|
||||
'rtlib' => 'external runtime library',
|
||||
'os' => 'operating system',
|
||||
'websrv' => 'web server',
|
||||
'sapi' => 'SAPI backend'
|
||||
);
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* PEAR_Command_Common constructor.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PEAR_Command_Common(&$ui, &$config)
|
||||
{
|
||||
parent::PEAR();
|
||||
$this->config = &$config;
|
||||
$this->ui = &$ui;
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
// {{{ getCommands()
|
||||
|
||||
/**
|
||||
* Return a list of all the commands defined by this class.
|
||||
* @return array list of commands
|
||||
* @access public
|
||||
*/
|
||||
function getCommands()
|
||||
{
|
||||
$ret = array();
|
||||
foreach (array_keys($this->commands) as $command) {
|
||||
$ret[$command] = $this->commands[$command]['summary'];
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getShortcuts()
|
||||
|
||||
/**
|
||||
* Return a list of all the command shortcuts defined by this class.
|
||||
* @return array shortcut => command
|
||||
* @access public
|
||||
*/
|
||||
function getShortcuts()
|
||||
{
|
||||
$ret = array();
|
||||
foreach (array_keys($this->commands) as $command) {
|
||||
if (isset($this->commands[$command]['shortcut'])) {
|
||||
$ret[$this->commands[$command]['shortcut']] = $command;
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getOptions()
|
||||
|
||||
function getOptions($command)
|
||||
{
|
||||
return @$this->commands[$command]['options'];
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getGetoptArgs()
|
||||
|
||||
function getGetoptArgs($command, &$short_args, &$long_args)
|
||||
{
|
||||
$short_args = "";
|
||||
$long_args = array();
|
||||
if (empty($this->commands[$command])) {
|
||||
return;
|
||||
}
|
||||
reset($this->commands[$command]);
|
||||
while (list($option, $info) = each($this->commands[$command]['options'])) {
|
||||
$larg = $sarg = '';
|
||||
if (isset($info['arg'])) {
|
||||
if ($info['arg']{0} == '(') {
|
||||
$larg = '==';
|
||||
$sarg = '::';
|
||||
$arg = substr($info['arg'], 1, -1);
|
||||
} else {
|
||||
$larg = '=';
|
||||
$sarg = ':';
|
||||
$arg = $info['arg'];
|
||||
}
|
||||
}
|
||||
if (isset($info['shortopt'])) {
|
||||
$short_args .= $info['shortopt'] . $sarg;
|
||||
}
|
||||
$long_args[] = $option . $larg;
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getHelp()
|
||||
/**
|
||||
* Returns the help message for the given command
|
||||
*
|
||||
* @param string $command The command
|
||||
* @return mixed A fail string if the command does not have help or
|
||||
* a two elements array containing [0]=>help string,
|
||||
* [1]=> help string for the accepted cmd args
|
||||
*/
|
||||
function getHelp($command)
|
||||
{
|
||||
$config = &PEAR_Config::singleton();
|
||||
$help = @$this->commands[$command]['doc'];
|
||||
if (empty($help)) {
|
||||
// XXX (cox) Fallback to summary if there is no doc (show both?)
|
||||
if (!$help = @$this->commands[$command]['summary']) {
|
||||
return "No help for command \"$command\"";
|
||||
}
|
||||
}
|
||||
if (preg_match_all('/{config\s+([^\}]+)}/e', $help, $matches)) {
|
||||
foreach($matches[0] as $k => $v) {
|
||||
$help = preg_replace("/$v/", $config->get($matches[1][$k]), $help);
|
||||
}
|
||||
}
|
||||
return array($help, $this->getHelpArgs($command));
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getHelpArgs()
|
||||
/**
|
||||
* Returns the help for the accepted arguments of a command
|
||||
*
|
||||
* @param string $command
|
||||
* @return string The help string
|
||||
*/
|
||||
function getHelpArgs($command)
|
||||
{
|
||||
if (isset($this->commands[$command]['options']) &&
|
||||
count($this->commands[$command]['options']))
|
||||
{
|
||||
$help = "Options:\n";
|
||||
foreach ($this->commands[$command]['options'] as $k => $v) {
|
||||
if (isset($v['arg'])) {
|
||||
if ($v['arg']{0} == '(') {
|
||||
$arg = substr($v['arg'], 1, -1);
|
||||
$sapp = " [$arg]";
|
||||
$lapp = "[=$arg]";
|
||||
} else {
|
||||
$sapp = " $v[arg]";
|
||||
$lapp = "=$v[arg]";
|
||||
}
|
||||
}
|
||||
if (isset($v['shortopt'])) {
|
||||
$s = $v['shortopt'];
|
||||
$help .= " -$s$sapp, --$k$lapp\n";
|
||||
} else {
|
||||
$help .= " --$k$lapp\n";
|
||||
}
|
||||
$p = " ";
|
||||
$doc = rtrim(str_replace("\n", "\n$p", $v['doc']));
|
||||
$help .= " $doc\n";
|
||||
}
|
||||
return $help;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ run()
|
||||
|
||||
function run($command, $options, $params)
|
||||
{
|
||||
$func = @$this->commands[$command]['function'];
|
||||
if (empty($func)) {
|
||||
// look for shortcuts
|
||||
foreach (array_keys($this->commands) as $cmd) {
|
||||
if (@$this->commands[$cmd]['shortcut'] == $command) {
|
||||
$command = $cmd;
|
||||
$func = @$this->commands[$command]['function'];
|
||||
if (empty($func)) {
|
||||
return $this->raiseError("unknown command `$command'");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this->$func($command, $options, $params);
|
||||
}
|
||||
|
||||
// }}}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,201 @@
|
||||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.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. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Stig Bakken <ssb@fast.no> |
|
||||
// | Tomas V.V.Cox <cox@idecnet.com> |
|
||||
// | |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id$
|
||||
|
||||
require_once "PEAR/Command/Common.php";
|
||||
require_once "PEAR/Config.php";
|
||||
|
||||
/**
|
||||
* PEAR commands for managing configuration data.
|
||||
*
|
||||
*/
|
||||
class PEAR_Command_Config extends PEAR_Command_Common
|
||||
{
|
||||
var $commands = array(
|
||||
'config-show' => array(
|
||||
'summary' => 'Show All Settings',
|
||||
'function' => 'doConfigShow',
|
||||
'shortcut' => 'csh',
|
||||
'options' => array(),
|
||||
'doc' => '
|
||||
Displays all configuration values. An optional argument
|
||||
may be used to tell which configuration layer to display. Valid
|
||||
configuration layers are "user", "system" and "default".
|
||||
',
|
||||
),
|
||||
'config-get' => array(
|
||||
'summary' => 'Show One Setting',
|
||||
'function' => 'doConfigGet',
|
||||
'shortcut' => 'cg',
|
||||
'options' => array(),
|
||||
'doc' => 'Displays the value of one configuration parameter. The
|
||||
first argument is the name of the parameter, an optional second argument
|
||||
may be used to tell which configuration layer to look in. Valid configuration
|
||||
layers are "user", "system" and "default". If no layer is specified, a value
|
||||
will be picked from the first layer that defines the parameter, in the order
|
||||
just specified.
|
||||
',
|
||||
),
|
||||
'config-set' => array(
|
||||
'summary' => 'Change Setting',
|
||||
'function' => 'doConfigSet',
|
||||
'shortcut' => 'cs',
|
||||
'options' => array(),
|
||||
'doc' => 'Sets the value of one configuration parameter. The first
|
||||
argument is the name of the parameter, the second argument is the new value.
|
||||
Some parameters are be subject to validation, and the command will fail with
|
||||
an error message if the new value does not make sense. An optional third
|
||||
argument may be used to specify which layer to set the configuration parameter
|
||||
in. The default layer is "user".
|
||||
',
|
||||
),
|
||||
'config-help' => array(
|
||||
'summary' => 'Show Information About Setting',
|
||||
'function' => 'doConfigHelp',
|
||||
'shortcut' => 'ch',
|
||||
'options' => array(),
|
||||
'doc' => '[parameter]
|
||||
Displays help for a configuration parameter. Without arguments it
|
||||
displays help for all configuration parameters.
|
||||
',
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* PEAR_Command_Config constructor.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PEAR_Command_Config(&$ui, &$config)
|
||||
{
|
||||
parent::PEAR_Command_Common($ui, $config);
|
||||
}
|
||||
|
||||
function doConfigShow($command, $options, $params)
|
||||
{
|
||||
// $params[0] -> the layer
|
||||
if ($error = $this->_checkLayer(@$params[0])) {
|
||||
return $this->raiseError($error);
|
||||
}
|
||||
$keys = $this->config->getKeys();
|
||||
sort($keys);
|
||||
$data = array('caption' => 'Configuration:');
|
||||
foreach ($keys as $key) {
|
||||
$type = $this->config->getType($key);
|
||||
$value = $this->config->get($key, @$params[0]);
|
||||
if ($type == 'password' && $value) {
|
||||
$value = '********';
|
||||
}
|
||||
if ($value === false) {
|
||||
$value = 'false';
|
||||
} elseif ($value === true) {
|
||||
$value = 'true';
|
||||
}
|
||||
$data['data'][$this->config->getGroup($key)][] = array($this->config->getPrompt($key) , $key, $value);
|
||||
}
|
||||
$this->ui->outputData($data, $command);
|
||||
return true;
|
||||
}
|
||||
|
||||
function doConfigGet($command, $options, $params)
|
||||
{
|
||||
// $params[0] -> the parameter
|
||||
// $params[1] -> the layer
|
||||
if ($error = $this->_checkLayer(@$params[1])) {
|
||||
return $this->raiseError($error);
|
||||
}
|
||||
if (sizeof($params) < 1 || sizeof($params) > 2) {
|
||||
return $this->raiseError("config-get expects 1 or 2 parameters");
|
||||
} elseif (sizeof($params) == 1) {
|
||||
$this->ui->outputData("$params[0]=" . $this->config->get($params[0]), $command);
|
||||
} else {
|
||||
$data = "$params[1].$params[0]=" .$this->config->get($params[0], $params[1]);
|
||||
$this->ui->outputData($data, $command);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function doConfigSet($command, $options, $params)
|
||||
{
|
||||
// $param[0] -> a parameter to set
|
||||
// $param[1] -> the value for the parameter
|
||||
// $param[2] -> the layer
|
||||
$failmsg = '';
|
||||
if (sizeof($params) < 2 || sizeof($params) > 3) {
|
||||
$failmsg .= "config-set expects 2 or 3 parameters";
|
||||
return PEAR::raiseError($failmsg);
|
||||
}
|
||||
if ($error = $this->_checkLayer(@$params[2])) {
|
||||
$failmsg .= $error;
|
||||
return PEAR::raiseError($failmsg);
|
||||
}
|
||||
if (!call_user_func_array(array(&$this->config, 'set'), $params))
|
||||
{
|
||||
$failmsg = "config-set (" . implode(", ", $params) . ") failed";
|
||||
} else {
|
||||
$this->config->store();
|
||||
}
|
||||
if ($failmsg) {
|
||||
return $this->raiseError($failmsg);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function doConfigHelp($command, $options, $params)
|
||||
{
|
||||
if (empty($params)) {
|
||||
$params = $this->config->getKeys();
|
||||
}
|
||||
$data['caption'] = "Config help" . ((count($params) == 1) ? " for $params[0]" : '');
|
||||
$data['headline'] = array('Name', 'Type', 'Description');
|
||||
$data['border'] = true;
|
||||
foreach ($params as $name) {
|
||||
$type = $this->config->getType($name);
|
||||
$docs = $this->config->getDocs($name);
|
||||
if ($type == 'set') {
|
||||
$docs = rtrim($docs) . "\nValid set: " .
|
||||
implode(' ', $this->config->getSetValues($name));
|
||||
}
|
||||
$data['data'][] = array($name, $type, $docs);
|
||||
}
|
||||
$this->ui->outputData($data, $command);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a layer is defined or not
|
||||
*
|
||||
* @param string $layer The layer to search for
|
||||
* @return mixed False on no error or the error message
|
||||
*/
|
||||
function _checkLayer($layer = null)
|
||||
{
|
||||
if (!empty($layer)) {
|
||||
$layers = $this->config->getLayers();
|
||||
if (!in_array($layer, $layers)) {
|
||||
return " only the layers: \"" . implode('" or "', $layers) . "\" are supported";
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,280 @@
|
||||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.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. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Stig Sæther Bakken <ssb@fast.no> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id$
|
||||
|
||||
require_once "PEAR/Command/Common.php";
|
||||
require_once "PEAR/Installer.php";
|
||||
require_once "Console/Getopt.php";
|
||||
|
||||
/**
|
||||
* PEAR commands for installation or deinstallation/upgrading of
|
||||
* packages.
|
||||
*
|
||||
*/
|
||||
class PEAR_Command_Install extends PEAR_Command_Common
|
||||
{
|
||||
// {{{ command definitions
|
||||
|
||||
var $commands = array(
|
||||
'install' => array(
|
||||
'summary' => 'Install Package',
|
||||
'function' => 'doInstall',
|
||||
'shortcut' => 'i',
|
||||
'options' => array(
|
||||
'force' => array(
|
||||
'shortopt' => 'f',
|
||||
'doc' => 'will overwrite newer installed packages',
|
||||
),
|
||||
'nodeps' => array(
|
||||
'shortopt' => 'n',
|
||||
'doc' => 'ignore dependencies, install anyway',
|
||||
),
|
||||
'register-only' => array(
|
||||
'shortopt' => 'r',
|
||||
'doc' => 'do not install files, only register the package as installed',
|
||||
),
|
||||
'soft' => array(
|
||||
'shortopt' => 's',
|
||||
'doc' => 'soft install, fail silently, or upgrade if already installed',
|
||||
),
|
||||
'nobuild' => array(
|
||||
'shortopt' => 'B',
|
||||
'doc' => 'don\'t build C extensions',
|
||||
),
|
||||
'nocompress' => array(
|
||||
'shortopt' => 'Z',
|
||||
'doc' => 'request uncompressed files when downloading',
|
||||
),
|
||||
'installroot' => array(
|
||||
'shortopt' => 'R',
|
||||
'arg' => 'DIR',
|
||||
'doc' => 'root directory used when installing files (ala PHP\'s INSTALL_ROOT)',
|
||||
),
|
||||
),
|
||||
'doc' => '<package> ...
|
||||
Installs one or more PEAR packages. You can specify a package to
|
||||
install in four ways:
|
||||
|
||||
"Package-1.0.tgz" : installs from a local file
|
||||
|
||||
"http://example.com/Package-1.0.tgz" : installs from
|
||||
anywhere on the net.
|
||||
|
||||
"package.xml" : installs the package described in
|
||||
package.xml. Useful for testing, or for wrapping a PEAR package in
|
||||
another package manager such as RPM.
|
||||
|
||||
"Package" : queries your configured server
|
||||
({config master_server}) and downloads the newest package with
|
||||
the preferred quality/state ({config preferred_state}).
|
||||
|
||||
More than one package may be specified at once. It is ok to mix these
|
||||
four ways of specifying packages.
|
||||
'),
|
||||
'upgrade' => array(
|
||||
'summary' => 'Upgrade Package',
|
||||
'function' => 'doInstall',
|
||||
'shortcut' => 'up',
|
||||
'options' => array(
|
||||
'force' => array(
|
||||
'shortopt' => 'f',
|
||||
'doc' => 'overwrite newer installed packages',
|
||||
),
|
||||
'nodeps' => array(
|
||||
'shortopt' => 'n',
|
||||
'doc' => 'ignore dependencies, upgrade anyway',
|
||||
),
|
||||
'register-only' => array(
|
||||
'shortopt' => 'r',
|
||||
'doc' => 'do not install files, only register the package as upgraded',
|
||||
),
|
||||
'nobuild' => array(
|
||||
'shortopt' => 'B',
|
||||
'doc' => 'don\'t build C extensions',
|
||||
),
|
||||
'nocompress' => array(
|
||||
'shortopt' => 'Z',
|
||||
'doc' => 'request uncompressed files when downloading',
|
||||
),
|
||||
'installroot' => array(
|
||||
'shortopt' => 'R',
|
||||
'arg' => 'DIR',
|
||||
'doc' => 'root directory used when installing files (ala PHP\'s INSTALL_ROOT)',
|
||||
),
|
||||
),
|
||||
'doc' => '<package> ...
|
||||
Upgrades one or more PEAR packages. See documentation for the
|
||||
"install" command for ways to specify a package.
|
||||
|
||||
When upgrading, your package will be updated if the provided new
|
||||
package has a higher version number (use the -f option if you need to
|
||||
upgrade anyway).
|
||||
|
||||
More than one package may be specified at once.
|
||||
'),
|
||||
'upgrade-all' => array(
|
||||
'summary' => 'Upgrade All Packages',
|
||||
'function' => 'doInstall',
|
||||
'shortcut' => 'ua',
|
||||
'options' => array(
|
||||
'nodeps' => array(
|
||||
'shortopt' => 'n',
|
||||
'doc' => 'ignore dependencies, upgrade anyway',
|
||||
),
|
||||
'register-only' => array(
|
||||
'shortopt' => 'r',
|
||||
'doc' => 'do not install files, only register the package as upgraded',
|
||||
),
|
||||
'nobuild' => array(
|
||||
'shortopt' => 'B',
|
||||
'doc' => 'don\'t build C extensions',
|
||||
),
|
||||
'nocompress' => array(
|
||||
'shortopt' => 'Z',
|
||||
'doc' => 'request uncompressed files when downloading',
|
||||
),
|
||||
'installroot' => array(
|
||||
'shortopt' => 'R',
|
||||
'arg' => 'DIR',
|
||||
'doc' => 'root directory used when installing files (ala PHP\'s INSTALL_ROOT)',
|
||||
),
|
||||
),
|
||||
'doc' => '
|
||||
Upgrades all packages that have a newer release available. Upgrades are
|
||||
done only if there is a release available of the state specified in
|
||||
"preferred_state" (currently {config preferred_state}), or a state considered
|
||||
more stable.
|
||||
'),
|
||||
'uninstall' => array(
|
||||
'summary' => 'Un-install Package',
|
||||
'function' => 'doUninstall',
|
||||
'shortcut' => 'un',
|
||||
'options' => array(
|
||||
'nodeps' => array(
|
||||
'shortopt' => 'n',
|
||||
'doc' => 'ignore dependencies, uninstall anyway',
|
||||
),
|
||||
'register-only' => array(
|
||||
'shortopt' => 'r',
|
||||
'doc' => 'do not remove files, only register the packages as not installed',
|
||||
),
|
||||
'installroot' => array(
|
||||
'shortopt' => 'R',
|
||||
'arg' => 'DIR',
|
||||
'doc' => 'root directory used when installing files (ala PHP\'s INSTALL_ROOT)',
|
||||
),
|
||||
),
|
||||
'doc' => '<package> ...
|
||||
Uninstalls one or more PEAR packages. More than one package may be
|
||||
specified at once.
|
||||
'),
|
||||
|
||||
);
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* PEAR_Command_Install constructor.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PEAR_Command_Install(&$ui, &$config)
|
||||
{
|
||||
parent::PEAR_Command_Common($ui, $config);
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
function doInstall($command, $options, $params)
|
||||
{
|
||||
if (empty($this->installer)) {
|
||||
$this->installer = &new PEAR_Installer($this->ui);
|
||||
}
|
||||
if ($command == 'upgrade') {
|
||||
$options[$command] = true;
|
||||
}
|
||||
if ($command == 'upgrade-all') {
|
||||
include_once "PEAR/Remote.php";
|
||||
$options['upgrade'] = true;
|
||||
$remote = new PEAR_Remote($this->config);
|
||||
$state = $this->config->get('preferred_state');
|
||||
if (empty($state) || $state == 'any') {
|
||||
$latest = $remote->call("package.listLatestReleases");
|
||||
} else {
|
||||
$latest = $remote->call("package.listLatestReleases", $state);
|
||||
}
|
||||
if (PEAR::isError($latest)) {
|
||||
return $latest;
|
||||
}
|
||||
$reg = new PEAR_Registry($this->config->get('php_dir'));
|
||||
$installed = array_flip($reg->listPackages());
|
||||
$params = array();
|
||||
foreach ($latest as $package => $info) {
|
||||
if (!isset($installed[$package])) {
|
||||
// skip packages we don't have installed
|
||||
continue;
|
||||
}
|
||||
$inst_version = $reg->packageInfo($package, 'version');
|
||||
if (version_compare("$info[version]", "$inst_version", "le")) {
|
||||
// installed version is up-to-date
|
||||
continue;
|
||||
}
|
||||
$params[] = $package;
|
||||
$this->ui->outputData("will upgrade $package", $command);
|
||||
}
|
||||
}
|
||||
foreach ($params as $pkg) {
|
||||
$bn = basename($pkg);
|
||||
$info = $this->installer->install($pkg, $options, $this->config);
|
||||
if (is_array($info)) {
|
||||
if ($this->config->get('verbose') > 0) {
|
||||
$label = "$info[package] $info[version]";
|
||||
$this->ui->outputData("$command ok: $label", $command);
|
||||
}
|
||||
} else {
|
||||
return $this->raiseError("$command failed");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function doUninstall($command, $options, $params)
|
||||
{
|
||||
if (empty($this->installer)) {
|
||||
$this->installer = &new PEAR_Installer($this->ui);
|
||||
}
|
||||
if (sizeof($params) < 1) {
|
||||
return $this->raiseError("Please supply the package(s) you want to uninstall");
|
||||
}
|
||||
foreach ($params as $pkg) {
|
||||
if ($this->installer->uninstall($pkg, $options)) {
|
||||
if ($this->config->get('verbose') > 0) {
|
||||
$this->ui->outputData("uninstall ok: $pkg", $command);
|
||||
}
|
||||
} else {
|
||||
return $this->raiseError("uninstall failed: $pkg");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,496 @@
|
||||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.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. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Stig Bakken <ssb@fast.no> |
|
||||
// | Martin Jansen <mj@php.net> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id$
|
||||
|
||||
require_once 'PEAR/Common.php';
|
||||
require_once 'PEAR/Command/Common.php';
|
||||
|
||||
class PEAR_Command_Package extends PEAR_Command_Common
|
||||
{
|
||||
var $commands = array(
|
||||
'package' => array(
|
||||
'summary' => 'Build Package',
|
||||
'function' => 'doPackage',
|
||||
'shortcut' => 'p',
|
||||
'options' => array(
|
||||
'nocompress' => array(
|
||||
'shortopt' => 'Z',
|
||||
'doc' => 'Do not gzip the package file'
|
||||
),
|
||||
'showname' => array(
|
||||
'shortopt' => 'n',
|
||||
'doc' => 'Print the name of the packaged file.',
|
||||
),
|
||||
),
|
||||
'doc' => '[descfile]
|
||||
Creates a PEAR package from its description file (usually called
|
||||
package.xml).
|
||||
'
|
||||
),
|
||||
'package-validate' => array(
|
||||
'summary' => 'Validate Package Consistency',
|
||||
'function' => 'doPackageValidate',
|
||||
'shortcut' => 'pv',
|
||||
'options' => array(),
|
||||
'doc' => '
|
||||
',
|
||||
),
|
||||
'cvstag' => array(
|
||||
'summary' => 'Set CVS Release Tag',
|
||||
'function' => 'doCvsTag',
|
||||
'shortcut' => 'ct',
|
||||
'options' => array(
|
||||
'quiet' => array(
|
||||
'shortopt' => 'q',
|
||||
'doc' => 'Be quiet',
|
||||
),
|
||||
'reallyquiet' => array(
|
||||
'shortopt' => 'Q',
|
||||
'doc' => 'Be really quiet',
|
||||
),
|
||||
'slide' => array(
|
||||
'shortopt' => 'F',
|
||||
'doc' => 'Move (slide) tag if it exists',
|
||||
),
|
||||
'delete' => array(
|
||||
'shortopt' => 'd',
|
||||
'doc' => 'Remove tag',
|
||||
),
|
||||
),
|
||||
'doc' => '
|
||||
Sets a CVS tag on all files in a package. Use this command after you have
|
||||
packaged a distribution tarball with the "package" command to tag what
|
||||
revisions of what files were in that release. If need to fix something
|
||||
after running cvstag once, but before the tarball is released to the public,
|
||||
use the "slide" option to move the release tag.
|
||||
',
|
||||
),
|
||||
'run-tests' => array(
|
||||
'summary' => 'Run Regression Tests',
|
||||
'function' => 'doRunTests',
|
||||
'shortcut' => 'rt',
|
||||
'options' => array(),
|
||||
'doc' => '[testfile|dir ...]
|
||||
Run regression tests with PHP\'s regression testing script (run-tests.php).',
|
||||
),
|
||||
'package-dependencies' => array(
|
||||
'summary' => 'Show package dependencies',
|
||||
'function' => 'doPackageDependencies',
|
||||
'shortcut' => 'pd',
|
||||
'options' => array(),
|
||||
'doc' => '
|
||||
List all depencies the package has.'
|
||||
),
|
||||
'sign' => array(
|
||||
'summary' => 'Sign a package distribution file',
|
||||
'function' => 'doSign',
|
||||
'shortcut' => 'si',
|
||||
'options' => array(),
|
||||
'doc' => '<package-file>
|
||||
Signs a package distribution (.tar or .tgz) file with GnuPG.',
|
||||
),
|
||||
'makerpm' => array(
|
||||
'summary' => 'Builds an RPM package from a PEAR package',
|
||||
'function' => 'doMakeRPM',
|
||||
'shortcut' => 'rpm',
|
||||
'options' => array(
|
||||
'spec-template' => array(
|
||||
'shortopt' => 't',
|
||||
'arg' => 'FILE',
|
||||
'doc' => 'Use FILE as RPM spec file template'
|
||||
),
|
||||
'rpm-pkgname' => array(
|
||||
'shortopt' => 'p',
|
||||
'arg' => 'FORMAT',
|
||||
'doc' => 'Use FORMAT as format string for RPM package name, %s is replaced
|
||||
by the PEAR package name, defaults to "PEAR::%s".',
|
||||
),
|
||||
),
|
||||
'doc' => '<package-file>
|
||||
|
||||
Creates an RPM .spec file for wrapping a PEAR package inside an RPM
|
||||
package. Intended to be used from the SPECS directory, with the PEAR
|
||||
package tarball in the SOURCES directory:
|
||||
|
||||
$ pear makerpm ../SOURCES/Net_Socket-1.0.tgz
|
||||
Wrote RPM spec file PEAR::Net_Geo-1.0.spec
|
||||
$ rpm -bb PEAR::Net_Socket-1.0.spec
|
||||
...
|
||||
Wrote: /usr/src/redhat/RPMS/i386/PEAR::Net_Socket-1.0-1.i386.rpm
|
||||
',
|
||||
),
|
||||
);
|
||||
|
||||
var $output;
|
||||
|
||||
/**
|
||||
* PEAR_Command_Package constructor.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PEAR_Command_Package(&$ui, &$config)
|
||||
{
|
||||
parent::PEAR_Command_Common($ui, $config);
|
||||
}
|
||||
|
||||
function _displayValidationResults($err, $warn, $strict = false)
|
||||
{
|
||||
foreach ($err as $e) {
|
||||
$this->output .= "Error: $e\n";
|
||||
}
|
||||
foreach ($warn as $w) {
|
||||
$this->output .= "Warning: $w\n";
|
||||
}
|
||||
$this->output .= sprintf('Validation: %d error(s), %d warning(s)'."\n",
|
||||
sizeof($err), sizeof($warn));
|
||||
if ($strict && sizeof($err) > 0) {
|
||||
$this->output .= "Fix these errors and try again.";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function doPackage($command, $options, $params)
|
||||
{
|
||||
$this->output = '';
|
||||
include_once 'PEAR/Packager.php';
|
||||
$pkginfofile = isset($params[0]) ? $params[0] : 'package.xml';
|
||||
ob_start();
|
||||
$packager =& new PEAR_Packager($this->config->get('php_dir'),
|
||||
$this->config->get('ext_dir'),
|
||||
$this->config->get('doc_dir'));
|
||||
$packager->debug = $this->config->get('verbose');
|
||||
$err = $warn = array();
|
||||
$packager->validatePackageInfo($pkginfofile, $err, $warn);
|
||||
if (!$this->_displayValidationResults($err, $warn, true)) {
|
||||
$this->ui->outputData($this->output, $command);
|
||||
return;
|
||||
}
|
||||
$compress = empty($options['nocompress']) ? true : false;
|
||||
$result = $packager->Package($pkginfofile, $compress);
|
||||
$this->output = ob_get_contents();
|
||||
ob_end_clean();
|
||||
if (PEAR::isError($result)) {
|
||||
$this->ui->outputData($this->output, $command);
|
||||
return $this->raiseError($result);
|
||||
}
|
||||
// Don't want output, only the package file name just created
|
||||
if (isset($options['showname'])) {
|
||||
$this->output = $result;
|
||||
}
|
||||
/* (cox) What is supposed to do that code?
|
||||
$lines = explode("\n", $this->output);
|
||||
foreach ($lines as $line) {
|
||||
$this->output .= $line."n";
|
||||
}
|
||||
*/
|
||||
if (PEAR::isError($result)) {
|
||||
$this->output .= "Package failed: ".$result->getMessage();
|
||||
}
|
||||
$this->ui->outputData($this->output, $command);
|
||||
return true;
|
||||
}
|
||||
|
||||
function doPackageValidate($command, $options, $params)
|
||||
{
|
||||
$this->output = '';
|
||||
if (sizeof($params) < 1) {
|
||||
$params[0] = "package.xml";
|
||||
}
|
||||
$obj = new PEAR_Common;
|
||||
$info = null;
|
||||
if ($fp = @fopen($params[0], "r")) {
|
||||
$test = fread($fp, 5);
|
||||
fclose($fp);
|
||||
if ($test == "<?xml") {
|
||||
$info = $obj->infoFromDescriptionFile($params[0]);
|
||||
}
|
||||
}
|
||||
if (empty($info)) {
|
||||
$info = $obj->infoFromTgzFile($params[0]);
|
||||
}
|
||||
if (PEAR::isError($info)) {
|
||||
return $this->raiseError($info);
|
||||
}
|
||||
$obj->validatePackageInfo($info, $err, $warn);
|
||||
$this->_displayValidationResults($err, $warn);
|
||||
$this->ui->outputData($this->output, $command);
|
||||
return true;
|
||||
}
|
||||
|
||||
function doCvsTag($command, $options, $params)
|
||||
{
|
||||
$this->output = '';
|
||||
$_cmd = $command;
|
||||
if (sizeof($params) < 1) {
|
||||
$help = $this->getHelp($command);
|
||||
return $this->raiseError("$command: missing parameter: $help[0]");
|
||||
}
|
||||
$obj = new PEAR_Common;
|
||||
$info = $obj->infoFromDescriptionFile($params[0]);
|
||||
if (PEAR::isError($info)) {
|
||||
return $this->raiseError($info);
|
||||
}
|
||||
$err = $warn = array();
|
||||
$obj->validatePackageInfo($info, $err, $warn);
|
||||
if (!$this->_displayValidationResults($err, $warn, true)) {
|
||||
$this->ui->outputData($this->output, $command);
|
||||
break;
|
||||
}
|
||||
$version = $info['version'];
|
||||
$cvsversion = preg_replace('/[^a-z0-9]/i', '_', $version);
|
||||
$cvstag = "RELEASE_$cvsversion";
|
||||
$files = array_keys($info['filelist']);
|
||||
$command = "cvs";
|
||||
if (isset($options['quiet'])) {
|
||||
$command .= ' -q';
|
||||
}
|
||||
if (isset($options['reallyquiet'])) {
|
||||
$command .= ' -Q';
|
||||
}
|
||||
$command .= ' tag';
|
||||
if (isset($options['slide'])) {
|
||||
$command .= ' -F';
|
||||
}
|
||||
if (isset($options['delete'])) {
|
||||
$command .= ' -d';
|
||||
}
|
||||
$command .= ' ' . $cvstag . ' ' . escapeshellarg($params[0]);
|
||||
foreach ($files as $file) {
|
||||
$command .= ' ' . escapeshellarg($file);
|
||||
}
|
||||
$this->output .= "+ $command\n";
|
||||
if (empty($options['n'])) {
|
||||
$fp = popen($command, "r");
|
||||
while ($line = fgets($fp, 1024)) {
|
||||
$this->output .= rtrim($line)."\n";
|
||||
}
|
||||
pclose($fp);
|
||||
}
|
||||
$this->ui->outputData($this->output, $_cmd);
|
||||
return true;
|
||||
}
|
||||
|
||||
function doRunTests($command, $options, $params)
|
||||
{
|
||||
$cwd = getcwd();
|
||||
$php = PHP_BINDIR . '/php' . (OS_WINDOWS ? '.exe' : '');
|
||||
putenv("TEST_PHP_EXECUTABLE=$php");
|
||||
$ip = ini_get("include_path");
|
||||
$ps = OS_WINDOWS ? ';' : ':';
|
||||
$run_tests = $this->config->get('php_dir') . DIRECTORY_SEPARATOR . 'run-tests.php';
|
||||
if (!file_exists($run_tests)) {
|
||||
$run_tests = PEAR_INSTALL_DIR . DIRECTORY_SEPARATOR . 'run-tests.php';
|
||||
if (!file_exists($run_tests)) {
|
||||
return $this->raiseError("No `run-test.php' file found");
|
||||
}
|
||||
}
|
||||
$plist = implode(" ", $params);
|
||||
$cmd = "$php -C -d include_path=$cwd$ps$ip -f $run_tests -- $plist";
|
||||
system($cmd);
|
||||
return true;
|
||||
}
|
||||
|
||||
function doPackageDependencies($command, $options, $params)
|
||||
{
|
||||
// $params[0] -> the PEAR package to list its information
|
||||
if (sizeof($params) != 1) {
|
||||
return $this->raiseError("bad parameter(s), try \"help $command\"");
|
||||
}
|
||||
|
||||
$obj = new PEAR_Common();
|
||||
if (PEAR::isError($info = $obj->infoFromAny($params[0]))) {
|
||||
return $this->raiseError($info);
|
||||
}
|
||||
|
||||
if (is_array($info['release_deps'])) {
|
||||
$data = array(
|
||||
'caption' => 'Dependencies for ' . $info['package'],
|
||||
'border' => true,
|
||||
'headline' => array("Type", "Name", "Relation", "Version"),
|
||||
);
|
||||
|
||||
foreach ($info['release_deps'] as $d) {
|
||||
|
||||
if (isset($this->_deps_rel_trans[$d['rel']])) {
|
||||
$rel = $this->_deps_rel_trans[$d['rel']];
|
||||
} else {
|
||||
$rel = $d['rel'];
|
||||
}
|
||||
|
||||
if (isset($this->_deps_type_trans[$d['type']])) {
|
||||
$type = ucfirst($this->_deps_type_trans[$d['type']]);
|
||||
} else {
|
||||
$type = $d['type'];
|
||||
}
|
||||
|
||||
if (isset($d['name'])) {
|
||||
$name = $d['name'];
|
||||
} else {
|
||||
$name = '';
|
||||
}
|
||||
|
||||
if (isset($d['version'])) {
|
||||
$version = $d['version'];
|
||||
} else {
|
||||
$version = '';
|
||||
}
|
||||
|
||||
$data['data'][] = array($type, $name, $rel, $version);
|
||||
}
|
||||
|
||||
$this->ui->outputData($data, $command);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Fallback
|
||||
$this->ui->outputData("This package does not have any dependencies.", $command);
|
||||
}
|
||||
|
||||
function doSign($command, $options, $params)
|
||||
{
|
||||
// should move most of this code into PEAR_Packager
|
||||
// so it'll be easy to implement "pear package --sign"
|
||||
if (sizeof($params) != 1) {
|
||||
return $this->raiseError("bad parameter(s), try \"help $command\"");
|
||||
}
|
||||
if (!file_exists($params[0])) {
|
||||
return $this->raiseError("file does not exist: $params[0]");
|
||||
}
|
||||
$obj = new PEAR_Common;
|
||||
$info = $obj->infoFromTgzFile($params[0]);
|
||||
if (PEAR::isError($info)) {
|
||||
return $this->raiseError($info);
|
||||
}
|
||||
include_once "Archive/Tar.php";
|
||||
include_once "System.php";
|
||||
$tar = new Archive_Tar($params[0]);
|
||||
$tmpdir = System::mktemp('-d pearsign');
|
||||
if (!$tar->extractList('package.xml package.sig', $tmpdir)) {
|
||||
return $this->raiseError("failed to extract tar file");
|
||||
}
|
||||
if (file_exists("$tmpdir/package.sig")) {
|
||||
return $this->raiseError("package already signed");
|
||||
}
|
||||
@unlink("$tmpdir/package.sig");
|
||||
$input = $this->ui->userDialog($command,
|
||||
array('GnuPG Passphrase'),
|
||||
array('password'));
|
||||
$gpg = popen("gpg --batch --passphrase-fd 0 --armor --detach-sign --output $tmpdir/package.sig $tmpdir/package.xml 2>/dev/null", "w");
|
||||
if (!$gpg) {
|
||||
return $this->raiseError("gpg command failed");
|
||||
}
|
||||
fwrite($gpg, "$input[0]\r");
|
||||
if (pclose($gpg) || !file_exists("$tmpdir/package.sig")) {
|
||||
return $this->raiseError("gpg sign failed");
|
||||
}
|
||||
$tar->addModify("$tmpdir/package.sig", '', $tmpdir);
|
||||
return true;
|
||||
}
|
||||
|
||||
function doMakeRPM($command, $options, $params)
|
||||
{
|
||||
if (sizeof($params) != 1) {
|
||||
return $this->raiseError("bad parameter(s), try \"help $command\"");
|
||||
}
|
||||
if (!file_exists($params[0])) {
|
||||
return $this->raiseError("file does not exist: $params[0]");
|
||||
}
|
||||
include_once "Archive/Tar.php";
|
||||
include_once "PEAR/Installer.php";
|
||||
include_once "System.php";
|
||||
$tar = new Archive_Tar($params[0]);
|
||||
$tmpdir = System::mktemp('-d pear2rpm');
|
||||
$instroot = System::mktemp('-d pear2rpm');
|
||||
$tmp = $this->config->get('verbose');
|
||||
$this->config->set('verbose', 0);
|
||||
$installer = new PEAR_Installer($this->ui);
|
||||
$info = $installer->install($params[0],
|
||||
array('installroot' => $instroot,
|
||||
'nodeps' => true));
|
||||
$pkgdir = "$info[package]-$info[version]";
|
||||
// print "instroot=$instroot\n";
|
||||
// print_r($info);
|
||||
// return true;
|
||||
|
||||
$info['rpm_xml_dir'] = '/var/lib/pear';
|
||||
$this->config->set('verbose', $tmp);
|
||||
if (!$tar->extractList("$pkgdir/package.xml", $tmpdir, $pkgdir)) {
|
||||
return $this->raiseError("failed to extract $params[0]");
|
||||
}
|
||||
if (!file_exists("$tmpdir/package.xml")) {
|
||||
return $this->raiseError("no package.xml found in $params[0]");
|
||||
}
|
||||
// System::mkdir("-p $instroot$info[rpm_xml_dir]");
|
||||
// if (!@copy("$tmpdir/package.xml", "$instroot$info[rpm_xml_dir]/$info[package].xml")) {
|
||||
// return $this->raiseError("could not copy package.xml file: $php_errormsg");
|
||||
// }
|
||||
if (isset($options['spec-template'])) {
|
||||
$spec_template = $options['spec-template'];
|
||||
} else {
|
||||
$spec_template = $this->config->get('data_dir') .
|
||||
'/PEAR/template.spec';
|
||||
}
|
||||
if (isset($options['rpm-pkgname'])) {
|
||||
$rpm_pkgname_format = $options['rpm-pkgname'];
|
||||
} else {
|
||||
$rpm_pkgname_format = "PEAR::%s";
|
||||
}
|
||||
|
||||
$info['extra_headers'] = '';
|
||||
$info['doc_files'] = '';
|
||||
$info['files'] = '';
|
||||
$info['rpm_package'] = sprintf($rpm_pkgname_format, $info['package']);
|
||||
$srcfiles = 0;
|
||||
foreach ($info['filelist'] as $name => $attr) {
|
||||
if ($attr['role'] == 'doc') {
|
||||
$info['doc_files'] .= " $name";
|
||||
} elseif ($attr['role'] == 'src') {
|
||||
$srcfiles++;
|
||||
}
|
||||
$info['files'] .= "$attr[installed_as]\n";
|
||||
}
|
||||
if ($srcfiles > 0) {
|
||||
include_once "OS/Guess.php";
|
||||
$os = new OS_Guess;
|
||||
$arch = $os->getCpu();
|
||||
} else {
|
||||
$arch = 'noarch';
|
||||
}
|
||||
$fp = @fopen($spec_template, "r");
|
||||
if (!$fp) {
|
||||
return $this->raiseError("could not open RPM spec file template $spec_template: $php_errormsg");
|
||||
}
|
||||
$spec_contents = preg_replace('/@([a-z0-9_-]+)@/e', '$info["\1"]', fread($fp, filesize($spec_template)));
|
||||
fclose($fp);
|
||||
$spec_file = "$info[rpm_package]-$info[version].spec";
|
||||
$wp = fopen($spec_file, "w");
|
||||
if (!$wp) {
|
||||
return $this->raiseError("could not write RPM spec file $spec_file: $php_errormsg");
|
||||
}
|
||||
fwrite($wp, $spec_contents);
|
||||
fclose($wp);
|
||||
$this->ui->outputData("Wrote RPM spec file $spec_file", $command);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,318 @@
|
||||
<?php
|
||||
// /* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.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. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Stig Bakken <ssb@fast.no> |
|
||||
// | |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id$
|
||||
|
||||
require_once 'PEAR/Command/Common.php';
|
||||
require_once 'PEAR/Registry.php';
|
||||
require_once 'PEAR/Config.php';
|
||||
|
||||
class PEAR_Command_Registry extends PEAR_Command_Common
|
||||
{
|
||||
// {{{ command definitions
|
||||
|
||||
var $commands = array(
|
||||
'list' => array(
|
||||
'summary' => 'List Installed Packages',
|
||||
'function' => 'doList',
|
||||
'shortcut' => 'l',
|
||||
'options' => array(),
|
||||
'doc' => '[package]
|
||||
If invoked without parameters, this command lists the PEAR packages
|
||||
installed in your php_dir ({config php_dir)). With a parameter, it
|
||||
lists the files in that package.
|
||||
',
|
||||
),
|
||||
'shell-test' => array(
|
||||
'summary' => 'Shell Script Test',
|
||||
'function' => 'doShellTest',
|
||||
'shortcut' => 'st',
|
||||
'options' => array(),
|
||||
'doc' => '<package> [[relation] version]
|
||||
Tests if a package is installed in the system. Will exit(1) if it is not.
|
||||
<relation> The version comparison operator. One of:
|
||||
<, lt, <=, le, >, gt, >=, ge, ==, =, eq, !=, <>, ne
|
||||
<version> The version to compare with
|
||||
'),
|
||||
'info' => array(
|
||||
'summary' => 'Display information about a package',
|
||||
'function' => 'doInfo',
|
||||
'shortcut' => 'i',
|
||||
'options' => array(),
|
||||
'doc' => '<pacakge>
|
||||
Displays information about a package. The package argument may be a
|
||||
local package file, an URL to a package file, or the name of an
|
||||
installed package.'
|
||||
)
|
||||
);
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* PEAR_Command_Registry constructor.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PEAR_Command_Registry(&$ui, &$config)
|
||||
{
|
||||
parent::PEAR_Command_Common($ui, $config);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ doList()
|
||||
|
||||
function _sortinfo($a, $b)
|
||||
{
|
||||
return strcmp($a['package'], $b['package']);
|
||||
}
|
||||
|
||||
function doList($command, $options, $params)
|
||||
{
|
||||
$reg = new PEAR_Registry($this->config->get('php_dir'));
|
||||
if (sizeof($params) == 0) {
|
||||
$installed = $reg->packageInfo();
|
||||
usort($installed, array(&$this, '_sortinfo'));
|
||||
$i = $j = 0;
|
||||
$data = array(
|
||||
'caption' => 'Installed packages:',
|
||||
'border' => true,
|
||||
'headline' => array('Package', 'Version', 'State')
|
||||
);
|
||||
foreach ($installed as $package) {
|
||||
$data['data'][] = array($package['package'],
|
||||
$package['version'],
|
||||
@$package['release_state']);
|
||||
}
|
||||
if (count($installed)==0) {
|
||||
$data = '(no packages installed)';
|
||||
}
|
||||
$this->ui->outputData($data, $command);
|
||||
} else {
|
||||
if (file_exists($params[0]) && !is_dir($params[0])) {
|
||||
include_once "PEAR/Common.php";
|
||||
$obj = &new PEAR_Common;
|
||||
$info = $obj->infoFromAny($params[0]);
|
||||
$headings = array('Package File', 'Install Path');
|
||||
$installed = false;
|
||||
} else {
|
||||
$info = $reg->packageInfo($params[0]);
|
||||
$headings = array('Type', 'Install Path');
|
||||
$installed = true;
|
||||
}
|
||||
if (PEAR::isError($info)) {
|
||||
return $this->raiseError($info);
|
||||
}
|
||||
if ($info === null) {
|
||||
return $this->raiseError("`$params[0]' not installed");
|
||||
}
|
||||
$list = $info['filelist'];
|
||||
if ($installed) {
|
||||
$caption = 'Installed Files For ' . $params[0];
|
||||
} else {
|
||||
$caption = 'Contents of ' . basename($params[0]);
|
||||
}
|
||||
$data = array(
|
||||
'caption' => $caption,
|
||||
'border' => true,
|
||||
'headline' => $headings);
|
||||
foreach ($list as $file => $att) {
|
||||
if ($installed) {
|
||||
if (empty($att['installed_as'])) {
|
||||
continue;
|
||||
}
|
||||
$data['data'][] = array($att['role'], $att['installed_as']);
|
||||
} else {
|
||||
if (isset($att['baseinstalldir'])) {
|
||||
$dest = $att['baseinstalldir'] . DIRECTORY_SEPARATOR .
|
||||
$file;
|
||||
} else {
|
||||
$dest = $file;
|
||||
}
|
||||
switch ($att['role']) {
|
||||
case 'test':
|
||||
case 'data':
|
||||
if ($installed) {
|
||||
break 2;
|
||||
}
|
||||
$dest = '-- will not be installed --';
|
||||
break;
|
||||
case 'doc':
|
||||
$dest = $this->config->get('doc_dir') . DIRECTORY_SEPARATOR .
|
||||
$dest;
|
||||
break;
|
||||
case 'php':
|
||||
default:
|
||||
$dest = $this->config->get('php_dir') . DIRECTORY_SEPARATOR .
|
||||
$dest;
|
||||
}
|
||||
$dest = preg_replace('!/+!', '/', $dest);
|
||||
$file = preg_replace('!/+!', '/', $file);
|
||||
$data['data'][] = array($file, $dest);
|
||||
}
|
||||
}
|
||||
$this->ui->outputData($data, $command);
|
||||
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ doShellTest()
|
||||
|
||||
function doShellTest($command, $options, $params)
|
||||
{
|
||||
$this->pushErrorHandling(PEAR_ERROR_RETURN);
|
||||
$reg = &new PEAR_Registry($this->config->get('php_dir'));
|
||||
// "pear shell-test Foo"
|
||||
if (sizeof($params) == 1) {
|
||||
if (!$reg->packageExists($params[0])) {
|
||||
exit(1);
|
||||
}
|
||||
// "pear shell-test Foo 1.0"
|
||||
} elseif (sizeof($params) == 2) {
|
||||
$v = $reg->packageInfo($params[0], 'version');
|
||||
if (!$v || !version_compare("$v", "{$params[1]}", "ge")) {
|
||||
exit(1);
|
||||
}
|
||||
// "pear shell-test Foo ge 1.0"
|
||||
} elseif (sizeof($params) == 3) {
|
||||
$v = $reg->packageInfo($params[0], 'version');
|
||||
if (!$v || !version_compare("$v", "{$params[2]}", $params[1])) {
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
$this->popErrorHandling();
|
||||
$this->raiseError("$command: expects 1 to 3 parameters");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ doInfo
|
||||
|
||||
function doInfo($command, $options, $params)
|
||||
{
|
||||
// $params[0] The package for showing info
|
||||
if (sizeof($params) != 1) {
|
||||
return $this->raiseError("This command only accepts one param: ".
|
||||
"the package you want information");
|
||||
}
|
||||
if (@is_file($params[0])) {
|
||||
$obj = &new PEAR_Common();
|
||||
$info = $obj->infoFromAny($params[0]);
|
||||
} else {
|
||||
$reg = &new PEAR_Registry($this->config->get('php_dir'));
|
||||
$info = $reg->packageInfo($params[0]);
|
||||
}
|
||||
if (PEAR::isError($info)) {
|
||||
return $info;
|
||||
}
|
||||
if (empty($info)) {
|
||||
$this->ui->displayLine("Nothing found for `$params[0]'");
|
||||
return;
|
||||
}
|
||||
unset($info['filelist']);
|
||||
unset($info['changelog']);
|
||||
$keys = array_keys($info);
|
||||
$longtext = array('description', 'summary');
|
||||
foreach ($keys as $key) {
|
||||
if (is_array($info[$key])) {
|
||||
switch ($key) {
|
||||
case 'maintainers': {
|
||||
$i = 0;
|
||||
$mstr = '';
|
||||
foreach ($info[$key] as $m) {
|
||||
if ($i++ > 0) {
|
||||
$mstr .= "\n";
|
||||
}
|
||||
$mstr .= $m['name'] . " <";
|
||||
if (isset($m['email'])) {
|
||||
$mstr .= $m['email'];
|
||||
} else {
|
||||
$mstr .= $m['handle'] . '@php.net';
|
||||
}
|
||||
$mstr .= "> ($m[role])";
|
||||
}
|
||||
$info[$key] = $mstr;
|
||||
break;
|
||||
}
|
||||
case 'release_deps': {
|
||||
$i = 0;
|
||||
$dstr = '';
|
||||
foreach ($info[$key] as $d) {
|
||||
if (isset($this->_deps_rel_trans[$d['rel']])) {
|
||||
$rel = $this->_deps_rel_trans[$d['rel']];
|
||||
} else {
|
||||
$rel = $d['rel'];
|
||||
}
|
||||
if (isset($this->_deps_type_trans[$d['type']])) {
|
||||
$type = ucfirst($this->_deps_type_trans[$d['type']]);
|
||||
} else {
|
||||
$type = $d['type'];
|
||||
}
|
||||
if (isset($d['name'])) {
|
||||
$name = $d['name'] . ' ';
|
||||
} else {
|
||||
$name = '';
|
||||
}
|
||||
if (isset($d['version'])) {
|
||||
$version = $d['version'] . ' ';
|
||||
} else {
|
||||
$version = '';
|
||||
}
|
||||
$dstr .= "$type $name$rel $version\n";
|
||||
}
|
||||
$info[$key] = $dstr;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
$info[$key] = implode(", ", $info[$key]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($key == '_lastmodified') {
|
||||
$hdate = date('Y-m-d', $info[$key]);
|
||||
unset($info[$key]);
|
||||
$info['Last Modified'] = $hdate;
|
||||
} else {
|
||||
$info[$key] = trim($info[$key]);
|
||||
if (in_array($key, $longtext)) {
|
||||
$info[$key] = preg_replace('/ +/', ' ', $info[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
$caption = 'About ' . $info['package'] . '-' . $info['version'];
|
||||
$data = array(
|
||||
'caption' => $caption,
|
||||
'border' => true);
|
||||
foreach ($info as $key => $value) {
|
||||
$key = ucwords(trim(str_replace('_', ' ', $key)));
|
||||
$data['data'][] = array($key, $value);
|
||||
}
|
||||
|
||||
$this->ui->outputData($data, 'package-info');
|
||||
}
|
||||
|
||||
// }}}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,357 @@
|
||||
<?php
|
||||
// /* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.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. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Stig Bakken <ssb@fast.no> |
|
||||
// | |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id$
|
||||
|
||||
require_once 'PEAR/Command/Common.php';
|
||||
require_once 'PEAR/Common.php';
|
||||
require_once 'PEAR/Remote.php';
|
||||
require_once 'PEAR/Registry.php';
|
||||
|
||||
class PEAR_Command_Remote extends PEAR_Command_Common
|
||||
{
|
||||
// {{{ command definitions
|
||||
|
||||
var $commands = array(
|
||||
'remote-info' => array(
|
||||
'summary' => 'Information About Remote Packages',
|
||||
'function' => 'doRemoteInfo',
|
||||
'shortcut' => 'ri',
|
||||
'options' => array(),
|
||||
'doc' => '<package>
|
||||
Get details on a package from the server.',
|
||||
),
|
||||
'list-upgrades' => array(
|
||||
'summary' => 'List Available Upgrades',
|
||||
'function' => 'doListUpgrades',
|
||||
'shortcut' => 'lu',
|
||||
'options' => array(),
|
||||
'doc' => '
|
||||
List releases on the server of packages you have installed where
|
||||
a newer version is available with the same release state (stable etc.).'
|
||||
),
|
||||
'remote-list' => array(
|
||||
'summary' => 'List Remote Packages',
|
||||
'function' => 'doRemoteList',
|
||||
'shortcut' => 'rl',
|
||||
'options' => array(),
|
||||
'doc' => '
|
||||
Lists the packages available on the configured server along with the
|
||||
latest stable release of each package.',
|
||||
),
|
||||
'search' => array(
|
||||
'summary' => 'Search remote package database',
|
||||
'function' => 'doSearch',
|
||||
'shortcut' => 'sp',
|
||||
'options' => array(),
|
||||
'doc' => '
|
||||
Lists all packages which match the search paramteres (first param
|
||||
is package name, second package info)',
|
||||
),
|
||||
'list-all' => array(
|
||||
'summary' => 'List All Packages',
|
||||
'function' => 'doListAll',
|
||||
'shortcut' => 'la',
|
||||
'options' => array(),
|
||||
'doc' => '
|
||||
Lists the packages available on the configured server along with the
|
||||
latest stable release of each package.',
|
||||
),
|
||||
'download' => array(
|
||||
'summary' => 'Download Package',
|
||||
'function' => 'doDownload',
|
||||
'shortcut' => 'd',
|
||||
'options' => array(
|
||||
'nocompress' => array(
|
||||
'shortopt' => 'Z',
|
||||
'doc' => 'download an uncompressed (.tar) file',
|
||||
),
|
||||
),
|
||||
'doc' => '{package|package-version}
|
||||
Download a package tarball. The file will be named as suggested by the
|
||||
server, for example if you download the DB package and the latest stable
|
||||
version of DB is 1.2, the downloaded file will be DB-1.2.tgz.',
|
||||
),
|
||||
);
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* PEAR_Command_Remote constructor.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PEAR_Command_Remote(&$ui, &$config)
|
||||
{
|
||||
parent::PEAR_Command_Common($ui, $config);
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
// {{{ remote-info
|
||||
|
||||
function doRemoteInfo($command, $options, $params)
|
||||
{
|
||||
if (sizeof($params) != 1) {
|
||||
return $this->raiseError("$command expects one param: the remote package name");
|
||||
}
|
||||
$r = new PEAR_Remote($this->config);
|
||||
$info = $r->call('package.info', $params[0]);
|
||||
if (PEAR::isError($info)) {
|
||||
return $this->raiseError($info);
|
||||
}
|
||||
|
||||
$reg = new PEAR_Registry($this->config->get('php_dir'));
|
||||
$installed = $reg->packageInfo($info['name']);
|
||||
$info['installed'] = $installed['version'] ? $installed['version'] : '- no -';
|
||||
|
||||
$this->ui->outputData($info, $command);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ list-remote
|
||||
|
||||
function doRemoteList($command, $options, $params)
|
||||
{
|
||||
$r = new PEAR_Remote($this->config);
|
||||
$list_options = false;
|
||||
if ($this->config->get('preferred_state') == 'stable')
|
||||
$list_options = true;
|
||||
$available = $r->call('package.listAll', $list_options);
|
||||
if (PEAR::isError($available)) {
|
||||
return $this->raiseError($available);
|
||||
}
|
||||
$i = $j = 0;
|
||||
$data = array(
|
||||
'caption' => 'Available packages:',
|
||||
'border' => true,
|
||||
'headline' => array('Package', 'Version'),
|
||||
);
|
||||
foreach ($available as $name => $info) {
|
||||
$data['data'][] = array($name, isset($info['stable']) ? $info['stable'] : '-n/a-');
|
||||
}
|
||||
if (count($available)==0) {
|
||||
$data = '(no packages installed yet)';
|
||||
}
|
||||
$this->ui->outputData($data, $command);
|
||||
return true;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ list-all
|
||||
|
||||
function doListAll($command, $options, $params)
|
||||
{
|
||||
$r = new PEAR_Remote($this->config);
|
||||
$reg = new PEAR_Registry($this->config->get('php_dir'));
|
||||
$list_options = false;
|
||||
if ($this->config->get('preferred_state') == 'stable')
|
||||
$list_options = true;
|
||||
$available = $r->call('package.listAll', $list_options);
|
||||
if (PEAR::isError($available)) {
|
||||
return $this->raiseError($available);
|
||||
}
|
||||
$data = array(
|
||||
'caption' => 'All packages:',
|
||||
'border' => true,
|
||||
'headline' => array('Package', 'Latest', 'Local'),
|
||||
);
|
||||
|
||||
foreach ($available as $name => $info) {
|
||||
$installed = $reg->packageInfo($name);
|
||||
$desc = $info['summary'];
|
||||
if (isset($params[$name]))
|
||||
$desc .= "\n\n".$info['description'];
|
||||
|
||||
if (isset($options['mode']))
|
||||
{
|
||||
if ($options['mode'] == 'installed' && !isset($installed['version']))
|
||||
continue;
|
||||
if ($options['mode'] == 'notinstalled' && isset($installed['version']))
|
||||
continue;
|
||||
if ($options['mode'] == 'upgrades'
|
||||
&& (!isset($installed['version']) || $installed['version'] == $info['stable']))
|
||||
{
|
||||
continue;
|
||||
};
|
||||
};
|
||||
|
||||
$data['data'][$info['category']][] = array(
|
||||
$name,
|
||||
$info['stable'],
|
||||
$installed['version'],
|
||||
$desc,
|
||||
$info['deps'],
|
||||
);
|
||||
}
|
||||
$this->ui->outputData($data, $command);
|
||||
return true;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ search
|
||||
|
||||
function doSearch($command, $options, $params)
|
||||
{
|
||||
if ((!isset($params[0]) || empty($params[0]))
|
||||
&& (!isset($params[1]) || empty($params[1])))
|
||||
{
|
||||
return $this->raiseError('no valid search string supplied');
|
||||
};
|
||||
|
||||
$r = new PEAR_Remote($this->config);
|
||||
$reg = new PEAR_Registry($this->config->get('php_dir'));
|
||||
$available = $r->call('package.listAll', true);
|
||||
if (PEAR::isError($available)) {
|
||||
return $this->raiseError($available);
|
||||
}
|
||||
$data = array(
|
||||
'caption' => 'Matched packages:',
|
||||
'border' => true,
|
||||
'headline' => array('Package', 'Latest', 'Local'),
|
||||
);
|
||||
|
||||
foreach ($available as $name => $info) {
|
||||
$found = (!empty($params[0]) && stristr($name, $params[0]) !== false);
|
||||
if (!$found && !(isset($params[1]) && !empty($params[1])
|
||||
&& (stristr($info['summary'], $params[1]) !== false
|
||||
|| stristr($info['description'], $params[1]) !== false)))
|
||||
{
|
||||
continue;
|
||||
};
|
||||
|
||||
$installed = $reg->packageInfo($name);
|
||||
$desc = $info['summary'];
|
||||
if (isset($params[$name]))
|
||||
$desc .= "\n\n".$info['description'];
|
||||
|
||||
$data['data'][$info['category']][] = array(
|
||||
$name,
|
||||
$info['stable'],
|
||||
$installed['version'],
|
||||
$desc,
|
||||
);
|
||||
}
|
||||
if (!isset($data['data'])) {
|
||||
return $this->raiseError('no packages found');
|
||||
};
|
||||
$this->ui->outputData($data, $command);
|
||||
return true;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ download
|
||||
|
||||
function doDownload($command, $options, $params)
|
||||
{
|
||||
//$params[0] -> The package to download
|
||||
if (count($params) != 1) {
|
||||
return PEAR::raiseError("download expects one argument: the package to download");
|
||||
}
|
||||
$server = $this->config->get('master_server');
|
||||
if (!ereg('^http://', $params[0])) {
|
||||
$pkgfile = "http://$server/get/$params[0]";
|
||||
} else {
|
||||
$pkgfile = $params[0];
|
||||
}
|
||||
$this->bytes_downloaded = 0;
|
||||
$saved = PEAR_Common::downloadHttp($pkgfile, $this->ui, '.',
|
||||
array(&$this, 'downloadCallback'));
|
||||
if (PEAR::isError($saved)) {
|
||||
return $this->raiseError($saved);
|
||||
}
|
||||
$fname = basename($saved);
|
||||
$this->ui->outputData("File $fname downloaded ($this->bytes_downloaded bytes)", $command);
|
||||
return true;
|
||||
}
|
||||
|
||||
function downloadCallback($msg, $params = null)
|
||||
{
|
||||
if ($msg == 'done') {
|
||||
$this->bytes_downloaded = $params;
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ list-upgrades
|
||||
|
||||
function doListUpgrades($command, $options, $params)
|
||||
{
|
||||
include_once "PEAR/Registry.php";
|
||||
$remote = new PEAR_Remote($this->config);
|
||||
if (empty($params[0])) {
|
||||
$state = $this->config->get('preferred_state');
|
||||
} else {
|
||||
$state = $params[0];
|
||||
}
|
||||
$caption = 'Available Upgrades';
|
||||
if (empty($state) || $state == 'any') {
|
||||
$latest = $remote->call("package.listLatestReleases");
|
||||
} else {
|
||||
$latest = $remote->call("package.listLatestReleases", $state);
|
||||
$caption .= ' (' . $state . ')';
|
||||
}
|
||||
$caption .= ':';
|
||||
if (PEAR::isError($latest)) {
|
||||
return $latest;
|
||||
}
|
||||
$reg = new PEAR_Registry($this->config->get('php_dir'));
|
||||
$inst = array_flip($reg->listPackages());
|
||||
$data = array(
|
||||
'caption' => $caption,
|
||||
'border' => 1,
|
||||
'headline' => array('Package', 'Version', 'Size'),
|
||||
);
|
||||
foreach ($latest as $package => $info) {
|
||||
if (!isset($inst[$package])) {
|
||||
// skip packages we don't have installed
|
||||
continue;
|
||||
}
|
||||
extract($info);
|
||||
$inst_version = $reg->packageInfo($package, 'version');
|
||||
if (version_compare("$version", "$inst_version", "le")) {
|
||||
// installed version is up-to-date
|
||||
continue;
|
||||
}
|
||||
if ($filesize >= 20480) {
|
||||
$filesize += 1024 - ($filesize % 1024);
|
||||
$fs = sprintf("%dkB", $filesize / 1024);
|
||||
} elseif ($filesize > 0) {
|
||||
$filesize += 103 - ($filesize % 103);
|
||||
$fs = sprintf("%.1fkB", $filesize / 1024.0);
|
||||
} else {
|
||||
$fs = " -"; // XXX center instead
|
||||
}
|
||||
$data['data'][] = array($package, $version, $fs);
|
||||
}
|
||||
if (empty($data['data'])) {
|
||||
$this->ui->outputData('No upgrades available');
|
||||
} else {
|
||||
$this->ui->outputData($data, $command);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// }}}
|
||||
}
|
||||
|
||||
?>
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,281 @@
|
||||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.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. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Tomas V.V.Cox <cox@idecnet.com> |
|
||||
// | Stig Bakken <ssb@fast.no> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id$
|
||||
|
||||
/**
|
||||
* Methods for dependencies check. Based on Stig's dependencies RFC
|
||||
* at http://cvs.php.net/cvs.php/pearweb/rfc
|
||||
* (requires php >= 4.1)
|
||||
*/
|
||||
|
||||
require_once "PEAR.php";
|
||||
|
||||
class PEAR_Dependency
|
||||
{
|
||||
function PEAR_Dependency(&$registry)
|
||||
{
|
||||
$this->registry = &$registry;
|
||||
}
|
||||
/**
|
||||
* This method maps the xml dependency definition to the
|
||||
* PEAR_dependecy one
|
||||
*
|
||||
* $opts => Array
|
||||
* (
|
||||
* [type] => pkg
|
||||
* [rel] => ge
|
||||
* [version] => 3.4
|
||||
* [name] => HTML_Common
|
||||
* )
|
||||
*/
|
||||
function callCheckMethod($opts)
|
||||
{
|
||||
$rel = isset($opts['rel']) ? $opts['rel'] : 'has';
|
||||
$req = isset($opts['version']) ? $opts['version'] : null;
|
||||
$name = isset($opts['name']) ? $opts['name'] : null;
|
||||
switch ($opts['type']) {
|
||||
case 'pkg':
|
||||
return $this->checkPackage($name, $req, $rel);
|
||||
break;
|
||||
case 'ext':
|
||||
return $this->checkExtension($name, $req, $rel);
|
||||
break;
|
||||
case 'php':
|
||||
return $this->checkPHP($req, $rel);
|
||||
break;
|
||||
case 'prog':
|
||||
return $this->checkProgram($name);
|
||||
break;
|
||||
case 'os':
|
||||
return $this->checkOS($name);
|
||||
break;
|
||||
case 'sapi':
|
||||
return $this->checkSAPI($name);
|
||||
break;
|
||||
case 'zend':
|
||||
return $this->checkZend($name);
|
||||
break;
|
||||
default:
|
||||
return "'{$opts['type']}' dependency type not supported";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Package dependencies check method
|
||||
*
|
||||
* @param string $name Name of the package to test
|
||||
* @param string $version The package version required
|
||||
* @param string $relation How to compare versions with eachother
|
||||
*
|
||||
* @return mixed bool false if no error or the error string
|
||||
*/
|
||||
function checkPackage($name, $req = null, $relation = 'has')
|
||||
{
|
||||
if (substr($relation, 0, 2) == 'v.') {
|
||||
$relation = substr($relation, 2);
|
||||
}
|
||||
switch ($relation) {
|
||||
case 'has':
|
||||
if (!$this->registry->packageExists($name)) {
|
||||
return "requires package `$name'";
|
||||
}
|
||||
return false;
|
||||
case 'not':
|
||||
if (!$this->registry->packageExists($name)) {
|
||||
return "conflicts with package `$name'";
|
||||
}
|
||||
return false;
|
||||
case 'lt':
|
||||
case 'le':
|
||||
case 'eq':
|
||||
case 'ne':
|
||||
case 'ge':
|
||||
case 'gt':
|
||||
$version = $this->registry->packageInfo($name, 'version');
|
||||
if (!$this->registry->packageExists($name)
|
||||
|| !version_compare("$version", "$req", $relation))
|
||||
{
|
||||
return "requires package `$name' " .
|
||||
$this->signOperator($relation) . " $req";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return "Relation '$relation' with requirement '$req' is not supported (name=$name)";
|
||||
}
|
||||
|
||||
/**
|
||||
* Extension dependencies check method
|
||||
*
|
||||
* @param string $name Name of the extension to test
|
||||
* @param string $req_ext_ver Required extension version to compare with
|
||||
* @param string $relation How to compare versions with eachother
|
||||
*
|
||||
* @return mixed bool false if no error or the error string
|
||||
*/
|
||||
function checkExtension($name, $req = null, $relation = 'has')
|
||||
{
|
||||
// XXX (ssb): could we avoid loading the extension here?
|
||||
if (!PEAR::loadExtension($name)) {
|
||||
return "'$name' PHP extension is not installed";
|
||||
}
|
||||
if ($relation == 'has') {
|
||||
return false;
|
||||
}
|
||||
if (substr($relation, 0, 2) == 'v.') {
|
||||
$ext_ver = phpversion($name);
|
||||
$operator = substr($relation, 2);
|
||||
// Force params to be strings, otherwise the comparation will fail (ex. 0.9==0.90)
|
||||
if (!version_compare("$ext_ver", "$req", $operator)) {
|
||||
return "'$name' PHP extension version " .
|
||||
$this->signOperator($operator) . " $req is required";
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Operating system dependencies check method
|
||||
*
|
||||
* @param string $os Name of the operating system
|
||||
*
|
||||
* @return mixed bool false if no error or the error string
|
||||
*/
|
||||
function checkOS($os)
|
||||
{
|
||||
// XXX Fixme: Implement a more flexible way, like
|
||||
// comma separated values or something similar to PEAR_OS
|
||||
|
||||
// only 'has' relation is supported
|
||||
if ($os == PHP_OS) {
|
||||
return false;
|
||||
}
|
||||
return "'$os' operating system not supported";
|
||||
}
|
||||
|
||||
/**
|
||||
* PHP version check method
|
||||
*
|
||||
* @param string $req which version to compare
|
||||
* @param string $relation how to compare the version
|
||||
*
|
||||
* @return mixed bool false if no error or the error string
|
||||
*/
|
||||
function checkPHP($req, $relation = 'ge')
|
||||
{
|
||||
if (substr($relation, 0, 2) == 'v.') {
|
||||
$php_ver = phpversion();
|
||||
$operator = substr($relation, 2);
|
||||
if (!version_compare("$php_ver", "$req", $operator)) {
|
||||
return "PHP version " . $this->signOperator($operator) .
|
||||
" $req is required";
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* External program check method. Looks for executable files in
|
||||
* directories listed in the PATH environment variable.
|
||||
*
|
||||
* @param string $program which program to look for
|
||||
*
|
||||
* @return mixed bool false if no error or the error string
|
||||
*/
|
||||
function checkProgram($program)
|
||||
{
|
||||
// XXX FIXME honor safe mode
|
||||
$path_delim = OS_WINDOWS ? ';' : ':';
|
||||
$exe_suffix = OS_WINDOWS ? '.exe' : '';
|
||||
$path_elements = explode($path_delim, getenv('PATH'));
|
||||
foreach ($path_elements as $dir) {
|
||||
$file = $dir . DIRECTORY_SEPARATOR . $program . $exe_suffix;
|
||||
if (@file_exists($file) && @is_executable($file)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return "'$program' program is not present in the PATH";
|
||||
}
|
||||
|
||||
/**
|
||||
* SAPI backend check method. Version comparison is not yet
|
||||
* available here.
|
||||
*
|
||||
* @param string $name name of SAPI backend
|
||||
* @param string $req which version to compare
|
||||
* @param string $relation how to compare versions (currently
|
||||
* hardcoded to 'has')
|
||||
* @return mixed bool false if no error or the error string
|
||||
*/
|
||||
function checkSAPI($name, $req = null, $relation = 'has')
|
||||
{
|
||||
// XXX Fixme: There is no way to know if the user has or
|
||||
// not other SAPI backends installed than the installer one
|
||||
|
||||
$sapi_backend = php_sapi_name();
|
||||
// Version comparisons not supported, sapi backends don't have
|
||||
// version information yet.
|
||||
if ($sapi_backend == $name) {
|
||||
return false;
|
||||
}
|
||||
return "'$sapi_backend' SAPI backend not supported";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Zend version check method
|
||||
*
|
||||
* @param string $req which version to compare
|
||||
* @param string $relation how to compare the version
|
||||
*
|
||||
* @return mixed bool false if no error or the error string
|
||||
*/
|
||||
function checkZend($req, $relation = 'ge')
|
||||
{
|
||||
if (substr($relation, 0, 2) == 'v.') {
|
||||
$zend_ver = zend_version();
|
||||
$operator = substr($relation, 2);
|
||||
if (!version_compare("$zend_ver", "$req", $operator)) {
|
||||
return "Zend version " . $this->signOperator($operator) .
|
||||
" $req is required";
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts text comparing operators to them sign equivalents
|
||||
* ex: 'ge' to '>='
|
||||
*/
|
||||
function signOperator($operator)
|
||||
{
|
||||
switch($operator) {
|
||||
case 'lt': return '<';
|
||||
case 'le': return '<=';
|
||||
case 'gt': return '>';
|
||||
case 'ge': return '>=';
|
||||
case 'eq': return '==';
|
||||
case 'ne': return '!=';
|
||||
default:
|
||||
return $operator;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,474 @@
|
||||
<?php
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| PHP Version 4 |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 1997-2002 The PHP Group |
|
||||
+----------------------------------------------------------------------+
|
||||
| This source file is subject to version 2.02 of the PHP license, |
|
||||
| that is bundled with this package in the file LICENSE, and is |
|
||||
| available at through the world-wide-web at |
|
||||
| http://www.php.net/license/2_02.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. |
|
||||
+----------------------------------------------------------------------+
|
||||
| Author: Stig Sæther Bakken <ssb@fast.no> |
|
||||
+----------------------------------------------------------------------+
|
||||
|
||||
$Id$
|
||||
*/
|
||||
|
||||
require_once "PEAR.php";
|
||||
|
||||
class PEAR_Frontend_CLI extends PEAR
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* What type of user interface this frontend is for.
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $type = 'CLI';
|
||||
var $lp = ''; // line prefix
|
||||
|
||||
var $omode = 'plain';
|
||||
var $params = array();
|
||||
var $term = array(
|
||||
'bold' => '',
|
||||
'normal' => '',
|
||||
);
|
||||
|
||||
// }}}
|
||||
|
||||
// {{{ constructor
|
||||
|
||||
function PEAR_Frontend_CLI()
|
||||
{
|
||||
parent::PEAR();
|
||||
$term = getenv('TERM'); //(cox) $_ENV is empty for me in 4.1.1
|
||||
if ($term) {
|
||||
// XXX can use ncurses extension here, if available
|
||||
if (preg_match('/^(xterm|vt220|linux)/', $term)) {
|
||||
$this->term['bold'] = sprintf("%c%c%c%c", 27, 91, 49, 109);
|
||||
$this->term['normal']=sprintf("%c%c%c", 27, 91, 109);
|
||||
} elseif (preg_match('/^vt100/', $term)) {
|
||||
$this->term['bold'] = sprintf("%c%c%c%c%c%c", 27, 91, 49, 109, 0, 0);
|
||||
$this->term['normal']=sprintf("%c%c%c%c%c", 27, 91, 109, 0, 0);
|
||||
}
|
||||
} elseif (OS_WINDOWS) {
|
||||
// XXX add ANSI codes here
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
// {{{ displayLine(text)
|
||||
|
||||
function displayLine($text)
|
||||
{
|
||||
trigger_error("Frontend::displayLine deprecated", E_USER_ERROR);
|
||||
}
|
||||
|
||||
function _displayLine($text)
|
||||
{
|
||||
print "$this->lp$text\n";
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ display(text)
|
||||
|
||||
function display($text)
|
||||
{
|
||||
trigger_error("Frontend::display deprecated", E_USER_ERROR);
|
||||
}
|
||||
|
||||
function _display($text)
|
||||
{
|
||||
print $text;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ displayError(eobj)
|
||||
|
||||
function displayError($eobj)
|
||||
{
|
||||
return $this->_displayLine($eobj->getMessage());
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ displayFatalError(eobj)
|
||||
|
||||
function displayFatalError($eobj)
|
||||
{
|
||||
$this->displayError($eobj);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ displayHeading(title)
|
||||
|
||||
function displayHeading($title)
|
||||
{
|
||||
trigger_error("Frontend::displayHeading deprecated", E_USER_ERROR);
|
||||
}
|
||||
|
||||
function _displayHeading($title)
|
||||
{
|
||||
print $this->lp.$this->bold($title)."\n";
|
||||
print $this->lp.str_repeat("=", strlen($title))."\n";
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ userDialog(prompt, [type], [default])
|
||||
|
||||
function userDialog($command, $prompts, $types = array(), $defaults = array())
|
||||
{
|
||||
$result = array();
|
||||
if (is_array($prompts)) {
|
||||
$fp = fopen("php://stdin", "r");
|
||||
foreach ($prompts as $key => $prompt) {
|
||||
$type = $types[$key];
|
||||
$default = @$defaults[$key];
|
||||
if ($type == 'password') {
|
||||
system('stty -echo');
|
||||
}
|
||||
print "$this->lp$prompt ";
|
||||
if ($default) {
|
||||
print "[$default] ";
|
||||
}
|
||||
print ": ";
|
||||
$line = fgets($fp, 2048);
|
||||
if ($type == 'password') {
|
||||
system('stty echo');
|
||||
print "\n";
|
||||
}
|
||||
if ($default && trim($line) == "") {
|
||||
$result[$key] = $default;
|
||||
} else {
|
||||
$result[$key] = $line;
|
||||
}
|
||||
}
|
||||
fclose($fp);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ userConfirm(prompt, [default])
|
||||
|
||||
function userConfirm($prompt, $default = 'yes')
|
||||
{
|
||||
trigger_error("Frontend::userConfirm not yet converted", E_USER_ERROR);
|
||||
static $positives = array('y', 'yes', 'on', '1');
|
||||
static $negatives = array('n', 'no', 'off', '0');
|
||||
print "$this->lp$prompt [$default] : ";
|
||||
$fp = fopen("php://stdin", "r");
|
||||
$line = fgets($fp, 2048);
|
||||
fclose($fp);
|
||||
$answer = strtolower(trim($line));
|
||||
if (empty($answer)) {
|
||||
$answer = $default;
|
||||
}
|
||||
if (in_array($answer, $positives)) {
|
||||
return true;
|
||||
}
|
||||
if (in_array($answer, $negatives)) {
|
||||
return false;
|
||||
}
|
||||
if (in_array($default, $positives)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ startTable([params])
|
||||
|
||||
function startTable($params = array())
|
||||
{
|
||||
trigger_error("Frontend::startTable deprecated", E_USER_ERROR);
|
||||
}
|
||||
|
||||
function _startTable($params = array())
|
||||
{
|
||||
$this->omode = 'table';
|
||||
$params['table_data'] = array();
|
||||
$params['widest'] = array(); // indexed by column
|
||||
$params['highest'] = array(); // indexed by row
|
||||
$params['ncols'] = 0;
|
||||
$this->params = $params;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ tableRow(columns, [rowparams], [colparams])
|
||||
|
||||
function tableRow($columns, $rowparams = array(), $colparams = array())
|
||||
{
|
||||
trigger_error("Frontend::tableRow deprecated", E_USER_ERROR);
|
||||
}
|
||||
|
||||
function _tableRow($columns, $rowparams = array(), $colparams = array())
|
||||
{
|
||||
$highest = 1;
|
||||
for ($i = 0; $i < sizeof($columns); $i++) {
|
||||
$col = &$columns[$i];
|
||||
if (isset($colparams[$i]) && !empty($colparams[$i]['wrap'])) {
|
||||
$col = wordwrap($col, $colparams[$i]['wrap'], "\n", 1);
|
||||
}
|
||||
if (strpos($col, "\n") !== false) {
|
||||
$multiline = explode("\n", $col);
|
||||
$w = 0;
|
||||
foreach ($multiline as $n => $line) {
|
||||
if (strlen($line) > $w) {
|
||||
$w = strlen($line);
|
||||
}
|
||||
}
|
||||
$lines = sizeof($multiline);
|
||||
} else {
|
||||
$w = strlen($col);
|
||||
}
|
||||
if ($w > @$this->params['widest'][$i]) {
|
||||
$this->params['widest'][$i] = $w;
|
||||
}
|
||||
$tmp = count_chars($columns[$i], 1);
|
||||
// handle unix, mac and windows formats
|
||||
$lines = (isset($tmp[10]) ? $tmp[10] : @$tmp[13]) + 1;
|
||||
if ($lines > $highest) {
|
||||
$highest = $lines;
|
||||
}
|
||||
}
|
||||
if (sizeof($columns) > $this->params['ncols']) {
|
||||
$this->params['ncols'] = sizeof($columns);
|
||||
}
|
||||
$new_row = array(
|
||||
'data' => $columns,
|
||||
'height' => $highest,
|
||||
'rowparams' => $rowparams,
|
||||
'colparams' => $colparams,
|
||||
);
|
||||
$this->params['table_data'][] = $new_row;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ endTable()
|
||||
|
||||
function endTable()
|
||||
{
|
||||
trigger_error("Frontend::tableRow deprecated", E_USER_ERROR);
|
||||
}
|
||||
|
||||
function _endTable()
|
||||
{
|
||||
$this->omode = '';
|
||||
extract($this->params);
|
||||
if (!empty($caption)) {
|
||||
$this->_displayHeading($caption);
|
||||
}
|
||||
if (count($table_data) == 0) {
|
||||
return;
|
||||
}
|
||||
if (!isset($width)) {
|
||||
$width = $widest;
|
||||
} else {
|
||||
for ($i = 0; $i < $ncols; $i++) {
|
||||
if (!isset($width[$i])) {
|
||||
$width[$i] = $widest[$i];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (empty($border)) {
|
||||
$cellstart = '';
|
||||
$cellend = ' ';
|
||||
$rowend = '';
|
||||
$padrowend = false;
|
||||
$borderline = '';
|
||||
} else {
|
||||
$cellstart = '| ';
|
||||
$cellend = ' ';
|
||||
$rowend = '|';
|
||||
$padrowend = true;
|
||||
$borderline = '+';
|
||||
foreach ($width as $w) {
|
||||
$borderline .= str_repeat('-', $w + strlen($cellstart) + strlen($cellend) - 1);
|
||||
$borderline .= '+';
|
||||
}
|
||||
}
|
||||
if ($borderline) {
|
||||
$this->_displayLine($borderline);
|
||||
}
|
||||
for ($i = 0; $i < sizeof($table_data); $i++) {
|
||||
extract($table_data[$i]);
|
||||
$rowlines = array();
|
||||
if ($height > 1) {
|
||||
for ($c = 0; $c < sizeof($data); $c++) {
|
||||
$rowlines[$c] = preg_split('/(\r?\n|\r)/', $data[$c]);
|
||||
if (sizeof($rowlines[$c]) < $height) {
|
||||
$rowlines[$c] = array_pad($rowlines[$c], $height, '');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for ($c = 0; $c < sizeof($data); $c++) {
|
||||
$rowlines[$c] = array($data[$c]);
|
||||
}
|
||||
}
|
||||
for ($r = 0; $r < $height; $r++) {
|
||||
$rowtext = '';
|
||||
for ($c = 0; $c < sizeof($data); $c++) {
|
||||
if (isset($colparams[$c])) {
|
||||
$attribs = array_merge($rowparams, $colparams);
|
||||
} else {
|
||||
$attribs = $rowparams;
|
||||
}
|
||||
$w = isset($width[$c]) ? $width[$c] : 0;
|
||||
//$cell = $data[$c];
|
||||
$cell = $rowlines[$c][$r];
|
||||
$l = strlen($cell);
|
||||
if ($l > $w) {
|
||||
$cell = substr($cell, 0, $w);
|
||||
}
|
||||
if (isset($attribs['bold'])) {
|
||||
$cell = $this->bold($cell);
|
||||
}
|
||||
if ($l < $w) {
|
||||
// not using str_pad here because we may
|
||||
// add bold escape characters to $cell
|
||||
$cell .= str_repeat(' ', $w - $l);
|
||||
}
|
||||
|
||||
$rowtext .= $cellstart . $cell . $cellend;
|
||||
}
|
||||
$rowtext .= $rowend;
|
||||
$this->_displayLine($rowtext);
|
||||
}
|
||||
}
|
||||
if ($borderline) {
|
||||
$this->_displayLine($borderline);
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ outputData()
|
||||
|
||||
function outputData($data, $command = '_default')
|
||||
{
|
||||
switch ($command)
|
||||
{
|
||||
case 'search':
|
||||
$this->_startTable($data);
|
||||
if (isset($data['headline']) && is_array($data['headline']))
|
||||
$this->_tableRow($data['headline'], array('bold' => true), array(1 => array('wrap' => 55)));
|
||||
|
||||
foreach($data['data'] as $category) {
|
||||
foreach($category as $pkg) {
|
||||
$this->_tableRow($pkg, null, array(1 => array('wrap' => 55)));
|
||||
}
|
||||
};
|
||||
$this->_endTable();
|
||||
break;
|
||||
case 'list-all':
|
||||
$this->_startTable($data);
|
||||
if (isset($data['headline']) && is_array($data['headline']))
|
||||
$this->_tableRow($data['headline'], array('bold' => true), array(1 => array('wrap' => 55)));
|
||||
|
||||
foreach($data['data'] as $category) {
|
||||
foreach($category as $pkg) {
|
||||
unset($pkg[3]);
|
||||
unset($pkg[4]);
|
||||
$this->_tableRow($pkg, null, array(1 => array('wrap' => 55)));
|
||||
}
|
||||
};
|
||||
$this->_endTable();
|
||||
break;
|
||||
case 'config-show':
|
||||
$data['border'] = true;
|
||||
$opts = array(0 => array('wrap' => 20),
|
||||
1 => array('wrap' => 20),
|
||||
2 => array('wrap' => 35));
|
||||
$this->_startTable($data);
|
||||
if (isset($data['headline']) && is_array($data['headline'])) {
|
||||
$this->_tableRow($data['headline'],
|
||||
array('bold' => true),
|
||||
$opts);
|
||||
}
|
||||
foreach($data['data'] as $group) {
|
||||
foreach($group as $value) {
|
||||
if ($value[2] == '') {
|
||||
$value[2] = "<not set>";
|
||||
}
|
||||
$this->_tableRow($value, null, $opts);
|
||||
}
|
||||
}
|
||||
$this->_endTable();
|
||||
break;
|
||||
case 'remote-info':
|
||||
$data = array(
|
||||
'caption' => 'Package details:',
|
||||
'border' => true,
|
||||
'data' => array(
|
||||
array("Latest", $data['stable']),
|
||||
array("Installed", $data['installed']),
|
||||
array("Package", $data['name']),
|
||||
array("License", $data['license']),
|
||||
array("Category", $data['category']),
|
||||
array("Summary", $data['summary']),
|
||||
array("Description", $data['description']),
|
||||
),
|
||||
);
|
||||
default: {
|
||||
if (is_array($data))
|
||||
{
|
||||
$this->_startTable($data);
|
||||
$count = count($data['data'][0]);
|
||||
if ($count == 2) {
|
||||
$opts = array(0 => array('wrap' => 25),
|
||||
1 => array('wrap' => 48)
|
||||
);
|
||||
} elseif ($count == 3) {
|
||||
$opts = array(0 => array('wrap' => 20),
|
||||
1 => array('wrap' => 20),
|
||||
2 => array('wrap' => 35)
|
||||
);
|
||||
}
|
||||
if (isset($data['headline']) && is_array($data['headline'])) {
|
||||
$this->_tableRow($data['headline'],
|
||||
array('bold' => true),
|
||||
$opts);
|
||||
}
|
||||
foreach($data['data'] as $row) {
|
||||
$this->_tableRow($row, null, $opts);
|
||||
}
|
||||
$this->_endTable();
|
||||
} else {
|
||||
$this->_displayLine($data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ log(text)
|
||||
|
||||
|
||||
function log($text)
|
||||
{
|
||||
return $this->_displayLine($text);
|
||||
}
|
||||
|
||||
|
||||
// }}}
|
||||
// {{{ bold($text)
|
||||
|
||||
function bold($text)
|
||||
{
|
||||
if (empty($this->term['bold'])) {
|
||||
return strtoupper($text);
|
||||
}
|
||||
return $this->term['bold'] . $text . $this->term['normal'];
|
||||
}
|
||||
|
||||
// }}}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,690 @@
|
||||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.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. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Stig Bakken <ssb@fast.no> |
|
||||
// | Tomas V.V.Cox <cox@idecnet.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id$
|
||||
|
||||
require_once 'PEAR/Common.php';
|
||||
require_once 'PEAR/Registry.php';
|
||||
require_once 'PEAR/Dependency.php';
|
||||
require_once 'System.php';
|
||||
|
||||
define('PEAR_INSTALLER_OK', 1);
|
||||
define('PEAR_INSTALLER_FAILED', 0);
|
||||
define('PEAR_INSTALLER_SKIPPED', -1);
|
||||
|
||||
/**
|
||||
* Administration class used to install PEAR packages and maintain the
|
||||
* installed package database.
|
||||
*
|
||||
* TODO:
|
||||
* - Check dependencies break on package uninstall (when no force given)
|
||||
* - add a guessInstallDest() method with the code from _installFile() and
|
||||
* use that method in Registry::_rebuildFileMap() & Command_Registry::doList(),
|
||||
* others..
|
||||
*
|
||||
* @since PHP 4.0.2
|
||||
* @author Stig Bakken <ssb@fast.no>
|
||||
*/
|
||||
class PEAR_Installer extends PEAR_Common
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
/** name of the package directory, for example Foo-1.0
|
||||
* @var string
|
||||
*/
|
||||
var $pkgdir;
|
||||
|
||||
/** directory where PHP code files go
|
||||
* @var string
|
||||
*/
|
||||
var $phpdir;
|
||||
|
||||
/** directory where PHP extension files go
|
||||
* @var string
|
||||
*/
|
||||
var $extdir;
|
||||
|
||||
/** directory where documentation goes
|
||||
* @var string
|
||||
*/
|
||||
var $docdir;
|
||||
|
||||
/** installation root directory (ala PHP's INSTALL_ROOT or
|
||||
* automake's DESTDIR
|
||||
* @var string
|
||||
*/
|
||||
var $installroot = '';
|
||||
|
||||
/** debug level
|
||||
* @var int
|
||||
*/
|
||||
var $debug = 1;
|
||||
|
||||
/** temporary directory
|
||||
* @var string
|
||||
*/
|
||||
var $tmpdir;
|
||||
|
||||
/** PEAR_Registry object used by the installer
|
||||
* @var object
|
||||
*/
|
||||
var $registry;
|
||||
|
||||
// }}}
|
||||
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* PEAR_Installer constructor.
|
||||
*
|
||||
* @param object $ui user interface object (instance of PEAR_Frontend_*)
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PEAR_Installer(&$ui)
|
||||
{
|
||||
$this->PEAR_Common();
|
||||
$this->setFrontendObject($ui);
|
||||
$this->debug = $this->config->get('verbose');
|
||||
$this->registry = &new PEAR_Registry($this->config->get('php_dir'));
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
// {{{ _deletePackageFiles()
|
||||
|
||||
/**
|
||||
* Delete a package's installed files, remove empty directories.
|
||||
*
|
||||
* @param string $package package name
|
||||
*
|
||||
* @return bool TRUE on success, or a PEAR error on failure
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
function _deletePackageFiles($package)
|
||||
{
|
||||
if (!strlen($package)) {
|
||||
return $this->raiseError("No package to uninstall given");
|
||||
}
|
||||
$filelist = $this->registry->packageInfo($package, 'filelist');
|
||||
if ($filelist == null) {
|
||||
return $this->raiseError("$package not installed");
|
||||
}
|
||||
foreach ($filelist as $file => $props) {
|
||||
if (empty($props['installed_as'])) {
|
||||
continue;
|
||||
}
|
||||
$path = $this->_prependPath($props['installed_as'], $this->installroot);
|
||||
if (!@unlink($path)) {
|
||||
$this->log(2, "unable to delete: $path");
|
||||
} else {
|
||||
$this->log(2, "deleted file $path");
|
||||
// Delete package directory if it's empty
|
||||
if (@rmdir(dirname($path))) {
|
||||
$this->log(3, "+ rmdir $path");
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ _installFile()
|
||||
|
||||
function _installFile($file, $atts, $tmp_path)
|
||||
{
|
||||
static $os;
|
||||
if (isset($atts['platform'])) {
|
||||
if (empty($os)) {
|
||||
include_once "OS/Guess.php";
|
||||
$os = new OS_Guess();
|
||||
}
|
||||
// return if this file is meant for another platform
|
||||
if (!$os->matchSignature($atts['platform'])) {
|
||||
$this->log(3, "skipped $file (meant for $atts[platform], we are ".$os->getSignature().")");
|
||||
return PEAR_INSTALLER_SKIPPED;
|
||||
}
|
||||
}
|
||||
|
||||
switch ($atts['role']) {
|
||||
case 'doc':
|
||||
case 'data':
|
||||
case 'test':
|
||||
$dest_dir = $this->config->get($atts['role'] . '_dir') .
|
||||
DIRECTORY_SEPARATOR . $this->pkginfo['package'];
|
||||
unset($atts['baseinstalldir']);
|
||||
break;
|
||||
case 'ext':
|
||||
case 'php':
|
||||
$dest_dir = $this->config->get($atts['role'] . '_dir');
|
||||
break;
|
||||
case 'script':
|
||||
$dest_dir = $this->config->get('bin_dir');
|
||||
break;
|
||||
case 'src':
|
||||
case 'extsrc':
|
||||
$this->source_files++;
|
||||
return;
|
||||
default:
|
||||
// Files with no role will end in "/"
|
||||
return $this->raiseError("Invalid role `$atts[role]' for file $file");
|
||||
}
|
||||
if (!empty($atts['baseinstalldir'])) {
|
||||
$dest_dir .= DIRECTORY_SEPARATOR . $atts['baseinstalldir'];
|
||||
}
|
||||
if (dirname($file) != '.' && empty($atts['install-as'])) {
|
||||
$dest_dir .= DIRECTORY_SEPARATOR . dirname($file);
|
||||
}
|
||||
if (empty($atts['install-as'])) {
|
||||
$dest_file = $dest_dir . DIRECTORY_SEPARATOR . basename($file);
|
||||
} else {
|
||||
$dest_file = $dest_dir . DIRECTORY_SEPARATOR . $atts['install-as'];
|
||||
}
|
||||
$orig_file = $tmp_path . DIRECTORY_SEPARATOR . $file;
|
||||
|
||||
// Clean up the DIRECTORY_SEPARATOR mess
|
||||
$ds2 = DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR;
|
||||
list($dest_file, $orig_file) = preg_replace(array('!\\\\+!', '!/!', "!$ds2+!"),
|
||||
DIRECTORY_SEPARATOR,
|
||||
array($dest_file, $orig_file));
|
||||
$installed_as = $dest_file;
|
||||
$dest_file = $this->_prependPath($dest_file, $this->installroot);
|
||||
$dest_dir = dirname($dest_file);
|
||||
if (!@is_dir($dest_dir)) {
|
||||
if (!$this->mkDirHier($dest_dir)) {
|
||||
return $this->raiseError("failed to mkdir $dest_dir",
|
||||
PEAR_INSTALLER_FAILED);
|
||||
}
|
||||
$this->log(3, "+ mkdir $dest_dir");
|
||||
}
|
||||
if (empty($atts['replacements'])) {
|
||||
if (!copy($orig_file, $dest_file)) {
|
||||
return $this->raiseError("failed to copy $orig_file to $dest_file",
|
||||
PEAR_INSTALLER_FAILED);
|
||||
}
|
||||
$this->log(3, "+ cp $orig_file $dest_file");
|
||||
if (isset($atts['md5sum'])) {
|
||||
$md5sum = md5_file($dest_file);
|
||||
}
|
||||
} else {
|
||||
$fp = fopen($orig_file, "r");
|
||||
$contents = fread($fp, filesize($orig_file));
|
||||
fclose($fp);
|
||||
if (isset($atts['md5sum'])) {
|
||||
$md5sum = md5($contents);
|
||||
}
|
||||
$subst_from = $subst_to = array();
|
||||
foreach ($atts['replacements'] as $a) {
|
||||
$to = '';
|
||||
if ($a['type'] == 'php-const') {
|
||||
if (preg_match('/^[a-z0-9_]+$/i', $a['to'])) {
|
||||
eval("\$to = $a[to];");
|
||||
} else {
|
||||
$this->log(0, "invalid php-const replacement: $a[to]");
|
||||
continue;
|
||||
}
|
||||
} elseif ($a['type'] == 'pear-config') {
|
||||
$to = $this->config->get($a['to']);
|
||||
} elseif ($a['type'] == 'package-info') {
|
||||
$to = $this->pkginfo[$a['to']];
|
||||
}
|
||||
if ($to) {
|
||||
$subst_from[] = $a['from'];
|
||||
$subst_to[] = $to;
|
||||
}
|
||||
}
|
||||
$this->log(3, "doing ".sizeof($subst_from)." substitution(s) for $dest_file");
|
||||
if (sizeof($subst_from)) {
|
||||
$contents = str_replace($subst_from, $subst_to, $contents);
|
||||
}
|
||||
$wp = @fopen($dest_file, "w");
|
||||
if (!is_resource($wp)) {
|
||||
return $this->raiseError("failed to create $dest_file",
|
||||
PEAR_INSTALLER_FAILED);
|
||||
}
|
||||
fwrite($wp, $contents);
|
||||
fclose($wp);
|
||||
}
|
||||
if (isset($md5sum)) {
|
||||
if ($md5sum == $atts['md5sum']) {
|
||||
$this->log(3, "md5sum ok: $dest_file");
|
||||
} else {
|
||||
$this->log(0, "warning : bad md5sum for file $dest_file");
|
||||
}
|
||||
}
|
||||
if (!OS_WINDOWS) {
|
||||
if ($atts['role'] == 'script') {
|
||||
$mode = 0777 & ~(int)octdec($this->config->get('umask'));
|
||||
$this->log(3, "+ chmod +x $dest_file");
|
||||
} else {
|
||||
$mode = 0666 & ~(int)octdec($this->config->get('umask'));
|
||||
}
|
||||
if (!@chmod($dest_file, $mode)) {
|
||||
$this->log(0, "failed to change mode of $dest_file");
|
||||
}
|
||||
}
|
||||
|
||||
// Store the full path where the file was installed for easy unistall
|
||||
$this->pkginfo['filelist'][$file]['installed_as'] = $installed_as;
|
||||
|
||||
$this->log(2, "installed: $dest_file");
|
||||
return PEAR_INSTALLER_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getPackageDownloadUrl()
|
||||
|
||||
function getPackageDownloadUrl($package)
|
||||
{
|
||||
if ($this === null || $this->config === null) {
|
||||
$package = "http://pear.php.net/get/$package";
|
||||
} else {
|
||||
$package = "http://" . $this->config->get('master_server') .
|
||||
"/get/$package";
|
||||
}
|
||||
if (!extension_loaded("zlib")) {
|
||||
$package .= '?uncompress=yes';
|
||||
}
|
||||
return $package;
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
// {{{ _prependPath($path, $prepend)
|
||||
|
||||
function _prependPath($path, $prepend)
|
||||
{
|
||||
if (OS_WINDOWS && preg_match('/^[a-z]:/i', $path)) {
|
||||
$path = $prepend . substr($path, 2);
|
||||
} else {
|
||||
$path = $prepend . $path;
|
||||
}
|
||||
return $path;
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
// {{{ install()
|
||||
|
||||
/**
|
||||
* Installs the files within the package file specified.
|
||||
*
|
||||
* @param $pkgfile path to the package file
|
||||
*
|
||||
* @return array package info if successful, null if not
|
||||
*/
|
||||
|
||||
function install($pkgfile, $options = array())
|
||||
{
|
||||
// recognized options:
|
||||
// - force : force installation
|
||||
// - register-only : update registry but don't install files
|
||||
// - upgrade : upgrade existing install
|
||||
// - soft : fail silently
|
||||
//
|
||||
$php_dir = $this->config->get('php_dir');
|
||||
if (isset($options['installroot'])) {
|
||||
if (substr($options['installroot'], -1) == DIRECTORY_SEPARATOR) {
|
||||
$options['installroot'] = substr($options['installroot'], 0, -1);
|
||||
}
|
||||
$php_dir = $this->_prependPath($php_dir, $options['installroot']);
|
||||
$this->registry = &new PEAR_Registry($php_dir);
|
||||
$this->installroot = $options['installroot'];
|
||||
} else {
|
||||
$registry = &$this->registry;
|
||||
$this->installroot = '';
|
||||
}
|
||||
$need_download = false;
|
||||
// ==> XXX should be removed later on
|
||||
$flag_old_format = false;
|
||||
if (preg_match('#^(http|ftp)://#', $pkgfile)) {
|
||||
$need_download = true;
|
||||
} elseif (!@is_file($pkgfile)) {
|
||||
if ($this->validPackageName($pkgfile)) {
|
||||
if ($this->registry->packageExists($pkgfile) &&
|
||||
empty($options['upgrade']) && empty($options['force']))
|
||||
{
|
||||
return $this->raiseError("$pkgfile already installed");
|
||||
}
|
||||
$pkgfile = $this->getPackageDownloadUrl($pkgfile);
|
||||
$need_download = true;
|
||||
} else {
|
||||
if (strlen($pkgfile)) {
|
||||
return $this->raiseError("Could not open the package file: $pkgfile");
|
||||
} else {
|
||||
return $this->raiseError("No package file given");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Download package -----------------------------------------------
|
||||
if ($need_download) {
|
||||
$downloaddir = $this->config->get('download_dir');
|
||||
if (empty($downloaddir)) {
|
||||
if (PEAR::isError($downloaddir = System::mktemp('-d'))) {
|
||||
return $downloaddir;
|
||||
}
|
||||
$this->log(2, '+ tmp dir created at ' . $downloaddir);
|
||||
}
|
||||
$callback = $this->ui ? array(&$this, '_downloadCallback') : null;
|
||||
$file = $this->downloadHttp($pkgfile, $this->ui, $downloaddir, $callback);
|
||||
if (PEAR::isError($file)) {
|
||||
return $this->raiseError($file);
|
||||
}
|
||||
$pkgfile = $file;
|
||||
}
|
||||
|
||||
if (substr($pkgfile, -4) == '.xml') {
|
||||
$descfile = $pkgfile;
|
||||
} else {
|
||||
// Decompress pack in tmp dir -------------------------------------
|
||||
|
||||
// To allow relative package file names
|
||||
$oldcwd = getcwd();
|
||||
if (@chdir(dirname($pkgfile))) {
|
||||
$pkgfile = getcwd() . DIRECTORY_SEPARATOR . basename($pkgfile);
|
||||
chdir($oldcwd);
|
||||
}
|
||||
|
||||
if (PEAR::isError($tmpdir = System::mktemp('-d'))) {
|
||||
return $tmpdir;
|
||||
}
|
||||
$this->log(2, '+ tmp dir created at ' . $tmpdir);
|
||||
|
||||
$tar = new Archive_Tar($pkgfile);
|
||||
if (!@$tar->extract($tmpdir)) {
|
||||
return $this->raiseError("unable to unpack $pkgfile");
|
||||
}
|
||||
|
||||
// ----- Look for existing package file
|
||||
$descfile = $tmpdir . DIRECTORY_SEPARATOR . 'package.xml';
|
||||
|
||||
if (!is_file($descfile)) {
|
||||
// ----- Look for old package archive format
|
||||
// In this format the package.xml file was inside the
|
||||
// Package-n.n directory
|
||||
$dp = opendir($tmpdir);
|
||||
do {
|
||||
$pkgdir = readdir($dp);
|
||||
} while ($pkgdir{0} == '.');
|
||||
|
||||
$descfile = $tmpdir . DIRECTORY_SEPARATOR . $pkgdir . DIRECTORY_SEPARATOR . 'package.xml';
|
||||
$flag_old_format = true;
|
||||
$this->log(0, "warning : you are using an archive with an old format");
|
||||
}
|
||||
// <== XXX This part should be removed later on
|
||||
}
|
||||
|
||||
if (!is_file($descfile)) {
|
||||
return $this->raiseError("no package.xml file after extracting the archive");
|
||||
}
|
||||
|
||||
// Parse xml file -----------------------------------------------
|
||||
$pkginfo = $this->infoFromDescriptionFile($descfile);
|
||||
if (PEAR::isError($pkginfo)) {
|
||||
return $pkginfo;
|
||||
}
|
||||
$this->validatePackageInfo($pkginfo, $errors, $warnings);
|
||||
// XXX We allow warnings, do we have to do it?
|
||||
if (count($errors)) {
|
||||
if (empty($options['force'])) {
|
||||
return $this->raiseError("The following errors where found (use force option to install anyway):\n".
|
||||
implode("\n", $errors));
|
||||
} else {
|
||||
$this->log(0, "warning : the following errors were found:\n".
|
||||
implode("\n", $errors));
|
||||
}
|
||||
}
|
||||
|
||||
$pkgname = $pkginfo['package'];
|
||||
|
||||
// Check dependencies -------------------------------------------
|
||||
if (isset($pkginfo['release_deps']) && empty($options['nodeps'])) {
|
||||
$error = $this->checkDeps($pkginfo);
|
||||
if ($error) {
|
||||
if (empty($options['soft'])) {
|
||||
$this->log(0, $error);
|
||||
}
|
||||
return $this->raiseError("$pkgname: dependencies failed");
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($options['force'])) {
|
||||
// checks to do when not in "force" mode
|
||||
$test = $this->registry->checkFileMap($pkginfo);
|
||||
if (sizeof($test)) {
|
||||
$tmp = $test;
|
||||
foreach ($tmp as $file => $pkg) {
|
||||
if ($pkg == $pkgname) {
|
||||
unset($test[$file]);
|
||||
}
|
||||
}
|
||||
if (sizeof($test)) {
|
||||
$msg = "$pkgname: conflicting files found:\n";
|
||||
$longest = max(array_map("strlen", array_keys($test)));
|
||||
$fmt = "%${longest}s (%s)\n";
|
||||
foreach ($test as $file => $pkg) {
|
||||
$msg .= sprintf($fmt, $file, $pkg);
|
||||
}
|
||||
return $this->raiseError($msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($options['upgrade'])) {
|
||||
// checks to do only when installing new packages
|
||||
if (empty($options['force']) && $this->registry->packageExists($pkgname)) {
|
||||
return $this->raiseError("$pkgname already installed");
|
||||
}
|
||||
} else {
|
||||
// checks to do only when upgrading packages
|
||||
if (!$this->registry->packageExists($pkgname)) {
|
||||
return $this->raiseError("$pkgname not installed");
|
||||
}
|
||||
$v1 = $this->registry->packageInfo($pkgname, 'version');
|
||||
$v2 = $pkginfo['version'];
|
||||
$cmp = version_compare("$v1", "$v2", 'gt');
|
||||
if (empty($options['force']) && !version_compare("$v2", "$v1", 'gt')) {
|
||||
return $this->raiseError("upgrade to a newer version ($v2 is not newer than $v1)");
|
||||
}
|
||||
if (empty($options['register-only'])) {
|
||||
// when upgrading, remove old release's files first:
|
||||
if (PEAR::isError($err = $this->_deletePackageFiles($pkgname))) {
|
||||
return $this->raiseError($err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Copy files to dest dir ---------------------------------------
|
||||
|
||||
// info from the package it self we want to access from _installFile
|
||||
$this->pkginfo = &$pkginfo;
|
||||
// used to determine whether we should build any C code
|
||||
$this->source_files = 0;
|
||||
|
||||
if (empty($options['register-only'])) {
|
||||
if (!is_dir($php_dir)) {
|
||||
return $this->raiseError("no script destination directory\n",
|
||||
null, PEAR_ERROR_DIE);
|
||||
}
|
||||
|
||||
// don't want strange characters
|
||||
$pkgname = ereg_replace ('[^a-zA-Z0-9._]', '_', $pkginfo['package']);
|
||||
$pkgversion = ereg_replace ('[^a-zA-Z0-9._\-]', '_', $pkginfo['version']);
|
||||
$tmp_path = dirname($descfile);
|
||||
if (substr($pkgfile, -4) != '.xml') {
|
||||
$tmp_path .= DIRECTORY_SEPARATOR . $pkgname . '-' . $pkgversion;
|
||||
}
|
||||
|
||||
// ==> XXX This part should be removed later on
|
||||
if ($flag_old_format) {
|
||||
$tmp_path = dirname($descfile);
|
||||
}
|
||||
// <== XXX This part should be removed later on
|
||||
|
||||
foreach ($pkginfo['filelist'] as $file => $atts) {
|
||||
$this->expectError(PEAR_INSTALLER_FAILED);
|
||||
$res = $this->_installFile($file, $atts, $tmp_path);
|
||||
$this->popExpect();
|
||||
if (PEAR::isError($res)) {
|
||||
if (empty($options['force'])) {
|
||||
return $this->raiseError($res);
|
||||
} else {
|
||||
$this->log(0, "Warning: " . $res->getMessage());
|
||||
}
|
||||
}
|
||||
if ($res != PEAR_INSTALLER_OK) {
|
||||
// Do not register files that were not installed
|
||||
unset($pkginfo['filelist'][$file]);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->source_files > 0 && empty($options['nobuild'])) {
|
||||
$this->log(1, "$this->source_files source files, building");
|
||||
$bob = &new PEAR_Builder($this->ui); // Malin loves Bob the Builder
|
||||
$bob->debug = $this->debug;
|
||||
$built = $bob->build($descfile, array(&$this, '_buildCallback'));
|
||||
if (PEAR::isError($built)) {
|
||||
return $built;
|
||||
}
|
||||
foreach ($built as $ext) {
|
||||
$bn = basename($ext['file']);
|
||||
$this->log(2, "installing $bn");
|
||||
$dest = $this->config->get('ext_dir') . DIRECTORY_SEPARATOR . $bn;
|
||||
$this->log(3, "+ cp $ext[file] ext_dir");
|
||||
$copyto = $dest->_prependPath($dest, $this->installroot);
|
||||
if (!@copy($ext['file'], $copyto)) {
|
||||
return $this->raiseError("failed to copy $bn to $copyto");
|
||||
}
|
||||
$pkginfo['filelist'][$bn] = array(
|
||||
'role' => 'ext',
|
||||
'installed_as' => $dest,
|
||||
'php_api' => $ext['php_api'],
|
||||
'zend_mod_api' => $ext['zend_mod_api'],
|
||||
'zend_ext_api' => $ext['zend_ext_api'],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Register that the package is installed -----------------------
|
||||
if (empty($options['upgrade'])) {
|
||||
// if 'force' is used, replace the info in registry
|
||||
if (!empty($options['force']) && $this->registry->packageExists($pkgname)) {
|
||||
$this->registry->deletePackage($pkgname);
|
||||
}
|
||||
$ret = $this->registry->addPackage($pkgname, $pkginfo);
|
||||
} else {
|
||||
$ret = $this->registry->updatePackage($pkgname, $pkginfo, false);
|
||||
}
|
||||
if (!$ret) {
|
||||
return null;
|
||||
}
|
||||
return $pkginfo;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ uninstall()
|
||||
|
||||
function uninstall($package, $options = array())
|
||||
{
|
||||
$php_dir = $this->config->get('php_dir');
|
||||
if (isset($options['installroot'])) {
|
||||
if (substr($options['installroot'], -1) == DIRECTORY_SEPARATOR) {
|
||||
$options['installroot'] = substr($options['installroot'], 0, -1);
|
||||
}
|
||||
$this->installroot = $options['installroot'];
|
||||
$php_dir = $this->_prependPath($php_dir, $this->installroot);
|
||||
} else {
|
||||
$this->installroot = '';
|
||||
}
|
||||
$this->registry = &new PEAR_Registry($php_dir);
|
||||
|
||||
// Delete the files
|
||||
if (PEAR::isError($err = $this->_deletePackageFiles($package))) {
|
||||
return $this->raiseError($err);
|
||||
}
|
||||
|
||||
// Register that the package is no longer installed
|
||||
return $this->registry->deletePackage($package);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ checkDeps()
|
||||
|
||||
function checkDeps(&$pkginfo)
|
||||
{
|
||||
$deps = &new PEAR_Dependency($this->registry);
|
||||
$errors = null;
|
||||
if (is_array($pkginfo['release_deps'])) {
|
||||
foreach($pkginfo['release_deps'] as $dep) {
|
||||
if ($error = $deps->callCheckMethod($dep)) {
|
||||
$errors .= "\n$error";
|
||||
}
|
||||
}
|
||||
if ($errors) {
|
||||
return $errors;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ _downloadCallback()
|
||||
|
||||
function _downloadCallback($msg, $params = null)
|
||||
{
|
||||
switch ($msg) {
|
||||
case 'saveas':
|
||||
$this->log(1, "downloading $params ...");
|
||||
break;
|
||||
case 'done':
|
||||
$this->log(1, '...done: ' . number_format($params, 0, '', ',') . ' bytes');
|
||||
break;
|
||||
}
|
||||
if (method_exists($this->ui, '_downloadCallback'))
|
||||
$this->ui->_downloadCallback($msg, $params);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ _buildCallback()
|
||||
|
||||
function _buildCallback($what, $data)
|
||||
{
|
||||
if (($what == 'cmdoutput' && $this->debug > 1) ||
|
||||
($what == 'output' && $this->debug > 0)) {
|
||||
$this->ui->outputData(rtrim($data), 'build');
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
}
|
||||
|
||||
if (!function_exists("md5_file")) {
|
||||
function md5_file($filename) {
|
||||
$fp = fopen($filename, "r");
|
||||
if (!$fp) return null;
|
||||
$contents = fread($fp, filesize($filename));
|
||||
fclose($fp);
|
||||
return md5($contents);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,161 @@
|
||||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.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. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Stig Bakken <ssb@fast.no> |
|
||||
// | Tomas V.V.Cox <cox@idecnet.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id$
|
||||
|
||||
require_once 'PEAR/Common.php';
|
||||
require_once 'System.php';
|
||||
|
||||
/**
|
||||
* Administration class used to make a PEAR release tarball.
|
||||
*
|
||||
* TODO:
|
||||
* - add an extra param the dir where to place the created package
|
||||
*
|
||||
* @since PHP 4.0.2
|
||||
* @author Stig Bakken <ssb@fast.no>
|
||||
*/
|
||||
class PEAR_Packager extends PEAR_Common
|
||||
{
|
||||
// {{{ constructor
|
||||
|
||||
function PEAR_Packager()
|
||||
{
|
||||
$this->PEAR_Common();
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ destructor
|
||||
|
||||
function _PEAR_Packager()
|
||||
{
|
||||
$this->_PEAR_Common();
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
// {{{ package()
|
||||
|
||||
function package($pkgfile = null, $compress = true)
|
||||
{
|
||||
if (empty($pkgfile)) {
|
||||
$pkgfile = 'package.xml';
|
||||
}
|
||||
$pkginfo = $this->infoFromDescriptionFile($pkgfile);
|
||||
if (PEAR::isError($pkginfo)) {
|
||||
return $this->raiseError($pkginfo);
|
||||
}
|
||||
if (empty($pkginfo['version'])) {
|
||||
return $this->raiseError("No version info found in $pkgfile");
|
||||
}
|
||||
// TMP DIR -------------------------------------------------
|
||||
// We allow calls like "pear package /home/user/mypack/package.xml"
|
||||
$oldcwd = getcwd();
|
||||
if (!@chdir(dirname($pkgfile))) {
|
||||
return $this->raiseError('Could not chdir to '.dirname($pkgfile));
|
||||
}
|
||||
$pkgfile = basename($pkgfile);
|
||||
if (@$pkginfo['release_state'] == 'snapshot' && empty($pkginfo['version'])) {
|
||||
$pkginfo['version'] = date('Ymd');
|
||||
}
|
||||
// don't want strange characters
|
||||
$pkgname = preg_replace('/[^a-z0-9._]/i', '_', $pkginfo['package']);
|
||||
$pkgversion = preg_replace('/[^a-z0-9._-]/i', '_', $pkginfo['version']);
|
||||
$pkgver = $pkgname . '-' . $pkgversion;
|
||||
|
||||
// ----- Create the package file list
|
||||
$filelist = array();
|
||||
$i = 0;
|
||||
|
||||
// Copy files -----------------------------------------------
|
||||
foreach ($pkginfo['filelist'] as $fname => $atts) {
|
||||
if (!file_exists($fname)) {
|
||||
chdir($oldcwd);
|
||||
return $this->raiseError("File $fname does not exist");
|
||||
} else {
|
||||
$filelist[$i++] = $fname;
|
||||
if (empty($pkginfo['filelist'][$fname]['md5sum'])) {
|
||||
$md5sum = md5_file($fname);
|
||||
$pkginfo['filelist'][$fname]['md5sum'] = $md5sum;
|
||||
}
|
||||
$this->log(2, "Adding file $fname");
|
||||
}
|
||||
}
|
||||
$new_xml = $this->xmlFromInfo($pkginfo);
|
||||
if (PEAR::isError($new_xml)) {
|
||||
chdir($oldcwd);
|
||||
return $this->raiseError($new_xml);
|
||||
}
|
||||
if (!($tmpdir = System::mktemp('-t '.getcwd().' -d'))) {
|
||||
return $this->raiseError("PEAR_Packager: mktemp failed");
|
||||
}
|
||||
$newpkgfile = $tmpdir . DIRECTORY_SEPARATOR . 'package.xml';
|
||||
$np = @fopen($newpkgfile, "w");
|
||||
if (!$np) {
|
||||
chdir($oldcwd);
|
||||
return $this->raiseError("PEAR_Packager: unable to rewrite $pkgfile as $newpkgfile");
|
||||
}
|
||||
fwrite($np, $new_xml);
|
||||
fclose($np);
|
||||
|
||||
// TAR the Package -------------------------------------------
|
||||
$ext = $compress ? '.tgz' : '.tar';
|
||||
$dest_package = $oldcwd . DIRECTORY_SEPARATOR . $pkgver . $ext;
|
||||
$tar =& new Archive_Tar($dest_package, $compress);
|
||||
$tar->setErrorHandling(PEAR_ERROR_RETURN); // XXX Don't print errors
|
||||
// ----- Creates with the package.xml file
|
||||
$ok = $tar->createModify($newpkgfile, '', $tmpdir);
|
||||
if (PEAR::isError($ok)) {
|
||||
chdir($oldcwd);
|
||||
return $this->raiseError($ok);
|
||||
} elseif (!$ok) {
|
||||
chdir($oldcwd);
|
||||
return $this->raiseError('PEAR_Packager: tarball creation failed');
|
||||
}
|
||||
// ----- Add the content of the package
|
||||
if (!$tar->addModify($filelist, $pkgver)) {
|
||||
chdir($oldcwd);
|
||||
return $this->raiseError('PEAR_Packager: tarball creation failed');
|
||||
}
|
||||
$this->log(1, "Package $dest_package done");
|
||||
if (file_exists("CVS/Root")) {
|
||||
$cvsversion = preg_replace('/[^a-z0-9]/i', '_', $pkgversion);
|
||||
$cvstag = "RELEASE_$cvsversion";
|
||||
$this->log(1, "Tag the released code with `pear cvstag $pkgfile'");
|
||||
$this->log(1, "(or set the CVS tag $cvstag by hand)");
|
||||
}
|
||||
chdir($oldcwd);
|
||||
return $dest_package;
|
||||
}
|
||||
|
||||
// }}}
|
||||
}
|
||||
|
||||
if (!function_exists('md5_file')) {
|
||||
function md5_file($file) {
|
||||
if (!$fd = @fopen($file, 'r')) {
|
||||
return false;
|
||||
}
|
||||
$md5 = md5(fread($fd, filesize($file)));
|
||||
fclose($fd);
|
||||
return $md5;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,692 @@
|
||||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.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. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Stig Bakken <ssb@fast.no> |
|
||||
// | Tomas V.V.Cox <cox@idecnet.com> |
|
||||
// | |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id$
|
||||
|
||||
/*
|
||||
TODO:
|
||||
- Transform into singleton()
|
||||
- Add application level lock (avoid change the registry from the cmdline
|
||||
while using the GTK interface, for ex.)
|
||||
*/
|
||||
require_once "System.php";
|
||||
require_once "PEAR.php";
|
||||
|
||||
define('PEAR_REGISTRY_ERROR_LOCK', -2);
|
||||
define('PEAR_REGISTRY_ERROR_FORMAT', -3);
|
||||
define('PEAR_REGISTRY_ERROR_FILE', -4);
|
||||
|
||||
/**
|
||||
* Administration class used to maintain the installed package database.
|
||||
*/
|
||||
class PEAR_Registry extends PEAR
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
/** Directory where registry files are stored.
|
||||
* @var string
|
||||
*/
|
||||
var $statedir = '';
|
||||
|
||||
/** File where the file map is stored
|
||||
* @var string
|
||||
*/
|
||||
var $filemap = '';
|
||||
|
||||
/** Name of file used for locking the registry
|
||||
* @var string
|
||||
*/
|
||||
var $lockfile = '';
|
||||
|
||||
/** File descriptor used during locking
|
||||
* @var resource
|
||||
*/
|
||||
var $lock_fp = null;
|
||||
|
||||
/** Mode used during locking
|
||||
* @var int
|
||||
*/
|
||||
var $lock_mode = 0; // XXX UNUSED
|
||||
|
||||
/** Cache of package information. Structure:
|
||||
* array(
|
||||
* 'package' => array('id' => ... ),
|
||||
* ... )
|
||||
* @var array
|
||||
*/
|
||||
var $pkginfo_cache = array();
|
||||
|
||||
/** Cache of file map. Structure:
|
||||
* array( '/path/to/file' => 'package', ... )
|
||||
* @var array
|
||||
*/
|
||||
var $filemap_cache = array();
|
||||
|
||||
// }}}
|
||||
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* PEAR_Registry constructor.
|
||||
*
|
||||
* @param string (optional) PEAR install directory (for .php files)
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PEAR_Registry($pear_install_dir = PEAR_INSTALL_DIR)
|
||||
{
|
||||
parent::PEAR();
|
||||
$ds = DIRECTORY_SEPARATOR;
|
||||
$this->install_dir = $pear_install_dir;
|
||||
$this->statedir = $pear_install_dir.$ds.'.registry';
|
||||
$this->filemap = $pear_install_dir.$ds.'.filemap';
|
||||
$this->lockfile = $pear_install_dir.$ds.'.lock';
|
||||
if (!file_exists($this->filemap)) {
|
||||
$this->rebuildFileMap();
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ destructor
|
||||
|
||||
/**
|
||||
* PEAR_Registry destructor. Makes sure no locks are forgotten.
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
function _PEAR_Registry()
|
||||
{
|
||||
parent::_PEAR();
|
||||
if (is_resource($this->lock_fp)) {
|
||||
$this->_unlock();
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
// {{{ _assertStateDir()
|
||||
|
||||
/**
|
||||
* Make sure the directory where we keep registry files exists.
|
||||
*
|
||||
* @return bool TRUE if directory exists, FALSE if it could not be
|
||||
* created
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
function _assertStateDir()
|
||||
{
|
||||
if (!@is_dir($this->statedir)) {
|
||||
if (!System::mkdir("-p {$this->statedir}")) {
|
||||
return $this->raiseError("could not create directory '{$this->statedir}'");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ _packageFileName()
|
||||
|
||||
/**
|
||||
* Get the name of the file where data for a given package is stored.
|
||||
*
|
||||
* @param string package name
|
||||
*
|
||||
* @return string registry file name
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function _packageFileName($package)
|
||||
{
|
||||
return "{$this->statedir}/{$package}.reg";
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ _openPackageFile()
|
||||
|
||||
function _openPackageFile($package, $mode)
|
||||
{
|
||||
$this->_assertStateDir();
|
||||
$file = $this->_packageFileName($package);
|
||||
$fp = @fopen($file, $mode);
|
||||
if (!$fp) {
|
||||
return null;
|
||||
}
|
||||
return $fp;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ _closePackageFile()
|
||||
|
||||
function _closePackageFile($fp)
|
||||
{
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ rebuildFileMap()
|
||||
|
||||
function rebuildFileMap()
|
||||
{
|
||||
$packages = $this->listPackages();
|
||||
$files = array();
|
||||
foreach ($packages as $package) {
|
||||
$version = $this->packageInfo($package, 'version');
|
||||
$filelist = $this->packageInfo($package, 'filelist');
|
||||
if (!is_array($filelist)) {
|
||||
continue;
|
||||
}
|
||||
foreach ($filelist as $name => $attrs) {
|
||||
if (isset($attrs['role']) && $attrs['role'] != 'php') {
|
||||
continue;
|
||||
}
|
||||
if (isset($attrs['baseinstalldir'])) {
|
||||
$file = $attrs['baseinstalldir'].DIRECTORY_SEPARATOR.$name;
|
||||
} else {
|
||||
$file = $name;
|
||||
}
|
||||
$file = preg_replace(',^/+,', '', $file);
|
||||
$files[$file] = $package;
|
||||
}
|
||||
}
|
||||
$this->_assertStateDir();
|
||||
$fp = @fopen($this->filemap, 'w');
|
||||
if (!$fp) {
|
||||
return false;
|
||||
}
|
||||
$this->filemap_cache = $files;
|
||||
fwrite($fp, serialize($files));
|
||||
fclose($fp);
|
||||
return true;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ readFileMap()
|
||||
|
||||
function readFileMap()
|
||||
{
|
||||
$fp = @fopen($this->filemap, 'r');
|
||||
if (!$fp) {
|
||||
return $this->raiseError('PEAR_Registry: could not open filemap', PEAR_REGISTRY_ERROR_FILE, null, null, $php_errormsg);
|
||||
}
|
||||
$fsize = filesize($this->filemap);
|
||||
$data = fread($fp, $fsize);
|
||||
fclose($fp);
|
||||
$tmp = unserialize($data);
|
||||
if (!$tmp && $fsize > 7) {
|
||||
return $this->raiseError('PEAR_Registry: invalid filemap data', PEAR_REGISTRY_ERROR_FORMAT, null, null, $data);
|
||||
}
|
||||
$this->filemap_cache = $tmp;
|
||||
return true;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ _lock()
|
||||
|
||||
/**
|
||||
* Lock the registry.
|
||||
*
|
||||
* @param integer lock mode, one of LOCK_EX, LOCK_SH or LOCK_UN.
|
||||
* See flock manual for more information.
|
||||
*
|
||||
* @return bool TRUE on success, FALSE if locking failed, or a
|
||||
* PEAR error if some other error occurs (such as the
|
||||
* lock file not being writable).
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
function _lock($mode = LOCK_EX)
|
||||
{
|
||||
if (!eregi('Windows 9', php_uname())) {
|
||||
if ($mode != LOCK_UN && is_resource($this->lock_fp)) {
|
||||
// XXX does not check type of lock (LOCK_SH/LOCK_EX)
|
||||
return true;
|
||||
}
|
||||
if (PEAR::isError($err = $this->_assertStateDir())) {
|
||||
return $err;
|
||||
}
|
||||
$open_mode = 'w';
|
||||
// XXX People reported problems with LOCK_SH and 'w'
|
||||
if ($mode === LOCK_SH) {
|
||||
if (@!is_file($this->lockfile)) {
|
||||
touch($this->lockfile);
|
||||
}
|
||||
$open_mode = 'r';
|
||||
}
|
||||
|
||||
@ini_set('track_errors', true);
|
||||
$this->lock_fp = @fopen($this->lockfile, $open_mode);
|
||||
@ini_restore('track_errors');
|
||||
|
||||
if (!is_resource($this->lock_fp)) {
|
||||
return $this->raiseError("could not create lock file" .
|
||||
(isset($php_errormsg) ? ": " . $php_errormsg : ""));
|
||||
}
|
||||
if (!(int)flock($this->lock_fp, $mode)) {
|
||||
switch ($mode) {
|
||||
case LOCK_SH: $str = 'shared'; break;
|
||||
case LOCK_EX: $str = 'exclusive'; break;
|
||||
case LOCK_UN: $str = 'unlock'; break;
|
||||
default: $str = 'unknown'; break;
|
||||
}
|
||||
return $this->raiseError("could not acquire $str lock ($this->lockfile)",
|
||||
PEAR_REGISTRY_ERROR_LOCK);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ _unlock()
|
||||
|
||||
function _unlock()
|
||||
{
|
||||
$ret = $this->_lock(LOCK_UN);
|
||||
$this->lock_fp = null;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ _packageExists()
|
||||
|
||||
function _packageExists($package)
|
||||
{
|
||||
return file_exists($this->_packageFileName($package));
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ _packageInfo()
|
||||
|
||||
function _packageInfo($package = null, $key = null)
|
||||
{
|
||||
if ($package === null) {
|
||||
return array_map(array($this, '_packageInfo'),
|
||||
$this->_listPackages());
|
||||
}
|
||||
$fp = $this->_openPackageFile($package, 'r');
|
||||
if ($fp === null) {
|
||||
return null;
|
||||
}
|
||||
$data = fread($fp, filesize($this->_packageFileName($package)));
|
||||
$this->_closePackageFile($fp);
|
||||
$data = unserialize($data);
|
||||
if ($key === null) {
|
||||
return $data;
|
||||
}
|
||||
if (isset($data[$key])) {
|
||||
return $data[$key];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ _listPackages()
|
||||
|
||||
function _listPackages()
|
||||
{
|
||||
$pkglist = array();
|
||||
$dp = @opendir($this->statedir);
|
||||
if (!$dp) {
|
||||
return $pkglist;
|
||||
}
|
||||
while ($ent = readdir($dp)) {
|
||||
if ($ent{0} == '.' || substr($ent, -4) != '.reg') {
|
||||
continue;
|
||||
}
|
||||
$pkglist[] = substr($ent, 0, -4);
|
||||
}
|
||||
return $pkglist;
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
// {{{ packageExists()
|
||||
|
||||
function packageExists($package)
|
||||
{
|
||||
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
|
||||
return $e;
|
||||
}
|
||||
$ret = $this->_packageExists($package);
|
||||
$this->_unlock();
|
||||
return $ret;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ packageInfo()
|
||||
|
||||
function packageInfo($package = null, $key = null)
|
||||
{
|
||||
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
|
||||
return $e;
|
||||
}
|
||||
$ret = $this->_packageInfo($package, $key);
|
||||
$this->_unlock();
|
||||
return $ret;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ listPackages()
|
||||
|
||||
function listPackages()
|
||||
{
|
||||
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
|
||||
return $e;
|
||||
}
|
||||
$ret = $this->_listPackages();
|
||||
$this->_unlock();
|
||||
return $ret;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ addPackage()
|
||||
|
||||
function addPackage($package, $info)
|
||||
{
|
||||
if ($this->packageExists($package)) {
|
||||
return false;
|
||||
}
|
||||
if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
|
||||
return $e;
|
||||
}
|
||||
$fp = $this->_openPackageFile($package, 'w');
|
||||
if ($fp === null) {
|
||||
$this->_unlock();
|
||||
return false;
|
||||
}
|
||||
$info['_lastmodified'] = time();
|
||||
fwrite($fp, serialize($info));
|
||||
$this->_closePackageFile($fp);
|
||||
$this->_unlock();
|
||||
return true;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ deletePackage()
|
||||
|
||||
function deletePackage($package)
|
||||
{
|
||||
if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
|
||||
return $e;
|
||||
}
|
||||
$file = $this->_packageFileName($package);
|
||||
$ret = @unlink($file);
|
||||
$this->rebuildFileMap();
|
||||
$this->_unlock();
|
||||
return $ret;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ updatePackage()
|
||||
|
||||
function updatePackage($package, $info, $merge = true)
|
||||
{
|
||||
$oldinfo = $this->packageInfo($package);
|
||||
if (empty($oldinfo)) {
|
||||
return false;
|
||||
}
|
||||
if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
|
||||
return $e;
|
||||
}
|
||||
$fp = $this->_openPackageFile($package, 'w');
|
||||
if ($fp === null) {
|
||||
$this->_unlock();
|
||||
return false;
|
||||
}
|
||||
$info['_lastmodified'] = time();
|
||||
if ($merge) {
|
||||
fwrite($fp, serialize(array_merge($oldinfo, $info)));
|
||||
} else {
|
||||
fwrite($fp, serialize($info));
|
||||
}
|
||||
$this->_closePackageFile($fp);
|
||||
if (isset($info['filelist'])) {
|
||||
$this->rebuildFileMap();
|
||||
}
|
||||
$this->_unlock();
|
||||
return true;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ checkFileMap()
|
||||
|
||||
/**
|
||||
* Test whether a file belongs to a package.
|
||||
*
|
||||
* @param string $path file path, absolute or relative to the pear
|
||||
* install dir
|
||||
*
|
||||
* @return string which package the file belongs to, or an empty
|
||||
* string if the file does not belong to an installed package
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function checkFileMap($path)
|
||||
{
|
||||
if (is_array($path)) {
|
||||
static $notempty;
|
||||
if (empty($notempty)) {
|
||||
$notempty = create_function('$a','return !empty($a);');
|
||||
}
|
||||
$pkgs = array();
|
||||
foreach ($path as $name => $attrs) {
|
||||
if (isset($attrs['baseinstalldir'])) {
|
||||
$name = $attrs['baseinstalldir'].DIRECTORY_SEPARATOR.$name;
|
||||
}
|
||||
$pkgs[$name] = $this->checkFileMap($name);
|
||||
}
|
||||
return array_filter($pkgs, $notempty);
|
||||
}
|
||||
if (empty($this->filemap_cache) && PEAR::isError($this->readFileMap())) {
|
||||
return $err;
|
||||
}
|
||||
if (isset($this->filemap_cache[$path])) {
|
||||
return $this->filemap_cache[$path];
|
||||
}
|
||||
$l = strlen($this->install_dir);
|
||||
if (substr($path, 0, $l) == $this->install_dir) {
|
||||
$path = preg_replace('!^'.DIRECTORY_SEPARATOR.'+!', '', substr($path, $l));
|
||||
}
|
||||
if (isset($this->filemap_cache[$path])) {
|
||||
return $this->filemap_cache[$path];
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
// {{{ rebuildDepsFile()
|
||||
|
||||
/**
|
||||
Experimental dependencies database handling functions (not yet in production)
|
||||
|
||||
TODO:
|
||||
- test it
|
||||
- Think on the "not" dep relation. It's supposed that a package can't
|
||||
be installed if conflicts with another. The problem comes when the
|
||||
user forces the installation and later upgrades it
|
||||
**/
|
||||
|
||||
// XXX Terrible slow, a lot of read, lock, write, unlock
|
||||
function rebuildDepsFile()
|
||||
{
|
||||
// Init the file with empty data
|
||||
$error = $this->_depWriteDepDB(array());
|
||||
if (PEAR::isError($error)) {
|
||||
return $error;
|
||||
}
|
||||
$packages = $this->listPackages();
|
||||
foreach ($packages as $package) {
|
||||
$deps = $this->packageInfo($package, 'release_deps');
|
||||
$error = $this->setPackageDep($package, $deps);
|
||||
if (PEAR::isError($error)) {
|
||||
return $error;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function &_depGetDepDB()
|
||||
{
|
||||
if (!$fp = fopen($this->depfile, 'r')) {
|
||||
return $this->raiseError("Could not open dependencies file `".$this->depfile."'");
|
||||
}
|
||||
$data = fread($fp, filesize($this->depfile));
|
||||
fclose($fp);
|
||||
return unserialize($data);
|
||||
}
|
||||
|
||||
function _depWriteDepDB(&$deps)
|
||||
{
|
||||
if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
|
||||
return $e;
|
||||
}
|
||||
if (!$fp = fopen($this->depfile, 'w')) {
|
||||
$this->_unlock();
|
||||
return $this->raiseError("Could not open dependencies file `".$this->depfile."' for writting");
|
||||
}
|
||||
fwrite($fp, serialize($deps));
|
||||
fclose($fp);
|
||||
$this->_unlock();
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
The data structure is as follows:
|
||||
$dep_db = array(
|
||||
// Other packages depends in some manner on this packages
|
||||
'deps' => array(
|
||||
'Package Name' => array(
|
||||
0 => array(
|
||||
// This package depends on 'Package Name'
|
||||
'depend' => 'Package',
|
||||
// Which version 'Package' needs of 'Package Name'
|
||||
'version' => '1.0',
|
||||
// The requirement (version_compare() operator)
|
||||
'rel' => 'ge'
|
||||
),
|
||||
),
|
||||
)
|
||||
// This packages are dependant on other packages
|
||||
'pkgs' => array(
|
||||
'Package Dependant' => array(
|
||||
// This is a index list with paths over the 'deps' array for quick
|
||||
// searching things like "what dependecies has this package?"
|
||||
// $dep_db['deps']['Package Name'][3]
|
||||
'Package Name' => 3 // key in array ['deps']['Package Name']
|
||||
),
|
||||
)
|
||||
)
|
||||
|
||||
Note: It only supports package dependencies no other type
|
||||
*/
|
||||
|
||||
function removePackageDep($package)
|
||||
{
|
||||
$data = &$this->_depGetDepDB();
|
||||
if (PEAR::isError($data)) {
|
||||
return $data;
|
||||
}
|
||||
// Other packages depends on this package, can't be removed
|
||||
if (isset($data['deps'][$package])) {
|
||||
return $data['deps'][$package];
|
||||
}
|
||||
// The package depends on others, remove those dependencies
|
||||
if (isset($data['pkgs'][$package])) {
|
||||
foreach ($data['pkgs'][$package] as $pkg => $key) {
|
||||
// remove the dependency
|
||||
unset($data['deps'][$pkg][$key]);
|
||||
// if no more dependencies, remove the subject too
|
||||
if (!count($data['deps'][$pkg])) {
|
||||
unset($data['deps'][$pkg]);
|
||||
}
|
||||
}
|
||||
// remove the package from the index list
|
||||
unset($data['pkgs'][$package]);
|
||||
}
|
||||
return $this->_depWriteDepDB();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update or insert a the dependencies of a package, prechecking
|
||||
* that the package won't break any dependency in the process
|
||||
*/
|
||||
function setPackageDep($package, $new_version, $rel_deps = array())
|
||||
{
|
||||
$data = &$this->_depGetDepDB();
|
||||
if (PEAR::isError($deps)) {
|
||||
return $deps;
|
||||
}
|
||||
// Other packages depend on this package, check deps. Mostly for
|
||||
// handling uncommon cases like:
|
||||
// <dep type='pkg' rel='lt' version='1.0'>Foo</dep> and we are trying to
|
||||
// update Foo to version 2.0
|
||||
if (isset($data['deps'][$package])) {
|
||||
foreach ($data['deps'][$package] as $dep) {
|
||||
$require = $dep['version'];
|
||||
$relation = $dep['rel'];
|
||||
// XXX (cox) Possible problem with changes in the way
|
||||
// PEAR_Dependency::checkPackage() works
|
||||
if ($relation != 'has') {
|
||||
if (!version_compare("$new_version", "$require", $relation)) {
|
||||
$fails[] = $dep;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($fails)) {
|
||||
return $fails;
|
||||
}
|
||||
}
|
||||
|
||||
// This package has no dependencies
|
||||
if (!is_array($rel_deps) || !count($rel_deps)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// The package depends on others, register that
|
||||
foreach ($rel_deps as $dep) {
|
||||
// We only support deps of type 'pkg's
|
||||
if ($dep && $dep['type'] == 'pkg' && isset($dep['name'])) {
|
||||
$write = array('depend' => $package,
|
||||
'version' => $dep['version'],
|
||||
'rel' => $dep['rel']);
|
||||
settype($data['deps'][$dep['name']], 'array');
|
||||
|
||||
// The dependency already exists, update it
|
||||
if (isset($data['pkgs'][$package][$dep['name']])) {
|
||||
$key = $data['pkgs'][$package][$dep['name']];
|
||||
$data['deps'][$dep['name']][$key] = $write;
|
||||
|
||||
// New dependency, insert it
|
||||
} else {
|
||||
$data['deps'][$dep['name']][] = $write;
|
||||
$key = key($data['deps'][$dep['name']]);
|
||||
settype($data['pkgs'][$package], 'array');
|
||||
$data['pkgs'][$package][$dep['name']] = $key;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this->_depWriteDepDB($data);
|
||||
}
|
||||
|
||||
// }}}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,349 @@
|
||||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.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. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Stig Bakken <ssb@fast.no> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id$
|
||||
|
||||
require_once 'PEAR.php';
|
||||
require_once 'PEAR/Config.php';
|
||||
|
||||
/**
|
||||
* This is a class for doing remote operations against the central
|
||||
* PEAR database.
|
||||
*
|
||||
* @nodep XML_RPC_Value
|
||||
* @nodep XML_RPC_Message
|
||||
* @nodep XML_RPC_Client
|
||||
*/
|
||||
class PEAR_Remote extends PEAR
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
var $config = null;
|
||||
var $cache = null;
|
||||
|
||||
// }}}
|
||||
|
||||
// {{{ PEAR_Remote(config_object)
|
||||
|
||||
function PEAR_Remote(&$config)
|
||||
{
|
||||
$this->PEAR();
|
||||
$this->config = &$config;
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
function getCache($args)
|
||||
{
|
||||
$id = md5(serialize($args));
|
||||
$cachedir = $this->config->get('cache_dir');
|
||||
if (!file_exists($cachedir)) {
|
||||
System::mkdir('-p '.$cachedir);
|
||||
}
|
||||
$filename = $cachedir.'/xmlrpc_cache_'.$id;
|
||||
if (!file_exists($filename)) {
|
||||
return null;
|
||||
};
|
||||
$result = array(
|
||||
'age' => time() - filemtime($filename),
|
||||
'lastChange' => filemtime($filename),
|
||||
'content' => unserialize(implode('', file($filename))),
|
||||
);
|
||||
return $result;
|
||||
}
|
||||
|
||||
function saveCache($args, $data)
|
||||
{
|
||||
$id = md5(serialize($args));
|
||||
$cachedir = $this->config->get('cache_dir');
|
||||
if (!file_exists($cachedir)) {
|
||||
System::mkdir('-p '.$cachedir);
|
||||
}
|
||||
$filename = $cachedir.'/xmlrpc_cache_'.$id;
|
||||
|
||||
$fp = @fopen($filename, "w");
|
||||
if ($fp !== null) {
|
||||
fwrite($fp, serialize($data));
|
||||
fclose($fp);
|
||||
};
|
||||
}
|
||||
|
||||
// {{{ call(method, [args...])
|
||||
|
||||
function call($method)
|
||||
{
|
||||
$_args = $args = func_get_args();
|
||||
|
||||
$this->cache = $this->getCache($args);
|
||||
$cachettl = $this->config->get('cache_ttl');
|
||||
// If cache is newer than $cachettl seconds, we use the cache!
|
||||
if ($this->cache !== null && $this->cache['age'] < $cachettl) {
|
||||
return $this->cache['content'];
|
||||
};
|
||||
|
||||
if (extension_loaded("xmlrpc")) {
|
||||
$result = call_user_func_array(array(&$this, 'call_epi'), $args);
|
||||
$this->saveCache($_args, $result);
|
||||
return $result;
|
||||
}
|
||||
if (!@include_once("XML/RPC.php")) {
|
||||
return $this->raiseError("For this remote PEAR operation you need to install the XML_RPC package");
|
||||
}
|
||||
array_shift($args);
|
||||
$server_host = $this->config->get('master_server');
|
||||
$username = $this->config->get('username');
|
||||
$password = $this->config->get('password');
|
||||
$eargs = array();
|
||||
foreach($args as $arg) $eargs[] = $this->_encode($arg);
|
||||
$f = new XML_RPC_Message($method, $eargs);
|
||||
if ($this->cache !== null) {
|
||||
$maxAge = '?maxAge='.$this->cache['lastChange'];
|
||||
} else {
|
||||
$maxAge = '';
|
||||
};
|
||||
$proxy_host = $proxy_port = $proxy_user = $proxy_pass = '';
|
||||
if ($proxy = parse_url($this->config->get('http_proxy'))) {
|
||||
$proxy_host = @$proxy['host'];
|
||||
$proxy_port = @$proxy['port'];
|
||||
$proxy_user = @$proxy['user'];
|
||||
$proxy_pass = @$proxy['pass'];
|
||||
}
|
||||
$c = new XML_RPC_Client('/xmlrpc.php'.$maxAge, $server_host, 80, $proxy_host, $proxy_port, $proxy_user, $proxy_pass);
|
||||
if ($username && $password) {
|
||||
$c->setCredentials($username, $password);
|
||||
}
|
||||
if ($this->config->get('verbose') >= 3) {
|
||||
$c->setDebug(1);
|
||||
}
|
||||
$r = $c->send($f);
|
||||
if (!$r) {
|
||||
return $this->raiseError("XML_RPC send failed");
|
||||
}
|
||||
$v = $r->value();
|
||||
if ($e = $r->faultCode()) {
|
||||
if ($e == $GLOBALS['XML_RPC_err']['http_error'] && strstr($r->faultString(), '304 Not Modified') !== false) {
|
||||
return $this->cache['content'];
|
||||
}
|
||||
return $this->raiseError($r->faultString(), $e);
|
||||
}
|
||||
|
||||
$result = XML_RPC_decode($v);
|
||||
$this->saveCache($_args, $result);
|
||||
return $result;
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
// {{{ call_epi(method, [args...])
|
||||
|
||||
function call_epi($method)
|
||||
{
|
||||
do {
|
||||
if (extension_loaded("xmlrpc")) {
|
||||
break;
|
||||
}
|
||||
if (OS_WINDOWS) {
|
||||
$ext = 'dll';
|
||||
} elseif (PHP_OS == 'HP-UX') {
|
||||
$ext = 'sl';
|
||||
} elseif (PHP_OS == 'AIX') {
|
||||
$ext = 'a';
|
||||
} else {
|
||||
$ext = 'so';
|
||||
}
|
||||
$ext = OS_WINDOWS ? 'dll' : 'so';
|
||||
@dl("xmlrpc-epi.$ext");
|
||||
if (extension_loaded("xmlrpc")) {
|
||||
break;
|
||||
}
|
||||
@dl("xmlrpc.$ext");
|
||||
if (extension_loaded("xmlrpc")) {
|
||||
break;
|
||||
}
|
||||
return $this->raiseError("unable to load xmlrpc extension");
|
||||
} while (false);
|
||||
$params = func_get_args();
|
||||
array_shift($params);
|
||||
$method = str_replace("_", ".", $method);
|
||||
$request = xmlrpc_encode_request($method, $params);
|
||||
$server_host = $this->config->get("master_server");
|
||||
if (empty($server_host)) {
|
||||
return $this->raiseError("PEAR_Remote::call: no master_server configured");
|
||||
}
|
||||
$server_port = 80;
|
||||
$fp = @fsockopen($server_host, $server_port);
|
||||
if (!$fp) {
|
||||
return $this->raiseError("PEAR_Remote::call: fsockopen(`$server_host', $server_port) failed");
|
||||
}
|
||||
$len = strlen($request);
|
||||
$req_headers = "Host: $server_host:$server_port\r\n" .
|
||||
"Content-type: text/xml\r\n" .
|
||||
"Content-length: $len\r\n";
|
||||
$username = $this->config->get('username');
|
||||
$password = $this->config->get('password');
|
||||
if ($username && $password) {
|
||||
$req_headers .= "Cookie: PEAR_USER=$username; PEAR_PW=$password\r\n";
|
||||
$tmp = base64_encode("$username:$password");
|
||||
$req_headers .= "Authorization: Basic $tmp\r\n";
|
||||
}
|
||||
if ($this->cache !== null) {
|
||||
$maxAge = '?maxAge='.$this->cache['lastChange'];
|
||||
} else {
|
||||
$maxAge = '';
|
||||
};
|
||||
|
||||
if ($this->config->get('verbose') > 3) {
|
||||
print "XMLRPC REQUEST HEADERS:\n";
|
||||
var_dump($req_headers);
|
||||
print "XMLRPC REQUEST BODY:\n";
|
||||
var_dump($request);
|
||||
}
|
||||
|
||||
fwrite($fp, ("POST /xmlrpc.php$maxAge HTTP/1.0\r\n$req_headers\r\n$request"));
|
||||
$response = '';
|
||||
$line1 = fgets($fp, 2048);
|
||||
if (!preg_match('!^HTTP/[0-9\.]+ (\d+) (.*)!', $line1, $matches)) {
|
||||
return $this->raiseError("PEAR_Remote: invalid HTTP response from XML-RPC server");
|
||||
}
|
||||
switch ($matches[1]) {
|
||||
case "200": // OK
|
||||
break;
|
||||
case "304": // Not Modified
|
||||
return $this->cache['content'];
|
||||
case "401": // Unauthorized
|
||||
if ($username && $password) {
|
||||
return $this->raiseError("PEAR_Remote: authorization failed", 401);
|
||||
} else {
|
||||
return $this->raiseError("PEAR_Remote: authorization required, please log in first", 401);
|
||||
}
|
||||
default:
|
||||
return $this->raiseError("PEAR_Remote: unexpected HTTP response", (int)$matches[1], null, null, "$matches[1] $matches[2]");
|
||||
}
|
||||
while (trim(fgets($fp, 2048)) != ''); // skip rest of headers
|
||||
while ($chunk = fread($fp, 10240)) {
|
||||
$response .= $chunk;
|
||||
}
|
||||
fclose($fp);
|
||||
if ($this->config->get('verbose') > 3) {
|
||||
print "XMLRPC RESPONSE:\n";
|
||||
var_dump($response);
|
||||
}
|
||||
$ret = xmlrpc_decode($response);
|
||||
if (is_array($ret) && isset($ret['__PEAR_TYPE__'])) {
|
||||
if ($ret['__PEAR_TYPE__'] == 'error') {
|
||||
if (isset($ret['__PEAR_CLASS__'])) {
|
||||
$class = $ret['__PEAR_CLASS__'];
|
||||
} else {
|
||||
$class = "PEAR_Error";
|
||||
}
|
||||
if ($ret['code'] === '') $ret['code'] = null;
|
||||
if ($ret['message'] === '') $ret['message'] = null;
|
||||
if ($ret['userinfo'] === '') $ret['userinfo'] = null;
|
||||
if (strtolower($class) == 'db_error') {
|
||||
$ret = $this->raiseError(PEAR::errorMessage($ret['code']),
|
||||
$ret['code'], null, null,
|
||||
$ret['userinfo']);
|
||||
} else {
|
||||
$ret = $this->raiseError($ret['message'], $ret['code'],
|
||||
null, null, $ret['userinfo']);
|
||||
}
|
||||
}
|
||||
} elseif (is_array($ret) && sizeof($ret) == 1 && is_array($ret[0]) &&
|
||||
!empty($ret[0]['faultString']) &&
|
||||
!empty($ret[0]['faultCode'])) {
|
||||
extract($ret[0]);
|
||||
$faultString = "XML-RPC Server Fault: " .
|
||||
str_replace("\n", " ", $faultString);
|
||||
return $this->raiseError($faultString, $faultCode);
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
// {{{ _encode
|
||||
|
||||
// a slightly extended version of XML_RPC_encode
|
||||
function _encode($php_val)
|
||||
{
|
||||
global $XML_RPC_Boolean, $XML_RPC_Int, $XML_RPC_Double;
|
||||
global $XML_RPC_String, $XML_RPC_Array, $XML_RPC_Struct;
|
||||
|
||||
$type = gettype($php_val);
|
||||
$xmlrpcval = new XML_RPC_Value;
|
||||
|
||||
switch($type) {
|
||||
case "array":
|
||||
reset($php_val);
|
||||
$firstkey = key($php_val);
|
||||
end($php_val);
|
||||
$lastkey = key($php_val);
|
||||
if ($firstkey === 0 && is_int($lastkey) &&
|
||||
($lastkey + 1) == count($php_val)) {
|
||||
$is_continous = true;
|
||||
reset($php_val);
|
||||
$size = count($php_val);
|
||||
for ($expect = 0; $expect < $size; $expect++, next($php_val)) {
|
||||
if (key($php_val) !== $expect) {
|
||||
$is_continous = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($is_continous) {
|
||||
reset($php_val);
|
||||
$arr = array();
|
||||
while (list($k, $v) = each($php_val)) {
|
||||
$arr[$k] = $this->_encode($v);
|
||||
}
|
||||
$xmlrpcval->addArray($arr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// fall though if not numerical and continous
|
||||
case "object":
|
||||
$arr = array();
|
||||
while (list($k, $v) = each($php_val)) {
|
||||
$arr[$k] = $this->_encode($v);
|
||||
}
|
||||
$xmlrpcval->addStruct($arr);
|
||||
break;
|
||||
case "integer":
|
||||
$xmlrpcval->addScalar($php_val, $XML_RPC_Int);
|
||||
break;
|
||||
case "double":
|
||||
$xmlrpcval->addScalar($php_val, $XML_RPC_Double);
|
||||
break;
|
||||
case "string":
|
||||
case "NULL":
|
||||
$xmlrpcval->addScalar($php_val, $XML_RPC_String);
|
||||
break;
|
||||
case "boolean":
|
||||
$xmlrpcval->addScalar($php_val, $XML_RPC_Boolean);
|
||||
break;
|
||||
case "unknown type":
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
return $xmlrpcval;
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
+439
@@ -0,0 +1,439 @@
|
||||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.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. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Tomas V.V.Cox <cox@idecnet.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
|
||||
require_once 'PEAR.php';
|
||||
require_once 'Console/Getopt.php';
|
||||
|
||||
$GLOBALS['_System_temp_files'] = array();
|
||||
|
||||
/**
|
||||
* System offers cross plattform compatible system functions
|
||||
*
|
||||
* Static functions for different operations. Should work under
|
||||
* Unix and Windows. The names and usage has been taken from its respectively
|
||||
* GNU commands. The functions will return (bool) false on error and will
|
||||
* trigger the error with the PHP trigger_error() function (you can silence
|
||||
* the error by prefixing a '@' sign after the function call).
|
||||
*
|
||||
* Documentation on this class you can find in:
|
||||
* http://pear.php.net/manual/
|
||||
*
|
||||
* Example usage:
|
||||
* if (!@System::rm('-r file1 dir1')) {
|
||||
* print "could not delete file1 or dir1";
|
||||
* }
|
||||
*
|
||||
* @package System
|
||||
* @author Tomas V.V.Cox <cox@idecnet.com>
|
||||
* @version $Revision$
|
||||
* @access public
|
||||
* @see http://pear.php.net/manual/
|
||||
*/
|
||||
class System
|
||||
{
|
||||
/**
|
||||
* returns the commandline arguments of a function
|
||||
*
|
||||
* @param string $argv the commandline
|
||||
* @param string $short_options the allowed option short-tags
|
||||
* @param string $long_options the allowed option long-tags
|
||||
* @return array the given options and there values
|
||||
* @access private
|
||||
*/
|
||||
function _parseArgs($argv, $short_options, $long_options = null)
|
||||
{
|
||||
if (!is_array($argv) && $argv !== null) {
|
||||
$argv = preg_split('/\s+/', $argv);
|
||||
}
|
||||
return Console_Getopt::getopt($argv, $short_options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Output errors with PHP trigger_error(). You can silence the errors
|
||||
* with prefixing a "@" sign to the function call: @System::mkdir(..);
|
||||
*
|
||||
* @param mixed $error a PEAR error or a string with the error message
|
||||
* @return bool false
|
||||
* @access private
|
||||
*/
|
||||
function raiseError($error)
|
||||
{
|
||||
if (PEAR::isError($error)) {
|
||||
$error = $error->getMessage();
|
||||
}
|
||||
trigger_error($error, E_USER_WARNING);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a nested array representing the structure of a directory
|
||||
*
|
||||
* System::_dirToStruct('dir1', 0) =>
|
||||
* Array
|
||||
* (
|
||||
* [dirs] => Array
|
||||
* (
|
||||
* [0] => dir1
|
||||
* )
|
||||
*
|
||||
* [files] => Array
|
||||
* (
|
||||
* [0] => dir1/file2
|
||||
* [1] => dir1/file3
|
||||
* )
|
||||
* )
|
||||
* @param string $sPath Name of the directory
|
||||
* @param integer $maxinst max. deep of the lookup
|
||||
* @param integer $aktinst starting deep of the lookup
|
||||
* @return array the structure of the dir
|
||||
* @access private
|
||||
*/
|
||||
|
||||
function _dirToStruct($sPath, $maxinst, $aktinst = 0)
|
||||
{
|
||||
$struct = array('dirs' => array(), 'files' => array());
|
||||
if (($dir = @opendir($sPath)) === false) {
|
||||
System::raiseError("Could not open dir $sPath");
|
||||
return $struct; // XXX could not open error
|
||||
}
|
||||
$struct['dirs'][] = $sPath; // XXX don't add if '.' or '..' ?
|
||||
$list = array();
|
||||
while ($file = readdir($dir)) {
|
||||
if ($file != '.' && $file != '..') {
|
||||
$list[] = $file;
|
||||
}
|
||||
}
|
||||
closedir($dir);
|
||||
sort($list);
|
||||
foreach($list as $val) {
|
||||
$path = $sPath . DIRECTORY_SEPARATOR . $val;
|
||||
if (is_dir($path)) {
|
||||
if ($aktinst < $maxinst || $maxinst == 0) {
|
||||
$tmp = System::_dirToStruct($path, $maxinst, $aktinst+1);
|
||||
$struct = array_merge_recursive($tmp, $struct);
|
||||
}
|
||||
} else {
|
||||
$struct['files'][] = $path;
|
||||
}
|
||||
}
|
||||
return $struct;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a nested array representing the structure of a directory and files
|
||||
*
|
||||
* @param array $files Array listing files and dirs
|
||||
* @return array
|
||||
* @see System::_dirToStruct()
|
||||
*/
|
||||
function _multipleToStruct($files)
|
||||
{
|
||||
$struct = array('dirs' => array(), 'files' => array());
|
||||
settype($files, 'array');
|
||||
foreach ($files as $file) {
|
||||
if (is_dir($file)) {
|
||||
$tmp = System::_dirToStruct($file, 0);
|
||||
$struct = array_merge_recursive($tmp, $struct);
|
||||
} else {
|
||||
$struct['files'][] = $file;
|
||||
}
|
||||
}
|
||||
return $struct;
|
||||
}
|
||||
|
||||
/**
|
||||
* The rm command for removing files.
|
||||
* Supports multiple files and dirs and also recursive deletes
|
||||
*
|
||||
* @param string $args the arguments for rm
|
||||
* @return mixed PEAR_Error or true for success
|
||||
* @access public
|
||||
*/
|
||||
function rm($args)
|
||||
{
|
||||
$opts = System::_parseArgs($args, 'rf'); // "f" do nothing but like it :-)
|
||||
if (PEAR::isError($opts)) {
|
||||
return System::raiseError($opts);
|
||||
}
|
||||
foreach($opts[0] as $opt) {
|
||||
if ($opt[0] == 'r') {
|
||||
$do_recursive = true;
|
||||
}
|
||||
}
|
||||
$ret = true;
|
||||
if (isset($do_recursive)) {
|
||||
$struct = System::_multipleToStruct($opts[1]);
|
||||
foreach($struct['files'] as $file) {
|
||||
if (!@unlink($file)) {
|
||||
$ret = false;
|
||||
}
|
||||
}
|
||||
foreach($struct['dirs'] as $dir) {
|
||||
if (!@rmdir($dir)) {
|
||||
$ret = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach ($opts[1] as $file) {
|
||||
$delete = (is_dir($file)) ? 'rmdir' : 'unlink';
|
||||
if (!@$delete($file)) {
|
||||
$ret = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make directories. Note that we use call_user_func('mkdir') to avoid
|
||||
* a problem with ZE2 calling System::mkDir instead of the native PHP func.
|
||||
*
|
||||
* @param string $args the name of the director(y|ies) to create
|
||||
* @return bool True for success
|
||||
* @access public
|
||||
*/
|
||||
function mkDir($args)
|
||||
{
|
||||
$opts = System::_parseArgs($args, 'pm:');
|
||||
if (PEAR::isError($opts)) {
|
||||
return System::raiseError($opts);
|
||||
}
|
||||
$mode = 0777; // default mode
|
||||
foreach($opts[0] as $opt) {
|
||||
if ($opt[0] == 'p') {
|
||||
$create_parents = true;
|
||||
} elseif($opt[0] == 'm') {
|
||||
$mode = $opt[1];
|
||||
}
|
||||
}
|
||||
$ret = true;
|
||||
if (isset($create_parents)) {
|
||||
foreach($opts[1] as $dir) {
|
||||
$dirstack = array();
|
||||
while (!@is_dir($dir) && $dir != DIRECTORY_SEPARATOR) {
|
||||
array_unshift($dirstack, $dir);
|
||||
$dir = dirname($dir);
|
||||
}
|
||||
while ($newdir = array_shift($dirstack)) {
|
||||
if (!call_user_func('mkdir', $newdir, $mode)) {
|
||||
$ret = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach($opts[1] as $dir) {
|
||||
if (!@is_dir($dir) && !call_user_func('mkdir', $dir, $mode)) {
|
||||
$ret = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Concatenate files
|
||||
*
|
||||
* Usage:
|
||||
* 1) $var = System::cat('sample.txt test.txt');
|
||||
* 2) System::cat('sample.txt test.txt > final.txt');
|
||||
* 3) System::cat('sample.txt test.txt >> final.txt');
|
||||
*
|
||||
* Note: as the class use fopen, urls should work also (test that)
|
||||
*
|
||||
* @param string $args the arguments
|
||||
* @return boolean true on success
|
||||
* @access public
|
||||
*/
|
||||
function &cat($args)
|
||||
{
|
||||
$ret = null;
|
||||
$files = array();
|
||||
if (!is_array($args)) {
|
||||
$args = preg_split('/\s+/', $args);
|
||||
}
|
||||
for($i=0; $i < count($args); $i++) {
|
||||
if ($args[$i] == '>') {
|
||||
$mode = 'wb';
|
||||
$outputfile = $args[$i+1];
|
||||
break;
|
||||
} elseif ($args[$i] == '>>') {
|
||||
$mode = 'ab+';
|
||||
$outputfile = $args[$i+1];
|
||||
break;
|
||||
} else {
|
||||
$files[] = $args[$i];
|
||||
}
|
||||
}
|
||||
if (isset($mode)) {
|
||||
if (!$outputfd = fopen($outputfile, $mode)) {
|
||||
return System::raiseError("Could not open $outputfile");
|
||||
}
|
||||
$ret = true;
|
||||
}
|
||||
foreach ($files as $file) {
|
||||
if (!$fd = fopen($file, 'r')) {
|
||||
System::raiseError("Could not open $file");
|
||||
continue;
|
||||
}
|
||||
while ($cont = fread($fd, 2048)) {
|
||||
if (isset($outputfd)) {
|
||||
fwrite($outputfd, $cont);
|
||||
} else {
|
||||
$ret .= $cont;
|
||||
}
|
||||
}
|
||||
fclose($fd);
|
||||
}
|
||||
if (@is_resource($outputfd)) {
|
||||
fclose($outputfd);
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates temporary files or directories. This function will remove
|
||||
* the created files when the scripts finish its execution.
|
||||
*
|
||||
* Usage:
|
||||
* 1) $tempfile = System::mktemp("prefix");
|
||||
* 2) $tempdir = System::mktemp("-d prefix");
|
||||
* 3) $tempfile = System::mktemp();
|
||||
* 4) $tempfile = System::mktemp("-t /var/tmp prefix");
|
||||
*
|
||||
* prefix -> The string that will be prepended to the temp name
|
||||
* (defaults to "tmp").
|
||||
* -d -> A temporary dir will be created instead of a file.
|
||||
* -t -> The target dir where the temporary (file|dir) will be created. If
|
||||
* this param is missing by default the env vars TMP on Windows or
|
||||
* TMPDIR in Unix will be used. If these vars are also missing
|
||||
* c:\windows\temp or /tmp will be used.
|
||||
*
|
||||
* @param string $args The arguments
|
||||
* @return mixed the full path of the created (file|dir) or false
|
||||
* @see System::tmpdir()
|
||||
* @access public
|
||||
*/
|
||||
function mktemp($args = null)
|
||||
{
|
||||
static $first_time = true;
|
||||
$opts = System::_parseArgs($args, 't:d');
|
||||
if (PEAR::isError($opts)) {
|
||||
return System::raiseError($opts);
|
||||
}
|
||||
foreach($opts[0] as $opt) {
|
||||
if($opt[0] == 'd') {
|
||||
$tmp_is_dir = true;
|
||||
} elseif($opt[0] == 't') {
|
||||
$tmpdir = $opt[1];
|
||||
}
|
||||
}
|
||||
$prefix = (isset($opts[1][0])) ? $opts[1][0] : 'tmp';
|
||||
if (!isset($tmpdir)) {
|
||||
$tmpdir = System::tmpdir();
|
||||
}
|
||||
if (!System::mkDir("-p $tmpdir")) {
|
||||
return false;
|
||||
}
|
||||
$tmp = tempnam($tmpdir, $prefix);
|
||||
if (isset($tmp_is_dir)) {
|
||||
unlink($tmp); // be careful possible race condition here
|
||||
if (!call_user_func('mkdir', $tmp, 0700)) {
|
||||
return System::raiseError("Unable to create temporary directory $tmpdir");
|
||||
}
|
||||
}
|
||||
$GLOBALS['_System_temp_files'][] = $tmp;
|
||||
if ($first_time) {
|
||||
PEAR::registerShutdownFunc(array('System', '_removeTmpFiles'));
|
||||
$first_time = false;
|
||||
}
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove temporary files created my mkTemp. This function is executed
|
||||
* at script shutdown time
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
function _removeTmpFiles()
|
||||
{
|
||||
if (count($GLOBALS['_System_temp_files'])) {
|
||||
$delete = $GLOBALS['_System_temp_files'];
|
||||
array_unshift($delete, '-r');
|
||||
System::rm($delete);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the path of the temporal directory set in the system
|
||||
* by looking in its environments variables.
|
||||
* Note: php.ini-recommended removes the "E" from the variables_order setting,
|
||||
* making unavaible the $_ENV array, that s why we do tests with _ENV
|
||||
*
|
||||
* @return string The temporal directory on the system
|
||||
*/
|
||||
function tmpdir()
|
||||
{
|
||||
if (OS_WINDOWS) {
|
||||
if ($var = isset($_ENV['TEMP']) ? $_ENV['TEMP'] : getenv('TEMP')) {
|
||||
return $var;
|
||||
}
|
||||
if ($var = isset($_ENV['TMP']) ? $_ENV['TMP'] : getenv('TMP')) {
|
||||
return $var;
|
||||
}
|
||||
if ($var = isset($_ENV['windir']) ? $_ENV['windir'] : getenv('windir')) {
|
||||
return $var;
|
||||
}
|
||||
return getenv('SystemRoot') . '\temp';
|
||||
}
|
||||
if ($var = isset($_ENV['TMPDIR']) ? $_ENV['TMPDIR'] : getenv('TMPDIR')) {
|
||||
return $var;
|
||||
}
|
||||
return '/tmp';
|
||||
}
|
||||
|
||||
/**
|
||||
* The "which" command (show the full path of a command)
|
||||
*
|
||||
* @param string $program The command to search for
|
||||
* @return mixed A string with the full path or false if not found
|
||||
* @author Stig Bakken <ssb@fast.no>
|
||||
*/
|
||||
function which($program, $fallback = false)
|
||||
{
|
||||
// full path given
|
||||
if (basename($program) != $program) {
|
||||
return (@is_executable($program)) ? $program : $fallback;
|
||||
}
|
||||
// XXX FIXME honor safe mode
|
||||
$path_delim = OS_WINDOWS ? ';' : ':';
|
||||
$exe_suffix = OS_WINDOWS ? '.exe' : '';
|
||||
$path_elements = explode($path_delim, getenv('PATH'));
|
||||
foreach ($path_elements as $dir) {
|
||||
$file = $dir . DIRECTORY_SEPARATOR . $program . $exe_suffix;
|
||||
if (@is_file($file) && @is_executable($file)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
return $fallback;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,215 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1" ?>
|
||||
<!DOCTYPE package SYSTEM "package.dtd">
|
||||
<package version="1.0">
|
||||
<name>PEAR</name>
|
||||
<summary>PEAR Base System</summary>
|
||||
<description>The PEAR package contains:
|
||||
* the PEAR base class
|
||||
* the PEAR_Error error handling mechanism
|
||||
* the PEAR installer, for creating, distributing
|
||||
and installing packages
|
||||
</description>
|
||||
<license>PHP License</license>
|
||||
<maintainers>
|
||||
<maintainer>
|
||||
<user>ssb</user>
|
||||
<role>lead</role>
|
||||
<name>Stig Sæther Bakken</name>
|
||||
<email>stig@php.net</email>
|
||||
</maintainer>
|
||||
<maintainer>
|
||||
<user>cox</user>
|
||||
<role>developer</role>
|
||||
<name>Tomas V.V.Cox</name>
|
||||
<email>cox@idecnet.com</email>
|
||||
</maintainer>
|
||||
<maintainer>
|
||||
<user>mj</user>
|
||||
<role>helper</role>
|
||||
<name>Martin Jansen</name>
|
||||
<email>mj@php.net</email>
|
||||
</maintainer>
|
||||
</maintainers>
|
||||
<release>
|
||||
<version>1.0b1</version>
|
||||
<state>stable</state>
|
||||
<date>2002-10-12</date>
|
||||
<notes>
|
||||
New Features, Installer:
|
||||
* new command: "pear makerpm"
|
||||
* new command: "pear search"
|
||||
* new command: "pear upgrade-all"
|
||||
* new command: "pear config-help"
|
||||
* new command: "pear sign"
|
||||
* Windows support for "pear build" (requires
|
||||
msdev)
|
||||
* new dependency type: "zend"
|
||||
* XML-RPC results may now be cached (see
|
||||
cache_dir and cache_ttl config)
|
||||
* HTTP proxy authorization support
|
||||
* install/upgrade install-root support
|
||||
|
||||
Bugfixes, Installer:
|
||||
* fix for XML-RPC bug that made some remote
|
||||
commands fail
|
||||
* fix problems under Windows with
|
||||
DIRECTORY_SEPARATOR
|
||||
* lots of other minor fixes
|
||||
* --force option did not work for "pear install
|
||||
Package"
|
||||
* http downloader used "4.2.1" rather than
|
||||
"PHP/4.2.1" as user agent
|
||||
* bending over a little more to figure out how
|
||||
PHP is installed
|
||||
* "platform" file attribute was not included
|
||||
during "pear package"
|
||||
|
||||
New Features, PEAR Library:
|
||||
* added PEAR::loadExtension($ext)
|
||||
* added PEAR::delExpect()
|
||||
* System::mkTemp() now cleans up at shutdown
|
||||
* defined PEAR_ZE2 constant (boolean)
|
||||
* added PEAR::throwError() with a simpler API
|
||||
than raiseError()
|
||||
|
||||
Bugfixes, PEAR Library:
|
||||
* ZE2 compatibility fixes
|
||||
* use getenv() as fallback for $_ENV
|
||||
</notes>
|
||||
<filelist>
|
||||
<file role="data" name="package.dtd"/>
|
||||
<file role="data" name="template.spec"/>
|
||||
<file role="php" name="PEAR.php"/>
|
||||
<file role="php" name="System.php"/>
|
||||
<dir name="PEAR">
|
||||
<file role="php" name="Autoloader.php"/>
|
||||
<file role="php" name="Command.php"/>
|
||||
<dir name="Command">
|
||||
<file role="php" name="Auth.php"/>
|
||||
<file role="php" name="Build.php"/>
|
||||
<file role="php" name="Common.php"/>
|
||||
<file role="php" name="Config.php"/>
|
||||
<file role="php" name="Install.php"/>
|
||||
<file role="php" name="Package.php"/>
|
||||
<file role="php" name="Registry.php"/>
|
||||
<file role="php" name="Remote.php"/>
|
||||
</dir>
|
||||
<file role="php" name="Common.php"/>
|
||||
<file role="php" name="Config.php"/>
|
||||
<file role="php" name="Dependency.php"/>
|
||||
<dir name="Frontend">
|
||||
<file role="php" name="CLI.php"/>
|
||||
</dir>
|
||||
<file role="php" name="Builder.php"/>
|
||||
<file role="php" name="Installer.php"/>
|
||||
<file role="php" name="Packager.php"/>
|
||||
<file role="php" name="Registry.php"/>
|
||||
<file role="php" name="Remote.php"/>
|
||||
</dir>
|
||||
<dir name="OS">
|
||||
<file role="php" name="Guess.php"/>
|
||||
</dir>
|
||||
<dir name="scripts">
|
||||
<file baseinstalldir="/" role="script" install-as="pear" name="pear.in">
|
||||
<replace from="@prefix@/bin" to="PHP_BINDIR" type="php-const"/>
|
||||
<replace from="@pear_version@" to="version" type="package-info"/>
|
||||
<replace from="@include_path@" to="php_dir" type="pear-config"/>
|
||||
</file>
|
||||
<file baseinstalldir="/" role="script" platform="windows" install-as="pear.bat" name="pear.bat"></file>
|
||||
</dir>
|
||||
</filelist>
|
||||
<deps>
|
||||
<dep type="php" rel="ge" version="4.1"/>
|
||||
<dep type="pkg" rel="ge" version="0.4">Archive_Tar</dep>
|
||||
<dep type="pkg" rel="ge" version="0.11">Console_Getopt</dep>
|
||||
</deps>
|
||||
</release>
|
||||
<changelog>
|
||||
<release>
|
||||
<version>0.90</version>
|
||||
<state>beta</state>
|
||||
<date>2002-05-28</date>
|
||||
<notes>
|
||||
* fix: "help" command was broken
|
||||
* new command: "info"
|
||||
* new command: "config-help"
|
||||
* un-indent multi-line data from xml description files
|
||||
* new command: "build"
|
||||
* fix: config-set did not work with "set" parameters
|
||||
* disable magic_quotes_runtime
|
||||
* "install" now builds and installs C extensions
|
||||
* added PEAR::delExpect()
|
||||
* System class no longer inherits PEAR
|
||||
* grouped PEAR_Config parameters
|
||||
* add --nobuild option to install/upgrade commands
|
||||
* new and more generic Frontend API
|
||||
</notes>
|
||||
<deps>
|
||||
<dep type="php" rel="ge" version="4.1"/>
|
||||
<dep type="pkg" rel="has" version="0.4">Archive_Tar</dep>
|
||||
<dep type="pkg" rel="ge" version="0.11">Console_Getopt</dep>
|
||||
</deps>
|
||||
</release>
|
||||
<release>
|
||||
<version>0.10</version>
|
||||
<state>beta</state>
|
||||
<date>2002-05-26</date>
|
||||
<notes>
|
||||
Lots of stuff this time. 0.9 was not actually self-hosting, even
|
||||
though it claimed to be. This version finally is self-hosting
|
||||
(really!), meaning you can upgrade the installer with the command
|
||||
"pear upgrade PEAR".
|
||||
|
||||
* new config paramers: http_proxy and umask
|
||||
* HTTP proxy support when downloading packages
|
||||
* generalized command handling code
|
||||
* and fixed the bug that would not let commands have the
|
||||
same options as "pear" itself
|
||||
* added long options to every command
|
||||
* added command shortcuts ("pear help shortcuts")
|
||||
* added stub for Gtk installer
|
||||
* some phpdoc fixes
|
||||
* added class dependency detector (using ext/tokenizer)
|
||||
* dependency handling fixes
|
||||
* added OS_Guess class for detecting OS
|
||||
* install files with the "platform" attribute set
|
||||
only on matching operating systems
|
||||
* PEAR_Remote now falls back to the XML_RPC package
|
||||
if xmlrpc-epi is not available
|
||||
* renamed command: package-list -> list
|
||||
* new command: package-dependencies
|
||||
* lots of minor fixes
|
||||
</notes>
|
||||
<deps>
|
||||
<dep type="php" rel="ge" version="4.1"/>
|
||||
<dep type="pkg" rel="has" version="0.5">Archive_Tar</dep>
|
||||
<dep type="pkg" rel="ge" version="0.11">Console_Getopt</dep>
|
||||
</deps>
|
||||
</release>
|
||||
<release>
|
||||
<version>0.9</version>
|
||||
<state>beta</state>
|
||||
<date>2002-04-07</date>
|
||||
<notes>
|
||||
First package release. Commands implemented:
|
||||
remote-package-info
|
||||
list-upgrades
|
||||
list-remote-packages
|
||||
download
|
||||
config-show
|
||||
config-get
|
||||
config-set
|
||||
list-installed
|
||||
shell-test
|
||||
install
|
||||
uninstall
|
||||
upgrade
|
||||
package
|
||||
package-list
|
||||
package-info
|
||||
login
|
||||
logout
|
||||
</notes>
|
||||
</release>
|
||||
</changelog>
|
||||
</package>
|
||||
@@ -0,0 +1,116 @@
|
||||
<!--
|
||||
$Id: package.dtd,v 1.27 2002-07-21 07:06:56 ssb Exp $
|
||||
|
||||
This is the PEAR package description, version 1.0b9.
|
||||
It should be used with the informal public identifier:
|
||||
|
||||
"-//PHP Group//DTD PEAR Package 1.0b9//EN//XML"
|
||||
|
||||
Copyright (c) 1997-2002 The PHP Group
|
||||
|
||||
This source file is subject to version 2.02 of the PHP license,
|
||||
that is bundled with this package in the file LICENSE, and is
|
||||
available at through the world-wide-web at
|
||||
http://www.php.net/license/2_02.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.
|
||||
|
||||
Authors:
|
||||
Stig S. Bakken <ssb@fast.no>
|
||||
|
||||
-->
|
||||
|
||||
<!ELEMENT package (name|summary|description|license|maintainers|release|changelog)+>
|
||||
<!ATTLIST package type (source|binary|empty) "empty"
|
||||
version CDATA #REQUIRED>
|
||||
|
||||
<!ELEMENT name (#PCDATA)>
|
||||
|
||||
<!ELEMENT summary (#PCDATA)>
|
||||
|
||||
<!ELEMENT description (#PCDATA)>
|
||||
|
||||
<!ELEMENT license (#PCDATA)>
|
||||
|
||||
<!ELEMENT maintainers (maintainer)+>
|
||||
|
||||
<!ELEMENT maintainer (user|role|name|email)+>
|
||||
|
||||
<!ELEMENT user (#PCDATA)>
|
||||
|
||||
<!ELEMENT role (#PCDATA)>
|
||||
|
||||
<!ELEMENT email (#PCDATA)>
|
||||
|
||||
<!ELEMENT changelog (release)+>
|
||||
|
||||
<!ELEMENT release (version|license|state|date|notes|filelist|deps|provides|script|configureoptions)+>
|
||||
|
||||
<!ELEMENT version (#PCDATA)>
|
||||
|
||||
<!ELEMENT state (#PCDATA)>
|
||||
|
||||
<!ELEMENT date (#PCDATA)>
|
||||
|
||||
<!ELEMENT notes (#PCDATA)>
|
||||
|
||||
<!ELEMENT filelist (dir|file|libfile)+>
|
||||
|
||||
<!ELEMENT dir (dir|file|libfile)+>
|
||||
<!ATTLIST dir name CDATA #REQUIRED
|
||||
baseinstalldir CDATA #IMPLIED>
|
||||
|
||||
<!ELEMENT file (replace*)>
|
||||
<!ATTLIST file role (php|ext|src|test|doc|data|script) 'php'
|
||||
debug (na|on|off) 'na'
|
||||
zts (na|on|off) 'na'
|
||||
phpapi NUMBER #IMPLIED
|
||||
zendapi NUMBER #IMPLIED
|
||||
format CDATA #IMPLIED
|
||||
baseinstalldir CDATA #IMPLIED
|
||||
platform CDATA #IMPLIED
|
||||
md5sum CDATA #IMPLIED
|
||||
name CDATA #REQUIRED
|
||||
install-as CDATA #IMPLIED>
|
||||
|
||||
<!ELEMENT replace EMPTY>
|
||||
<!ATTLIST replace from CDATA #REQUIRED
|
||||
to CDATA #REQUIRED
|
||||
type CDATA #REQUIRED>
|
||||
|
||||
<!ELEMENT libfile (libname|sources|includes|libadd)+>
|
||||
|
||||
<!ELEMENT libname (#PCDATA)>
|
||||
|
||||
<!ELEMENT sources (#PCDATA)>
|
||||
|
||||
<!ELEMENT libadd (#PCDATA)>
|
||||
|
||||
<!ELEMENT deps (dep)+>
|
||||
|
||||
<!ELEMENT dep (#PCDATA)>
|
||||
<!ATTLIST dep
|
||||
type (pkg|ext|php|prog|ldlib|rtlib|os|websrv|sapi|zend) #REQUIRED
|
||||
rel (has|eq|lt|le|gt|ge) 'has'
|
||||
version CDATA #IMPLIED>
|
||||
|
||||
<!ELEMENT provides (#PCDATA)>
|
||||
<!ATTLIST provides
|
||||
type (ext|prog|class|function|feature|api) #REQUIRED
|
||||
name CDATA #REQUIRED>
|
||||
|
||||
<!ELEMENT script (#PCDATA)>
|
||||
<!ATTLIST script
|
||||
phase (pre-install |post-install |
|
||||
pre-uninstall|post-uninstall|
|
||||
pre-build |post-build |
|
||||
pre-setup |post-setup ) #REQUIRED>
|
||||
|
||||
<!ELEMENT configureoptions (configureoption*)>
|
||||
|
||||
<!ELEMENT configureoption EMPTY>
|
||||
<!ATTLIST configureoption
|
||||
name CDATA #REQUIRED
|
||||
default CDATA #IMPLIED
|
||||
prompt CDATA #REQUIRED>
|
||||
Executable
+28
@@ -0,0 +1,28 @@
|
||||
@ECHO OFF
|
||||
|
||||
REM ----------------------------------------------------------------------
|
||||
REM PHP version 4.0
|
||||
REM ----------------------------------------------------------------------
|
||||
REM Copyright (c) 1997-2002 The PHP Group
|
||||
REM ----------------------------------------------------------------------
|
||||
REM This source file is subject to version 2.02 of the PHP license,
|
||||
REM that is bundled with this package in the file LICENSE, and is
|
||||
REM available at through the world-wide-web at
|
||||
REM http://www.php.net/license/2_02.txt.
|
||||
REM If you did not receive a copy of the PHP license and are unable to
|
||||
REM obtain it through the world-wide-web, please send a note to
|
||||
REM license@php.net so we can mail you a copy immediately.
|
||||
REM ----------------------------------------------------------------------
|
||||
REM Authors: Alexander Merz (alexmerz@php.net)
|
||||
REM ----------------------------------------------------------------------
|
||||
REM
|
||||
REM $Id: pear.bat,v 1.9 2002/07/26 10:48:20 cox Exp $
|
||||
|
||||
REM change this lines to match the paths of your system
|
||||
REM -------------------
|
||||
|
||||
set PHP_BIN=c:\php\php.exe
|
||||
set PEAR_PATH=c:\php\pear
|
||||
|
||||
%PHP_BIN% -C -d output_buffer=0 -d include_path=%PEAR_PATH% -f %PEAR_PATH%\scripts\pear.in -- %1 %2 %3 %4 %5 %6 %7 %8 %9
|
||||
@ECHO ON
|
||||
@@ -0,0 +1,294 @@
|
||||
#!@prefix@/bin/php -Cq
|
||||
<?php // -*- PHP -*-
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.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. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Stig Bakken <ssb@fast.no> |
|
||||
// | Tomas V.V.Cox <cox@idecnet.com> |
|
||||
// | |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id$
|
||||
|
||||
/**
|
||||
* @nodep Gtk
|
||||
*/
|
||||
if ('@include_path@' != '@'.'include_path'.'@') {
|
||||
ini_set('include_path', '@include_path@');
|
||||
}
|
||||
ini_set('allow_url_fopen', true);
|
||||
set_time_limit(0);
|
||||
ob_implicit_flush(true);
|
||||
ini_set('track_errors', true);
|
||||
ini_set('html_errors', false);
|
||||
ini_set('magic_quotes_runtime', false);
|
||||
error_reporting(E_ALL & ~E_NOTICE);
|
||||
set_error_handler('error_handler');
|
||||
|
||||
$pear_package_version = "@pear_version@";
|
||||
|
||||
require_once 'PEAR.php';
|
||||
require_once 'PEAR/Config.php';
|
||||
require_once 'PEAR/Command.php';
|
||||
require_once 'Console/Getopt.php';
|
||||
|
||||
PEAR_Command::setFrontendType('CLI');
|
||||
$all_commands = PEAR_Command::getCommands();
|
||||
|
||||
$argv = Console_Getopt::readPHPArgv();
|
||||
$progname = basename($argv[0]);
|
||||
$options = Console_Getopt::getopt($argv, "c:C:d:D:Gh?sSqu:vV");
|
||||
if (PEAR::isError($options)) {
|
||||
usage($options);
|
||||
}
|
||||
|
||||
$opts = $options[0];
|
||||
|
||||
$fetype = 'CLI';
|
||||
if ($progname == 'gpear' || $progname == 'pear-gtk') {
|
||||
$fetype = 'Gtk';
|
||||
} else {
|
||||
foreach ($opts as $opt) {
|
||||
if ($opt[0] == 'G') {
|
||||
$fetype = 'Gtk';
|
||||
}
|
||||
}
|
||||
}
|
||||
PEAR_Command::setFrontendType($fetype);
|
||||
$ui = &PEAR_Command::getFrontendObject();
|
||||
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($ui, "displayFatalError"));
|
||||
|
||||
$pear_user_config = '';
|
||||
$pear_system_config = '';
|
||||
$store_user_config = false;
|
||||
$store_system_config = false;
|
||||
$verbose = 1;
|
||||
|
||||
foreach ($opts as $opt) {
|
||||
switch ($opt[0]) {
|
||||
case 'c':
|
||||
$pear_user_config = $opt[1];
|
||||
break;
|
||||
case 'C':
|
||||
$pear_system_config = $opt[1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$config = &PEAR_Config::singleton($pear_user_config, $pear_system_config);
|
||||
$verbose = $config->get("verbose");
|
||||
$cmdopts = array();
|
||||
|
||||
foreach ($opts as $opt) {
|
||||
$param = !empty($opt[1]) ? $opt[1] : true;
|
||||
switch ($opt[0]) {
|
||||
case 'd':
|
||||
list($key, $value) = explode('=', $param);
|
||||
$config->set($key, $value, 'user');
|
||||
break;
|
||||
case 'D':
|
||||
list($key, $value) = explode('=', $param);
|
||||
$config->set($key, $value, 'system');
|
||||
break;
|
||||
case 's':
|
||||
$store_user_config = true;
|
||||
break;
|
||||
case 'S':
|
||||
$store_system_config = true;
|
||||
break;
|
||||
case 'u':
|
||||
$config->remove($param, 'user');
|
||||
break;
|
||||
case 'v':
|
||||
$config->set('verbose', $config->get('verbose') + 1);
|
||||
break;
|
||||
case 'q':
|
||||
$config->set('verbose', $config->get('verbose') - 1);
|
||||
break;
|
||||
case 'V':
|
||||
usage(null, 'version');
|
||||
default:
|
||||
// all non pear params goes to the command
|
||||
$cmdopts[$opt[0]] = $param;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($store_system_config) {
|
||||
$config->store('system');
|
||||
}
|
||||
|
||||
if ($store_user_config) {
|
||||
$config->store('user');
|
||||
}
|
||||
|
||||
$command = (isset($options[1][0])) ? $options[1][0] : null;
|
||||
|
||||
if (empty($command) && ($store_user_config || $store_system_config)) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($fetype == 'Gtk') {
|
||||
Gtk::main();
|
||||
} else do {
|
||||
if ($command == 'help') {
|
||||
usage(null, @$options[1][1]);
|
||||
}
|
||||
|
||||
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
|
||||
$cmd = PEAR_Command::factory($command, $config);
|
||||
PEAR::popErrorHandling();
|
||||
if (PEAR::isError($cmd)) {
|
||||
usage(null, @$options[1][1]);
|
||||
}
|
||||
|
||||
$short_args = $long_args = null;
|
||||
PEAR_Command::getGetoptArgs($command, $short_args, $long_args);
|
||||
if (PEAR::isError($tmp = Console_Getopt::getopt($options[1], $short_args, $long_args))) {
|
||||
break;
|
||||
}
|
||||
list($tmpopt, $params) = $tmp;
|
||||
$opts = array();
|
||||
foreach ($tmpopt as $foo => $tmp2) {
|
||||
list($opt, $value) = $tmp2;
|
||||
if ($value === null) {
|
||||
$value = true; // options without args
|
||||
}
|
||||
if (strlen($opt) == 1) {
|
||||
$cmdoptions = $cmd->getOptions($command);
|
||||
foreach ($cmdoptions as $o => $d) {
|
||||
if (@$d['shortopt'] == $opt) {
|
||||
$opts[$o] = $value;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (substr($opt, 0, 2) == '--') {
|
||||
$opts[substr($opt, 2)] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
$ok = $cmd->run($command, $opts, $params);
|
||||
if ($ok === false) {
|
||||
PEAR::raiseError("unknown command `$command'");
|
||||
}
|
||||
} while (false);
|
||||
|
||||
// {{{ usage()
|
||||
|
||||
function usage($error = null, $helpsubject = null)
|
||||
{
|
||||
global $progname, $all_commands;
|
||||
$stderr = fopen('php://stderr', 'w');
|
||||
if (PEAR::isError($error)) {
|
||||
fputs($stderr, $error->getMessage() . "\n");
|
||||
} elseif ($error !== null) {
|
||||
fputs($stderr, "$error\n");
|
||||
}
|
||||
if ($helpsubject != null) {
|
||||
$put = cmdHelp($helpsubject);
|
||||
} else {
|
||||
$put =
|
||||
"Usage: $progname [options] command [command-options] <parameters>\n".
|
||||
"Type \"$progname help options\" to list all options.\n".
|
||||
"Type \"$progname help <command>\" to get the help for the specified command.\n".
|
||||
"Commands:\n";
|
||||
$maxlen = max(array_map("strlen", $all_commands));
|
||||
$formatstr = "%-{$maxlen}s %s\n";
|
||||
ksort($all_commands);
|
||||
foreach ($all_commands as $cmd => $class) {
|
||||
$put .= sprintf($formatstr, $cmd, PEAR_Command::getDescription($cmd));
|
||||
}
|
||||
}
|
||||
fputs($stderr, "$put\n");
|
||||
fclose($stderr);
|
||||
exit;
|
||||
}
|
||||
|
||||
function cmdHelp($command)
|
||||
{
|
||||
global $progname, $all_commands, $config;
|
||||
if ($command == "options") {
|
||||
return
|
||||
"Options:\n".
|
||||
" -v increase verbosity level (default 1)\n".
|
||||
" -q be quiet, decrease verbosity level\n".
|
||||
" -c file find user configuration in `file'\n".
|
||||
" -C file find system configuration in `file'\n".
|
||||
" -d foo=bar set user config variable `foo' to `bar'\n".
|
||||
" -D foo=bar set system config variable `foo' to `bar'\n".
|
||||
" -G start in graphical (Gtk) mode\n".
|
||||
" -s store user configuration\n".
|
||||
" -S store system configuration\n".
|
||||
" -u foo unset `foo' in the user configuration\n".
|
||||
" -h, -? display help/usage (this message)\n".
|
||||
" -V version information\n";
|
||||
} elseif ($command == "shortcuts") {
|
||||
$sc = PEAR_Command::getShortcuts();
|
||||
$ret = "Shortcuts:\n";
|
||||
foreach ($sc as $s => $c) {
|
||||
$ret .= sprintf(" %-8s %s\n", $s, $c);
|
||||
}
|
||||
return $ret;
|
||||
|
||||
} elseif ($command == "version") {
|
||||
return "PEAR Version: ".$GLOBALS['pear_package_version']."\nPHP Version: ".phpversion()."\nZend Engine Version: ".zend_version();
|
||||
|
||||
} elseif ($help = PEAR_Command::getHelp($command)) {
|
||||
if (is_string($help)) {
|
||||
return "$progname $command [options] $help\n";
|
||||
}
|
||||
if ($help[1] === null) {
|
||||
return "$progname $command $help[0]";
|
||||
} else {
|
||||
return "$progname $command [options] $help[0]\n$help[1]";
|
||||
}
|
||||
}
|
||||
return "No such command";
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
function error_handler($errno, $errmsg, $file, $line, $vars) {
|
||||
if (error_reporting() == 0) {
|
||||
return; // @silenced error
|
||||
}
|
||||
$errortype = array (
|
||||
1 => "Error",
|
||||
2 => "Warning",
|
||||
4 => "Parsing Error",
|
||||
8 => "Notice",
|
||||
16 => "Core Error",
|
||||
32 => "Core Warning",
|
||||
64 => "Compile Error",
|
||||
128 => "Compile Warning",
|
||||
256 => "User Error",
|
||||
512 => "User Warning",
|
||||
1024=> "User Notice"
|
||||
);
|
||||
$prefix = $errortype[$errno];
|
||||
$file = basename($file);
|
||||
print "\n$prefix: $errmsg in $file on line $line\n";
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* indent-tabs-mode: nil
|
||||
* End:
|
||||
*/
|
||||
// vim600:syn=php
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,43 @@
|
||||
Summary: PEAR: @summary@
|
||||
Name: @rpm_package@
|
||||
Version: @version@
|
||||
Release: 1
|
||||
License: @release_license@
|
||||
Group: Development/Libraries
|
||||
Source: http://pear.php.net/get/@package@-%{version}.tgz
|
||||
BuildRoot: %{_tmppath}/%{name}-root
|
||||
URL: http://pear.php.net/
|
||||
Prefix: %{_prefix}
|
||||
Docdir: %{_docdir}
|
||||
@extra_headers@
|
||||
|
||||
%description
|
||||
@description@
|
||||
|
||||
%prep
|
||||
#rm -rf Console_Getopt-%{version} package.xml
|
||||
#mkdir -p Console_Getopt-%{version}
|
||||
#ln -s Console_Getopt-%{version}/package.xml package.xml
|
||||
%setup -q -D -n @package@-%{version}
|
||||
mv ../package.xml .
|
||||
|
||||
%build
|
||||
echo BuildRoot=%{buildroot}
|
||||
|
||||
%post
|
||||
pear uninstall --nodeps -r @package@
|
||||
|
||||
%postun
|
||||
pear install --nodeps -r @rpm_xml_dir@/@package@.xml
|
||||
|
||||
%install
|
||||
rm -rf %{buildroot}/*
|
||||
pear -q install -R %{buildroot} -n package.xml
|
||||
mkdir -p %{buildroot}@rpm_xml_dir@
|
||||
cp -p package.xml %{buildroot}@rpm_xml_dir@/@package@.xml
|
||||
|
||||
%files
|
||||
%defattr(-,root,root)
|
||||
%doc @doc_files@
|
||||
@files@
|
||||
@rpm_xml_dir@/@package@.xml
|
||||
Reference in new issue
Block a user