Revert "remove the 3rdparty files. everything is now in https://gitorious.org/owncloud/3rdparty"

This reverts commit dccdeca258.
This commit is contained in:
Robin Appelman 2012-02-16 09:44:49 +01:00
parent 19827b8b35
commit 20553c1afe
419 changed files with 123978 additions and 2 deletions

251
3rdparty/Console/Getopt.php vendored Normal file
View File

@ -0,0 +1,251 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | PHP Version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2003 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: Andrei Zmievski <andrei@php.net> |
// +----------------------------------------------------------------------+
//
// $Id: Getopt.php,v 1.21.4.7 2003/12/05 21:57:01 andrei Exp $
require_once( 'PEAR.php');
/**
* Command-line options parsing class.
*
* @author Andrei Zmievski <andrei@php.net>
*
*/
class Console_Getopt {
/**
* Parses the command-line options.
*
* The first parameter to this function should be the list of command-line
* arguments without the leading reference to the running program.
*
* The second parameter is a string of allowed short options. Each of the
* option letters can be followed by a colon ':' to specify that the option
* requires an argument, or a double colon '::' to specify that the option
* takes an optional argument.
*
* The third argument is an optional array of allowed long options. The
* leading '--' should not be included in the option name. Options that
* require an argument should be followed by '=', and options that take an
* option argument should be followed by '=='.
*
* The return value is an array of two elements: the list of parsed
* options and the list of non-option command-line arguments. Each entry in
* the list of parsed options is a pair of elements - the first one
* specifies the option, and the second one specifies the option argument,
* if there was one.
*
* Long and short options can be mixed.
*
* Most of the semantics of this function are based on GNU getopt_long().
*
* @param array $args an array of command-line arguments
* @param string $short_options specifies the list of allowed short options
* @param array $long_options specifies the list of allowed long options
*
* @return array two-element array containing the list of parsed options and
* the non-option arguments
*
* @access public
*
*/
function getopt2($args, $short_options, $long_options = null)
{
return Console_Getopt::doGetopt(2, $args, $short_options, $long_options);
}
/**
* This function expects $args to start with the script name (POSIX-style).
* Preserved for backwards compatibility.
* @see getopt2()
*/
function getopt($args, $short_options, $long_options = null)
{
return Console_Getopt::doGetopt(1, $args, $short_options, $long_options);
}
/**
* The actual implementation of the argument parsing code.
*/
function doGetopt($version, $args, $short_options, $long_options = null)
{
// in case you pass directly readPHPArgv() as the first arg
if (PEAR::isError($args)) {
return $args;
}
if (empty($args)) {
return array(array(), array());
}
$opts = array();
$non_opts = array();
settype($args, 'array');
if ($long_options) {
sort($long_options);
}
/*
* Preserve backwards compatibility with callers that relied on
* erroneous POSIX fix.
*/
if ($version < 2) {
if (isset($args[0]{0}) && $args[0]{0} != '-') {
array_shift($args);
}
}
reset($args);
while (list($i, $arg) = each($args)) {
/* The special element '--' means explicit end of
options. Treat the rest of the arguments as non-options
and end the loop. */
if ($arg == '--') {
$non_opts = array_merge($non_opts, array_slice($args, $i + 1));
break;
}
if ($arg{0} != '-' || (strlen($arg) > 1 && $arg{1} == '-' && !$long_options)) {
$non_opts = array_merge($non_opts, array_slice($args, $i));
break;
} elseif (strlen($arg) > 1 && $arg{1} == '-') {
$error = Console_Getopt::_parseLongOption(substr($arg, 2), $long_options, $opts, $args);
if (PEAR::isError($error))
return $error;
} else {
$error = Console_Getopt::_parseShortOption(substr($arg, 1), $short_options, $opts, $args);
if (PEAR::isError($error))
return $error;
}
}
return array($opts, $non_opts);
}
/**
* @access private
*
*/
function _parseShortOption($arg, $short_options, &$opts, &$args)
{
for ($i = 0; $i < strlen($arg); $i++) {
$opt = $arg{$i};
$opt_arg = null;
/* Try to find the short option in the specifier string. */
if (($spec = strstr($short_options, $opt)) === false || $arg{$i} == ':')
{
return PEAR::raiseError("Console_Getopt: unrecognized option -- $opt");
}
if (strlen($spec) > 1 && $spec{1} == ':') {
if (strlen($spec) > 2 && $spec{2} == ':') {
if ($i + 1 < strlen($arg)) {
/* Option takes an optional argument. Use the remainder of
the arg string if there is anything left. */
$opts[] = array($opt, substr($arg, $i + 1));
break;
}
} else {
/* Option requires an argument. Use the remainder of the arg
string if there is anything left. */
if ($i + 1 < strlen($arg)) {
$opts[] = array($opt, substr($arg, $i + 1));
break;
} else if (list(, $opt_arg) = each($args))
/* Else use the next argument. */;
else
return PEAR::raiseError("Console_Getopt: option requires an argument -- $opt");
}
}
$opts[] = array($opt, $opt_arg);
}
}
/**
* @access private
*
*/
function _parseLongOption($arg, $long_options, &$opts, &$args)
{
@list($opt, $opt_arg) = explode('=', $arg);
$opt_len = strlen($opt);
for ($i = 0; $i < count($long_options); $i++) {
$long_opt = $long_options[$i];
$opt_start = substr($long_opt, 0, $opt_len);
/* Option doesn't match. Go on to the next one. */
if ($opt_start != $opt)
continue;
$opt_rest = substr($long_opt, $opt_len);
/* Check that the options uniquely matches one of the allowed
options. */
if ($opt_rest != '' && $opt{0} != '=' &&
$i + 1 < count($long_options) &&
$opt == substr($long_options[$i+1], 0, $opt_len)) {
return PEAR::raiseError("Console_Getopt: option --$opt is ambiguous");
}
if (substr($long_opt, -1) == '=') {
if (substr($long_opt, -2) != '==') {
/* Long option requires an argument.
Take the next argument if one wasn't specified. */;
if (!strlen($opt_arg) && !(list(, $opt_arg) = each($args))) {
return PEAR::raiseError("Console_Getopt: option --$opt requires an argument");
}
}
} else if ($opt_arg) {
return PEAR::raiseError("Console_Getopt: option --$opt doesn't allow an argument");
}
$opts[] = array('--' . $opt, $opt_arg);
return;
}
return PEAR::raiseError("Console_Getopt: unrecognized option --$opt");
}
/**
* Safely read the $argv PHP array across different PHP configurations.
* Will take care on register_globals and register_argc_argv ini directives
*
* @access public
* @return mixed the $argv PHP array or PEAR error if not registered
*/
function readPHPArgv()
{
global $argv;
if (!is_array($argv)) {
if (!@is_array($_SERVER['argv'])) {
if (!@is_array($GLOBALS['HTTP_SERVER_VARS']['argv'])) {
return PEAR::raiseError("Console_Getopt: Could not read cmd args (register_argc_argv=Off?)");
}
return $GLOBALS['HTTP_SERVER_VARS']['argv'];
}
return $_SERVER['argv'];
}
return $argv;
}
}
?>

317
3rdparty/Crypt_Blowfish/Blowfish.php vendored Normal file
View File

@ -0,0 +1,317 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Crypt_Blowfish allows for encryption and decryption on the fly using
* the Blowfish algorithm. Crypt_Blowfish does not require the mcrypt
* PHP extension, it uses only PHP.
* Crypt_Blowfish support encryption/decryption with or without a secret key.
*
*
* PHP versions 4 and 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
*
* @category Encryption
* @package Crypt_Blowfish
* @author Matthew Fonda <mfonda@php.net>
* @copyright 2005 Matthew Fonda
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id: Blowfish.php,v 1.81 2005/05/30 18:40:36 mfonda Exp $
* @link http://pear.php.net/package/Crypt_Blowfish
*/
require_once 'PEAR.php';
/**
*
* Example usage:
* $bf = new Crypt_Blowfish('some secret key!');
* $encrypted = $bf->encrypt('this is some example plain text');
* $plaintext = $bf->decrypt($encrypted);
* echo "plain text: $plaintext";
*
*
* @category Encryption
* @package Crypt_Blowfish
* @author Matthew Fonda <mfonda@php.net>
* @copyright 2005 Matthew Fonda
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @link http://pear.php.net/package/Crypt_Blowfish
* @version @package_version@
* @access public
*/
class Crypt_Blowfish
{
/**
* P-Array contains 18 32-bit subkeys
*
* @var array
* @access private
*/
var $_P = array();
/**
* Array of four S-Blocks each containing 256 32-bit entries
*
* @var array
* @access private
*/
var $_S = array();
/**
* Mcrypt td resource
*
* @var resource
* @access private
*/
var $_td = null;
/**
* Initialization vector
*
* @var string
* @access private
*/
var $_iv = null;
/**
* Crypt_Blowfish Constructor
* Initializes the Crypt_Blowfish object, and gives a sets
* the secret key
*
* @param string $key
* @access public
*/
function Crypt_Blowfish($key)
{
if (extension_loaded('mcrypt')) {
$this->_td = mcrypt_module_open(MCRYPT_BLOWFISH, '', 'ecb', '');
$this->_iv = mcrypt_create_iv(8, MCRYPT_RAND);
}
$this->setKey($key);
}
/**
* Deprecated isReady method
*
* @return bool
* @access public
* @deprecated
*/
function isReady()
{
return true;
}
/**
* Deprecated init method - init is now a private
* method and has been replaced with _init
*
* @return bool
* @access public
* @deprecated
* @see Crypt_Blowfish::_init()
*/
function init()
{
$this->_init();
}
/**
* Initializes the Crypt_Blowfish object
*
* @access private
*/
function _init()
{
$defaults = new Crypt_Blowfish_DefaultKey();
$this->_P = $defaults->P;
$this->_S = $defaults->S;
}
/**
* Enciphers a single 64 bit block
*
* @param int &$Xl
* @param int &$Xr
* @access private
*/
function _encipher(&$Xl, &$Xr)
{
for ($i = 0; $i < 16; $i++) {
$temp = $Xl ^ $this->_P[$i];
$Xl = ((($this->_S[0][($temp>>24) & 255] +
$this->_S[1][($temp>>16) & 255]) ^
$this->_S[2][($temp>>8) & 255]) +
$this->_S[3][$temp & 255]) ^ $Xr;
$Xr = $temp;
}
$Xr = $Xl ^ $this->_P[16];
$Xl = $temp ^ $this->_P[17];
}
/**
* Deciphers a single 64 bit block
*
* @param int &$Xl
* @param int &$Xr
* @access private
*/
function _decipher(&$Xl, &$Xr)
{
for ($i = 17; $i > 1; $i--) {
$temp = $Xl ^ $this->_P[$i];
$Xl = ((($this->_S[0][($temp>>24) & 255] +
$this->_S[1][($temp>>16) & 255]) ^
$this->_S[2][($temp>>8) & 255]) +
$this->_S[3][$temp & 255]) ^ $Xr;
$Xr = $temp;
}
$Xr = $Xl ^ $this->_P[1];
$Xl = $temp ^ $this->_P[0];
}
/**
* Encrypts a string
*
* @param string $plainText
* @return string Returns cipher text on success, PEAR_Error on failure
* @access public
*/
function encrypt($plainText)
{
if (!is_string($plainText)) {
PEAR::raiseError('Plain text must be a string', 0, PEAR_ERROR_DIE);
}
if (extension_loaded('mcrypt')) {
return mcrypt_generic($this->_td, $plainText);
}
$cipherText = '';
$len = strlen($plainText);
$plainText .= str_repeat(chr(0),(8 - ($len%8))%8);
for ($i = 0; $i < $len; $i += 8) {
list(,$Xl,$Xr) = unpack("N2",substr($plainText,$i,8));
$this->_encipher($Xl, $Xr);
$cipherText .= pack("N2", $Xl, $Xr);
}
return $cipherText;
}
/**
* Decrypts an encrypted string
*
* @param string $cipherText
* @return string Returns plain text on success, PEAR_Error on failure
* @access public
*/
function decrypt($cipherText)
{
if (!is_string($cipherText)) {
PEAR::raiseError('Chiper text must be a string', 1, PEAR_ERROR_DIE);
}
if (extension_loaded('mcrypt')) {
return mdecrypt_generic($this->_td, $cipherText);
}
$plainText = '';
$len = strlen($cipherText);
$cipherText .= str_repeat(chr(0),(8 - ($len%8))%8);
for ($i = 0; $i < $len; $i += 8) {
list(,$Xl,$Xr) = unpack("N2",substr($cipherText,$i,8));
$this->_decipher($Xl, $Xr);
$plainText .= pack("N2", $Xl, $Xr);
}
return $plainText;
}
/**
* Sets the secret key
* The key must be non-zero, and less than or equal to
* 56 characters in length.
*
* @param string $key
* @return bool Returns true on success, PEAR_Error on failure
* @access public
*/
function setKey($key)
{
if (!is_string($key)) {
PEAR::raiseError('Key must be a string', 2, PEAR_ERROR_DIE);
}
$len = strlen($key);
if ($len > 56 || $len == 0) {
PEAR::raiseError('Key must be less than 56 characters and non-zero. Supplied key length: ' . $len, 3, PEAR_ERROR_DIE);
}
if (extension_loaded('mcrypt')) {
mcrypt_generic_init($this->_td, $key, $this->_iv);
return true;
}
require_once 'Blowfish/DefaultKey.php';
$this->_init();
$k = 0;
$data = 0;
$datal = 0;
$datar = 0;
for ($i = 0; $i < 18; $i++) {
$data = 0;
for ($j = 4; $j > 0; $j--) {
$data = $data << 8 | ord($key{$k});
$k = ($k+1) % $len;
}
$this->_P[$i] ^= $data;
}
for ($i = 0; $i <= 16; $i += 2) {
$this->_encipher($datal, $datar);
$this->_P[$i] = $datal;
$this->_P[$i+1] = $datar;
}
for ($i = 0; $i < 256; $i += 2) {
$this->_encipher($datal, $datar);
$this->_S[0][$i] = $datal;
$this->_S[0][$i+1] = $datar;
}
for ($i = 0; $i < 256; $i += 2) {
$this->_encipher($datal, $datar);
$this->_S[1][$i] = $datal;
$this->_S[1][$i+1] = $datar;
}
for ($i = 0; $i < 256; $i += 2) {
$this->_encipher($datal, $datar);
$this->_S[2][$i] = $datal;
$this->_S[2][$i+1] = $datar;
}
for ($i = 0; $i < 256; $i += 2) {
$this->_encipher($datal, $datar);
$this->_S[3][$i] = $datal;
$this->_S[3][$i+1] = $datar;
}
return true;
}
}
?>

View File

@ -0,0 +1,327 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Crypt_Blowfish allows for encryption and decryption on the fly using
* the Blowfish algorithm. Crypt_Blowfish does not require the mcrypt
* PHP extension, it uses only PHP.
* Crypt_Blowfish support encryption/decryption with or without a secret key.
*
*
* PHP versions 4 and 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
*
* @category Encryption
* @package Crypt_Blowfish
* @author Matthew Fonda <mfonda@php.net>
* @copyright 2005 Matthew Fonda
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id: DefaultKey.php,v 1.81 2005/05/30 18:40:37 mfonda Exp $
* @link http://pear.php.net/package/Crypt_Blowfish
*/
/**
* Class containing default key
*
* @category Encryption
* @package Crypt_Blowfish
* @author Matthew Fonda <mfonda@php.net>
* @copyright 2005 Matthew Fonda
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @link http://pear.php.net/package/Crypt_Blowfish
* @version @package_version@
* @access public
*/
class Crypt_Blowfish_DefaultKey
{
var $P = array();
var $S = array();
function Crypt_Blowfish_DefaultKey()
{
$this->P = array(
0x243F6A88, 0x85A308D3, 0x13198A2E, 0x03707344,
0xA4093822, 0x299F31D0, 0x082EFA98, 0xEC4E6C89,
0x452821E6, 0x38D01377, 0xBE5466CF, 0x34E90C6C,
0xC0AC29B7, 0xC97C50DD, 0x3F84D5B5, 0xB5470917,
0x9216D5D9, 0x8979FB1B
);
$this->S = array(
array(
0xD1310BA6, 0x98DFB5AC, 0x2FFD72DB, 0xD01ADFB7,
0xB8E1AFED, 0x6A267E96, 0xBA7C9045, 0xF12C7F99,
0x24A19947, 0xB3916CF7, 0x0801F2E2, 0x858EFC16,
0x636920D8, 0x71574E69, 0xA458FEA3, 0xF4933D7E,
0x0D95748F, 0x728EB658, 0x718BCD58, 0x82154AEE,
0x7B54A41D, 0xC25A59B5, 0x9C30D539, 0x2AF26013,
0xC5D1B023, 0x286085F0, 0xCA417918, 0xB8DB38EF,
0x8E79DCB0, 0x603A180E, 0x6C9E0E8B, 0xB01E8A3E,
0xD71577C1, 0xBD314B27, 0x78AF2FDA, 0x55605C60,
0xE65525F3, 0xAA55AB94, 0x57489862, 0x63E81440,
0x55CA396A, 0x2AAB10B6, 0xB4CC5C34, 0x1141E8CE,
0xA15486AF, 0x7C72E993, 0xB3EE1411, 0x636FBC2A,
0x2BA9C55D, 0x741831F6, 0xCE5C3E16, 0x9B87931E,
0xAFD6BA33, 0x6C24CF5C, 0x7A325381, 0x28958677,
0x3B8F4898, 0x6B4BB9AF, 0xC4BFE81B, 0x66282193,
0x61D809CC, 0xFB21A991, 0x487CAC60, 0x5DEC8032,
0xEF845D5D, 0xE98575B1, 0xDC262302, 0xEB651B88,
0x23893E81, 0xD396ACC5, 0x0F6D6FF3, 0x83F44239,
0x2E0B4482, 0xA4842004, 0x69C8F04A, 0x9E1F9B5E,
0x21C66842, 0xF6E96C9A, 0x670C9C61, 0xABD388F0,
0x6A51A0D2, 0xD8542F68, 0x960FA728, 0xAB5133A3,
0x6EEF0B6C, 0x137A3BE4, 0xBA3BF050, 0x7EFB2A98,
0xA1F1651D, 0x39AF0176, 0x66CA593E, 0x82430E88,
0x8CEE8619, 0x456F9FB4, 0x7D84A5C3, 0x3B8B5EBE,
0xE06F75D8, 0x85C12073, 0x401A449F, 0x56C16AA6,
0x4ED3AA62, 0x363F7706, 0x1BFEDF72, 0x429B023D,
0x37D0D724, 0xD00A1248, 0xDB0FEAD3, 0x49F1C09B,
0x075372C9, 0x80991B7B, 0x25D479D8, 0xF6E8DEF7,
0xE3FE501A, 0xB6794C3B, 0x976CE0BD, 0x04C006BA,
0xC1A94FB6, 0x409F60C4, 0x5E5C9EC2, 0x196A2463,
0x68FB6FAF, 0x3E6C53B5, 0x1339B2EB, 0x3B52EC6F,
0x6DFC511F, 0x9B30952C, 0xCC814544, 0xAF5EBD09,
0xBEE3D004, 0xDE334AFD, 0x660F2807, 0x192E4BB3,
0xC0CBA857, 0x45C8740F, 0xD20B5F39, 0xB9D3FBDB,
0x5579C0BD, 0x1A60320A, 0xD6A100C6, 0x402C7279,
0x679F25FE, 0xFB1FA3CC, 0x8EA5E9F8, 0xDB3222F8,
0x3C7516DF, 0xFD616B15, 0x2F501EC8, 0xAD0552AB,
0x323DB5FA, 0xFD238760, 0x53317B48, 0x3E00DF82,
0x9E5C57BB, 0xCA6F8CA0, 0x1A87562E, 0xDF1769DB,
0xD542A8F6, 0x287EFFC3, 0xAC6732C6, 0x8C4F5573,
0x695B27B0, 0xBBCA58C8, 0xE1FFA35D, 0xB8F011A0,
0x10FA3D98, 0xFD2183B8, 0x4AFCB56C, 0x2DD1D35B,
0x9A53E479, 0xB6F84565, 0xD28E49BC, 0x4BFB9790,
0xE1DDF2DA, 0xA4CB7E33, 0x62FB1341, 0xCEE4C6E8,
0xEF20CADA, 0x36774C01, 0xD07E9EFE, 0x2BF11FB4,
0x95DBDA4D, 0xAE909198, 0xEAAD8E71, 0x6B93D5A0,
0xD08ED1D0, 0xAFC725E0, 0x8E3C5B2F, 0x8E7594B7,
0x8FF6E2FB, 0xF2122B64, 0x8888B812, 0x900DF01C,
0x4FAD5EA0, 0x688FC31C, 0xD1CFF191, 0xB3A8C1AD,
0x2F2F2218, 0xBE0E1777, 0xEA752DFE, 0x8B021FA1,
0xE5A0CC0F, 0xB56F74E8, 0x18ACF3D6, 0xCE89E299,
0xB4A84FE0, 0xFD13E0B7, 0x7CC43B81, 0xD2ADA8D9,
0x165FA266, 0x80957705, 0x93CC7314, 0x211A1477,
0xE6AD2065, 0x77B5FA86, 0xC75442F5, 0xFB9D35CF,
0xEBCDAF0C, 0x7B3E89A0, 0xD6411BD3, 0xAE1E7E49,
0x00250E2D, 0x2071B35E, 0x226800BB, 0x57B8E0AF,
0x2464369B, 0xF009B91E, 0x5563911D, 0x59DFA6AA,
0x78C14389, 0xD95A537F, 0x207D5BA2, 0x02E5B9C5,
0x83260376, 0x6295CFA9, 0x11C81968, 0x4E734A41,
0xB3472DCA, 0x7B14A94A, 0x1B510052, 0x9A532915,
0xD60F573F, 0xBC9BC6E4, 0x2B60A476, 0x81E67400,
0x08BA6FB5, 0x571BE91F, 0xF296EC6B, 0x2A0DD915,
0xB6636521, 0xE7B9F9B6, 0xFF34052E, 0xC5855664,
0x53B02D5D, 0xA99F8FA1, 0x08BA4799, 0x6E85076A
),
array(
0x4B7A70E9, 0xB5B32944, 0xDB75092E, 0xC4192623,
0xAD6EA6B0, 0x49A7DF7D, 0x9CEE60B8, 0x8FEDB266,
0xECAA8C71, 0x699A17FF, 0x5664526C, 0xC2B19EE1,
0x193602A5, 0x75094C29, 0xA0591340, 0xE4183A3E,
0x3F54989A, 0x5B429D65, 0x6B8FE4D6, 0x99F73FD6,
0xA1D29C07, 0xEFE830F5, 0x4D2D38E6, 0xF0255DC1,
0x4CDD2086, 0x8470EB26, 0x6382E9C6, 0x021ECC5E,
0x09686B3F, 0x3EBAEFC9, 0x3C971814, 0x6B6A70A1,
0x687F3584, 0x52A0E286, 0xB79C5305, 0xAA500737,
0x3E07841C, 0x7FDEAE5C, 0x8E7D44EC, 0x5716F2B8,
0xB03ADA37, 0xF0500C0D, 0xF01C1F04, 0x0200B3FF,
0xAE0CF51A, 0x3CB574B2, 0x25837A58, 0xDC0921BD,
0xD19113F9, 0x7CA92FF6, 0x94324773, 0x22F54701,
0x3AE5E581, 0x37C2DADC, 0xC8B57634, 0x9AF3DDA7,
0xA9446146, 0x0FD0030E, 0xECC8C73E, 0xA4751E41,
0xE238CD99, 0x3BEA0E2F, 0x3280BBA1, 0x183EB331,
0x4E548B38, 0x4F6DB908, 0x6F420D03, 0xF60A04BF,
0x2CB81290, 0x24977C79, 0x5679B072, 0xBCAF89AF,
0xDE9A771F, 0xD9930810, 0xB38BAE12, 0xDCCF3F2E,
0x5512721F, 0x2E6B7124, 0x501ADDE6, 0x9F84CD87,
0x7A584718, 0x7408DA17, 0xBC9F9ABC, 0xE94B7D8C,
0xEC7AEC3A, 0xDB851DFA, 0x63094366, 0xC464C3D2,
0xEF1C1847, 0x3215D908, 0xDD433B37, 0x24C2BA16,
0x12A14D43, 0x2A65C451, 0x50940002, 0x133AE4DD,
0x71DFF89E, 0x10314E55, 0x81AC77D6, 0x5F11199B,
0x043556F1, 0xD7A3C76B, 0x3C11183B, 0x5924A509,
0xF28FE6ED, 0x97F1FBFA, 0x9EBABF2C, 0x1E153C6E,
0x86E34570, 0xEAE96FB1, 0x860E5E0A, 0x5A3E2AB3,
0x771FE71C, 0x4E3D06FA, 0x2965DCB9, 0x99E71D0F,
0x803E89D6, 0x5266C825, 0x2E4CC978, 0x9C10B36A,
0xC6150EBA, 0x94E2EA78, 0xA5FC3C53, 0x1E0A2DF4,
0xF2F74EA7, 0x361D2B3D, 0x1939260F, 0x19C27960,
0x5223A708, 0xF71312B6, 0xEBADFE6E, 0xEAC31F66,
0xE3BC4595, 0xA67BC883, 0xB17F37D1, 0x018CFF28,
0xC332DDEF, 0xBE6C5AA5, 0x65582185, 0x68AB9802,
0xEECEA50F, 0xDB2F953B, 0x2AEF7DAD, 0x5B6E2F84,
0x1521B628, 0x29076170, 0xECDD4775, 0x619F1510,
0x13CCA830, 0xEB61BD96, 0x0334FE1E, 0xAA0363CF,
0xB5735C90, 0x4C70A239, 0xD59E9E0B, 0xCBAADE14,
0xEECC86BC, 0x60622CA7, 0x9CAB5CAB, 0xB2F3846E,
0x648B1EAF, 0x19BDF0CA, 0xA02369B9, 0x655ABB50,
0x40685A32, 0x3C2AB4B3, 0x319EE9D5, 0xC021B8F7,
0x9B540B19, 0x875FA099, 0x95F7997E, 0x623D7DA8,
0xF837889A, 0x97E32D77, 0x11ED935F, 0x16681281,
0x0E358829, 0xC7E61FD6, 0x96DEDFA1, 0x7858BA99,
0x57F584A5, 0x1B227263, 0x9B83C3FF, 0x1AC24696,
0xCDB30AEB, 0x532E3054, 0x8FD948E4, 0x6DBC3128,
0x58EBF2EF, 0x34C6FFEA, 0xFE28ED61, 0xEE7C3C73,
0x5D4A14D9, 0xE864B7E3, 0x42105D14, 0x203E13E0,
0x45EEE2B6, 0xA3AAABEA, 0xDB6C4F15, 0xFACB4FD0,
0xC742F442, 0xEF6ABBB5, 0x654F3B1D, 0x41CD2105,
0xD81E799E, 0x86854DC7, 0xE44B476A, 0x3D816250,
0xCF62A1F2, 0x5B8D2646, 0xFC8883A0, 0xC1C7B6A3,
0x7F1524C3, 0x69CB7492, 0x47848A0B, 0x5692B285,
0x095BBF00, 0xAD19489D, 0x1462B174, 0x23820E00,
0x58428D2A, 0x0C55F5EA, 0x1DADF43E, 0x233F7061,
0x3372F092, 0x8D937E41, 0xD65FECF1, 0x6C223BDB,
0x7CDE3759, 0xCBEE7460, 0x4085F2A7, 0xCE77326E,
0xA6078084, 0x19F8509E, 0xE8EFD855, 0x61D99735,
0xA969A7AA, 0xC50C06C2, 0x5A04ABFC, 0x800BCADC,
0x9E447A2E, 0xC3453484, 0xFDD56705, 0x0E1E9EC9,
0xDB73DBD3, 0x105588CD, 0x675FDA79, 0xE3674340,
0xC5C43465, 0x713E38D8, 0x3D28F89E, 0xF16DFF20,
0x153E21E7, 0x8FB03D4A, 0xE6E39F2B, 0xDB83ADF7
),
array(
0xE93D5A68, 0x948140F7, 0xF64C261C, 0x94692934,
0x411520F7, 0x7602D4F7, 0xBCF46B2E, 0xD4A20068,
0xD4082471, 0x3320F46A, 0x43B7D4B7, 0x500061AF,
0x1E39F62E, 0x97244546, 0x14214F74, 0xBF8B8840,
0x4D95FC1D, 0x96B591AF, 0x70F4DDD3, 0x66A02F45,
0xBFBC09EC, 0x03BD9785, 0x7FAC6DD0, 0x31CB8504,
0x96EB27B3, 0x55FD3941, 0xDA2547E6, 0xABCA0A9A,
0x28507825, 0x530429F4, 0x0A2C86DA, 0xE9B66DFB,
0x68DC1462, 0xD7486900, 0x680EC0A4, 0x27A18DEE,
0x4F3FFEA2, 0xE887AD8C, 0xB58CE006, 0x7AF4D6B6,
0xAACE1E7C, 0xD3375FEC, 0xCE78A399, 0x406B2A42,
0x20FE9E35, 0xD9F385B9, 0xEE39D7AB, 0x3B124E8B,
0x1DC9FAF7, 0x4B6D1856, 0x26A36631, 0xEAE397B2,
0x3A6EFA74, 0xDD5B4332, 0x6841E7F7, 0xCA7820FB,
0xFB0AF54E, 0xD8FEB397, 0x454056AC, 0xBA489527,
0x55533A3A, 0x20838D87, 0xFE6BA9B7, 0xD096954B,
0x55A867BC, 0xA1159A58, 0xCCA92963, 0x99E1DB33,
0xA62A4A56, 0x3F3125F9, 0x5EF47E1C, 0x9029317C,
0xFDF8E802, 0x04272F70, 0x80BB155C, 0x05282CE3,
0x95C11548, 0xE4C66D22, 0x48C1133F, 0xC70F86DC,
0x07F9C9EE, 0x41041F0F, 0x404779A4, 0x5D886E17,
0x325F51EB, 0xD59BC0D1, 0xF2BCC18F, 0x41113564,
0x257B7834, 0x602A9C60, 0xDFF8E8A3, 0x1F636C1B,
0x0E12B4C2, 0x02E1329E, 0xAF664FD1, 0xCAD18115,
0x6B2395E0, 0x333E92E1, 0x3B240B62, 0xEEBEB922,
0x85B2A20E, 0xE6BA0D99, 0xDE720C8C, 0x2DA2F728,
0xD0127845, 0x95B794FD, 0x647D0862, 0xE7CCF5F0,
0x5449A36F, 0x877D48FA, 0xC39DFD27, 0xF33E8D1E,
0x0A476341, 0x992EFF74, 0x3A6F6EAB, 0xF4F8FD37,
0xA812DC60, 0xA1EBDDF8, 0x991BE14C, 0xDB6E6B0D,
0xC67B5510, 0x6D672C37, 0x2765D43B, 0xDCD0E804,
0xF1290DC7, 0xCC00FFA3, 0xB5390F92, 0x690FED0B,
0x667B9FFB, 0xCEDB7D9C, 0xA091CF0B, 0xD9155EA3,
0xBB132F88, 0x515BAD24, 0x7B9479BF, 0x763BD6EB,
0x37392EB3, 0xCC115979, 0x8026E297, 0xF42E312D,
0x6842ADA7, 0xC66A2B3B, 0x12754CCC, 0x782EF11C,
0x6A124237, 0xB79251E7, 0x06A1BBE6, 0x4BFB6350,
0x1A6B1018, 0x11CAEDFA, 0x3D25BDD8, 0xE2E1C3C9,
0x44421659, 0x0A121386, 0xD90CEC6E, 0xD5ABEA2A,
0x64AF674E, 0xDA86A85F, 0xBEBFE988, 0x64E4C3FE,
0x9DBC8057, 0xF0F7C086, 0x60787BF8, 0x6003604D,
0xD1FD8346, 0xF6381FB0, 0x7745AE04, 0xD736FCCC,
0x83426B33, 0xF01EAB71, 0xB0804187, 0x3C005E5F,
0x77A057BE, 0xBDE8AE24, 0x55464299, 0xBF582E61,
0x4E58F48F, 0xF2DDFDA2, 0xF474EF38, 0x8789BDC2,
0x5366F9C3, 0xC8B38E74, 0xB475F255, 0x46FCD9B9,
0x7AEB2661, 0x8B1DDF84, 0x846A0E79, 0x915F95E2,
0x466E598E, 0x20B45770, 0x8CD55591, 0xC902DE4C,
0xB90BACE1, 0xBB8205D0, 0x11A86248, 0x7574A99E,
0xB77F19B6, 0xE0A9DC09, 0x662D09A1, 0xC4324633,
0xE85A1F02, 0x09F0BE8C, 0x4A99A025, 0x1D6EFE10,
0x1AB93D1D, 0x0BA5A4DF, 0xA186F20F, 0x2868F169,
0xDCB7DA83, 0x573906FE, 0xA1E2CE9B, 0x4FCD7F52,
0x50115E01, 0xA70683FA, 0xA002B5C4, 0x0DE6D027,
0x9AF88C27, 0x773F8641, 0xC3604C06, 0x61A806B5,
0xF0177A28, 0xC0F586E0, 0x006058AA, 0x30DC7D62,
0x11E69ED7, 0x2338EA63, 0x53C2DD94, 0xC2C21634,
0xBBCBEE56, 0x90BCB6DE, 0xEBFC7DA1, 0xCE591D76,
0x6F05E409, 0x4B7C0188, 0x39720A3D, 0x7C927C24,
0x86E3725F, 0x724D9DB9, 0x1AC15BB4, 0xD39EB8FC,
0xED545578, 0x08FCA5B5, 0xD83D7CD3, 0x4DAD0FC4,
0x1E50EF5E, 0xB161E6F8, 0xA28514D9, 0x6C51133C,
0x6FD5C7E7, 0x56E14EC4, 0x362ABFCE, 0xDDC6C837,
0xD79A3234, 0x92638212, 0x670EFA8E, 0x406000E0
),
array(
0x3A39CE37, 0xD3FAF5CF, 0xABC27737, 0x5AC52D1B,
0x5CB0679E, 0x4FA33742, 0xD3822740, 0x99BC9BBE,
0xD5118E9D, 0xBF0F7315, 0xD62D1C7E, 0xC700C47B,
0xB78C1B6B, 0x21A19045, 0xB26EB1BE, 0x6A366EB4,
0x5748AB2F, 0xBC946E79, 0xC6A376D2, 0x6549C2C8,
0x530FF8EE, 0x468DDE7D, 0xD5730A1D, 0x4CD04DC6,
0x2939BBDB, 0xA9BA4650, 0xAC9526E8, 0xBE5EE304,
0xA1FAD5F0, 0x6A2D519A, 0x63EF8CE2, 0x9A86EE22,
0xC089C2B8, 0x43242EF6, 0xA51E03AA, 0x9CF2D0A4,
0x83C061BA, 0x9BE96A4D, 0x8FE51550, 0xBA645BD6,
0x2826A2F9, 0xA73A3AE1, 0x4BA99586, 0xEF5562E9,
0xC72FEFD3, 0xF752F7DA, 0x3F046F69, 0x77FA0A59,
0x80E4A915, 0x87B08601, 0x9B09E6AD, 0x3B3EE593,
0xE990FD5A, 0x9E34D797, 0x2CF0B7D9, 0x022B8B51,
0x96D5AC3A, 0x017DA67D, 0xD1CF3ED6, 0x7C7D2D28,
0x1F9F25CF, 0xADF2B89B, 0x5AD6B472, 0x5A88F54C,
0xE029AC71, 0xE019A5E6, 0x47B0ACFD, 0xED93FA9B,
0xE8D3C48D, 0x283B57CC, 0xF8D56629, 0x79132E28,
0x785F0191, 0xED756055, 0xF7960E44, 0xE3D35E8C,
0x15056DD4, 0x88F46DBA, 0x03A16125, 0x0564F0BD,
0xC3EB9E15, 0x3C9057A2, 0x97271AEC, 0xA93A072A,
0x1B3F6D9B, 0x1E6321F5, 0xF59C66FB, 0x26DCF319,
0x7533D928, 0xB155FDF5, 0x03563482, 0x8ABA3CBB,
0x28517711, 0xC20AD9F8, 0xABCC5167, 0xCCAD925F,
0x4DE81751, 0x3830DC8E, 0x379D5862, 0x9320F991,
0xEA7A90C2, 0xFB3E7BCE, 0x5121CE64, 0x774FBE32,
0xA8B6E37E, 0xC3293D46, 0x48DE5369, 0x6413E680,
0xA2AE0810, 0xDD6DB224, 0x69852DFD, 0x09072166,
0xB39A460A, 0x6445C0DD, 0x586CDECF, 0x1C20C8AE,
0x5BBEF7DD, 0x1B588D40, 0xCCD2017F, 0x6BB4E3BB,
0xDDA26A7E, 0x3A59FF45, 0x3E350A44, 0xBCB4CDD5,
0x72EACEA8, 0xFA6484BB, 0x8D6612AE, 0xBF3C6F47,
0xD29BE463, 0x542F5D9E, 0xAEC2771B, 0xF64E6370,
0x740E0D8D, 0xE75B1357, 0xF8721671, 0xAF537D5D,
0x4040CB08, 0x4EB4E2CC, 0x34D2466A, 0x0115AF84,
0xE1B00428, 0x95983A1D, 0x06B89FB4, 0xCE6EA048,
0x6F3F3B82, 0x3520AB82, 0x011A1D4B, 0x277227F8,
0x611560B1, 0xE7933FDC, 0xBB3A792B, 0x344525BD,
0xA08839E1, 0x51CE794B, 0x2F32C9B7, 0xA01FBAC9,
0xE01CC87E, 0xBCC7D1F6, 0xCF0111C3, 0xA1E8AAC7,
0x1A908749, 0xD44FBD9A, 0xD0DADECB, 0xD50ADA38,
0x0339C32A, 0xC6913667, 0x8DF9317C, 0xE0B12B4F,
0xF79E59B7, 0x43F5BB3A, 0xF2D519FF, 0x27D9459C,
0xBF97222C, 0x15E6FC2A, 0x0F91FC71, 0x9B941525,
0xFAE59361, 0xCEB69CEB, 0xC2A86459, 0x12BAA8D1,
0xB6C1075E, 0xE3056A0C, 0x10D25065, 0xCB03A442,
0xE0EC6E0E, 0x1698DB3B, 0x4C98A0BE, 0x3278E964,
0x9F1F9532, 0xE0D392DF, 0xD3A0342B, 0x8971F21E,
0x1B0A7441, 0x4BA3348C, 0xC5BE7120, 0xC37632D8,
0xDF359F8D, 0x9B992F2E, 0xE60B6F47, 0x0FE3F11D,
0xE54CDA54, 0x1EDAD891, 0xCE6279CF, 0xCD3E7E6F,
0x1618B166, 0xFD2C1D05, 0x848FD2C5, 0xF6FB2299,
0xF523F357, 0xA6327623, 0x93A83531, 0x56CCCD02,
0xACF08162, 0x5A75EBB5, 0x6E163697, 0x88D273CC,
0xDE966292, 0x81B949D0, 0x4C50901B, 0x71C65614,
0xE6C6C7BD, 0x327A140A, 0x45E1D006, 0xC3F27B9A,
0xC9AA53FD, 0x62A80F00, 0xBB25BFE2, 0x35BDD2F6,
0x71126905, 0xB2040222, 0xB6CBCF7C, 0xCD769C2B,
0x53113EC0, 0x1640E3D3, 0x38ABBD60, 0x2547ADF0,
0xBA38209C, 0xF746CE76, 0x77AFA1C5, 0x20756060,
0x85CBFE4E, 0x8AE88DD8, 0x7AAAF9B0, 0x4CF9AA7E,
0x1948C25C, 0x02FB8A8C, 0x01C36AE4, 0xD6EBE1F9,
0x90D4F869, 0xA65CDEA0, 0x3F09252D, 0xC208E69F,
0xB74E6132, 0xCE77E25B, 0x578FDFE3, 0x3AC372E6
)
);
}
}
?>

4316
3rdparty/MDB2.php vendored Normal file

File diff suppressed because it is too large Load Diff

183
3rdparty/MDB2/Date.php vendored Normal file
View File

@ -0,0 +1,183 @@
<?php
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. |
// | |
// | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions |
// | are met: |
// | |
// | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. |
// | |
// | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. |
// | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior|
// | written permission. |
// | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
// $Id: Date.php,v 1.10 2006/03/01 12:15:32 lsmith Exp $
//
/**
* @package MDB2
* @category Database
* @author Lukas Smith <smith@pooteeweet.org>
*/
/**
* Several methods to convert the MDB2 native timestamp format (ISO based)
* to and from data structures that are convenient to worth with in side of php.
* For more complex date arithmetic please take a look at the Date package in PEAR
*
* @package MDB2
* @category Database
* @author Lukas Smith <smith@pooteeweet.org>
*/
class MDB2_Date
{
// {{{ mdbNow()
/**
* return the current datetime
*
* @return string current datetime in the MDB2 format
* @access public
*/
function mdbNow()
{
return date('Y-m-d H:i:s');
}
// }}}
// {{{ mdbToday()
/**
* return the current date
*
* @return string current date in the MDB2 format
* @access public
*/
function mdbToday()
{
return date('Y-m-d');
}
// }}}
// {{{ mdbTime()
/**
* return the current time
*
* @return string current time in the MDB2 format
* @access public
*/
function mdbTime()
{
return date('H:i:s');
}
// }}}
// {{{ date2Mdbstamp()
/**
* convert a date into a MDB2 timestamp
*
* @param int hour of the date
* @param int minute of the date
* @param int second of the date
* @param int month of the date
* @param int day of the date
* @param int year of the date
*
* @return string a valid MDB2 timestamp
* @access public
*/
function date2Mdbstamp($hour = null, $minute = null, $second = null,
$month = null, $day = null, $year = null)
{
return MDB2_Date::unix2Mdbstamp(mktime($hour, $minute, $second, $month, $day, $year, -1));
}
// }}}
// {{{ unix2Mdbstamp()
/**
* convert a unix timestamp into a MDB2 timestamp
*
* @param int a valid unix timestamp
*
* @return string a valid MDB2 timestamp
* @access public
*/
function unix2Mdbstamp($unix_timestamp)
{
return date('Y-m-d H:i:s', $unix_timestamp);
}
// }}}
// {{{ mdbstamp2Unix()
/**
* convert a MDB2 timestamp into a unix timestamp
*
* @param int a valid MDB2 timestamp
* @return string unix timestamp with the time stored in the MDB2 format
*
* @access public
*/
function mdbstamp2Unix($mdb_timestamp)
{
$arr = MDB2_Date::mdbstamp2Date($mdb_timestamp);
return mktime($arr['hour'], $arr['minute'], $arr['second'], $arr['month'], $arr['day'], $arr['year'], -1);
}
// }}}
// {{{ mdbstamp2Date()
/**
* convert a MDB2 timestamp into an array containing all
* values necessary to pass to php's date() function
*
* @param int a valid MDB2 timestamp
*
* @return array with the time split
* @access public
*/
function mdbstamp2Date($mdb_timestamp)
{
list($arr['year'], $arr['month'], $arr['day'], $arr['hour'], $arr['minute'], $arr['second']) =
sscanf($mdb_timestamp, "%04u-%02u-%02u %02u:%02u:%02u");
return $arr;
}
// }}}
}
?>

1824
3rdparty/MDB2/Driver/Datatype/Common.php vendored Normal file

File diff suppressed because it is too large Load Diff

553
3rdparty/MDB2/Driver/Datatype/mysql.php vendored Normal file
View File

@ -0,0 +1,553 @@
<?php
// vim: set et ts=4 sw=4 fdm=marker:
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2008 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. |
// | |
// | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions |
// | are met: |
// | |
// | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. |
// | |
// | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. |
// | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior|
// | written permission. |
// | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
// $Id: mysql.php,v 1.65 2008/02/22 19:23:49 quipo Exp $
//
require_once('MDB2/Driver/Datatype/Common.php');
/**
* MDB2 MySQL driver
*
* @package MDB2
* @category Database
* @author Lukas Smith <smith@pooteeweet.org>
*/
class MDB2_Driver_Datatype_mysql extends MDB2_Driver_Datatype_Common
{
// {{{ _getCharsetFieldDeclaration()
/**
* Obtain DBMS specific SQL code portion needed to set the CHARACTER SET
* of a field declaration to be used in statements like CREATE TABLE.
*
* @param string $charset name of the charset
* @return string DBMS specific SQL code portion needed to set the CHARACTER SET
* of a field declaration.
*/
function _getCharsetFieldDeclaration($charset)
{
return 'CHARACTER SET '.$charset;
}
// }}}
// {{{ _getCollationFieldDeclaration()
/**
* Obtain DBMS specific SQL code portion needed to set the COLLATION
* of a field declaration to be used in statements like CREATE TABLE.
*
* @param string $collation name of the collation
* @return string DBMS specific SQL code portion needed to set the COLLATION
* of a field declaration.
*/
function _getCollationFieldDeclaration($collation)
{
return 'COLLATE '.$collation;
}
// }}}
// {{{ getTypeDeclaration()
/**
* Obtain DBMS specific SQL code portion needed to declare an text type
* field to be used in statements like CREATE TABLE.
*
* @param array $field associative array with the name of the properties
* of the field being declared as array indexes. Currently, the types
* of supported field properties are as follows:
*
* length
* Integer value that determines the maximum length of the text
* field. If this argument is missing the field should be
* declared to have the longest length allowed by the DBMS.
*
* default
* Text value to be used as default for this field.
*
* notnull
* Boolean flag that indicates whether this field is constrained
* to not be set to null.
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
* @access public
*/
function getTypeDeclaration($field)
{
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
switch ($field['type']) {
case 'text':
if (empty($field['length']) && array_key_exists('default', $field)) {
$field['length'] = $db->varchar_max_length;
}
$length = !empty($field['length']) ? $field['length'] : false;
$fixed = !empty($field['fixed']) ? $field['fixed'] : false;
return $fixed ? ($length ? 'CHAR('.$length.')' : 'CHAR(255)')
: ($length ? 'VARCHAR('.$length.')' : 'TEXT');
case 'clob':
if (!empty($field['length'])) {
$length = $field['length'];
if ($length <= 255) {
return 'TINYTEXT';
} elseif ($length <= 65532) {
return 'TEXT';
} elseif ($length <= 16777215) {
return 'MEDIUMTEXT';
}
}
return 'LONGTEXT';
case 'blob':
if (!empty($field['length'])) {
$length = $field['length'];
if ($length <= 255) {
return 'TINYBLOB';
} elseif ($length <= 65532) {
return 'BLOB';
} elseif ($length <= 16777215) {
return 'MEDIUMBLOB';
}
}
return 'LONGBLOB';
case 'integer':
if (!empty($field['length'])) {
$length = $field['length'];
if ($length <= 1) {
return 'TINYINT';
} elseif ($length == 2) {
return 'SMALLINT';
} elseif ($length == 3) {
return 'MEDIUMINT';
} elseif ($length == 4) {
return 'INT';
} elseif ($length > 4) {
return 'BIGINT';
}
}
return 'INT';
case 'boolean':
return 'TINYINT(1)';
case 'date':
return 'DATE';
case 'time':
return 'TIME';
case 'timestamp':
return 'DATETIME';
case 'float':
return 'DOUBLE';
case 'decimal':
$length = !empty($field['length']) ? $field['length'] : 18;
$scale = !empty($field['scale']) ? $field['scale'] : $db->options['decimal_places'];
return 'DECIMAL('.$length.','.$scale.')';
}
return '';
}
// }}}
// {{{ _getIntegerDeclaration()
/**
* Obtain DBMS specific SQL code portion needed to declare an integer type
* field to be used in statements like CREATE TABLE.
*
* @param string $name name the field to be declared.
* @param string $field associative array with the name of the properties
* of the field being declared as array indexes.
* Currently, the types of supported field
* properties are as follows:
*
* unsigned
* Boolean flag that indicates whether the field
* should be declared as unsigned integer if
* possible.
*
* default
* Integer value to be used as default for this
* field.
*
* notnull
* Boolean flag that indicates whether this field is
* constrained to not be set to null.
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
* @access protected
*/
function _getIntegerDeclaration($name, $field)
{
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$default = $autoinc = '';
if (!empty($field['autoincrement'])) {
$autoinc = ' AUTO_INCREMENT PRIMARY KEY';
} elseif (array_key_exists('default', $field)) {
if ($field['default'] === '') {
$field['default'] = empty($field['notnull']) ? null : 0;
}
$default = ' DEFAULT '.$this->quote($field['default'], 'integer');
}
$notnull = empty($field['notnull']) ? '' : ' NOT NULL';
$unsigned = empty($field['unsigned']) ? '' : ' UNSIGNED';
$name = $db->quoteIdentifier($name, true);
return $name.' '.$this->getTypeDeclaration($field).$unsigned.$default.$notnull.$autoinc;
}
// }}}
// {{{ _getFloatDeclaration()
/**
* Obtain DBMS specific SQL code portion needed to declare an float type
* field to be used in statements like CREATE TABLE.
*
* @param string $name name the field to be declared.
* @param string $field associative array with the name of the properties
* of the field being declared as array indexes.
* Currently, the types of supported field
* properties are as follows:
*
* unsigned
* Boolean flag that indicates whether the field
* should be declared as unsigned float if
* possible.
*
* default
* float value to be used as default for this
* field.
*
* notnull
* Boolean flag that indicates whether this field is
* constrained to not be set to null.
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
* @access protected
*/
function _getFloatDeclaration($name, $field)
{
// Since AUTO_INCREMENT can be used for integer or floating-point types,
// reuse the INTEGER declaration
// @see http://bugs.mysql.com/bug.php?id=31032
return $this->_getIntegerDeclaration($name, $field);
}
// }}}
// {{{ _getDecimalDeclaration()
/**
* Obtain DBMS specific SQL code portion needed to declare an decimal type
* field to be used in statements like CREATE TABLE.
*
* @param string $name name the field to be declared.
* @param string $field associative array with the name of the properties
* of the field being declared as array indexes.
* Currently, the types of supported field
* properties are as follows:
*
* unsigned
* Boolean flag that indicates whether the field
* should be declared as unsigned integer if
* possible.
*
* default
* Decimal value to be used as default for this
* field.
*
* notnull
* Boolean flag that indicates whether this field is
* constrained to not be set to null.
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
* @access protected
*/
function _getDecimalDeclaration($name, $field)
{
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$default = '';
if (array_key_exists('default', $field)) {
if ($field['default'] === '') {
$field['default'] = empty($field['notnull']) ? null : 0;
}
$default = ' DEFAULT '.$this->quote($field['default'], 'integer');
} elseif (empty($field['notnull'])) {
$default = ' DEFAULT NULL';
}
$notnull = empty($field['notnull']) ? '' : ' NOT NULL';
$unsigned = empty($field['unsigned']) ? '' : ' UNSIGNED';
$name = $db->quoteIdentifier($name, true);
return $name.' '.$this->getTypeDeclaration($field).$unsigned.$default.$notnull;
}
// }}}
// {{{ matchPattern()
/**
* build a pattern matching string
*
* @access public
*
* @param array $pattern even keys are strings, odd are patterns (% and _)
* @param string $operator optional pattern operator (LIKE, ILIKE and maybe others in the future)
* @param string $field optional field name that is being matched against
* (might be required when emulating ILIKE)
*
* @return string SQL pattern
*/
function matchPattern($pattern, $operator = null, $field = null)
{
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$match = '';
if (!is_null($operator)) {
$field = is_null($field) ? '' : $field.' ';
$operator = strtoupper($operator);
switch ($operator) {
// case insensitive
case 'ILIKE':
$match = $field.'LIKE ';
break;
// case sensitive
case 'LIKE':
$match = $field.'LIKE BINARY ';
break;
default:
return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'not a supported operator type:'. $operator, __FUNCTION__);
}
}
$match.= "'";
foreach ($pattern as $key => $value) {
if ($key % 2) {
$match.= $value;
} else {
$match.= $db->escapePattern($db->escape($value));
}
}
$match.= "'";
$match.= $this->patternEscapeString();
return $match;
}
// }}}
// {{{ _mapNativeDatatype()
/**
* Maps a native array description of a field to a MDB2 datatype and length
*
* @param array $field native field description
* @return array containing the various possible types, length, sign, fixed
* @access public
*/
function _mapNativeDatatype($field)
{
$db_type = strtolower($field['type']);
$db_type = strtok($db_type, '(), ');
if ($db_type == 'national') {
$db_type = strtok('(), ');
}
if (!empty($field['length'])) {
$length = strtok($field['length'], ', ');
$decimal = strtok(', ');
} else {
$length = strtok('(), ');
$decimal = strtok('(), ');
}
$type = array();
$unsigned = $fixed = null;
switch ($db_type) {
case 'tinyint':
$type[] = 'integer';
$type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type);
}
$unsigned = preg_match('/ unsigned/i', $field['type']);
$length = 1;
break;
case 'smallint':
$type[] = 'integer';
$unsigned = preg_match('/ unsigned/i', $field['type']);
$length = 2;
break;
case 'mediumint':
$type[] = 'integer';
$unsigned = preg_match('/ unsigned/i', $field['type']);
$length = 3;
break;
case 'int':
case 'integer':
$type[] = 'integer';
$unsigned = preg_match('/ unsigned/i', $field['type']);
$length = 4;
break;
case 'bigint':
$type[] = 'integer';
$unsigned = preg_match('/ unsigned/i', $field['type']);
$length = 8;
break;
case 'tinytext':
case 'mediumtext':
case 'longtext':
case 'text':
case 'varchar':
$fixed = false;
case 'string':
case 'char':
$type[] = 'text';
if ($length == '1') {
$type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type);
}
} elseif (strstr($db_type, 'text')) {
$type[] = 'clob';
if ($decimal == 'binary') {
$type[] = 'blob';
}
$type = array_reverse($type);
}
if ($fixed !== false) {
$fixed = true;
}
break;
case 'enum':
$type[] = 'text';
preg_match_all('/\'.+\'/U', $field['type'], $matches);
$length = 0;
$fixed = false;
if (is_array($matches)) {
foreach ($matches[0] as $value) {
$length = max($length, strlen($value)-2);
}
if ($length == '1' && count($matches[0]) == 2) {
$type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type);
}
}
}
$type[] = 'integer';
case 'set':
$fixed = false;
$type[] = 'text';
$type[] = 'integer';
break;
case 'date':
$type[] = 'date';
$length = null;
break;
case 'datetime':
case 'timestamp':
$type[] = 'timestamp';
$length = null;
break;
case 'time':
$type[] = 'time';
$length = null;
break;
case 'float':
case 'double':
case 'real':
$type[] = 'float';
$unsigned = preg_match('/ unsigned/i', $field['type']);
break;
case 'unknown':
case 'decimal':
case 'numeric':
$type[] = 'decimal';
$unsigned = preg_match('/ unsigned/i', $field['type']);
if ($decimal !== false) {
$length = $length.','.$decimal;
}
break;
case 'tinyblob':
case 'mediumblob':
case 'longblob':
case 'blob':
$type[] = 'blob';
$length = null;
break;
case 'binary':
case 'varbinary':
$type[] = 'blob';
break;
case 'year':
$type[] = 'integer';
$type[] = 'date';
$length = null;
break;
default:
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'unknown database attribute type: '.$db_type, __FUNCTION__);
}
if ((int)$length <= 0) {
$length = null;
}
return array($type, $length, $unsigned, $fixed);
}
// }}}
}
?>

554
3rdparty/MDB2/Driver/Datatype/pgsql.php vendored Normal file
View File

@ -0,0 +1,554 @@
<?php
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2007 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. |
// | |
// | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions |
// | are met: |
// | |
// | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. |
// | |
// | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. |
// | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior|
// | written permission. |
// | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+
// | Author: Paul Cooper <pgc@ucecom.com> |
// +----------------------------------------------------------------------+
//
// $Id: pgsql.php,v 1.93 2008/08/28 20:32:57 afz Exp $
require_once('MDB2/Driver/Datatype/Common.php');
/**
* MDB2 PostGreSQL driver
*
* @package MDB2
* @category Database
* @author Paul Cooper <pgc@ucecom.com>
*/
class MDB2_Driver_Datatype_pgsql extends MDB2_Driver_Datatype_Common
{
// {{{ _baseConvertResult()
/**
* General type conversion method
*
* @param mixed $value refernce to a value to be converted
* @param string $type specifies which type to convert to
* @param boolean $rtrim [optional] when TRUE [default], apply rtrim() to text
* @return object a MDB2 error on failure
* @access protected
*/
function _baseConvertResult($value, $type, $rtrim = true)
{
if (is_null($value)) {
return null;
}
switch ($type) {
case 'boolean':
return $value == 't';
case 'float':
return doubleval($value);
case 'date':
return $value;
case 'time':
return substr($value, 0, strlen('HH:MM:SS'));
case 'timestamp':
return substr($value, 0, strlen('YYYY-MM-DD HH:MM:SS'));
case 'blob':
$value = pg_unescape_bytea($value);
return parent::_baseConvertResult($value, $type, $rtrim);
}
return parent::_baseConvertResult($value, $type, $rtrim);
}
// }}}
// {{{ getTypeDeclaration()
/**
* Obtain DBMS specific SQL code portion needed to declare an text type
* field to be used in statements like CREATE TABLE.
*
* @param array $field associative array with the name of the properties
* of the field being declared as array indexes. Currently, the types
* of supported field properties are as follows:
*
* length
* Integer value that determines the maximum length of the text
* field. If this argument is missing the field should be
* declared to have the longest length allowed by the DBMS.
*
* default
* Text value to be used as default for this field.
*
* notnull
* Boolean flag that indicates whether this field is constrained
* to not be set to null.
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
* @access public
*/
function getTypeDeclaration($field)
{
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
switch ($field['type']) {
case 'text':
$length = !empty($field['length']) ? $field['length'] : false;
$fixed = !empty($field['fixed']) ? $field['fixed'] : false;
return $fixed ? ($length ? 'CHAR('.$length.')' : 'CHAR('.$db->options['default_text_field_length'].')')
: ($length ? 'VARCHAR('.$length.')' : 'TEXT');
case 'clob':
return 'TEXT';
case 'blob':
return 'BYTEA';
case 'integer':
if (!empty($field['autoincrement'])) {
if (!empty($field['length'])) {
$length = $field['length'];
if ($length > 4) {
return 'BIGSERIAL PRIMARY KEY';
}
}
return 'SERIAL PRIMARY KEY';
}
if (!empty($field['length'])) {
$length = $field['length'];
if ($length <= 2) {
return 'SMALLINT';
} elseif ($length == 3 || $length == 4) {
return 'INT';
} elseif ($length > 4) {
return 'BIGINT';
}
}
return 'INT';
case 'boolean':
return 'BOOLEAN';
case 'date':
return 'DATE';
case 'time':
return 'TIME without time zone';
case 'timestamp':
return 'TIMESTAMP without time zone';
case 'float':
return 'FLOAT8';
case 'decimal':
$length = !empty($field['length']) ? $field['length'] : 18;
$scale = !empty($field['scale']) ? $field['scale'] : $db->options['decimal_places'];
return 'NUMERIC('.$length.','.$scale.')';
}
}
// }}}
// {{{ _getIntegerDeclaration()
/**
* Obtain DBMS specific SQL code portion needed to declare an integer type
* field to be used in statements like CREATE TABLE.
*
* @param string $name name the field to be declared.
* @param array $field associative array with the name of the properties
* of the field being declared as array indexes. Currently, the types
* of supported field properties are as follows:
*
* unsigned
* Boolean flag that indicates whether the field should be
* declared as unsigned integer if possible.
*
* default
* Integer value to be used as default for this field.
*
* notnull
* Boolean flag that indicates whether this field is constrained
* to not be set to null.
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
* @access protected
*/
function _getIntegerDeclaration($name, $field)
{
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
if (!empty($field['unsigned'])) {
$db->warnings[] = "unsigned integer field \"$name\" is being declared as signed integer";
}
if (!empty($field['autoincrement'])) {
$name = $db->quoteIdentifier($name, true);
return $name.' '.$this->getTypeDeclaration($field);
}
$default = '';
if (array_key_exists('default', $field)) {
if ($field['default'] === '') {
$field['default'] = empty($field['notnull']) ? null : 0;
}
$default = ' DEFAULT '.$this->quote($field['default'], 'integer');
}
$notnull = empty($field['notnull']) ? '' : ' NOT NULL';
$name = $db->quoteIdentifier($name, true);
return $name.' '.$this->getTypeDeclaration($field).$default.$notnull;
}
// }}}
// {{{ _quoteCLOB()
/**
* Convert a text value into a DBMS specific format that is suitable to
* compose query statements.
*
* @param string $value text string value that is intended to be converted.
* @param bool $quote determines if the value should be quoted and escaped
* @param bool $escape_wildcards if to escape escape wildcards
* @return string text string that represents the given argument value in
* a DBMS specific format.
* @access protected
*/
function _quoteCLOB($value, $quote, $escape_wildcards)
{
return $this->_quoteText($value, $quote, $escape_wildcards);
}
// }}}
// {{{ _quoteBLOB()
/**
* Convert a text value into a DBMS specific format that is suitable to
* compose query statements.
*
* @param string $value text string value that is intended to be converted.
* @param bool $quote determines if the value should be quoted and escaped
* @param bool $escape_wildcards if to escape escape wildcards
* @return string text string that represents the given argument value in
* a DBMS specific format.
* @access protected
*/
function _quoteBLOB($value, $quote, $escape_wildcards)
{
if (!$quote) {
return $value;
}
if (version_compare(PHP_VERSION, '5.2.0RC6', '>=')) {
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$connection = $db->getConnection();
if (PEAR::isError($connection)) {
return $connection;
}
$value = @pg_escape_bytea($connection, $value);
} else {
$value = @pg_escape_bytea($value);
}
return "'".$value."'";
}
// }}}
// {{{ _quoteBoolean()
/**
* Convert a text value into a DBMS specific format that is suitable to
* compose query statements.
*
* @param string $value text string value that is intended to be converted.
* @param bool $quote determines if the value should be quoted and escaped
* @param bool $escape_wildcards if to escape escape wildcards
* @return string text string that represents the given argument value in
* a DBMS specific format.
* @access protected
*/
function _quoteBoolean($value, $quote, $escape_wildcards)
{
$value = $value ? 't' : 'f';
if (!$quote) {
return $value;
}
return "'".$value."'";
}
// }}}
// {{{ matchPattern()
/**
* build a pattern matching string
*
* @access public
*
* @param array $pattern even keys are strings, odd are patterns (% and _)
* @param string $operator optional pattern operator (LIKE, ILIKE and maybe others in the future)
* @param string $field optional field name that is being matched against
* (might be required when emulating ILIKE)
*
* @return string SQL pattern
*/
function matchPattern($pattern, $operator = null, $field = null)
{
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$match = '';
if (!is_null($operator)) {
$field = is_null($field) ? '' : $field.' ';
$operator = strtoupper($operator);
switch ($operator) {
// case insensitive
case 'ILIKE':
$match = $field.'ILIKE ';
break;
// case sensitive
case 'LIKE':
$match = $field.'LIKE ';
break;
default:
return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'not a supported operator type:'. $operator, __FUNCTION__);
}
}
$match.= "'";
foreach ($pattern as $key => $value) {
if ($key % 2) {
$match.= $value;
} else {
$match.= $db->escapePattern($db->escape($value));
}
}
$match.= "'";
$match.= $this->patternEscapeString();
return $match;
}
// }}}
// {{{ patternEscapeString()
/**
* build string to define escape pattern string
*
* @access public
*
*
* @return string define escape pattern
*/
function patternEscapeString()
{
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
return ' ESCAPE '.$this->quote($db->string_quoting['escape_pattern']);
}
// }}}
// {{{ _mapNativeDatatype()
/**
* Maps a native array description of a field to a MDB2 datatype and length
*
* @param array $field native field description
* @return array containing the various possible types, length, sign, fixed
* @access public
*/
function _mapNativeDatatype($field)
{
$db_type = strtolower($field['type']);
$length = $field['length'];
$type = array();
$unsigned = $fixed = null;
switch ($db_type) {
case 'smallint':
case 'int2':
$type[] = 'integer';
$unsigned = false;
$length = 2;
if ($length == '2') {
$type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type);
}
}
break;
case 'int':
case 'int4':
case 'integer':
case 'serial':
case 'serial4':
$type[] = 'integer';
$unsigned = false;
$length = 4;
break;
case 'bigint':
case 'int8':
case 'bigserial':
case 'serial8':
$type[] = 'integer';
$unsigned = false;
$length = 8;
break;
case 'bool':
case 'boolean':
$type[] = 'boolean';
$length = null;
break;
case 'text':
case 'varchar':
$fixed = false;
case 'unknown':
case 'char':
case 'bpchar':
$type[] = 'text';
if ($length == '1') {
$type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type);
}
} elseif (strstr($db_type, 'text')) {
$type[] = 'clob';
$type = array_reverse($type);
}
if ($fixed !== false) {
$fixed = true;
}
break;
case 'date':
$type[] = 'date';
$length = null;
break;
case 'datetime':
case 'timestamp':
case 'timestamptz':
$type[] = 'timestamp';
$length = null;
break;
case 'time':
$type[] = 'time';
$length = null;
break;
case 'float':
case 'float4':
case 'float8':
case 'double':
case 'real':
$type[] = 'float';
break;
case 'decimal':
case 'money':
case 'numeric':
$type[] = 'decimal';
if (isset($field['scale'])) {
$length = $length.','.$field['scale'];
}
break;
case 'tinyblob':
case 'mediumblob':
case 'longblob':
case 'blob':
case 'bytea':
$type[] = 'blob';
$length = null;
break;
case 'oid':
$type[] = 'blob';
$type[] = 'clob';
$length = null;
break;
case 'year':
$type[] = 'integer';
$type[] = 'date';
$length = null;
break;
default:
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'unknown database attribute type: '.$db_type, __FUNCTION__);
}
if ((int)$length <= 0) {
$length = null;
}
return array($type, $length, $unsigned, $fixed);
}
// }}}
// {{{ mapPrepareDatatype()
/**
* Maps an mdb2 datatype to native prepare type
*
* @param string $type
* @return string
* @access public
*/
function mapPrepareDatatype($type)
{
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
if (!empty($db->options['datatype_map'][$type])) {
$type = $db->options['datatype_map'][$type];
if (!empty($db->options['datatype_map_callback'][$type])) {
$parameter = array('type' => $type);
return call_user_func_array($db->options['datatype_map_callback'][$type], array(&$db, __FUNCTION__, $parameter));
}
}
switch ($type) {
case 'integer':
return 'int';
case 'boolean':
return 'bool';
case 'decimal':
case 'float':
return 'numeric';
case 'clob':
return 'text';
case 'blob':
return 'bytea';
default:
break;
}
return $type;
}
// }}}
}
?>

409
3rdparty/MDB2/Driver/Datatype/sqlite.php vendored Normal file
View File

@ -0,0 +1,409 @@
<?php
// vim: set et ts=4 sw=4 fdm=marker:
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2007 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. |
// | |
// | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions |
// | are met: |
// | |
// | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. |
// | |
// | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. |
// | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior|
// | written permission. |
// | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
// $Id: sqlite.php,v 1.67 2008/02/22 19:58:06 quipo Exp $
//
require_once('MDB2/Driver/Datatype/Common.php');
/**
* MDB2 SQLite driver
*
* @package MDB2
* @category Database
* @author Lukas Smith <smith@pooteeweet.org>
*/
class MDB2_Driver_Datatype_sqlite extends MDB2_Driver_Datatype_Common
{
// {{{ _getCollationFieldDeclaration()
/**
* Obtain DBMS specific SQL code portion needed to set the COLLATION
* of a field declaration to be used in statements like CREATE TABLE.
*
* @param string $collation name of the collation
*
* @return string DBMS specific SQL code portion needed to set the COLLATION
* of a field declaration.
*/
function _getCollationFieldDeclaration($collation)
{
return 'COLLATE '.$collation;
}
// }}}
// {{{ getTypeDeclaration()
/**
* Obtain DBMS specific SQL code portion needed to declare an text type
* field to be used in statements like CREATE TABLE.
*
* @param array $field associative array with the name of the properties
* of the field being declared as array indexes. Currently, the types
* of supported field properties are as follows:
*
* length
* Integer value that determines the maximum length of the text
* field. If this argument is missing the field should be
* declared to have the longest length allowed by the DBMS.
*
* default
* Text value to be used as default for this field.
*
* notnull
* Boolean flag that indicates whether this field is constrained
* to not be set to null.
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
* @access public
*/
function getTypeDeclaration($field)
{
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
switch ($field['type']) {
case 'text':
$length = !empty($field['length'])
? $field['length'] : false;
$fixed = !empty($field['fixed']) ? $field['fixed'] : false;
return $fixed ? ($length ? 'CHAR('.$length.')' : 'CHAR('.$db->options['default_text_field_length'].')')
: ($length ? 'VARCHAR('.$length.')' : 'TEXT');
case 'clob':
if (!empty($field['length'])) {
$length = $field['length'];
if ($length <= 255) {
return 'TINYTEXT';
} elseif ($length <= 65532) {
return 'TEXT';
} elseif ($length <= 16777215) {
return 'MEDIUMTEXT';
}
}
return 'LONGTEXT';
case 'blob':
if (!empty($field['length'])) {
$length = $field['length'];
if ($length <= 255) {
return 'TINYBLOB';
} elseif ($length <= 65532) {
return 'BLOB';
} elseif ($length <= 16777215) {
return 'MEDIUMBLOB';
}
}
return 'LONGBLOB';
case 'integer':
if (!empty($field['length'])) {
$length = $field['length'];
if ($length <= 2) {
return 'SMALLINT';
} elseif ($length == 3 || $length == 4) {
return 'INTEGER';
} elseif ($length > 4) {
return 'BIGINT';
}
}
return 'INTEGER';
case 'boolean':
return 'BOOLEAN';
case 'date':
return 'DATE';
case 'time':
return 'TIME';
case 'timestamp':
return 'DATETIME';
case 'float':
return 'DOUBLE'.($db->options['fixed_float'] ? '('.
($db->options['fixed_float']+2).','.$db->options['fixed_float'].')' : '');
case 'decimal':
$length = !empty($field['length']) ? $field['length'] : 18;
$scale = !empty($field['scale']) ? $field['scale'] : $db->options['decimal_places'];
return 'DECIMAL('.$length.','.$scale.')';
}
return '';
}
// }}}
// {{{ _getIntegerDeclaration()
/**
* Obtain DBMS specific SQL code portion needed to declare an integer type
* field to be used in statements like CREATE TABLE.
*
* @param string $name name the field to be declared.
* @param string $field associative array with the name of the properties
* of the field being declared as array indexes.
* Currently, the types of supported field
* properties are as follows:
*
* unsigned
* Boolean flag that indicates whether the field
* should be declared as unsigned integer if
* possible.
*
* default
* Integer value to be used as default for this
* field.
*
* notnull
* Boolean flag that indicates whether this field is
* constrained to not be set to null.
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
* @access protected
*/
function _getIntegerDeclaration($name, $field)
{
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$default = $autoinc = '';
if (!empty($field['autoincrement'])) {
$autoinc = ' PRIMARY KEY';
} elseif (array_key_exists('default', $field)) {
if ($field['default'] === '') {
$field['default'] = empty($field['notnull']) ? null : 0;
}
$default = ' DEFAULT '.$this->quote($field['default'], 'integer');
}
$notnull = empty($field['notnull']) ? '' : ' NOT NULL';
$unsigned = empty($field['unsigned']) ? '' : ' UNSIGNED';
$name = $db->quoteIdentifier($name, true);
return $name.' '.$this->getTypeDeclaration($field).$unsigned.$default.$notnull.$autoinc;
}
// }}}
// {{{ matchPattern()
/**
* build a pattern matching string
*
* @access public
*
* @param array $pattern even keys are strings, odd are patterns (% and _)
* @param string $operator optional pattern operator (LIKE, ILIKE and maybe others in the future)
* @param string $field optional field name that is being matched against
* (might be required when emulating ILIKE)
*
* @return string SQL pattern
*/
function matchPattern($pattern, $operator = null, $field = null)
{
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$match = '';
if (!is_null($operator)) {
$field = is_null($field) ? '' : $field.' ';
$operator = strtoupper($operator);
switch ($operator) {
// case insensitive
case 'ILIKE':
$match = $field.'LIKE ';
break;
// case sensitive
case 'LIKE':
$match = $field.'LIKE ';
break;
default:
return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'not a supported operator type:'. $operator, __FUNCTION__);
}
}
$match.= "'";
foreach ($pattern as $key => $value) {
if ($key % 2) {
$match.= $value;
} else {
$match.= $db->escapePattern($db->escape($value));
}
}
$match.= "'";
$match.= $this->patternEscapeString();
return $match;
}
// }}}
// {{{ _mapNativeDatatype()
/**
* Maps a native array description of a field to a MDB2 datatype and length
*
* @param array $field native field description
* @return array containing the various possible types, length, sign, fixed
* @access public
*/
function _mapNativeDatatype($field)
{
$db_type = strtolower($field['type']);
$length = !empty($field['length']) ? $field['length'] : null;
$unsigned = !empty($field['unsigned']) ? $field['unsigned'] : null;
$fixed = null;
$type = array();
switch ($db_type) {
case 'boolean':
$type[] = 'boolean';
break;
case 'tinyint':
$type[] = 'integer';
$type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type);
}
$unsigned = preg_match('/ unsigned/i', $field['type']);
$length = 1;
break;
case 'smallint':
$type[] = 'integer';
$unsigned = preg_match('/ unsigned/i', $field['type']);
$length = 2;
break;
case 'mediumint':
$type[] = 'integer';
$unsigned = preg_match('/ unsigned/i', $field['type']);
$length = 3;
break;
case 'int':
case 'integer':
case 'serial':
$type[] = 'integer';
$unsigned = preg_match('/ unsigned/i', $field['type']);
$length = 4;
break;
case 'bigint':
case 'bigserial':
$type[] = 'integer';
$unsigned = preg_match('/ unsigned/i', $field['type']);
$length = 8;
break;
case 'clob':
$type[] = 'clob';
$fixed = false;
break;
case 'tinytext':
case 'mediumtext':
case 'longtext':
case 'text':
case 'varchar':
case 'varchar2':
$fixed = false;
case 'char':
$type[] = 'text';
if ($length == '1') {
$type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type);
}
} elseif (strstr($db_type, 'text')) {
$type[] = 'clob';
$type = array_reverse($type);
}
if ($fixed !== false) {
$fixed = true;
}
break;
case 'date':
$type[] = 'date';
$length = null;
break;
case 'datetime':
case 'timestamp':
$type[] = 'timestamp';
$length = null;
break;
case 'time':
$type[] = 'time';
$length = null;
break;
case 'float':
case 'double':
case 'real':
$type[] = 'float';
break;
case 'decimal':
case 'numeric':
$type[] = 'decimal';
$length = $length.','.$field['decimal'];
break;
case 'tinyblob':
case 'mediumblob':
case 'longblob':
case 'blob':
$type[] = 'blob';
$length = null;
break;
case 'year':
$type[] = 'integer';
$type[] = 'date';
$length = null;
break;
default:
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'unknown database attribute type: '.$db_type, __FUNCTION__);
}
if ((int)$length <= 0) {
$length = null;
}
return array($type, $length, $unsigned, $fixed);
}
// }}}
}
?>

293
3rdparty/MDB2/Driver/Function/Common.php vendored Normal file
View File

@ -0,0 +1,293 @@
<?php
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. |
// | |
// | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions |
// | are met: |
// | |
// | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. |
// | |
// | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. |
// | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior|
// | written permission. |
// | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
// $Id: Common.php,v 1.21 2008/02/17 18:51:39 quipo Exp $
//
/**
* @package MDB2
* @category Database
* @author Lukas Smith <smith@pooteeweet.org>
*/
/**
* Base class for the function modules that is extended by each MDB2 driver
*
* To load this module in the MDB2 object:
* $mdb->loadModule('Function');
*
* @package MDB2
* @category Database
* @author Lukas Smith <smith@pooteeweet.org>
*/
class MDB2_Driver_Function_Common extends MDB2_Module_Common
{
// {{{ executeStoredProc()
/**
* Execute a stored procedure and return any results
*
* @param string $name string that identifies the function to execute
* @param mixed $params array that contains the paramaters to pass the stored proc
* @param mixed $types array that contains the types of the columns in
* the result set
* @param mixed $result_class string which specifies which result class to use
* @param mixed $result_wrap_class string which specifies which class to wrap results in
*
* @return mixed a result handle or MDB2_OK on success, a MDB2 error on failure
* @access public
*/
function &executeStoredProc($name, $params = null, $types = null, $result_class = true, $result_wrap_class = false)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$error =& $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'method not implemented', __FUNCTION__);
return $error;
}
// }}}
// {{{ functionTable()
/**
* return string for internal table used when calling only a function
*
* @return string for internal table used when calling only a function
* @access public
*/
function functionTable()
{
return '';
}
// }}}
// {{{ now()
/**
* Return string to call a variable with the current timestamp inside an SQL statement
* There are three special variables for current date and time:
* - CURRENT_TIMESTAMP (date and time, TIMESTAMP type)
* - CURRENT_DATE (date, DATE type)
* - CURRENT_TIME (time, TIME type)
*
* @param string $type 'timestamp' | 'time' | 'date'
*
* @return string to call a variable with the current timestamp
* @access public
*/
function now($type = 'timestamp')
{
switch ($type) {
case 'time':
return 'CURRENT_TIME';
case 'date':
return 'CURRENT_DATE';
case 'timestamp':
default:
return 'CURRENT_TIMESTAMP';
}
}
// }}}
// {{{ unixtimestamp()
/**
* return string to call a function to get the unix timestamp from a iso timestamp
*
* @param string $expression
*
* @return string to call a variable with the timestamp
* @access public
*/
function unixtimestamp($expression)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$error =& $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'method not implemented', __FUNCTION__);
return $error;
}
// }}}
// {{{ substring()
/**
* return string to call a function to get a substring inside an SQL statement
*
* @return string to call a function to get a substring
* @access public
*/
function substring($value, $position = 1, $length = null)
{
if (!is_null($length)) {
return "SUBSTRING($value FROM $position FOR $length)";
}
return "SUBSTRING($value FROM $position)";
}
// }}}
// {{{ replace()
/**
* return string to call a function to get replace inside an SQL statement.
*
* @return string to call a function to get a replace
* @access public
*/
function replace($str, $from_str, $to_str)
{
return "REPLACE($str, $from_str , $to_str)";
}
// }}}
// {{{ concat()
/**
* Returns string to concatenate two or more string parameters
*
* @param string $value1
* @param string $value2
* @param string $values...
*
* @return string to concatenate two strings
* @access public
*/
function concat($value1, $value2)
{
$args = func_get_args();
return "(".implode(' || ', $args).")";
}
// }}}
// {{{ random()
/**
* return string to call a function to get random value inside an SQL statement
*
* @return return string to generate float between 0 and 1
* @access public
*/
function random()
{
return 'RAND()';
}
// }}}
// {{{ lower()
/**
* return string to call a function to lower the case of an expression
*
* @param string $expression
*
* @return return string to lower case of an expression
* @access public
*/
function lower($expression)
{
return "LOWER($expression)";
}
// }}}
// {{{ upper()
/**
* return string to call a function to upper the case of an expression
*
* @param string $expression
*
* @return return string to upper case of an expression
* @access public
*/
function upper($expression)
{
return "UPPER($expression)";
}
// }}}
// {{{ length()
/**
* return string to call a function to get the length of a string expression
*
* @param string $expression
*
* @return return string to get the string expression length
* @access public
*/
function length($expression)
{
return "LENGTH($expression)";
}
// }}}
// {{{ guid()
/**
* Returns global unique identifier
*
* @return string to get global unique identifier
* @access public
*/
function guid()
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$error =& $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'method not implemented', __FUNCTION__);
return $error;
}
// }}}
}
?>

136
3rdparty/MDB2/Driver/Function/mysql.php vendored Normal file
View File

@ -0,0 +1,136 @@
<?php
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2008 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. |
// | |
// | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions |
// | are met: |
// | |
// | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. |
// | |
// | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. |
// | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior|
// | written permission. |
// | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
// $Id: mysql.php,v 1.12 2008/02/17 18:54:08 quipo Exp $
//
require_once('MDB2/Driver/Function/Common.php');
/**
* MDB2 MySQL driver for the function modules
*
* @package MDB2
* @category Database
* @author Lukas Smith <smith@pooteeweet.org>
*/
class MDB2_Driver_Function_mysql extends MDB2_Driver_Function_Common
{
// }}}
// {{{ executeStoredProc()
/**
* Execute a stored procedure and return any results
*
* @param string $name string that identifies the function to execute
* @param mixed $params array that contains the paramaters to pass the stored proc
* @param mixed $types array that contains the types of the columns in
* the result set
* @param mixed $result_class string which specifies which result class to use
* @param mixed $result_wrap_class string which specifies which class to wrap results in
* @return mixed a result handle or MDB2_OK on success, a MDB2 error on failure
* @access public
*/
function &executeStoredProc($name, $params = null, $types = null, $result_class = true, $result_wrap_class = false)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$query = 'CALL '.$name;
$query .= $params ? '('.implode(', ', $params).')' : '()';
return $db->query($query, $types, $result_class, $result_wrap_class);
}
// }}}
// {{{ unixtimestamp()
/**
* return string to call a function to get the unix timestamp from a iso timestamp
*
* @param string $expression
*
* @return string to call a variable with the timestamp
* @access public
*/
function unixtimestamp($expression)
{
return 'UNIX_TIMESTAMP('. $expression.')';
}
// }}}
// {{{ concat()
/**
* Returns string to concatenate two or more string parameters
*
* @param string $value1
* @param string $value2
* @param string $values...
* @return string to concatenate two strings
* @access public
**/
function concat($value1, $value2)
{
$args = func_get_args();
return "CONCAT(".implode(', ', $args).")";
}
// }}}
// {{{ guid()
/**
* Returns global unique identifier
*
* @return string to get global unique identifier
* @access public
*/
function guid()
{
return 'UUID()';
}
// }}}
}
?>

115
3rdparty/MDB2/Driver/Function/pgsql.php vendored Normal file
View File

@ -0,0 +1,115 @@
<?php
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2008 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. |
// | |
// | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions |
// | are met: |
// | |
// | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. |
// | |
// | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. |
// | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior|
// | written permission. |
// | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+
// | Author: Paul Cooper <pgc@ucecom.com> |
// +----------------------------------------------------------------------+
//
// $Id: pgsql.php,v 1.11 2008/11/09 19:46:50 quipo Exp $
require_once('MDB2/Driver/Function/Common.php');
/**
* MDB2 MySQL driver for the function modules
*
* @package MDB2
* @category Database
* @author Lukas Smith <smith@pooteeweet.org>
*/
class MDB2_Driver_Function_pgsql extends MDB2_Driver_Function_Common
{
// {{{ executeStoredProc()
/**
* Execute a stored procedure and return any results
*
* @param string $name string that identifies the function to execute
* @param mixed $params array that contains the paramaters to pass the stored proc
* @param mixed $types array that contains the types of the columns in
* the result set
* @param mixed $result_class string which specifies which result class to use
* @param mixed $result_wrap_class string which specifies which class to wrap results in
* @return mixed a result handle or MDB2_OK on success, a MDB2 error on failure
* @access public
*/
function &executeStoredProc($name, $params = null, $types = null, $result_class = true, $result_wrap_class = false)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$query = 'SELECT * FROM '.$name;
$query .= $params ? '('.implode(', ', $params).')' : '()';
return $db->query($query, $types, $result_class, $result_wrap_class);
}
// }}}
// {{{ unixtimestamp()
/**
* return string to call a function to get the unix timestamp from a iso timestamp
*
* @param string $expression
*
* @return string to call a variable with the timestamp
* @access public
*/
function unixtimestamp($expression)
{
return 'EXTRACT(EPOCH FROM DATE_TRUNC(\'seconds\', CAST ((' . $expression . ') AS TIMESTAMP)))';
}
// }}}
// {{{ random()
/**
* return string to call a function to get random value inside an SQL statement
*
* @return return string to generate float between 0 and 1
* @access public
*/
function random()
{
return 'RANDOM()';
}
// }}}
}
?>

162
3rdparty/MDB2/Driver/Function/sqlite.php vendored Normal file
View File

@ -0,0 +1,162 @@
<?php
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2008 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. |
// | |
// | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions |
// | are met: |
// | |
// | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. |
// | |
// | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. |
// | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior|
// | written permission. |
// | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
// $Id: sqlite.php,v 1.10 2008/02/17 18:54:08 quipo Exp $
//
require_once('MDB2/Driver/Function/Common.php');
/**
* MDB2 SQLite driver for the function modules
*
* @package MDB2
* @category Database
* @author Lukas Smith <smith@pooteeweet.org>
*/
class MDB2_Driver_Function_sqlite extends MDB2_Driver_Function_Common
{
// {{{ constructor
/**
* Constructor
*/
function __construct($db_index)
{
parent::__construct($db_index);
// create all sorts of UDFs
}
// {{{ now()
/**
* Return string to call a variable with the current timestamp inside an SQL statement
* There are three special variables for current date and time.
*
* @return string to call a variable with the current timestamp
* @access public
*/
function now($type = 'timestamp')
{
switch ($type) {
case 'time':
return 'time(\'now\')';
case 'date':
return 'date(\'now\')';
case 'timestamp':
default:
return 'datetime(\'now\')';
}
}
// }}}
// {{{ unixtimestamp()
/**
* return string to call a function to get the unix timestamp from a iso timestamp
*
* @param string $expression
*
* @return string to call a variable with the timestamp
* @access public
*/
function unixtimestamp($expression)
{
return 'strftime("%s",'. $expression.', "utc")';
}
// }}}
// {{{ substring()
/**
* return string to call a function to get a substring inside an SQL statement
*
* @return string to call a function to get a substring
* @access public
*/
function substring($value, $position = 1, $length = null)
{
if (!is_null($length)) {
return "substr($value,$position,$length)";
}
return "substr($value,$position,length($value))";
}
// }}}
// {{{ random()
/**
* return string to call a function to get random value inside an SQL statement
*
* @return return string to generate float between 0 and 1
* @access public
*/
function random()
{
return '((RANDOM()+2147483648)/4294967296)';
}
// }}}
// {{{ replace()
/**
* return string to call a function to get a replacement inside an SQL statement.
*
* @return string to call a function to get a replace
* @access public
*/
function replace($str, $from_str, $to_str)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$error =& $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'method not implemented', __FUNCTION__);
return $error;
}
// }}}
}
?>

1014
3rdparty/MDB2/Driver/Manager/Common.php vendored Normal file

File diff suppressed because it is too large Load Diff

1432
3rdparty/MDB2/Driver/Manager/mysql.php vendored Normal file

File diff suppressed because it is too large Load Diff

951
3rdparty/MDB2/Driver/Manager/pgsql.php vendored Normal file
View File

@ -0,0 +1,951 @@
<?php
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2008 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. |
// | |
// | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions |
// | are met: |
// | |
// | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. |
// | |
// | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. |
// | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior|
// | written permission. |
// | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+
// | Author: Paul Cooper <pgc@ucecom.com> |
// +----------------------------------------------------------------------+
//
// $Id: pgsql.php,v 1.87 2008/11/29 14:09:59 afz Exp $
require_once('MDB2/Driver/Manager/Common.php');
/**
* MDB2 MySQL driver for the management modules
*
* @package MDB2
* @category Database
* @author Paul Cooper <pgc@ucecom.com>
*/
class MDB2_Driver_Manager_pgsql extends MDB2_Driver_Manager_Common
{
// {{{ createDatabase()
/**
* create a new database
*
* @param string $name name of the database that should be created
* @param array $options array with charset info
*
* @return mixed MDB2_OK on success, a MDB2 error on failure
* @access public
*/
function createDatabase($name, $options = array())
{
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$name = $db->quoteIdentifier($name, true);
$query = 'CREATE DATABASE ' . $name;
if (!empty($options['charset'])) {
$query .= ' WITH ENCODING ' . $db->quote($options['charset'], 'text');
}
return $db->standaloneQuery($query, null, true);
}
// }}}
// {{{ alterDatabase()
/**
* alter an existing database
*
* @param string $name name of the database that is intended to be changed
* @param array $options array with name, owner info
*
* @return mixed MDB2_OK on success, a MDB2 error on failure
* @access public
*/
function alterDatabase($name, $options = array())
{
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$query = 'ALTER DATABASE '. $db->quoteIdentifier($name, true);
if (!empty($options['name'])) {
$query .= ' RENAME TO ' . $options['name'];
}
if (!empty($options['owner'])) {
$query .= ' OWNER TO ' . $options['owner'];
}
return $db->standaloneQuery($query, null, true);
}
// }}}
// {{{ dropDatabase()
/**
* drop an existing database
*
* @param string $name name of the database that should be dropped
* @return mixed MDB2_OK on success, a MDB2 error on failure
* @access public
*/
function dropDatabase($name)
{
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$name = $db->quoteIdentifier($name, true);
$query = "DROP DATABASE $name";
return $db->standaloneQuery($query, null, true);
}
// }}}
// {{{ _getAdvancedFKOptions()
/**
* Return the FOREIGN KEY query section dealing with non-standard options
* as MATCH, INITIALLY DEFERRED, ON UPDATE, ...
*
* @param array $definition
* @return string
* @access protected
*/
function _getAdvancedFKOptions($definition)
{
$query = '';
if (!empty($definition['match'])) {
$query .= ' MATCH '.$definition['match'];
}
if (!empty($definition['onupdate'])) {
$query .= ' ON UPDATE '.$definition['onupdate'];
}
if (!empty($definition['ondelete'])) {
$query .= ' ON DELETE '.$definition['ondelete'];
}
if (!empty($definition['deferrable'])) {
$query .= ' DEFERRABLE';
} else {
$query .= ' NOT DEFERRABLE';
}
if (!empty($definition['initiallydeferred'])) {
$query .= ' INITIALLY DEFERRED';
} else {
$query .= ' INITIALLY IMMEDIATE';
}
return $query;
}
// }}}
// {{{ truncateTable()
/**
* Truncate an existing table (if the TRUNCATE TABLE syntax is not supported,
* it falls back to a DELETE FROM TABLE query)
*
* @param string $name name of the table that should be truncated
* @return mixed MDB2_OK on success, a MDB2 error on failure
* @access public
*/
function truncateTable($name)
{
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$name = $db->quoteIdentifier($name, true);
return $db->exec("TRUNCATE TABLE $name");
}
// }}}
// {{{ vacuum()
/**
* Optimize (vacuum) all the tables in the db (or only the specified table)
* and optionally run ANALYZE.
*
* @param string $table table name (all the tables if empty)
* @param array $options an array with driver-specific options:
* - timeout [int] (in seconds) [mssql-only]
* - analyze [boolean] [pgsql and mysql]
* - full [boolean] [pgsql-only]
* - freeze [boolean] [pgsql-only]
*
* @return mixed MDB2_OK success, a MDB2 error on failure
* @access public
*/
function vacuum($table = null, $options = array())
{
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$query = 'VACUUM';
if (!empty($options['full'])) {
$query .= ' FULL';
}
if (!empty($options['freeze'])) {
$query .= ' FREEZE';
}
if (!empty($options['analyze'])) {
$query .= ' ANALYZE';
}
if (!empty($table)) {
$query .= ' '.$db->quoteIdentifier($table, true);
}
return $db->exec($query);
}
// }}}
// {{{ alterTable()
/**
* alter an existing table
*
* @param string $name name of the table that is intended to be changed.
* @param array $changes associative array that contains the details of each type
* of change that is intended to be performed. The types of
* changes that are currently supported are defined as follows:
*
* name
*
* New name for the table.
*
* add
*
* Associative array with the names of fields to be added as
* indexes of the array. The value of each entry of the array
* should be set to another associative array with the properties
* of the fields to be added. The properties of the fields should
* be the same as defined by the MDB2 parser.
*
*
* remove
*
* Associative array with the names of fields to be removed as indexes
* of the array. Currently the values assigned to each entry are ignored.
* An empty array should be used for future compatibility.
*
* rename
*
* Associative array with the names of fields to be renamed as indexes
* of the array. The value of each entry of the array should be set to
* another associative array with the entry named name with the new
* field name and the entry named Declaration that is expected to contain
* the portion of the field declaration already in DBMS specific SQL code
* as it is used in the CREATE TABLE statement.
*
* change
*
* Associative array with the names of the fields to be changed as indexes
* of the array. Keep in mind that if it is intended to change either the
* name of a field and any other properties, the change array entries
* should have the new names of the fields as array indexes.
*
* The value of each entry of the array should be set to another associative
* array with the properties of the fields to that are meant to be changed as
* array entries. These entries should be assigned to the new values of the
* respective properties. The properties of the fields should be the same
* as defined by the MDB2 parser.
*
* Example
* array(
* 'name' => 'userlist',
* 'add' => array(
* 'quota' => array(
* 'type' => 'integer',
* 'unsigned' => 1
* )
* ),
* 'remove' => array(
* 'file_limit' => array(),
* 'time_limit' => array()
* ),
* 'change' => array(
* 'name' => array(
* 'length' => '20',
* 'definition' => array(
* 'type' => 'text',
* 'length' => 20,
* ),
* )
* ),
* 'rename' => array(
* 'sex' => array(
* 'name' => 'gender',
* 'definition' => array(
* 'type' => 'text',
* 'length' => 1,
* 'default' => 'M',
* ),
* )
* )
* )
*
* @param boolean $check indicates whether the function should just check if the DBMS driver
* can perform the requested table alterations if the value is true or
* actually perform them otherwise.
* @access public
*
* @return mixed MDB2_OK on success, a MDB2 error on failure
*/
function alterTable($name, $changes, $check)
{
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
foreach ($changes as $change_name => $change) {
switch ($change_name) {
case 'add':
case 'remove':
case 'change':
case 'name':
case 'rename':
break;
default:
return $db->raiseError(MDB2_ERROR_CANNOT_ALTER, null, null,
'change type "'.$change_name.'\" not yet supported', __FUNCTION__);
}
}
if ($check) {
return MDB2_OK;
}
$name = $db->quoteIdentifier($name, true);
if (!empty($changes['remove']) && is_array($changes['remove'])) {
foreach ($changes['remove'] as $field_name => $field) {
$field_name = $db->quoteIdentifier($field_name, true);
$query = 'DROP ' . $field_name;
$result = $db->exec("ALTER TABLE $name $query");
if (PEAR::isError($result)) {
return $result;
}
}
}
if (!empty($changes['rename']) && is_array($changes['rename'])) {
foreach ($changes['rename'] as $field_name => $field) {
$field_name = $db->quoteIdentifier($field_name, true);
$result = $db->exec("ALTER TABLE $name RENAME COLUMN $field_name TO ".$db->quoteIdentifier($field['name'], true));
if (PEAR::isError($result)) {
return $result;
}
}
}
if (!empty($changes['add']) && is_array($changes['add'])) {
foreach ($changes['add'] as $field_name => $field) {
$query = 'ADD ' . $db->getDeclaration($field['type'], $field_name, $field);
$result = $db->exec("ALTER TABLE $name $query");
if (PEAR::isError($result)) {
return $result;
}
}
}
if (!empty($changes['change']) && is_array($changes['change'])) {
foreach ($changes['change'] as $field_name => $field) {
$field_name = $db->quoteIdentifier($field_name, true);
if (!empty($field['definition']['type'])) {
$server_info = $db->getServerVersion();
if (PEAR::isError($server_info)) {
return $server_info;
}
if (is_array($server_info) && $server_info['major'] < 8) {
return $db->raiseError(MDB2_ERROR_CANNOT_ALTER, null, null,
'changing column type for "'.$change_name.'\" requires PostgreSQL 8.0 or above', __FUNCTION__);
}
$db->loadModule('Datatype', null, true);
$type = $db->datatype->getTypeDeclaration($field['definition']);
if($type=='SERIAL PRIMARY KEY'){//not correct when altering a table, since serials arent a real type
$type='INTEGER';//use integer instead
}
$query = "ALTER $field_name TYPE $type USING CAST($field_name AS $type)";
$result = $db->exec("ALTER TABLE $name $query");
if (PEAR::isError($result)) {
return $result;
}
}
if (array_key_exists('default', $field['definition'])) {
$query = "ALTER $field_name SET DEFAULT ".$db->quote($field['definition']['default'], $field['definition']['type']);
$result = $db->exec("ALTER TABLE $name $query");
if (PEAR::isError($result)) {
return $result;
}
}
if (!empty($field['definition']['notnull'])) {
$query = "ALTER $field_name ".($field['definition']['notnull'] ? 'SET' : 'DROP').' NOT NULL';
$result = $db->exec("ALTER TABLE $name $query");
if (PEAR::isError($result)) {
return $result;
}
}
}
}
if (!empty($changes['name'])) {
$change_name = $db->quoteIdentifier($changes['name'], true);
$result = $db->exec("ALTER TABLE $name RENAME TO ".$change_name);
if (PEAR::isError($result)) {
return $result;
}
}
return MDB2_OK;
}
// }}}
// {{{ listDatabases()
/**
* list all databases
*
* @return mixed array of database names on success, a MDB2 error on failure
* @access public
*/
function listDatabases()
{
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$query = 'SELECT datname FROM pg_database';
$result2 = $db->standaloneQuery($query, array('text'), false);
if (!MDB2::isResultCommon($result2)) {
return $result2;
}
$result = $result2->fetchCol();
$result2->free();
if (PEAR::isError($result)) {
return $result;
}
if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
$result = array_map(($db->options['field_case'] == CASE_LOWER ? 'strtolower' : 'strtoupper'), $result);
}
return $result;
}
// }}}
// {{{ listUsers()
/**
* list all users
*
* @return mixed array of user names on success, a MDB2 error on failure
* @access public
*/
function listUsers()
{
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$query = 'SELECT usename FROM pg_user';
$result2 = $db->standaloneQuery($query, array('text'), false);
if (!MDB2::isResultCommon($result2)) {
return $result2;
}
$result = $result2->fetchCol();
$result2->free();
return $result;
}
// }}}
// {{{ listViews()
/**
* list all views in the current database
*
* @return mixed array of view names on success, a MDB2 error on failure
* @access public
*/
function listViews($database = null)
{
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$query = "SELECT viewname
FROM pg_views
WHERE schemaname NOT IN ('pg_catalog', 'information_schema')
AND viewname !~ '^pg_'";
$result = $db->queryCol($query);
if (PEAR::isError($result)) {
return $result;
}
if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
$result = array_map(($db->options['field_case'] == CASE_LOWER ? 'strtolower' : 'strtoupper'), $result);
}
return $result;
}
// }}}
// {{{ listTableViews()
/**
* list the views in the database that reference a given table
*
* @param string table for which all referenced views should be found
* @return mixed array of view names on success, a MDB2 error on failure
* @access public
*/
function listTableViews($table)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$query = 'SELECT viewname FROM pg_views NATURAL JOIN pg_tables';
$query.= ' WHERE tablename ='.$db->quote($table, 'text');
$result = $db->queryCol($query);
if (PEAR::isError($result)) {
return $result;
}
if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
$result = array_map(($db->options['field_case'] == CASE_LOWER ? 'strtolower' : 'strtoupper'), $result);
}
return $result;
}
// }}}
// {{{ listFunctions()
/**
* list all functions in the current database
*
* @return mixed array of function names on success, a MDB2 error on failure
* @access public
*/
function listFunctions()
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$query = "
SELECT
proname
FROM
pg_proc pr,
pg_type tp
WHERE
tp.oid = pr.prorettype
AND pr.proisagg = FALSE
AND tp.typname <> 'trigger'
AND pr.pronamespace IN
(SELECT oid FROM pg_namespace WHERE nspname NOT LIKE 'pg_%' AND nspname != 'information_schema')";
$result = $db->queryCol($query);
if (PEAR::isError($result)) {
return $result;
}
if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
$result = array_map(($db->options['field_case'] == CASE_LOWER ? 'strtolower' : 'strtoupper'), $result);
}
return $result;
}
// }}}
// {{{ listTableTriggers()
/**
* list all triggers in the database that reference a given table
*
* @param string table for which all referenced triggers should be found
* @return mixed array of trigger names on success, a MDB2 error on failure
* @access public
*/
function listTableTriggers($table = null)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$query = 'SELECT trg.tgname AS trigger_name
FROM pg_trigger trg,
pg_class tbl
WHERE trg.tgrelid = tbl.oid';
if (!is_null($table)) {
$table = $db->quote(strtoupper($table), 'text');
$query .= " AND tbl.relname = $table";
}
$result = $db->queryCol($query);
if (PEAR::isError($result)) {
return $result;
}
if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
$result = array_map(($db->options['field_case'] == CASE_LOWER ? 'strtolower' : 'strtoupper'), $result);
}
return $result;
}
// }}}
// {{{ listTables()
/**
* list all tables in the current database
*
* @return mixed array of table names on success, a MDB2 error on failure
* @access public
*/
function listTables($database = null)
{
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
// gratuitously stolen from PEAR DB _getSpecialQuery in pgsql.php
$query = 'SELECT c.relname AS "Name"'
. ' FROM pg_class c, pg_user u'
. ' WHERE c.relowner = u.usesysid'
. " AND c.relkind = 'r'"
. ' AND NOT EXISTS'
. ' (SELECT 1 FROM pg_views'
. ' WHERE viewname = c.relname)'
. " AND c.relname !~ '^(pg_|sql_)'"
. ' UNION'
. ' SELECT c.relname AS "Name"'
. ' FROM pg_class c'
. " WHERE c.relkind = 'r'"
. ' AND NOT EXISTS'
. ' (SELECT 1 FROM pg_views'
. ' WHERE viewname = c.relname)'
. ' AND NOT EXISTS'
. ' (SELECT 1 FROM pg_user'
. ' WHERE usesysid = c.relowner)'
. " AND c.relname !~ '^pg_'";
$result = $db->queryCol($query);
if (PEAR::isError($result)) {
return $result;
}
if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
$result = array_map(($db->options['field_case'] == CASE_LOWER ? 'strtolower' : 'strtoupper'), $result);
}
return $result;
}
// }}}
// {{{ listTableFields()
/**
* list all fields in a table in the current database
*
* @param string $table name of table that should be used in method
* @return mixed array of field names on success, a MDB2 error on failure
* @access public
*/
function listTableFields($table)
{
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
list($schema, $table) = $this->splitTableSchema($table);
$table = $db->quoteIdentifier($table, true);
if (!empty($schema)) {
$table = $db->quoteIdentifier($schema, true) . '.' .$table;
}
$db->setLimit(1);
$result2 = $db->query("SELECT * FROM $table LIMIT 1");
if (PEAR::isError($result2)) {
return $result2;
}
$result = $result2->getColumnNames();
$result2->free();
if (PEAR::isError($result)) {
return $result;
}
return array_flip($result);
}
// }}}
// {{{ listTableIndexes()
/**
* list all indexes in a table
*
* @param string $table name of table that should be used in method
* @return mixed array of index names on success, a MDB2 error on failure
* @access public
*/
function listTableIndexes($table)
{
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
list($schema, $table) = $this->splitTableSchema($table);
$table = $db->quote($table, 'text');
$subquery = "SELECT indexrelid
FROM pg_index
LEFT JOIN pg_class ON pg_class.oid = pg_index.indrelid
LEFT JOIN pg_namespace ON pg_class.relnamespace = pg_namespace.oid
WHERE pg_class.relname = $table
AND indisunique != 't'
AND indisprimary != 't'";
if (!empty($schema)) {
$subquery .= ' AND pg_namespace.nspname = '.$db->quote($schema, 'text');
}
$query = "SELECT relname FROM pg_class WHERE oid IN ($subquery)";
$indexes = $db->queryCol($query, 'text');
if (PEAR::isError($indexes)) {
return $indexes;
}
$result = array();
foreach ($indexes as $index) {
$index = $this->_fixIndexName($index);
if (!empty($index)) {
$result[$index] = true;
}
}
if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
$result = array_change_key_case($result, $db->options['field_case']);
}
return array_keys($result);
}
// }}}
// {{{ dropConstraint()
/**
* drop existing constraint
*
* @param string $table name of table that should be used in method
* @param string $name name of the constraint to be dropped
* @param string $primary hint if the constraint is primary
*
* @return mixed MDB2_OK on success, a MDB2 error on failure
* @access public
*/
function dropConstraint($table, $name, $primary = false)
{
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
// is it an UNIQUE index?
$query = 'SELECT relname
FROM pg_class
WHERE oid IN (
SELECT indexrelid
FROM pg_index, pg_class
WHERE pg_class.relname = '.$db->quote($table, 'text').'
AND pg_class.oid = pg_index.indrelid
AND indisunique = \'t\')
EXCEPT
SELECT conname
FROM pg_constraint, pg_class
WHERE pg_constraint.conrelid = pg_class.oid
AND relname = '. $db->quote($table, 'text');
$unique = $db->queryCol($query, 'text');
if (PEAR::isError($unique) || empty($unique)) {
// not an UNIQUE index, maybe a CONSTRAINT
return parent::dropConstraint($table, $name, $primary);
}
if (in_array($name, $unique)) {
return $db->exec('DROP INDEX '.$db->quoteIdentifier($name, true));
}
$idxname = $db->getIndexName($name);
if (in_array($idxname, $unique)) {
return $db->exec('DROP INDEX '.$db->quoteIdentifier($idxname, true));
}
return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
$name . ' is not an existing constraint for table ' . $table, __FUNCTION__);
}
// }}}
// {{{ listTableConstraints()
/**
* list all constraints in a table
*
* @param string $table name of table that should be used in method
* @return mixed array of constraint names on success, a MDB2 error on failure
* @access public
*/
function listTableConstraints($table)
{
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
list($schema, $table) = $this->splitTableSchema($table);
$table = $db->quote($table, 'text');
$query = 'SELECT conname
FROM pg_constraint
LEFT JOIN pg_class ON pg_constraint.conrelid = pg_class.oid
LEFT JOIN pg_namespace ON pg_class.relnamespace = pg_namespace.oid
WHERE relname = ' .$table;
if (!empty($schema)) {
$query .= ' AND pg_namespace.nspname = ' . $db->quote($schema, 'text');
}
$query .= '
UNION DISTINCT
SELECT relname
FROM pg_class
WHERE oid IN (
SELECT indexrelid
FROM pg_index
LEFT JOIN pg_class ON pg_class.oid = pg_index.indrelid
LEFT JOIN pg_namespace ON pg_class.relnamespace = pg_namespace.oid
WHERE pg_class.relname = '.$table.'
AND indisunique = \'t\'';
if (!empty($schema)) {
$query .= ' AND pg_namespace.nspname = ' . $db->quote($schema, 'text');
}
$query .= ')';
$constraints = $db->queryCol($query);
if (PEAR::isError($constraints)) {
return $constraints;
}
$result = array();
foreach ($constraints as $constraint) {
$constraint = $this->_fixIndexName($constraint);
if (!empty($constraint)) {
$result[$constraint] = true;
}
}
if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE
&& $db->options['field_case'] == CASE_LOWER
) {
$result = array_change_key_case($result, $db->options['field_case']);
}
return array_keys($result);
}
// }}}
// {{{ createSequence()
/**
* create sequence
*
* @param string $seq_name name of the sequence to be created
* @param string $start start value of the sequence; default is 1
* @return mixed MDB2_OK on success, a MDB2 error on failure
* @access public
*/
function createSequence($seq_name, $start = 1)
{
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$sequence_name = $db->quoteIdentifier($db->getSequenceName($seq_name), true);
return $db->exec("CREATE SEQUENCE $sequence_name INCREMENT 1".
($start < 1 ? " MINVALUE $start" : '')." START $start");
}
// }}}
// {{{ dropSequence()
/**
* drop existing sequence
*
* @param string $seq_name name of the sequence to be dropped
* @return mixed MDB2_OK on success, a MDB2 error on failure
* @access public
*/
function dropSequence($seq_name)
{
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$sequence_name = $db->quoteIdentifier($db->getSequenceName($seq_name), true);
return $db->exec("DROP SEQUENCE $sequence_name");
}
// }}}
// {{{ listSequences()
/**
* list all sequences in the current database
*
* @return mixed array of sequence names on success, a MDB2 error on failure
* @access public
*/
function listSequences($database = null)
{
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$query = "SELECT relname FROM pg_class WHERE relkind = 'S' AND relnamespace IN";
$query.= "(SELECT oid FROM pg_namespace WHERE nspname NOT LIKE 'pg_%' AND nspname != 'information_schema')";
$table_names = $db->queryCol($query);
if (PEAR::isError($table_names)) {
return $table_names;
}
$result = array();
foreach ($table_names as $table_name) {
$result[] = $this->_fixSequenceName($table_name);
}
if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
$result = array_map(($db->options['field_case'] == CASE_LOWER ? 'strtolower' : 'strtoupper'), $result);
}
return $result;
}
}
?>

1366
3rdparty/MDB2/Driver/Manager/sqlite.php vendored Normal file

File diff suppressed because it is too large Load Diff

61
3rdparty/MDB2/Driver/Native/Common.php vendored Normal file
View File

@ -0,0 +1,61 @@
<?php
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. |
// | |
// | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions |
// | are met: |
// | |
// | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. |
// | |
// | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. |
// | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior|
// | written permission. |
// | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
// $Id: Common.php,v 1.2 2007/09/09 13:47:36 quipo Exp $
//
/**
* Base class for the natuve modules that is extended by each MDB2 driver
*
* To load this module in the MDB2 object:
* $mdb->loadModule('Native');
*
* @package MDB2
* @category Database
* @author Lukas Smith <smith@pooteeweet.org>
*/
class MDB2_Driver_Native_Common extends MDB2_Module_Common
{
}
?>

60
3rdparty/MDB2/Driver/Native/mysql.php vendored Normal file
View File

@ -0,0 +1,60 @@
<?php
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. |
// | |
// | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions |
// | are met: |
// | |
// | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. |
// | |
// | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. |
// | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior|
// | written permission. |
// | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
// $Id: mysql.php,v 1.9 2006/06/18 21:59:05 lsmith Exp $
//
require_once 'MDB2/Driver/Native/Common.php';
/**
* MDB2 MySQL driver for the native module
*
* @package MDB2
* @category Database
* @author Lukas Smith <smith@pooteeweet.org>
*/
class MDB2_Driver_Native_mysql extends MDB2_Driver_Native_Common
{
}
?>

88
3rdparty/MDB2/Driver/Native/pgsql.php vendored Normal file
View File

@ -0,0 +1,88 @@
<?php
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. |
// | |
// | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions |
// | are met: |
// | |
// | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. |
// | |
// | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. |
// | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior|
// | written permission. |
// | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+
// | Author: Paul Cooper <pgc@ucecom.com> |
// +----------------------------------------------------------------------+
//
// $Id: pgsql.php,v 1.12 2006/07/15 13:07:15 lsmith Exp $
require_once 'MDB2/Driver/Native/Common.php';
/**
* MDB2 PostGreSQL driver for the native module
*
* @package MDB2
* @category Database
* @author Paul Cooper <pgc@ucecom.com>
*/
class MDB2_Driver_Native_pgsql extends MDB2_Driver_Native_Common
{
// }}}
// {{{ deleteOID()
/**
* delete an OID
*
* @param integer $OID
* @return mixed MDB2_OK on success or MDB2 Error Object on failure
* @access public
*/
function deleteOID($OID)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$connection = $db->getConnection();
if (PEAR::isError($connection)) {
return $connection;
}
if (!@pg_lo_unlink($connection, $OID)) {
return $db->raiseError(null, null, null,
'Unable to unlink OID: '.$OID, __FUNCTION__);
}
return MDB2_OK;
}
}
?>

60
3rdparty/MDB2/Driver/Native/sqlite.php vendored Normal file
View File

@ -0,0 +1,60 @@
<?php
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. |
// | |
// | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions |
// | are met: |
// | |
// | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. |
// | |
// | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. |
// | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior|
// | written permission. |
// | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
// $Id: sqlite.php,v 1.9 2006/06/18 21:59:05 lsmith Exp $
//
require_once 'MDB2/Driver/Native/Common.php';
/**
* MDB2 SQLite driver for the native module
*
* @package MDB2
* @category Database
* @author Lukas Smith <smith@pooteeweet.org>
*/
class MDB2_Driver_Native_sqlite extends MDB2_Driver_Native_Common
{
}
?>

517
3rdparty/MDB2/Driver/Reverse/Common.php vendored Normal file
View File

@ -0,0 +1,517 @@
<?php
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2007 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. |
// | |
// | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions |
// | are met: |
// | |
// | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. |
// | |
// | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. |
// | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior|
// | written permission. |
// | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
// $Id: Common.php,v 1.43 2009/01/14 15:01:21 quipo Exp $
//
/**
* @package MDB2
* @category Database
*/
/**
* These are constants for the tableInfo-function
* they are bitwised or'ed. so if there are more constants to be defined
* in the future, adjust MDB2_TABLEINFO_FULL accordingly
*/
define('MDB2_TABLEINFO_ORDER', 1);
define('MDB2_TABLEINFO_ORDERTABLE', 2);
define('MDB2_TABLEINFO_FULL', 3);
/**
* Base class for the schema reverse engineering module that is extended by each MDB2 driver
*
* To load this module in the MDB2 object:
* $mdb->loadModule('Reverse');
*
* @package MDB2
* @category Database
* @author Lukas Smith <smith@pooteeweet.org>
*/
class MDB2_Driver_Reverse_Common extends MDB2_Module_Common
{
// {{{ splitTableSchema()
/**
* Split the "[owner|schema].table" notation into an array
*
* @param string $table [schema and] table name
*
* @return array array(schema, table)
* @access private
*/
function splitTableSchema($table)
{
$ret = array();
if (strpos($table, '.') !== false) {
return explode('.', $table);
}
return array(null, $table);
}
// }}}
// {{{ getTableFieldDefinition()
/**
* Get the structure of a field into an array
*
* @param string $table name of table that should be used in method
* @param string $field name of field that should be used in method
* @return mixed data array on success, a MDB2 error on failure.
* The returned array contains an array for each field definition,
* with all or some of these indices, depending on the field data type:
* [notnull] [nativetype] [length] [fixed] [default] [type] [mdb2type]
* @access public
*/
function getTableFieldDefinition($table, $field)
{
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'method not implemented', __FUNCTION__);
}
// }}}
// {{{ getTableIndexDefinition()
/**
* Get the structure of an index into an array
*
* @param string $table name of table that should be used in method
* @param string $index name of index that should be used in method
* @return mixed data array on success, a MDB2 error on failure
* The returned array has this structure:
* </pre>
* array (
* [fields] => array (
* [field1name] => array() // one entry per each field covered
* [field2name] => array() // by the index
* [field3name] => array(
* [sorting] => ascending
* )
* )
* );
* </pre>
* @access public
*/
function getTableIndexDefinition($table, $index)
{
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'method not implemented', __FUNCTION__);
}
// }}}
// {{{ getTableConstraintDefinition()
/**
* Get the structure of an constraints into an array
*
* @param string $table name of table that should be used in method
* @param string $index name of index that should be used in method
* @return mixed data array on success, a MDB2 error on failure
* The returned array has this structure:
* <pre>
* array (
* [primary] => 0
* [unique] => 0
* [foreign] => 1
* [check] => 0
* [fields] => array (
* [field1name] => array() // one entry per each field covered
* [field2name] => array() // by the index
* [field3name] => array(
* [sorting] => ascending
* [position] => 3
* )
* )
* [references] => array(
* [table] => name
* [fields] => array(
* [field1name] => array( //one entry per each referenced field
* [position] => 1
* )
* )
* )
* [deferrable] => 0
* [initiallydeferred] => 0
* [onupdate] => CASCADE|RESTRICT|SET NULL|SET DEFAULT|NO ACTION
* [ondelete] => CASCADE|RESTRICT|SET NULL|SET DEFAULT|NO ACTION
* [match] => SIMPLE|PARTIAL|FULL
* );
* </pre>
* @access public
*/
function getTableConstraintDefinition($table, $index)
{
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'method not implemented', __FUNCTION__);
}
// }}}
// {{{ getSequenceDefinition()
/**
* Get the structure of a sequence into an array
*
* @param string $sequence name of sequence that should be used in method
* @return mixed data array on success, a MDB2 error on failure
* The returned array has this structure:
* <pre>
* array (
* [start] => n
* );
* </pre>
* @access public
*/
function getSequenceDefinition($sequence)
{
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$start = $db->currId($sequence);
if (PEAR::isError($start)) {
return $start;
}
if ($db->supports('current_id')) {
$start++;
} else {
$db->warnings[] = 'database does not support getting current
sequence value, the sequence value was incremented';
}
$definition = array();
if ($start != 1) {
$definition = array('start' => $start);
}
return $definition;
}
// }}}
// {{{ getTriggerDefinition()
/**
* Get the structure of a trigger into an array
*
* EXPERIMENTAL
*
* WARNING: this function is experimental and may change the returned value
* at any time until labelled as non-experimental
*
* @param string $trigger name of trigger that should be used in method
* @return mixed data array on success, a MDB2 error on failure
* The returned array has this structure:
* <pre>
* array (
* [trigger_name] => 'trigger name',
* [table_name] => 'table name',
* [trigger_body] => 'trigger body definition',
* [trigger_type] => 'BEFORE' | 'AFTER',
* [trigger_event] => 'INSERT' | 'UPDATE' | 'DELETE'
* //or comma separated list of multiple events, when supported
* [trigger_enabled] => true|false
* [trigger_comment] => 'trigger comment',
* );
* </pre>
* The oci8 driver also returns a [when_clause] index.
* @access public
*/
function getTriggerDefinition($trigger)
{
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'method not implemented', __FUNCTION__);
}
// }}}
// {{{ tableInfo()
/**
* Returns information about a table or a result set
*
* The format of the resulting array depends on which <var>$mode</var>
* you select. The sample output below is based on this query:
* <pre>
* SELECT tblFoo.fldID, tblFoo.fldPhone, tblBar.fldId
* FROM tblFoo
* JOIN tblBar ON tblFoo.fldId = tblBar.fldId
* </pre>
*
* <ul>
* <li>
*
* <kbd>null</kbd> (default)
* <pre>
* [0] => Array (
* [table] => tblFoo
* [name] => fldId
* [type] => int
* [len] => 11
* [flags] => primary_key not_null
* )
* [1] => Array (
* [table] => tblFoo
* [name] => fldPhone
* [type] => string
* [len] => 20
* [flags] =>
* )
* [2] => Array (
* [table] => tblBar
* [name] => fldId
* [type] => int
* [len] => 11
* [flags] => primary_key not_null
* )
* </pre>
*
* </li><li>
*
* <kbd>MDB2_TABLEINFO_ORDER</kbd>
*
* <p>In addition to the information found in the default output,
* a notation of the number of columns is provided by the
* <samp>num_fields</samp> element while the <samp>order</samp>
* element provides an array with the column names as the keys and
* their location index number (corresponding to the keys in the
* the default output) as the values.</p>
*
* <p>If a result set has identical field names, the last one is
* used.</p>
*
* <pre>
* [num_fields] => 3
* [order] => Array (
* [fldId] => 2
* [fldTrans] => 1
* )
* </pre>
*
* </li><li>
*
* <kbd>MDB2_TABLEINFO_ORDERTABLE</kbd>
*
* <p>Similar to <kbd>MDB2_TABLEINFO_ORDER</kbd> but adds more
* dimensions to the array in which the table names are keys and
* the field names are sub-keys. This is helpful for queries that
* join tables which have identical field names.</p>
*
* <pre>
* [num_fields] => 3
* [ordertable] => Array (
* [tblFoo] => Array (
* [fldId] => 0
* [fldPhone] => 1
* )
* [tblBar] => Array (
* [fldId] => 2
* )
* )
* </pre>
*
* </li>
* </ul>
*
* The <samp>flags</samp> element contains a space separated list
* of extra information about the field. This data is inconsistent
* between DBMS's due to the way each DBMS works.
* + <samp>primary_key</samp>
* + <samp>unique_key</samp>
* + <samp>multiple_key</samp>
* + <samp>not_null</samp>
*
* Most DBMS's only provide the <samp>table</samp> and <samp>flags</samp>
* elements if <var>$result</var> is a table name. The following DBMS's
* provide full information from queries:
* + fbsql
* + mysql
*
* If the 'portability' option has <samp>MDB2_PORTABILITY_FIX_CASE</samp>
* turned on, the names of tables and fields will be lower or upper cased.
*
* @param object|string $result MDB2_result object from a query or a
* string containing the name of a table.
* While this also accepts a query result
* resource identifier, this behavior is
* deprecated.
* @param int $mode either unused or one of the tableInfo modes:
* <kbd>MDB2_TABLEINFO_ORDERTABLE</kbd>,
* <kbd>MDB2_TABLEINFO_ORDER</kbd> or
* <kbd>MDB2_TABLEINFO_FULL</kbd> (which does both).
* These are bitwise, so the first two can be
* combined using <kbd>|</kbd>.
*
* @return array an associative array with the information requested.
* A MDB2_Error object on failure.
*
* @see MDB2_Driver_Common::setOption()
*/
function tableInfo($result, $mode = null)
{
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
if (!is_string($result)) {
return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'method not implemented', __FUNCTION__);
}
$db->loadModule('Manager', null, true);
$fields = $db->manager->listTableFields($result);
if (PEAR::isError($fields)) {
return $fields;
}
$flags = array();
$idxname_format = $db->getOption('idxname_format');
$db->setOption('idxname_format', '%s');
$indexes = $db->manager->listTableIndexes($result);
if (PEAR::isError($indexes)) {
$db->setOption('idxname_format', $idxname_format);
return $indexes;
}
foreach ($indexes as $index) {
$definition = $this->getTableIndexDefinition($result, $index);
if (PEAR::isError($definition)) {
$db->setOption('idxname_format', $idxname_format);
return $definition;
}
if (count($definition['fields']) > 1) {
foreach ($definition['fields'] as $field => $sort) {
$flags[$field] = 'multiple_key';
}
}
}
$constraints = $db->manager->listTableConstraints($result);
if (PEAR::isError($constraints)) {
return $constraints;
}
foreach ($constraints as $constraint) {
$definition = $this->getTableConstraintDefinition($result, $constraint);
if (PEAR::isError($definition)) {
$db->setOption('idxname_format', $idxname_format);
return $definition;
}
$flag = !empty($definition['primary'])
? 'primary_key' : (!empty($definition['unique'])
? 'unique_key' : false);
if ($flag) {
foreach ($definition['fields'] as $field => $sort) {
if (empty($flags[$field]) || $flags[$field] != 'primary_key') {
$flags[$field] = $flag;
}
}
}
}
$res = array();
if ($mode) {
$res['num_fields'] = count($fields);
}
foreach ($fields as $i => $field) {
$definition = $this->getTableFieldDefinition($result, $field);
if (PEAR::isError($definition)) {
$db->setOption('idxname_format', $idxname_format);
return $definition;
}
$res[$i] = $definition[0];
$res[$i]['name'] = $field;
$res[$i]['table'] = $result;
$res[$i]['type'] = preg_replace('/^([a-z]+).*$/i', '\\1', trim($definition[0]['nativetype']));
// 'primary_key', 'unique_key', 'multiple_key'
$res[$i]['flags'] = empty($flags[$field]) ? '' : $flags[$field];
// not_null', 'unsigned', 'auto_increment', 'default_[rawencodedvalue]'
if (!empty($res[$i]['notnull'])) {
$res[$i]['flags'].= ' not_null';
}
if (!empty($res[$i]['unsigned'])) {
$res[$i]['flags'].= ' unsigned';
}
if (!empty($res[$i]['auto_increment'])) {
$res[$i]['flags'].= ' autoincrement';
}
if (!empty($res[$i]['default'])) {
$res[$i]['flags'].= ' default_'.rawurlencode($res[$i]['default']);
}
if ($mode & MDB2_TABLEINFO_ORDER) {
$res['order'][$res[$i]['name']] = $i;
}
if ($mode & MDB2_TABLEINFO_ORDERTABLE) {
$res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
}
}
$db->setOption('idxname_format', $idxname_format);
return $res;
}
}
?>

536
3rdparty/MDB2/Driver/Reverse/mysql.php vendored Normal file
View File

@ -0,0 +1,536 @@
<?php
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2007 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. |
// | |
// | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions |
// | are met: |
// | |
// | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. |
// | |
// | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. |
// | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior|
// | written permission. |
// | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
// $Id: mysql.php,v 1.80 2008/03/26 21:15:37 quipo Exp $
//
require_once('MDB2/Driver/Reverse/Common.php');
/**
* MDB2 MySQL driver for the schema reverse engineering module
*
* @package MDB2
* @category Database
* @author Lukas Smith <smith@pooteeweet.org>
* @author Lorenzo Alberton <l.alberton@quipo.it>
*/
class MDB2_Driver_Reverse_mysql extends MDB2_Driver_Reverse_Common
{
// {{{ getTableFieldDefinition()
/**
* Get the structure of a field into an array
*
* @param string $table_name name of table that should be used in method
* @param string $field_name name of field that should be used in method
* @return mixed data array on success, a MDB2 error on failure
* @access public
*/
function getTableFieldDefinition($table_name, $field_name)
{
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$result = $db->loadModule('Datatype', null, true);
if (PEAR::isError($result)) {
return $result;
}
list($schema, $table) = $this->splitTableSchema($table_name);
$table = $db->quoteIdentifier($table, true);
$query = "SHOW FULL COLUMNS FROM $table LIKE ".$db->quote($field_name);
$columns = $db->queryAll($query, null, MDB2_FETCHMODE_ASSOC);
if (PEAR::isError($columns)) {
return $columns;
}
foreach ($columns as $column) {
$column = array_change_key_case($column, CASE_LOWER);
$column['name'] = $column['field'];
unset($column['field']);
if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
if ($db->options['field_case'] == CASE_LOWER) {
$column['name'] = strtolower($column['name']);
} else {
$column['name'] = strtoupper($column['name']);
}
} else {
$column = array_change_key_case($column, $db->options['field_case']);
}
if ($field_name == $column['name']) {
$mapped_datatype = $db->datatype->mapNativeDatatype($column);
if (PEAR::isError($mapped_datatype)) {
return $mapped_datatype;
}
list($types, $length, $unsigned, $fixed) = $mapped_datatype;
$notnull = false;
if (empty($column['null']) || $column['null'] !== 'YES') {
$notnull = true;
}
$default = false;
if (array_key_exists('default', $column)) {
$default = $column['default'];
if (is_null($default) && $notnull) {
$default = '';
}
}
$autoincrement = false;
if (!empty($column['extra']) && $column['extra'] == 'auto_increment') {
$autoincrement = true;
}
$collate = null;
if (!empty($column['collation'])) {
$collate = $column['collation'];
$charset = preg_replace('/(.+?)(_.+)?/', '$1', $collate);
}
$definition[0] = array(
'notnull' => $notnull,
'nativetype' => preg_replace('/^([a-z]+)[^a-z].*/i', '\\1', $column['type'])
);
if (!is_null($length)) {
$definition[0]['length'] = $length;
}
if (!is_null($unsigned)) {
$definition[0]['unsigned'] = $unsigned;
}
if (!is_null($fixed)) {
$definition[0]['fixed'] = $fixed;
}
if ($default !== false) {
$definition[0]['default'] = $default;
}
if ($autoincrement !== false) {
$definition[0]['autoincrement'] = $autoincrement;
}
if (!is_null($collate)) {
$definition[0]['collate'] = $collate;
$definition[0]['charset'] = $charset;
}
foreach ($types as $key => $type) {
$definition[$key] = $definition[0];
if ($type == 'clob' || $type == 'blob') {
unset($definition[$key]['default']);
} elseif ($type == 'timestamp' && $notnull && empty($definition[$key]['default'])) {
$definition[$key]['default'] = '0000-00-00 00:00:00';
}
$definition[$key]['type'] = $type;
$definition[$key]['mdb2type'] = $type;
}
return $definition;
}
}
return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
'it was not specified an existing table column', __FUNCTION__);
}
// }}}
// {{{ getTableIndexDefinition()
/**
* Get the structure of an index into an array
*
* @param string $table_name name of table that should be used in method
* @param string $index_name name of index that should be used in method
* @return mixed data array on success, a MDB2 error on failure
* @access public
*/
function getTableIndexDefinition($table_name, $index_name)
{
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
list($schema, $table) = $this->splitTableSchema($table_name);
$table = $db->quoteIdentifier($table, true);
$query = "SHOW INDEX FROM $table /*!50002 WHERE Key_name = %s */";
$index_name_mdb2 = $db->getIndexName($index_name);
$result = $db->queryRow(sprintf($query, $db->quote($index_name_mdb2)));
if (!PEAR::isError($result) && !is_null($result)) {
// apply 'idxname_format' only if the query succeeded, otherwise
// fallback to the given $index_name, without transformation
$index_name = $index_name_mdb2;
}
$result = $db->query(sprintf($query, $db->quote($index_name)));
if (PEAR::isError($result)) {
return $result;
}
$colpos = 1;
$definition = array();
while (is_array($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))) {
$row = array_change_key_case($row, CASE_LOWER);
$key_name = $row['key_name'];
if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
if ($db->options['field_case'] == CASE_LOWER) {
$key_name = strtolower($key_name);
} else {
$key_name = strtoupper($key_name);
}
}
if ($index_name == $key_name) {
if (!$row['non_unique']) {
return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
$index_name . ' is not an existing table index', __FUNCTION__);
}
$column_name = $row['column_name'];
if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
if ($db->options['field_case'] == CASE_LOWER) {
$column_name = strtolower($column_name);
} else {
$column_name = strtoupper($column_name);
}
}
$definition['fields'][$column_name] = array(
'position' => $colpos++
);
if (!empty($row['collation'])) {
$definition['fields'][$column_name]['sorting'] = ($row['collation'] == 'A'
? 'ascending' : 'descending');
}
}
}
$result->free();
if (empty($definition['fields'])) {
return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
$index_name . ' is not an existing table index', __FUNCTION__);
}
return $definition;
}
// }}}
// {{{ getTableConstraintDefinition()
/**
* Get the structure of a constraint into an array
*
* @param string $table_name name of table that should be used in method
* @param string $constraint_name name of constraint that should be used in method
* @return mixed data array on success, a MDB2 error on failure
* @access public
*/
function getTableConstraintDefinition($table_name, $constraint_name)
{
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
list($schema, $table) = $this->splitTableSchema($table_name);
$constraint_name_original = $constraint_name;
$table = $db->quoteIdentifier($table, true);
$query = "SHOW INDEX FROM $table /*!50002 WHERE Key_name = %s */";
if (strtolower($constraint_name) != 'primary') {
$constraint_name_mdb2 = $db->getIndexName($constraint_name);
$result = $db->queryRow(sprintf($query, $db->quote($constraint_name_mdb2)));
if (!PEAR::isError($result) && !is_null($result)) {
// apply 'idxname_format' only if the query succeeded, otherwise
// fallback to the given $index_name, without transformation
$constraint_name = $constraint_name_mdb2;
}
}
$result = $db->query(sprintf($query, $db->quote($constraint_name)));
if (PEAR::isError($result)) {
return $result;
}
$colpos = 1;
//default values, eventually overridden
$definition = array(
'primary' => false,
'unique' => false,
'foreign' => false,
'check' => false,
'fields' => array(),
'references' => array(
'table' => '',
'fields' => array(),
),
'onupdate' => '',
'ondelete' => '',
'match' => '',
'deferrable' => false,
'initiallydeferred' => false,
);
while (is_array($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))) {
$row = array_change_key_case($row, CASE_LOWER);
$key_name = $row['key_name'];
if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
if ($db->options['field_case'] == CASE_LOWER) {
$key_name = strtolower($key_name);
} else {
$key_name = strtoupper($key_name);
}
}
if ($constraint_name == $key_name) {
if ($row['non_unique']) {
//FOREIGN KEY?
return $this->_getTableFKConstraintDefinition($table, $constraint_name_original, $definition);
}
if ($row['key_name'] == 'PRIMARY') {
$definition['primary'] = true;
} elseif (!$row['non_unique']) {
$definition['unique'] = true;
}
$column_name = $row['column_name'];
if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
if ($db->options['field_case'] == CASE_LOWER) {
$column_name = strtolower($column_name);
} else {
$column_name = strtoupper($column_name);
}
}
$definition['fields'][$column_name] = array(
'position' => $colpos++
);
if (!empty($row['collation'])) {
$definition['fields'][$column_name]['sorting'] = ($row['collation'] == 'A'
? 'ascending' : 'descending');
}
}
}
$result->free();
if (empty($definition['fields'])) {
return $this->_getTableFKConstraintDefinition($table, $constraint_name_original, $definition);
}
return $definition;
}
// }}}
// {{{ _getTableFKConstraintDefinition()
/**
* Get the FK definition from the CREATE TABLE statement
*
* @param string $table table name
* @param string $constraint_name constraint name
* @param array $definition default values for constraint definition
*
* @return array|PEAR_Error
* @access private
*/
function _getTableFKConstraintDefinition($table, $constraint_name, $definition)
{
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$query = 'SHOW CREATE TABLE '. $db->escape($table);
$constraint = $db->queryOne($query, 'text', 1);
if (!PEAR::isError($constraint) && !empty($constraint)) {
if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
if ($db->options['field_case'] == CASE_LOWER) {
$constraint = strtolower($constraint);
} else {
$constraint = strtoupper($constraint);
}
}
$constraint_name_original = $constraint_name;
$constraint_name = $db->getIndexName($constraint_name);
$pattern = '/\bCONSTRAINT\s+'.$constraint_name.'\s+FOREIGN KEY\s+\(([^\)]+)\) \bREFERENCES\b ([^ ]+) \(([^\)]+)\)/i';
if (!preg_match($pattern, str_replace('`', '', $constraint), $matches)) {
//fallback to original constraint name
$pattern = '/\bCONSTRAINT\s+'.$constraint_name_original.'\s+FOREIGN KEY\s+\(([^\)]+)\) \bREFERENCES\b ([^ ]+) \(([^\)]+)\)/i';
}
if (preg_match($pattern, str_replace('`', '', $constraint), $matches)) {
$definition['foreign'] = true;
$column_names = explode(',', $matches[1]);
$referenced_cols = explode(',', $matches[3]);
$definition['references'] = array(
'table' => $matches[2],
'fields' => array(),
);
$colpos = 1;
foreach ($column_names as $column_name) {
$definition['fields'][trim($column_name)] = array(
'position' => $colpos++
);
}
$colpos = 1;
foreach ($referenced_cols as $column_name) {
$definition['references']['fields'][trim($column_name)] = array(
'position' => $colpos++
);
}
$definition['onupdate'] = 'NO ACTION';
$definition['ondelete'] = 'NO ACTION';
$definition['match'] = 'SIMPLE';
return $definition;
}
}
return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
$constraint_name . ' is not an existing table constraint', __FUNCTION__);
}
// }}}
// {{{ getTriggerDefinition()
/**
* Get the structure of a trigger into an array
*
* EXPERIMENTAL
*
* WARNING: this function is experimental and may change the returned value
* at any time until labelled as non-experimental
*
* @param string $trigger name of trigger that should be used in method
* @return mixed data array on success, a MDB2 error on failure
* @access public
*/
function getTriggerDefinition($trigger)
{
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$query = 'SELECT trigger_name,
event_object_table AS table_name,
action_statement AS trigger_body,
action_timing AS trigger_type,
event_manipulation AS trigger_event
FROM information_schema.triggers
WHERE trigger_name = '. $db->quote($trigger, 'text');
$types = array(
'trigger_name' => 'text',
'table_name' => 'text',
'trigger_body' => 'text',
'trigger_type' => 'text',
'trigger_event' => 'text',
);
$def = $db->queryRow($query, $types, MDB2_FETCHMODE_ASSOC);
if (PEAR::isError($def)) {
return $def;
}
$def['trigger_comment'] = '';
$def['trigger_enabled'] = true;
return $def;
}
// }}}
// {{{ tableInfo()
/**
* Returns information about a table or a result set
*
* @param object|string $result MDB2_result object from a query or a
* string containing the name of a table.
* While this also accepts a query result
* resource identifier, this behavior is
* deprecated.
* @param int $mode a valid tableInfo mode
*
* @return array an associative array with the information requested.
* A MDB2_Error object on failure.
*
* @see MDB2_Driver_Common::setOption()
*/
function tableInfo($result, $mode = null)
{
if (is_string($result)) {
return parent::tableInfo($result, $mode);
}
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$resource = MDB2::isResultCommon($result) ? $result->getResource() : $result;
if (!is_resource($resource)) {
return $db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null,
'Could not generate result resource', __FUNCTION__);
}
if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
if ($db->options['field_case'] == CASE_LOWER) {
$case_func = 'strtolower';
} else {
$case_func = 'strtoupper';
}
} else {
$case_func = 'strval';
}
$count = @mysql_num_fields($resource);
$res = array();
if ($mode) {
$res['num_fields'] = $count;
}
$db->loadModule('Datatype', null, true);
for ($i = 0; $i < $count; $i++) {
$res[$i] = array(
'table' => $case_func(@mysql_field_table($resource, $i)),
'name' => $case_func(@mysql_field_name($resource, $i)),
'type' => @mysql_field_type($resource, $i),
'length' => @mysql_field_len($resource, $i),
'flags' => @mysql_field_flags($resource, $i),
);
if ($res[$i]['type'] == 'string') {
$res[$i]['type'] = 'char';
} elseif ($res[$i]['type'] == 'unknown') {
$res[$i]['type'] = 'decimal';
}
$mdb2type_info = $db->datatype->mapNativeDatatype($res[$i]);
if (PEAR::isError($mdb2type_info)) {
return $mdb2type_info;
}
$res[$i]['mdb2type'] = $mdb2type_info[0][0];
if ($mode & MDB2_TABLEINFO_ORDER) {
$res['order'][$res[$i]['name']] = $i;
}
if ($mode & MDB2_TABLEINFO_ORDERTABLE) {
$res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
}
}
return $res;
}
}
?>

573
3rdparty/MDB2/Driver/Reverse/pgsql.php vendored Normal file
View File

@ -0,0 +1,573 @@
<?php
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2008 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. |
// | |
// | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions |
// | are met: |
// | |
// | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. |
// | |
// | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. |
// | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior|
// | written permission. |
// | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+
// | Authors: Paul Cooper <pgc@ucecom.com> |
// | Lorenzo Alberton <l.alberton@quipo.it> |
// +----------------------------------------------------------------------+
//
// $Id: pgsql.php,v 1.75 2008/08/22 16:36:20 quipo Exp $
require_once('MDB2/Driver/Reverse/Common.php');
/**
* MDB2 PostGreSQL driver for the schema reverse engineering module
*
* @package MDB2
* @category Database
* @author Paul Cooper <pgc@ucecom.com>
* @author Lorenzo Alberton <l.alberton@quipo.it>
*/
class MDB2_Driver_Reverse_pgsql extends MDB2_Driver_Reverse_Common
{
// {{{ getTableFieldDefinition()
/**
* Get the structure of a field into an array
*
* @param string $table_name name of table that should be used in method
* @param string $field_name name of field that should be used in method
* @return mixed data array on success, a MDB2 error on failure
* @access public
*/
function getTableFieldDefinition($table_name, $field_name)
{
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$result = $db->loadModule('Datatype', null, true);
if (PEAR::isError($result)) {
return $result;
}
list($schema, $table) = $this->splitTableSchema($table_name);
$query = "SELECT a.attname AS name,
t.typname AS type,
CASE a.attlen
WHEN -1 THEN
CASE t.typname
WHEN 'numeric' THEN (a.atttypmod / 65536)
WHEN 'decimal' THEN (a.atttypmod / 65536)
WHEN 'money' THEN (a.atttypmod / 65536)
ELSE CASE a.atttypmod
WHEN -1 THEN NULL
ELSE a.atttypmod - 4
END
END
ELSE a.attlen
END AS length,
CASE t.typname
WHEN 'numeric' THEN (a.atttypmod % 65536) - 4
WHEN 'decimal' THEN (a.atttypmod % 65536) - 4
WHEN 'money' THEN (a.atttypmod % 65536) - 4
ELSE 0
END AS scale,
a.attnotnull,
a.atttypmod,
a.atthasdef,
(SELECT substring(pg_get_expr(d.adbin, d.adrelid) for 128)
FROM pg_attrdef d
WHERE d.adrelid = a.attrelid
AND d.adnum = a.attnum
AND a.atthasdef
) as default
FROM pg_attribute a,
pg_class c,
pg_type t
WHERE c.relname = ".$db->quote($table, 'text')."
AND a.atttypid = t.oid
AND c.oid = a.attrelid
AND NOT a.attisdropped
AND a.attnum > 0
AND a.attname = ".$db->quote($field_name, 'text')."
ORDER BY a.attnum";
$column = $db->queryRow($query, null, MDB2_FETCHMODE_ASSOC);
if (PEAR::isError($column)) {
return $column;
}
if (empty($column)) {
return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
'it was not specified an existing table column', __FUNCTION__);
}
$column = array_change_key_case($column, CASE_LOWER);
$mapped_datatype = $db->datatype->mapNativeDatatype($column);
if (PEAR::isError($mapped_datatype)) {
return $mapped_datatype;
}
list($types, $length, $unsigned, $fixed) = $mapped_datatype;
$notnull = false;
if (!empty($column['attnotnull']) && $column['attnotnull'] == 't') {
$notnull = true;
}
$default = null;
if ($column['atthasdef'] === 't'
&& !preg_match("/nextval\('([^']+)'/", $column['default'])
) {
$pattern = '/^\'(.*)\'::[\w ]+$/i';
$default = $column['default'];#substr($column['adsrc'], 1, -1);
if (is_null($default) && $notnull) {
$default = '';
} elseif (!empty($default) && preg_match($pattern, $default)) {
//remove data type cast
$default = preg_replace ($pattern, '\\1', $default);
}
}
$autoincrement = false;
if (preg_match("/nextval\('([^']+)'/", $column['default'], $nextvals)) {
$autoincrement = true;
}
$definition[0] = array('notnull' => $notnull, 'nativetype' => $column['type']);
if (!is_null($length)) {
$definition[0]['length'] = $length;
}
if (!is_null($unsigned)) {
$definition[0]['unsigned'] = $unsigned;
}
if (!is_null($fixed)) {
$definition[0]['fixed'] = $fixed;
}
if ($default !== false) {
$definition[0]['default'] = $default;
}
if ($autoincrement !== false) {
$definition[0]['autoincrement'] = $autoincrement;
}
foreach ($types as $key => $type) {
$definition[$key] = $definition[0];
if ($type == 'clob' || $type == 'blob') {
unset($definition[$key]['default']);
}
$definition[$key]['type'] = $type;
$definition[$key]['mdb2type'] = $type;
}
return $definition;
}
// }}}
// {{{ getTableIndexDefinition()
/**
* Get the structure of an index into an array
*
* @param string $table_name name of table that should be used in method
* @param string $index_name name of index that should be used in method
* @return mixed data array on success, a MDB2 error on failure
* @access public
*/
function getTableIndexDefinition($table_name, $index_name)
{
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
list($schema, $table) = $this->splitTableSchema($table_name);
$query = 'SELECT relname, indkey FROM pg_index, pg_class';
$query.= ' WHERE pg_class.oid = pg_index.indexrelid';
$query.= " AND indisunique != 't' AND indisprimary != 't'";
$query.= ' AND pg_class.relname = %s';
$index_name_mdb2 = $db->getIndexName($index_name);
$row = $db->queryRow(sprintf($query, $db->quote($index_name_mdb2, 'text')), null, MDB2_FETCHMODE_ASSOC);
if (PEAR::isError($row) || empty($row)) {
// fallback to the given $index_name, without transformation
$row = $db->queryRow(sprintf($query, $db->quote($index_name, 'text')), null, MDB2_FETCHMODE_ASSOC);
}
if (PEAR::isError($row)) {
return $row;
}
if (empty($row)) {
return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
'it was not specified an existing table index', __FUNCTION__);
}
$row = array_change_key_case($row, CASE_LOWER);
$db->loadModule('Manager', null, true);
$columns = $db->manager->listTableFields($table_name);
$definition = array();
$index_column_numbers = explode(' ', $row['indkey']);
$colpos = 1;
foreach ($index_column_numbers as $number) {
$definition['fields'][$columns[($number - 1)]] = array(
'position' => $colpos++,
'sorting' => 'ascending',
);
}
return $definition;
}
// }}}
// {{{ getTableConstraintDefinition()
/**
* Get the structure of a constraint into an array
*
* @param string $table_name name of table that should be used in method
* @param string $constraint_name name of constraint that should be used in method
* @return mixed data array on success, a MDB2 error on failure
* @access public
*/
function getTableConstraintDefinition($table_name, $constraint_name)
{
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
list($schema, $table) = $this->splitTableSchema($table_name);
$query = "SELECT c.oid,
c.conname AS constraint_name,
CASE WHEN c.contype = 'c' THEN 1 ELSE 0 END AS \"check\",
CASE WHEN c.contype = 'f' THEN 1 ELSE 0 END AS \"foreign\",
CASE WHEN c.contype = 'p' THEN 1 ELSE 0 END AS \"primary\",
CASE WHEN c.contype = 'u' THEN 1 ELSE 0 END AS \"unique\",
CASE WHEN c.condeferrable = 'f' THEN 0 ELSE 1 END AS deferrable,
CASE WHEN c.condeferred = 'f' THEN 0 ELSE 1 END AS initiallydeferred,
--array_to_string(c.conkey, ' ') AS constraint_key,
t.relname AS table_name,
t2.relname AS references_table,
CASE confupdtype
WHEN 'a' THEN 'NO ACTION'
WHEN 'r' THEN 'RESTRICT'
WHEN 'c' THEN 'CASCADE'
WHEN 'n' THEN 'SET NULL'
WHEN 'd' THEN 'SET DEFAULT'
END AS onupdate,
CASE confdeltype
WHEN 'a' THEN 'NO ACTION'
WHEN 'r' THEN 'RESTRICT'
WHEN 'c' THEN 'CASCADE'
WHEN 'n' THEN 'SET NULL'
WHEN 'd' THEN 'SET DEFAULT'
END AS ondelete,
CASE confmatchtype
WHEN 'u' THEN 'UNSPECIFIED'
WHEN 'f' THEN 'FULL'
WHEN 'p' THEN 'PARTIAL'
END AS match,
--array_to_string(c.confkey, ' ') AS fk_constraint_key,
consrc
FROM pg_constraint c
LEFT JOIN pg_class t ON c.conrelid = t.oid
LEFT JOIN pg_class t2 ON c.confrelid = t2.oid
WHERE c.conname = %s
AND t.relname = " . $db->quote($table, 'text');
$constraint_name_mdb2 = $db->getIndexName($constraint_name);
$row = $db->queryRow(sprintf($query, $db->quote($constraint_name_mdb2, 'text')), null, MDB2_FETCHMODE_ASSOC);
if (PEAR::isError($row) || empty($row)) {
// fallback to the given $index_name, without transformation
$constraint_name_mdb2 = $constraint_name;
$row = $db->queryRow(sprintf($query, $db->quote($constraint_name_mdb2, 'text')), null, MDB2_FETCHMODE_ASSOC);
}
if (PEAR::isError($row)) {
return $row;
}
$uniqueIndex = false;
if (empty($row)) {
// We might be looking for a UNIQUE index that was not created
// as a constraint but should be treated as such.
$query = 'SELECT relname AS constraint_name,
indkey,
0 AS "check",
0 AS "foreign",
0 AS "primary",
1 AS "unique",
0 AS deferrable,
0 AS initiallydeferred,
NULL AS references_table,
NULL AS onupdate,
NULL AS ondelete,
NULL AS match
FROM pg_index, pg_class
WHERE pg_class.oid = pg_index.indexrelid
AND indisunique = \'t\'
AND pg_class.relname = %s';
$constraint_name_mdb2 = $db->getIndexName($constraint_name);
$row = $db->queryRow(sprintf($query, $db->quote($constraint_name_mdb2, 'text')), null, MDB2_FETCHMODE_ASSOC);
if (PEAR::isError($row) || empty($row)) {
// fallback to the given $index_name, without transformation
$constraint_name_mdb2 = $constraint_name;
$row = $db->queryRow(sprintf($query, $db->quote($constraint_name_mdb2, 'text')), null, MDB2_FETCHMODE_ASSOC);
}
if (PEAR::isError($row)) {
return $row;
}
if (empty($row)) {
return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
$constraint_name . ' is not an existing table constraint', __FUNCTION__);
}
$uniqueIndex = true;
}
$row = array_change_key_case($row, CASE_LOWER);
$definition = array(
'primary' => (boolean)$row['primary'],
'unique' => (boolean)$row['unique'],
'foreign' => (boolean)$row['foreign'],
'check' => (boolean)$row['check'],
'fields' => array(),
'references' => array(
'table' => $row['references_table'],
'fields' => array(),
),
'deferrable' => (boolean)$row['deferrable'],
'initiallydeferred' => (boolean)$row['initiallydeferred'],
'onupdate' => $row['onupdate'],
'ondelete' => $row['ondelete'],
'match' => $row['match'],
);
if ($uniqueIndex) {
$db->loadModule('Manager', null, true);
$columns = $db->manager->listTableFields($table_name);
$index_column_numbers = explode(' ', $row['indkey']);
$colpos = 1;
foreach ($index_column_numbers as $number) {
$definition['fields'][$columns[($number - 1)]] = array(
'position' => $colpos++,
'sorting' => 'ascending',
);
}
return $definition;
}
$query = 'SELECT a.attname
FROM pg_constraint c
LEFT JOIN pg_class t ON c.conrelid = t.oid
LEFT JOIN pg_attribute a ON a.attrelid = t.oid AND a.attnum = ANY(c.conkey)
WHERE c.conname = %s
AND t.relname = ' . $db->quote($table, 'text');
$fields = $db->queryCol(sprintf($query, $db->quote($constraint_name_mdb2, 'text')), null);
if (PEAR::isError($fields)) {
return $fields;
}
$colpos = 1;
foreach ($fields as $field) {
$definition['fields'][$field] = array(
'position' => $colpos++,
'sorting' => 'ascending',
);
}
if ($definition['foreign']) {
$query = 'SELECT a.attname
FROM pg_constraint c
LEFT JOIN pg_class t ON c.confrelid = t.oid
LEFT JOIN pg_attribute a ON a.attrelid = t.oid AND a.attnum = ANY(c.confkey)
WHERE c.conname = %s
AND t.relname = ' . $db->quote($definition['references']['table'], 'text');
$foreign_fields = $db->queryCol(sprintf($query, $db->quote($constraint_name_mdb2, 'text')), null);
if (PEAR::isError($foreign_fields)) {
return $foreign_fields;
}
$colpos = 1;
foreach ($foreign_fields as $foreign_field) {
$definition['references']['fields'][$foreign_field] = array(
'position' => $colpos++,
);
}
}
if ($definition['check']) {
$check_def = $db->queryOne("SELECT pg_get_constraintdef(" . $row['oid'] . ", 't')");
// ...
}
return $definition;
}
// }}}
// {{{ getTriggerDefinition()
/**
* Get the structure of a trigger into an array
*
* EXPERIMENTAL
*
* WARNING: this function is experimental and may change the returned value
* at any time until labelled as non-experimental
*
* @param string $trigger name of trigger that should be used in method
* @return mixed data array on success, a MDB2 error on failure
* @access public
*
* @TODO: add support for plsql functions and functions with args
*/
function getTriggerDefinition($trigger)
{
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$query = "SELECT trg.tgname AS trigger_name,
tbl.relname AS table_name,
CASE
WHEN p.proname IS NOT NULL THEN 'EXECUTE PROCEDURE ' || p.proname || '();'
ELSE ''
END AS trigger_body,
CASE trg.tgtype & cast(2 as int2)
WHEN 0 THEN 'AFTER'
ELSE 'BEFORE'
END AS trigger_type,
CASE trg.tgtype & cast(28 as int2)
WHEN 16 THEN 'UPDATE'
WHEN 8 THEN 'DELETE'
WHEN 4 THEN 'INSERT'
WHEN 20 THEN 'INSERT, UPDATE'
WHEN 28 THEN 'INSERT, UPDATE, DELETE'
WHEN 24 THEN 'UPDATE, DELETE'
WHEN 12 THEN 'INSERT, DELETE'
END AS trigger_event,
CASE trg.tgenabled
WHEN 'O' THEN 't'
ELSE trg.tgenabled
END AS trigger_enabled,
obj_description(trg.oid, 'pg_trigger') AS trigger_comment
FROM pg_trigger trg,
pg_class tbl,
pg_proc p
WHERE trg.tgrelid = tbl.oid
AND trg.tgfoid = p.oid
AND trg.tgname = ". $db->quote($trigger, 'text');
$types = array(
'trigger_name' => 'text',
'table_name' => 'text',
'trigger_body' => 'text',
'trigger_type' => 'text',
'trigger_event' => 'text',
'trigger_comment' => 'text',
'trigger_enabled' => 'boolean',
);
return $db->queryRow($query, $types, MDB2_FETCHMODE_ASSOC);
}
// }}}
// {{{ tableInfo()
/**
* Returns information about a table or a result set
*
* NOTE: only supports 'table' and 'flags' if <var>$result</var>
* is a table name.
*
* @param object|string $result MDB2_result object from a query or a
* string containing the name of a table.
* While this also accepts a query result
* resource identifier, this behavior is
* deprecated.
* @param int $mode a valid tableInfo mode
*
* @return array an associative array with the information requested.
* A MDB2_Error object on failure.
*
* @see MDB2_Driver_Common::tableInfo()
*/
function tableInfo($result, $mode = null)
{
if (is_string($result)) {
return parent::tableInfo($result, $mode);
}
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$resource = MDB2::isResultCommon($result) ? $result->getResource() : $result;
if (!is_resource($resource)) {
return $db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null,
'Could not generate result resource', __FUNCTION__);
}
if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
if ($db->options['field_case'] == CASE_LOWER) {
$case_func = 'strtolower';
} else {
$case_func = 'strtoupper';
}
} else {
$case_func = 'strval';
}
$count = @pg_num_fields($resource);
$res = array();
if ($mode) {
$res['num_fields'] = $count;
}
$db->loadModule('Datatype', null, true);
for ($i = 0; $i < $count; $i++) {
$res[$i] = array(
'table' => function_exists('pg_field_table') ? @pg_field_table($resource, $i) : '',
'name' => $case_func(@pg_field_name($resource, $i)),
'type' => @pg_field_type($resource, $i),
'length' => @pg_field_size($resource, $i),
'flags' => '',
);
$mdb2type_info = $db->datatype->mapNativeDatatype($res[$i]);
if (PEAR::isError($mdb2type_info)) {
return $mdb2type_info;
}
$res[$i]['mdb2type'] = $mdb2type_info[0][0];
if ($mode & MDB2_TABLEINFO_ORDER) {
$res['order'][$res[$i]['name']] = $i;
}
if ($mode & MDB2_TABLEINFO_ORDERTABLE) {
$res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
}
}
return $res;
}
}
?>

609
3rdparty/MDB2/Driver/Reverse/sqlite.php vendored Normal file
View File

@ -0,0 +1,609 @@
<?php
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2007 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith, Lorenzo Alberton |
// | All rights reserved. |
// +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. |
// | |
// | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions |
// | are met: |
// | |
// | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. |
// | |
// | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. |
// | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior|
// | written permission. |
// | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+
// | Authors: Lukas Smith <smith@pooteeweet.org> |
// | Lorenzo Alberton <l.alberton@quipo.it> |
// +----------------------------------------------------------------------+
//
// $Id: sqlite.php,v 1.80 2008/05/03 10:30:14 quipo Exp $
//
require_once('MDB2/Driver/Reverse/Common.php');
/**
* MDB2 SQlite driver for the schema reverse engineering module
*
* @package MDB2
* @category Database
* @author Lukas Smith <smith@pooteeweet.org>
*/
class MDB2_Driver_Reverse_sqlite extends MDB2_Driver_Reverse_Common
{
/**
* Remove SQL comments from the field definition
*
* @access private
*/
function _removeComments($sql) {
$lines = explode("\n", $sql);
foreach ($lines as $k => $line) {
$pieces = explode('--', $line);
if (count($pieces) > 1 && (substr_count($pieces[0], '\'') % 2) == 0) {
$lines[$k] = substr($line, 0, strpos($line, '--'));
}
}
return implode("\n", $lines);
}
/**
*
*/
function _getTableColumns($sql)
{
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$start_pos = strpos($sql, '(');
$end_pos = strrpos($sql, ')');
$column_def = substr($sql, $start_pos+1, $end_pos-$start_pos-1);
// replace the decimal length-places-separator with a colon
$column_def = preg_replace('/(\d),(\d)/', '\1:\2', $column_def);
$column_def = $this->_removeComments($column_def);
$column_sql = explode(',', $column_def);
$columns = array();
$count = count($column_sql);
if ($count == 0) {
return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'unexpected empty table column definition list', __FUNCTION__);
}
$regexp = '/^\s*([^\s]+) +(CHAR|VARCHAR|VARCHAR2|TEXT|BOOLEAN|SMALLINT|INT|INTEGER|DECIMAL|BIGINT|DOUBLE|FLOAT|DATETIME|DATE|TIME|LONGTEXT|LONGBLOB)( ?\(([1-9][0-9]*)(:([1-9][0-9]*))?\))?( NULL| NOT NULL)?( UNSIGNED)?( NULL| NOT NULL)?( PRIMARY KEY)?( DEFAULT (\'[^\']*\'|[^ ]+))?( NULL| NOT NULL)?( PRIMARY KEY)?(\s*\-\-.*)?$/i';
$regexp2 = '/^\s*([^ ]+) +(PRIMARY|UNIQUE|CHECK)$/i';
for ($i=0, $j=0; $i<$count; ++$i) {
if (!preg_match($regexp, trim($column_sql[$i]), $matches)) {
if (!preg_match($regexp2, trim($column_sql[$i]))) {
continue;
}
return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'unexpected table column SQL definition: "'.$column_sql[$i].'"', __FUNCTION__);
}
$columns[$j]['name'] = trim($matches[1], implode('', $db->identifier_quoting));
$columns[$j]['type'] = strtolower($matches[2]);
if (isset($matches[4]) && strlen($matches[4])) {
$columns[$j]['length'] = $matches[4];
}
if (isset($matches[6]) && strlen($matches[6])) {
$columns[$j]['decimal'] = $matches[6];
}
if (isset($matches[8]) && strlen($matches[8])) {
$columns[$j]['unsigned'] = true;
}
if (isset($matches[9]) && strlen($matches[9])) {
$columns[$j]['autoincrement'] = true;
}
if (isset($matches[12]) && strlen($matches[12])) {
$default = $matches[12];
if (strlen($default) && $default[0]=="'") {
$default = str_replace("''", "'", substr($default, 1, strlen($default)-2));
}
if ($default === 'NULL') {
$default = null;
}
$columns[$j]['default'] = $default;
}
if (isset($matches[7]) && strlen($matches[7])) {
$columns[$j]['notnull'] = ($matches[7] === ' NOT NULL');
} else if (isset($matches[9]) && strlen($matches[9])) {
$columns[$j]['notnull'] = ($matches[9] === ' NOT NULL');
} else if (isset($matches[13]) && strlen($matches[13])) {
$columns[$j]['notnull'] = ($matches[13] === ' NOT NULL');
}
++$j;
}
return $columns;
}
// {{{ getTableFieldDefinition()
/**
* Get the stucture of a field into an array
*
* @param string $table_name name of table that should be used in method
* @param string $field_name name of field that should be used in method
* @return mixed data array on success, a MDB2 error on failure.
* The returned array contains an array for each field definition,
* with (some of) these indices:
* [notnull] [nativetype] [length] [fixed] [default] [type] [mdb2type]
* @access public
*/
function getTableFieldDefinition($table_name, $field_name)
{
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
list($schema, $table) = $this->splitTableSchema($table_name);
$result = $db->loadModule('Datatype', null, true);
if (PEAR::isError($result)) {
return $result;
}
$query = "SELECT sql FROM sqlite_master WHERE type='table' AND ";
if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
$query.= 'LOWER(name)='.$db->quote(strtolower($table), 'text');
} else {
$query.= 'name='.$db->quote($table, 'text');
}
$sql = $db->queryOne($query);
if (PEAR::isError($sql)) {
return $sql;
}
$columns = $this->_getTableColumns($sql);
foreach ($columns as $column) {
if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
if ($db->options['field_case'] == CASE_LOWER) {
$column['name'] = strtolower($column['name']);
} else {
$column['name'] = strtoupper($column['name']);
}
} else {
$column = array_change_key_case($column, $db->options['field_case']);
}
if ($field_name == $column['name']) {
$mapped_datatype = $db->datatype->mapNativeDatatype($column);
if (PEAR::isError($mapped_datatype)) {
return $mapped_datatype;
}
list($types, $length, $unsigned, $fixed) = $mapped_datatype;
$notnull = false;
if (!empty($column['notnull'])) {
$notnull = $column['notnull'];
}
$default = false;
if (array_key_exists('default', $column)) {
$default = $column['default'];
if (is_null($default) && $notnull) {
$default = '';
}
}
$autoincrement = false;
if (!empty($column['autoincrement'])) {
$autoincrement = true;
}
$definition[0] = array(
'notnull' => $notnull,
'nativetype' => preg_replace('/^([a-z]+)[^a-z].*/i', '\\1', $column['type'])
);
if (!is_null($length)) {
$definition[0]['length'] = $length;
}
if (!is_null($unsigned)) {
$definition[0]['unsigned'] = $unsigned;
}
if (!is_null($fixed)) {
$definition[0]['fixed'] = $fixed;
}
if ($default !== false) {
$definition[0]['default'] = $default;
}
if ($autoincrement !== false) {
$definition[0]['autoincrement'] = $autoincrement;
}
foreach ($types as $key => $type) {
$definition[$key] = $definition[0];
if ($type == 'clob' || $type == 'blob') {
unset($definition[$key]['default']);
}
$definition[$key]['type'] = $type;
$definition[$key]['mdb2type'] = $type;
}
return $definition;
}
}
return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
'it was not specified an existing table column', __FUNCTION__);
}
// }}}
// {{{ getTableIndexDefinition()
/**
* Get the stucture of an index into an array
*
* @param string $table_name name of table that should be used in method
* @param string $index_name name of index that should be used in method
* @return mixed data array on success, a MDB2 error on failure
* @access public
*/
function getTableIndexDefinition($table_name, $index_name)
{
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
list($schema, $table) = $this->splitTableSchema($table_name);
$query = "SELECT sql FROM sqlite_master WHERE type='index' AND ";
if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
$query.= 'LOWER(name)=%s AND LOWER(tbl_name)=' . $db->quote(strtolower($table), 'text');
} else {
$query.= 'name=%s AND tbl_name=' . $db->quote($table, 'text');
}
$query.= ' AND sql NOT NULL ORDER BY name';
$index_name_mdb2 = $db->getIndexName($index_name);
if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
$qry = sprintf($query, $db->quote(strtolower($index_name_mdb2), 'text'));
} else {
$qry = sprintf($query, $db->quote($index_name_mdb2, 'text'));
}
$sql = $db->queryOne($qry, 'text');
if (PEAR::isError($sql) || empty($sql)) {
// fallback to the given $index_name, without transformation
if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
$qry = sprintf($query, $db->quote(strtolower($index_name), 'text'));
} else {
$qry = sprintf($query, $db->quote($index_name, 'text'));
}
$sql = $db->queryOne($qry, 'text');
}
if (PEAR::isError($sql)) {
return $sql;
}
if (!$sql) {
return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
'it was not specified an existing table index', __FUNCTION__);
}
$sql = strtolower($sql);
$start_pos = strpos($sql, '(');
$end_pos = strrpos($sql, ')');
$column_names = substr($sql, $start_pos+1, $end_pos-$start_pos-1);
$column_names = explode(',', $column_names);
if (preg_match("/^create unique/", $sql)) {
return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
'it was not specified an existing table index', __FUNCTION__);
}
$definition = array();
$count = count($column_names);
for ($i=0; $i<$count; ++$i) {
$column_name = strtok($column_names[$i], ' ');
$collation = strtok(' ');
$definition['fields'][$column_name] = array(
'position' => $i+1
);
if (!empty($collation)) {
$definition['fields'][$column_name]['sorting'] =
($collation=='ASC' ? 'ascending' : 'descending');
}
}
if (empty($definition['fields'])) {
return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
'it was not specified an existing table index', __FUNCTION__);
}
return $definition;
}
// }}}
// {{{ getTableConstraintDefinition()
/**
* Get the stucture of a constraint into an array
*
* @param string $table_name name of table that should be used in method
* @param string $constraint_name name of constraint that should be used in method
* @return mixed data array on success, a MDB2 error on failure
* @access public
*/
function getTableConstraintDefinition($table_name, $constraint_name)
{
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
list($schema, $table) = $this->splitTableSchema($table_name);
$query = "SELECT sql FROM sqlite_master WHERE type='index' AND ";
if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
$query.= 'LOWER(name)=%s AND LOWER(tbl_name)=' . $db->quote(strtolower($table), 'text');
} else {
$query.= 'name=%s AND tbl_name=' . $db->quote($table, 'text');
}
$query.= ' AND sql NOT NULL ORDER BY name';
$constraint_name_mdb2 = $db->getIndexName($constraint_name);
if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
$qry = sprintf($query, $db->quote(strtolower($constraint_name_mdb2), 'text'));
} else {
$qry = sprintf($query, $db->quote($constraint_name_mdb2, 'text'));
}
$sql = $db->queryOne($qry, 'text');
if (PEAR::isError($sql) || empty($sql)) {
// fallback to the given $index_name, without transformation
if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
$qry = sprintf($query, $db->quote(strtolower($constraint_name), 'text'));
} else {
$qry = sprintf($query, $db->quote($constraint_name, 'text'));
}
$sql = $db->queryOne($qry, 'text');
}
if (PEAR::isError($sql)) {
return $sql;
}
//default values, eventually overridden
$definition = array(
'primary' => false,
'unique' => false,
'foreign' => false,
'check' => false,
'fields' => array(),
'references' => array(
'table' => '',
'fields' => array(),
),
'onupdate' => '',
'ondelete' => '',
'match' => '',
'deferrable' => false,
'initiallydeferred' => false,
);
if (!$sql) {
$query = "SELECT sql FROM sqlite_master WHERE type='table' AND ";
if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
$query.= 'LOWER(name)='.$db->quote(strtolower($table), 'text');
} else {
$query.= 'name='.$db->quote($table, 'text');
}
$query.= " AND sql NOT NULL ORDER BY name";
$sql = $db->queryOne($query, 'text');
if (PEAR::isError($sql)) {
return $sql;
}
if ($constraint_name == 'primary') {
// search in table definition for PRIMARY KEYs
if (preg_match("/\bPRIMARY\s+KEY\b\s*\(([^)]+)/i", $sql, $tmp)) {
$definition['primary'] = true;
$definition['fields'] = array();
$column_names = explode(',', $tmp[1]);
$colpos = 1;
foreach ($column_names as $column_name) {
$definition['fields'][trim($column_name)] = array(
'position' => $colpos++
);
}
return $definition;
}
if (preg_match("/\"([^\"]+)\"[^\,\"]+\bPRIMARY\s+KEY\b[^\,\)]*/i", $sql, $tmp)) {
$definition['primary'] = true;
$definition['fields'] = array();
$column_names = explode(',', $tmp[1]);
$colpos = 1;
foreach ($column_names as $column_name) {
$definition['fields'][trim($column_name)] = array(
'position' => $colpos++
);
}
return $definition;
}
} else {
// search in table definition for FOREIGN KEYs
$pattern = "/\bCONSTRAINT\b\s+%s\s+
\bFOREIGN\s+KEY\b\s*\(([^\)]+)\)\s*
\bREFERENCES\b\s+([^\s]+)\s*\(([^\)]+)\)\s*
(?:\bMATCH\s*([^\s]+))?\s*
(?:\bON\s+UPDATE\s+([^\s,\)]+))?\s*
(?:\bON\s+DELETE\s+([^\s,\)]+))?\s*
/imsx";
$found_fk = false;
if (preg_match(sprintf($pattern, $constraint_name_mdb2), $sql, $tmp)) {
$found_fk = true;
} elseif (preg_match(sprintf($pattern, $constraint_name), $sql, $tmp)) {
$found_fk = true;
}
if ($found_fk) {
$definition['foreign'] = true;
$definition['match'] = 'SIMPLE';
$definition['onupdate'] = 'NO ACTION';
$definition['ondelete'] = 'NO ACTION';
$definition['references']['table'] = $tmp[2];
$column_names = explode(',', $tmp[1]);
$colpos = 1;
foreach ($column_names as $column_name) {
$definition['fields'][trim($column_name)] = array(
'position' => $colpos++
);
}
$referenced_cols = explode(',', $tmp[3]);
$colpos = 1;
foreach ($referenced_cols as $column_name) {
$definition['references']['fields'][trim($column_name)] = array(
'position' => $colpos++
);
}
if (isset($tmp[4])) {
$definition['match'] = $tmp[4];
}
if (isset($tmp[5])) {
$definition['onupdate'] = $tmp[5];
}
if (isset($tmp[6])) {
$definition['ondelete'] = $tmp[6];
}
return $definition;
}
}
$sql = false;
}
if (!$sql) {
return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
$constraint_name . ' is not an existing table constraint', __FUNCTION__);
}
$sql = strtolower($sql);
$start_pos = strpos($sql, '(');
$end_pos = strrpos($sql, ')');
$column_names = substr($sql, $start_pos+1, $end_pos-$start_pos-1);
$column_names = explode(',', $column_names);
if (!preg_match("/^create unique/", $sql)) {
return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
$constraint_name . ' is not an existing table constraint', __FUNCTION__);
}
$definition['unique'] = true;
$count = count($column_names);
for ($i=0; $i<$count; ++$i) {
$column_name = strtok($column_names[$i]," ");
$collation = strtok(" ");
$definition['fields'][$column_name] = array(
'position' => $i+1
);
if (!empty($collation)) {
$definition['fields'][$column_name]['sorting'] =
($collation=='ASC' ? 'ascending' : 'descending');
}
}
if (empty($definition['fields'])) {
return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
$constraint_name . ' is not an existing table constraint', __FUNCTION__);
}
return $definition;
}
// }}}
// {{{ getTriggerDefinition()
/**
* Get the structure of a trigger into an array
*
* EXPERIMENTAL
*
* WARNING: this function is experimental and may change the returned value
* at any time until labelled as non-experimental
*
* @param string $trigger name of trigger that should be used in method
* @return mixed data array on success, a MDB2 error on failure
* @access public
*/
function getTriggerDefinition($trigger)
{
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$query = "SELECT name as trigger_name,
tbl_name AS table_name,
sql AS trigger_body,
NULL AS trigger_type,
NULL AS trigger_event,
NULL AS trigger_comment,
1 AS trigger_enabled
FROM sqlite_master
WHERE type='trigger'";
if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
$query.= ' AND LOWER(name)='.$db->quote(strtolower($trigger), 'text');
} else {
$query.= ' AND name='.$db->quote($trigger, 'text');
}
$types = array(
'trigger_name' => 'text',
'table_name' => 'text',
'trigger_body' => 'text',
'trigger_type' => 'text',
'trigger_event' => 'text',
'trigger_comment' => 'text',
'trigger_enabled' => 'boolean',
);
$def = $db->queryRow($query, $types, MDB2_FETCHMODE_ASSOC);
if (PEAR::isError($def)) {
return $def;
}
if (empty($def)) {
return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
'it was not specified an existing trigger', __FUNCTION__);
}
if (preg_match("/^create\s+(?:temp|temporary)?trigger\s+(?:if\s+not\s+exists\s+)?.*(before|after)?\s+(insert|update|delete)/Uims", $def['trigger_body'], $tmp)) {
$def['trigger_type'] = strtoupper($tmp[1]);
$def['trigger_event'] = strtoupper($tmp[2]);
}
return $def;
}
// }}}
// {{{ tableInfo()
/**
* Returns information about a table
*
* @param string $result a string containing the name of a table
* @param int $mode a valid tableInfo mode
*
* @return array an associative array with the information requested.
* A MDB2_Error object on failure.
*
* @see MDB2_Driver_Common::tableInfo()
* @since Method available since Release 1.7.0
*/
function tableInfo($result, $mode = null)
{
if (is_string($result)) {
return parent::tableInfo($result, $mode);
}
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
return $db->raiseError(MDB2_ERROR_NOT_CAPABLE, null, null,
'This DBMS can not obtain tableInfo from result sets', __FUNCTION__);
}
}
?>

1700
3rdparty/MDB2/Driver/mysql.php vendored Normal file

File diff suppressed because it is too large Load Diff

1519
3rdparty/MDB2/Driver/pgsql.php vendored Normal file

File diff suppressed because it is too large Load Diff

1088
3rdparty/MDB2/Driver/sqlite.php vendored Normal file

File diff suppressed because it is too large Load Diff

721
3rdparty/MDB2/Extended.php vendored Normal file
View File

@ -0,0 +1,721 @@
<?php
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. |
// | |
// | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions |
// | are met: |
// | |
// | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. |
// | |
// | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. |
// | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior|
// | written permission. |
// | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
// $Id: Extended.php,v 1.60 2007/11/28 19:49:34 quipo Exp $
/**
* @package MDB2
* @category Database
* @author Lukas Smith <smith@pooteeweet.org>
*/
/**
* Used by autoPrepare()
*/
define('MDB2_AUTOQUERY_INSERT', 1);
define('MDB2_AUTOQUERY_UPDATE', 2);
define('MDB2_AUTOQUERY_DELETE', 3);
define('MDB2_AUTOQUERY_SELECT', 4);
/**
* MDB2_Extended: class which adds several high level methods to MDB2
*
* @package MDB2
* @category Database
* @author Lukas Smith <smith@pooteeweet.org>
*/
class MDB2_Extended extends MDB2_Module_Common
{
// {{{ autoPrepare()
/**
* Generate an insert, update or delete query and call prepare() on it
*
* @param string table
* @param array the fields names
* @param int type of query to build
* MDB2_AUTOQUERY_INSERT
* MDB2_AUTOQUERY_UPDATE
* MDB2_AUTOQUERY_DELETE
* MDB2_AUTOQUERY_SELECT
* @param string (in case of update and delete queries, this string will be put after the sql WHERE statement)
* @param array that contains the types of the placeholders
* @param mixed array that contains the types of the columns in
* the result set or MDB2_PREPARE_RESULT, if set to
* MDB2_PREPARE_MANIP the query is handled as a manipulation query
*
* @return resource handle for the query
* @see buildManipSQL
* @access public
*/
function autoPrepare($table, $table_fields, $mode = MDB2_AUTOQUERY_INSERT,
$where = false, $types = null, $result_types = MDB2_PREPARE_MANIP)
{
$query = $this->buildManipSQL($table, $table_fields, $mode, $where);
if (PEAR::isError($query)) {
return $query;
}
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$lobs = array();
foreach ((array)$types as $param => $type) {
if (($type == 'clob') || ($type == 'blob')) {
$lobs[$param] = $table_fields[$param];
}
}
return $db->prepare($query, $types, $result_types, $lobs);
}
// }}}
// {{{ autoExecute()
/**
* Generate an insert, update or delete query and call prepare() and execute() on it
*
* @param string name of the table
* @param array assoc ($key=>$value) where $key is a field name and $value its value
* @param int type of query to build
* MDB2_AUTOQUERY_INSERT
* MDB2_AUTOQUERY_UPDATE
* MDB2_AUTOQUERY_DELETE
* MDB2_AUTOQUERY_SELECT
* @param string (in case of update and delete queries, this string will be put after the sql WHERE statement)
* @param array that contains the types of the placeholders
* @param string which specifies which result class to use
* @param mixed array that contains the types of the columns in
* the result set or MDB2_PREPARE_RESULT, if set to
* MDB2_PREPARE_MANIP the query is handled as a manipulation query
*
* @return bool|MDB2_Error true on success, a MDB2 error on failure
* @see buildManipSQL
* @see autoPrepare
* @access public
*/
function &autoExecute($table, $fields_values, $mode = MDB2_AUTOQUERY_INSERT,
$where = false, $types = null, $result_class = true, $result_types = MDB2_PREPARE_MANIP)
{
$fields_values = (array)$fields_values;
if ($mode == MDB2_AUTOQUERY_SELECT) {
if (is_array($result_types)) {
$keys = array_keys($result_types);
} elseif (!empty($fields_values)) {
$keys = $fields_values;
} else {
$keys = array();
}
} else {
$keys = array_keys($fields_values);
}
$params = array_values($fields_values);
if (empty($params)) {
$query = $this->buildManipSQL($table, $keys, $mode, $where);
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
if ($mode == MDB2_AUTOQUERY_SELECT) {
$result =& $db->query($query, $result_types, $result_class);
} else {
$result = $db->exec($query);
}
} else {
$stmt = $this->autoPrepare($table, $keys, $mode, $where, $types, $result_types);
if (PEAR::isError($stmt)) {
return $stmt;
}
$result =& $stmt->execute($params, $result_class);
$stmt->free();
}
return $result;
}
// }}}
// {{{ buildManipSQL()
/**
* Make automaticaly an sql query for prepare()
*
* Example : buildManipSQL('table_sql', array('field1', 'field2', 'field3'), MDB2_AUTOQUERY_INSERT)
* will return the string : INSERT INTO table_sql (field1,field2,field3) VALUES (?,?,?)
* NB : - This belongs more to a SQL Builder class, but this is a simple facility
* - Be carefull ! If you don't give a $where param with an UPDATE/DELETE query, all
* the records of the table will be updated/deleted !
*
* @param string name of the table
* @param ordered array containing the fields names
* @param int type of query to build
* MDB2_AUTOQUERY_INSERT
* MDB2_AUTOQUERY_UPDATE
* MDB2_AUTOQUERY_DELETE
* MDB2_AUTOQUERY_SELECT
* @param string (in case of update and delete queries, this string will be put after the sql WHERE statement)
*
* @return string sql query for prepare()
* @access public
*/
function buildManipSQL($table, $table_fields, $mode, $where = false)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
if ($db->options['quote_identifier']) {
$table = $db->quoteIdentifier($table);
}
if (!empty($table_fields) && $db->options['quote_identifier']) {
foreach ($table_fields as $key => $field) {
$table_fields[$key] = $db->quoteIdentifier($field);
}
}
if ($where !== false && !is_null($where)) {
if (is_array($where)) {
$where = implode(' AND ', $where);
}
$where = ' WHERE '.$where;
}
switch ($mode) {
case MDB2_AUTOQUERY_INSERT:
if (empty($table_fields)) {
return $db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null,
'Insert requires table fields', __FUNCTION__);
}
$cols = implode(', ', $table_fields);
$values = '?'.str_repeat(', ?', (count($table_fields) - 1));
return 'INSERT INTO '.$table.' ('.$cols.') VALUES ('.$values.')';
break;
case MDB2_AUTOQUERY_UPDATE:
if (empty($table_fields)) {
return $db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null,
'Update requires table fields', __FUNCTION__);
}
$set = implode(' = ?, ', $table_fields).' = ?';
$sql = 'UPDATE '.$table.' SET '.$set.$where;
return $sql;
break;
case MDB2_AUTOQUERY_DELETE:
$sql = 'DELETE FROM '.$table.$where;
return $sql;
break;
case MDB2_AUTOQUERY_SELECT:
$cols = !empty($table_fields) ? implode(', ', $table_fields) : '*';
$sql = 'SELECT '.$cols.' FROM '.$table.$where;
return $sql;
break;
}
return $db->raiseError(MDB2_ERROR_SYNTAX, null, null,
'Non existant mode', __FUNCTION__);
}
// }}}
// {{{ limitQuery()
/**
* Generates a limited query
*
* @param string query
* @param array that contains the types of the columns in the result set
* @param integer the numbers of rows to fetch
* @param integer the row to start to fetching
* @param string which specifies which result class to use
* @param mixed string which specifies which class to wrap results in
*
* @return MDB2_Result|MDB2_Error result set on success, a MDB2 error on failure
* @access public
*/
function &limitQuery($query, $types, $limit, $offset = 0, $result_class = true,
$result_wrap_class = false)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$result = $db->setLimit($limit, $offset);
if (PEAR::isError($result)) {
return $result;
}
$result =& $db->query($query, $types, $result_class, $result_wrap_class);
return $result;
}
// }}}
// {{{ execParam()
/**
* Execute a parameterized DML statement.
*
* @param string the SQL query
* @param array if supplied, prepare/execute will be used
* with this array as execute parameters
* @param array that contains the types of the values defined in $params
*
* @return int|MDB2_Error affected rows on success, a MDB2 error on failure
* @access public
*/
function execParam($query, $params = array(), $param_types = null)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
settype($params, 'array');
if (empty($params)) {
return $db->exec($query);
}
$stmt = $db->prepare($query, $param_types, MDB2_PREPARE_MANIP);
if (PEAR::isError($stmt)) {
return $stmt;
}
$result = $stmt->execute($params);
if (PEAR::isError($result)) {
return $result;
}
$stmt->free();
return $result;
}
// }}}
// {{{ getOne()
/**
* Fetch the first column of the first row of data returned from a query.
* Takes care of doing the query and freeing the results when finished.
*
* @param string the SQL query
* @param string that contains the type of the column in the result set
* @param array if supplied, prepare/execute will be used
* with this array as execute parameters
* @param array that contains the types of the values defined in $params
* @param int|string which column to return
*
* @return scalar|MDB2_Error data on success, a MDB2 error on failure
* @access public
*/
function getOne($query, $type = null, $params = array(),
$param_types = null, $colnum = 0)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
settype($params, 'array');
settype($type, 'array');
if (empty($params)) {
return $db->queryOne($query, $type, $colnum);
}
$stmt = $db->prepare($query, $param_types, $type);
if (PEAR::isError($stmt)) {
return $stmt;
}
$result = $stmt->execute($params);
if (!MDB2::isResultCommon($result)) {
return $result;
}
$one = $result->fetchOne($colnum);
$stmt->free();
$result->free();
return $one;
}
// }}}
// {{{ getRow()
/**
* Fetch the first row of data returned from a query. Takes care
* of doing the query and freeing the results when finished.
*
* @param string the SQL query
* @param array that contains the types of the columns in the result set
* @param array if supplied, prepare/execute will be used
* with this array as execute parameters
* @param array that contains the types of the values defined in $params
* @param int the fetch mode to use
*
* @return array|MDB2_Error data on success, a MDB2 error on failure
* @access public
*/
function getRow($query, $types = null, $params = array(),
$param_types = null, $fetchmode = MDB2_FETCHMODE_DEFAULT)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
settype($params, 'array');
if (empty($params)) {
return $db->queryRow($query, $types, $fetchmode);
}
$stmt = $db->prepare($query, $param_types, $types);
if (PEAR::isError($stmt)) {
return $stmt;
}
$result = $stmt->execute($params);
if (!MDB2::isResultCommon($result)) {
return $result;
}
$row = $result->fetchRow($fetchmode);
$stmt->free();
$result->free();
return $row;
}
// }}}
// {{{ getCol()
/**
* Fetch a single column from a result set and return it as an
* indexed array.
*
* @param string the SQL query
* @param string that contains the type of the column in the result set
* @param array if supplied, prepare/execute will be used
* with this array as execute parameters
* @param array that contains the types of the values defined in $params
* @param int|string which column to return
*
* @return array|MDB2_Error data on success, a MDB2 error on failure
* @access public
*/
function getCol($query, $type = null, $params = array(),
$param_types = null, $colnum = 0)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
settype($params, 'array');
settype($type, 'array');
if (empty($params)) {
return $db->queryCol($query, $type, $colnum);
}
$stmt = $db->prepare($query, $param_types, $type);
if (PEAR::isError($stmt)) {
return $stmt;
}
$result = $stmt->execute($params);
if (!MDB2::isResultCommon($result)) {
return $result;
}
$col = $result->fetchCol($colnum);
$stmt->free();
$result->free();
return $col;
}
// }}}
// {{{ getAll()
/**
* Fetch all the rows returned from a query.
*
* @param string the SQL query
* @param array that contains the types of the columns in the result set
* @param array if supplied, prepare/execute will be used
* with this array as execute parameters
* @param array that contains the types of the values defined in $params
* @param int the fetch mode to use
* @param bool if set to true, the $all will have the first
* column as its first dimension
* @param bool $force_array used only when the query returns exactly
* two columns. If true, the values of the returned array will be
* one-element arrays instead of scalars.
* @param bool $group if true, the values of the returned array is
* wrapped in another array. If the same key value (in the first
* column) repeats itself, the values will be appended to this array
* instead of overwriting the existing values.
*
* @return array|MDB2_Error data on success, a MDB2 error on failure
* @access public
*/
function getAll($query, $types = null, $params = array(),
$param_types = null, $fetchmode = MDB2_FETCHMODE_DEFAULT,
$rekey = false, $force_array = false, $group = false)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
settype($params, 'array');
if (empty($params)) {
return $db->queryAll($query, $types, $fetchmode, $rekey, $force_array, $group);
}
$stmt = $db->prepare($query, $param_types, $types);
if (PEAR::isError($stmt)) {
return $stmt;
}
$result = $stmt->execute($params);
if (!MDB2::isResultCommon($result)) {
return $result;
}
$all = $result->fetchAll($fetchmode, $rekey, $force_array, $group);
$stmt->free();
$result->free();
return $all;
}
// }}}
// {{{ getAssoc()
/**
* Fetch the entire result set of a query and return it as an
* associative array using the first column as the key.
*
* If the result set contains more than two columns, the value
* will be an array of the values from column 2-n. If the result
* set contains only two columns, the returned value will be a
* scalar with the value of the second column (unless forced to an
* array with the $force_array parameter). A MDB2 error code is
* returned on errors. If the result set contains fewer than two
* columns, a MDB2_ERROR_TRUNCATED error is returned.
*
* For example, if the table 'mytable' contains:
* <pre>
* ID TEXT DATE
* --------------------------------
* 1 'one' 944679408
* 2 'two' 944679408
* 3 'three' 944679408
* </pre>
* Then the call getAssoc('SELECT id,text FROM mytable') returns:
* <pre>
* array(
* '1' => 'one',
* '2' => 'two',
* '3' => 'three',
* )
* </pre>
* ...while the call getAssoc('SELECT id,text,date FROM mytable') returns:
* <pre>
* array(
* '1' => array('one', '944679408'),
* '2' => array('two', '944679408'),
* '3' => array('three', '944679408')
* )
* </pre>
*
* If the more than one row occurs with the same value in the
* first column, the last row overwrites all previous ones by
* default. Use the $group parameter if you don't want to
* overwrite like this. Example:
* <pre>
* getAssoc('SELECT category,id,name FROM mytable', null, null
* MDB2_FETCHMODE_ASSOC, false, true) returns:
* array(
* '1' => array(array('id' => '4', 'name' => 'number four'),
* array('id' => '6', 'name' => 'number six')
* ),
* '9' => array(array('id' => '4', 'name' => 'number four'),
* array('id' => '6', 'name' => 'number six')
* )
* )
* </pre>
*
* Keep in mind that database functions in PHP usually return string
* values for results regardless of the database's internal type.
*
* @param string the SQL query
* @param array that contains the types of the columns in the result set
* @param array if supplied, prepare/execute will be used
* with this array as execute parameters
* @param array that contains the types of the values defined in $params
* @param bool $force_array used only when the query returns
* exactly two columns. If TRUE, the values of the returned array
* will be one-element arrays instead of scalars.
* @param bool $group if TRUE, the values of the returned array
* is wrapped in another array. If the same key value (in the first
* column) repeats itself, the values will be appended to this array
* instead of overwriting the existing values.
*
* @return array|MDB2_Error data on success, a MDB2 error on failure
* @access public
*/
function getAssoc($query, $types = null, $params = array(), $param_types = null,
$fetchmode = MDB2_FETCHMODE_DEFAULT, $force_array = false, $group = false)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
settype($params, 'array');
if (empty($params)) {
return $db->queryAll($query, $types, $fetchmode, true, $force_array, $group);
}
$stmt = $db->prepare($query, $param_types, $types);
if (PEAR::isError($stmt)) {
return $stmt;
}
$result = $stmt->execute($params);
if (!MDB2::isResultCommon($result)) {
return $result;
}
$all = $result->fetchAll($fetchmode, true, $force_array, $group);
$stmt->free();
$result->free();
return $all;
}
// }}}
// {{{ executeMultiple()
/**
* This function does several execute() calls on the same statement handle.
* $params must be an array indexed numerically from 0, one execute call is
* done for every 'row' in the array.
*
* If an error occurs during execute(), executeMultiple() does not execute
* the unfinished rows, but rather returns that error.
*
* @param resource query handle from prepare()
* @param array numeric array containing the data to insert into the query
*
* @return bool|MDB2_Error true on success, a MDB2 error on failure
* @access public
* @see prepare(), execute()
*/
function executeMultiple(&$stmt, $params = null)
{
for ($i = 0, $j = count($params); $i < $j; $i++) {
$result = $stmt->execute($params[$i]);
if (PEAR::isError($result)) {
return $result;
}
}
return MDB2_OK;
}
// }}}
// {{{ getBeforeID()
/**
* Returns the next free id of a sequence if the RDBMS
* does not support auto increment
*
* @param string name of the table into which a new row was inserted
* @param string name of the field into which a new row was inserted
* @param bool when true the sequence is automatic created, if it not exists
* @param bool if the returned value should be quoted
*
* @return int|MDB2_Error id on success, a MDB2 error on failure
* @access public
*/
function getBeforeID($table, $field = null, $ondemand = true, $quote = true)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
if ($db->supports('auto_increment') !== true) {
$seq = $table.(empty($field) ? '' : '_'.$field);
$id = $db->nextID($seq, $ondemand);
if (!$quote || PEAR::isError($id)) {
return $id;
}
return $db->quote($id, 'integer');
} elseif (!$quote) {
return null;
}
return 'NULL';
}
// }}}
// {{{ getAfterID()
/**
* Returns the autoincrement ID if supported or $id
*
* @param mixed value as returned by getBeforeId()
* @param string name of the table into which a new row was inserted
* @param string name of the field into which a new row was inserted
*
* @return int|MDB2_Error id on success, a MDB2 error on failure
* @access public
*/
function getAfterID($id, $table, $field = null)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
if ($db->supports('auto_increment') !== true) {
return $id;
}
return $db->lastInsertID($table, $field);
}
// }}}
}
?>

259
3rdparty/MDB2/Iterator.php vendored Normal file
View File

@ -0,0 +1,259 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. |
// | |
// | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions |
// | are met: |
// | |
// | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. |
// | |
// | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. |
// | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior|
// | written permission. |
// | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
// $Id: Iterator.php,v 1.22 2006/05/06 14:03:41 lsmith Exp $
/**
* PHP5 Iterator
*
* @package MDB2
* @category Database
* @author Lukas Smith <smith@pooteeweet.org>
*/
class MDB2_Iterator implements Iterator
{
protected $fetchmode;
protected $result;
protected $row;
// {{{ constructor
/**
* Constructor
*/
public function __construct($result, $fetchmode = MDB2_FETCHMODE_DEFAULT)
{
$this->result = $result;
$this->fetchmode = $fetchmode;
}
// }}}
// {{{ seek()
/**
* Seek forward to a specific row in a result set
*
* @param int number of the row where the data can be found
*
* @return void
* @access public
*/
public function seek($rownum)
{
$this->row = null;
if ($this->result) {
$this->result->seek($rownum);
}
}
// }}}
// {{{ next()
/**
* Fetch next row of data
*
* @return void
* @access public
*/
public function next()
{
$this->row = null;
}
// }}}
// {{{ current()
/**
* return a row of data
*
* @return void
* @access public
*/
public function current()
{
if (is_null($this->row)) {
$row = $this->result->fetchRow($this->fetchmode);
if (PEAR::isError($row)) {
$row = false;
}
$this->row = $row;
}
return $this->row;
}
// }}}
// {{{ valid()
/**
* Check if the end of the result set has been reached
*
* @return bool true/false, false is also returned on failure
* @access public
*/
public function valid()
{
return (bool)$this->current();
}
// }}}
// {{{ free()
/**
* Free the internal resources associated with result.
*
* @return bool|MDB2_Error true on success, false|MDB2_Error if result is invalid
* @access public
*/
public function free()
{
if ($this->result) {
return $this->result->free();
}
$this->result = false;
$this->row = null;
return false;
}
// }}}
// {{{ key()
/**
* Returns the row number
*
* @return int|bool|MDB2_Error true on success, false|MDB2_Error if result is invalid
* @access public
*/
public function key()
{
if ($this->result) {
return $this->result->rowCount();
}
return false;
}
// }}}
// {{{ rewind()
/**
* Seek to the first row in a result set
*
* @return void
* @access public
*/
public function rewind()
{
}
// }}}
// {{{ destructor
/**
* Destructor
*/
public function __destruct()
{
$this->free();
}
// }}}
}
/**
* PHP5 buffered Iterator
*
* @package MDB2
* @category Database
* @author Lukas Smith <smith@pooteeweet.org>
*/
class MDB2_BufferedIterator extends MDB2_Iterator implements SeekableIterator
{
// {{{ valid()
/**
* Check if the end of the result set has been reached
*
* @return bool|MDB2_Error true on success, false|MDB2_Error if result is invalid
* @access public
*/
public function valid()
{
if ($this->result) {
return $this->result->valid();
}
return false;
}
// }}}
// {{{count()
/**
* Returns the number of rows in a result object
*
* @return int|MDB2_Error number of rows, false|MDB2_Error if result is invalid
* @access public
*/
public function count()
{
if ($this->result) {
return $this->result->numRows();
}
return false;
}
// }}}
// {{{ rewind()
/**
* Seek to the first row in a result set
*
* @return void
* @access public
*/
public function rewind()
{
$this->seek(0);
}
// }}}
}
?>

264
3rdparty/MDB2/LOB.php vendored Normal file
View File

@ -0,0 +1,264 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. |
// | |
// | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions |
// | are met: |
// | |
// | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. |
// | |
// | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. |
// | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior|
// | written permission. |
// | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
// $Id: LOB.php,v 1.34 2006/10/25 11:52:21 lsmith Exp $
/**
* @package MDB2
* @category Database
* @author Lukas Smith <smith@pooteeweet.org>
*/
require_once('MDB2.php');
/**
* MDB2_LOB: user land stream wrapper implementation for LOB support
*
* @package MDB2
* @category Database
* @author Lukas Smith <smith@pooteeweet.org>
*/
class MDB2_LOB
{
/**
* contains the key to the global MDB2 instance array of the associated
* MDB2 instance
*
* @var integer
* @access protected
*/
var $db_index;
/**
* contains the key to the global MDB2_LOB instance array of the associated
* MDB2_LOB instance
*
* @var integer
* @access protected
*/
var $lob_index;
// {{{ stream_open()
/**
* open stream
*
* @param string specifies the URL that was passed to fopen()
* @param string the mode used to open the file
* @param int holds additional flags set by the streams API
* @param string not used
*
* @return bool
* @access public
*/
function stream_open($path, $mode, $options, &$opened_path)
{
if (!preg_match('/^rb?\+?$/', $mode)) {
return false;
}
$url = parse_url($path);
if (empty($url['host'])) {
return false;
}
$this->db_index = (int)$url['host'];
if (!isset($GLOBALS['_MDB2_databases'][$this->db_index])) {
return false;
}
$db =& $GLOBALS['_MDB2_databases'][$this->db_index];
$this->lob_index = (int)$url['user'];
if (!isset($db->datatype->lobs[$this->lob_index])) {
return false;
}
return true;
}
// }}}
// {{{ stream_read()
/**
* read stream
*
* @param int number of bytes to read
*
* @return string
* @access public
*/
function stream_read($count)
{
if (isset($GLOBALS['_MDB2_databases'][$this->db_index])) {
$db =& $GLOBALS['_MDB2_databases'][$this->db_index];
$db->datatype->_retrieveLOB($db->datatype->lobs[$this->lob_index]);
$data = $db->datatype->_readLOB($db->datatype->lobs[$this->lob_index], $count);
$length = strlen($data);
if ($length == 0) {
$db->datatype->lobs[$this->lob_index]['endOfLOB'] = true;
}
$db->datatype->lobs[$this->lob_index]['position'] += $length;
return $data;
}
}
// }}}
// {{{ stream_write()
/**
* write stream, note implemented
*
* @param string data
*
* @return int
* @access public
*/
function stream_write($data)
{
return 0;
}
// }}}
// {{{ stream_tell()
/**
* return the current position
*
* @return int current position
* @access public
*/
function stream_tell()
{
if (isset($GLOBALS['_MDB2_databases'][$this->db_index])) {
$db =& $GLOBALS['_MDB2_databases'][$this->db_index];
return $db->datatype->lobs[$this->lob_index]['position'];
}
}
// }}}
// {{{ stream_eof()
/**
* Check if stream reaches EOF
*
* @return bool
* @access public
*/
function stream_eof()
{
if (!isset($GLOBALS['_MDB2_databases'][$this->db_index])) {
return true;
}
$db =& $GLOBALS['_MDB2_databases'][$this->db_index];
$result = $db->datatype->_endOfLOB($db->datatype->lobs[$this->lob_index]);
if (version_compare(phpversion(), "5.0", ">=")
&& version_compare(phpversion(), "5.1", "<")
) {
return !$result;
}
return $result;
}
// }}}
// {{{ stream_seek()
/**
* Seek stream, not implemented
*
* @param int offset
* @param int whence
*
* @return bool
* @access public
*/
function stream_seek($offset, $whence)
{
return false;
}
// }}}
// {{{ stream_stat()
/**
* return information about stream
*
* @access public
*/
function stream_stat()
{
if (isset($GLOBALS['_MDB2_databases'][$this->db_index])) {
$db =& $GLOBALS['_MDB2_databases'][$this->db_index];
return array(
'db_index' => $this->db_index,
'lob_index' => $this->lob_index,
);
}
}
// }}}
// {{{ stream_close()
/**
* close stream
*
* @access public
*/
function stream_close()
{
if (isset($GLOBALS['_MDB2_databases'][$this->db_index])) {
$db =& $GLOBALS['_MDB2_databases'][$this->db_index];
if (isset($db->datatype->lobs[$this->lob_index])) {
$db->datatype->_destroyLOB($db->datatype->lobs[$this->lob_index]);
unset($db->datatype->lobs[$this->lob_index]);
}
}
}
// }}}
}
// register streams wrapper
if (!stream_wrapper_register("MDB2LOB", "MDB2_LOB")) {
MDB2::raiseError();
return false;
}
?>

2763
3rdparty/MDB2/Schema.php vendored Normal file

File diff suppressed because it is too large Load Diff

812
3rdparty/MDB2/Schema/Parser.php vendored Normal file
View File

@ -0,0 +1,812 @@
<?php
/**
* PHP versions 4 and 5
*
* Copyright (c) 1998-2008 Manuel Lemos, Tomas V.V.Cox,
* Stig. S. Bakken, Lukas Smith, Igor Feghali
* All rights reserved.
*
* MDB2_Schema enables users to maintain RDBMS independant schema files
* in XML that can be used to manipulate both data and database schemas
* This LICENSE is in the BSD license style.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken,
* Lukas Smith, Igor Feghali nor the names of his contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* Author: Christian Dickmann <dickmann@php.net>
* Author: Igor Feghali <ifeghali@php.net>
*
* $Id: Parser.php,v 1.68 2008/11/30 03:34:00 clockwerx Exp $
*
* @category Database
* @package MDB2_Schema
* @author Christian Dickmann <dickmann@php.net>
* @author Igor Feghali <ifeghali@php.net>
* @license BSD http://www.opensource.org/licenses/bsd-license.php
* @version CVS: $Id: Parser.php,v 1.68 2008/11/30 03:34:00 clockwerx Exp $
* @link http://pear.php.net/packages/MDB2_Schema
*/
require_once('XML/Parser.php');
require_once('MDB2/Schema/Validate.php');
/**
* Parses an XML schema file
*
* @category Database
* @package MDB2_Schema
* @author Christian Dickmann <dickmann@php.net>
* @license BSD http://www.opensource.org/licenses/bsd-license.php
* @link http://pear.php.net/packages/MDB2_Schema
*/
class MDB2_Schema_Parser extends XML_Parser
{
var $database_definition = array();
var $elements = array();
var $element = '';
var $count = 0;
var $table = array();
var $table_name = '';
var $field = array();
var $field_name = '';
var $init = array();
var $init_function = array();
var $init_expression = array();
var $init_field = array();
var $index = array();
var $index_name = '';
var $constraint = array();
var $constraint_name = '';
var $var_mode = false;
var $variables = array();
var $sequence = array();
var $sequence_name = '';
var $error;
var $structure = false;
var $val;
function __construct($variables, $fail_on_invalid_names = true,
$structure = false, $valid_types = array(),
$force_defaults = true)
{
// force ISO-8859-1 due to different defaults for PHP4 and PHP5
// todo: this probably needs to be investigated some more andcleaned up
parent::__construct('ISO-8859-1');
$this->variables = $variables;
$this->structure = $structure;
$this->val =new MDB2_Schema_Validate($fail_on_invalid_names, $valid_types, $force_defaults);
}
function startHandler($xp, $element, $attribs)
{
if (strtolower($element) == 'variable') {
$this->var_mode = true;
return;
}
$this->elements[$this->count++] = strtolower($element);
$this->element = implode('-', $this->elements);
switch ($this->element) {
/* Initialization */
case 'database-table-initialization':
$this->table['initialization'] = array();
break;
/* Insert */
/* insert: field+ */
case 'database-table-initialization-insert':
$this->init = array('type' => 'insert', 'data' => array('field' => array()));
break;
/* insert-select: field+, table, where? */
case 'database-table-initialization-insert-select':
$this->init['data']['table'] = '';
break;
/* Update */
/* update: field+, where? */
case 'database-table-initialization-update':
$this->init = array('type' => 'update', 'data' => array('field' => array()));
break;
/* Delete */
/* delete: where */
case 'database-table-initialization-delete':
$this->init = array('type' => 'delete', 'data' => array('where' => array()));
break;
/* Insert and Update */
case 'database-table-initialization-insert-field':
case 'database-table-initialization-insert-select-field':
case 'database-table-initialization-update-field':
$this->init_field = array('name' => '', 'group' => array());
break;
case 'database-table-initialization-insert-field-value':
case 'database-table-initialization-insert-select-field-value':
case 'database-table-initialization-update-field-value':
/* if value tag is empty cdataHandler is not called so we must force value element creation here */
$this->init_field['group'] = array('type' => 'value', 'data' => '');
break;
case 'database-table-initialization-insert-field-null':
case 'database-table-initialization-insert-select-field-null':
case 'database-table-initialization-update-field-null':
$this->init_field['group'] = array('type' => 'null');
break;
case 'database-table-initialization-insert-field-function':
case 'database-table-initialization-insert-select-field-function':
case 'database-table-initialization-update-field-function':
$this->init_function = array('name' => '');
break;
case 'database-table-initialization-insert-field-expression':
case 'database-table-initialization-insert-select-field-expression':
case 'database-table-initialization-update-field-expression':
$this->init_expression = array();
break;
/* All */
case 'database-table-initialization-insert-select-where':
case 'database-table-initialization-update-where':
case 'database-table-initialization-delete-where':
$this->init['data']['where'] = array('type' => '', 'data' => array());
break;
case 'database-table-initialization-insert-select-where-expression':
case 'database-table-initialization-update-where-expression':
case 'database-table-initialization-delete-where-expression':
$this->init_expression = array();
break;
/* One level simulation of expression-function recursion */
case 'database-table-initialization-insert-field-expression-function':
case 'database-table-initialization-insert-select-field-expression-function':
case 'database-table-initialization-insert-select-where-expression-function':
case 'database-table-initialization-update-field-expression-function':
case 'database-table-initialization-update-where-expression-function':
case 'database-table-initialization-delete-where-expression-function':
$this->init_function = array('name' => '');
break;
/* One level simulation of function-expression recursion */
case 'database-table-initialization-insert-field-function-expression':
case 'database-table-initialization-insert-select-field-function-expression':
case 'database-table-initialization-insert-select-where-function-expression':
case 'database-table-initialization-update-field-function-expression':
case 'database-table-initialization-update-where-function-expression':
case 'database-table-initialization-delete-where-function-expression':
$this->init_expression = array();
break;
/* Definition */
case 'database':
$this->database_definition = array(
'name' => '',
'create' => '',
'overwrite' => '',
'charset' => '',
'description' => '',
'comments' => '',
'tables' => array(),
'sequences' => array()
);
break;
case 'database-table':
$this->table_name = '';
$this->table = array(
'was' => '',
'description' => '',
'comments' => '',
'fields' => array(),
'indexes' => array(),
'constraints' => array(),
'initialization' => array()
);
break;
case 'database-table-declaration-field':
case 'database-table-declaration-foreign-field':
case 'database-table-declaration-foreign-references-field':
$this->field_name = '';
$this->field = array();
break;
case 'database-table-declaration-index-field':
$this->field_name = '';
$this->field = array('sorting' => '', 'length' => '');
break;
/* force field attributes to be initialized when the tag is empty in the XML */
case 'database-table-declaration-field-was':
$this->field['was'] = '';
break;
case 'database-table-declaration-field-type':
$this->field['type'] = '';
break;
case 'database-table-declaration-field-fixed':
$this->field['fixed'] = '';
break;
case 'database-table-declaration-field-default':
$this->field['default'] = '';
break;
case 'database-table-declaration-field-notnull':
$this->field['notnull'] = '';
break;
case 'database-table-declaration-field-autoincrement':
$this->field['autoincrement'] = '';
break;
case 'database-table-declaration-field-unsigned':
$this->field['unsigned'] = '';
break;
case 'database-table-declaration-field-length':
$this->field['length'] = '';
break;
case 'database-table-declaration-field-description':
$this->field['description'] = '';
break;
case 'database-table-declaration-field-comments':
$this->field['comments'] = '';
break;
case 'database-table-declaration-index':
$this->index_name = '';
$this->index = array(
'was' => '',
'unique' =>'',
'primary' => '',
'fields' => array()
);
break;
case 'database-table-declaration-foreign':
$this->constraint_name = '';
$this->constraint = array(
'was' => '',
'match' => '',
'ondelete' => '',
'onupdate' => '',
'deferrable' => '',
'initiallydeferred' => '',
'foreign' => true,
'fields' => array(),
'references' => array('table' => '', 'fields' => array())
);
break;
case 'database-sequence':
$this->sequence_name = '';
$this->sequence = array(
'was' => '',
'start' => '',
'description' => '',
'comments' => '',
'on' => array('table' => '', 'field' => '')
);
break;
}
}
function endHandler($xp, $element)
{
if (strtolower($element) == 'variable') {
$this->var_mode = false;
return;
}
switch ($this->element) {
/* Initialization */
/* Insert */
case 'database-table-initialization-insert-select':
$this->init['data'] = array('select' => $this->init['data']);
break;
/* Insert and Delete */
case 'database-table-initialization-insert-field':
case 'database-table-initialization-insert-select-field':
case 'database-table-initialization-update-field':
$result = $this->val->validateDataField($this->table['fields'], $this->init['data']['field'], $this->init_field);
if (PEAR::isError($result)) {
$this->raiseError($result->getUserinfo(), 0, $xp, $result->getCode());
} else {
$this->init['data']['field'][] = $this->init_field;
}
break;
case 'database-table-initialization-insert-field-function':
case 'database-table-initialization-insert-select-field-function':
case 'database-table-initialization-update-field-function':
$this->init_field['group'] = array('type' => 'function', 'data' => $this->init_function);
break;
case 'database-table-initialization-insert-field-expression':
case 'database-table-initialization-insert-select-field-expression':
case 'database-table-initialization-update-field-expression':
$this->init_field['group'] = array('type' => 'expression', 'data' => $this->init_expression);
break;
/* All */
case 'database-table-initialization-insert-select-where-expression':
case 'database-table-initialization-update-where-expression':
case 'database-table-initialization-delete-where-expression':
$this->init['data']['where']['type'] = 'expression';
$this->init['data']['where']['data'] = $this->init_expression;
break;
case 'database-table-initialization-insert':
case 'database-table-initialization-delete':
case 'database-table-initialization-update':
$this->table['initialization'][] = $this->init;
break;
/* One level simulation of expression-function recursion */
case 'database-table-initialization-insert-field-expression-function':
case 'database-table-initialization-insert-select-field-expression-function':
case 'database-table-initialization-insert-select-where-expression-function':
case 'database-table-initialization-update-field-expression-function':
case 'database-table-initialization-update-where-expression-function':
case 'database-table-initialization-delete-where-expression-function':
$this->init_expression['operants'][] = array('type' => 'function', 'data' => $this->init_function);
break;
/* One level simulation of function-expression recursion */
case 'database-table-initialization-insert-field-function-expression':
case 'database-table-initialization-insert-select-field-function-expression':
case 'database-table-initialization-insert-select-where-function-expression':
case 'database-table-initialization-update-field-function-expression':
case 'database-table-initialization-update-where-function-expression':
case 'database-table-initialization-delete-where-function-expression':
$this->init_function['arguments'][] = array('type' => 'expression', 'data' => $this->init_expression);
break;
/* Table definition */
case 'database-table':
$result = $this->val->validateTable($this->database_definition['tables'], $this->table, $this->table_name);
if (PEAR::isError($result)) {
$this->raiseError($result->getUserinfo(), 0, $xp, $result->getCode());
} else {
$this->database_definition['tables'][$this->table_name] = $this->table;
}
break;
case 'database-table-name':
if (isset($this->structure['tables'][$this->table_name])) {
$this->table = $this->structure['tables'][$this->table_name];
}
break;
/* Field declaration */
case 'database-table-declaration-field':
$result = $this->val->validateField($this->table['fields'], $this->field, $this->field_name);
if (PEAR::isError($result)) {
$this->raiseError($result->getUserinfo(), 0, $xp, $result->getCode());
} else {
$this->table['fields'][$this->field_name] = $this->field;
}
break;
/* Index declaration */
case 'database-table-declaration-index':
$result = $this->val->validateIndex($this->table['indexes'], $this->index, $this->index_name);
if (PEAR::isError($result)) {
$this->raiseError($result->getUserinfo(), 0, $xp, $result->getCode());
} else {
$this->table['indexes'][$this->index_name] = $this->index;
}
break;
case 'database-table-declaration-index-field':
$result = $this->val->validateIndexField($this->index['fields'], $this->field, $this->field_name);
if (PEAR::isError($result)) {
$this->raiseError($result->getUserinfo(), 0, $xp, $result->getCode());
} else {
$this->index['fields'][$this->field_name] = $this->field;
}
break;
/* Foreign Key declaration */
case 'database-table-declaration-foreign':
$result = $this->val->validateConstraint($this->table['constraints'], $this->constraint, $this->constraint_name);
if (PEAR::isError($result)) {
$this->raiseError($result->getUserinfo(), 0, $xp, $result->getCode());
} else {
$this->table['constraints'][$this->constraint_name] = $this->constraint;
}
break;
case 'database-table-declaration-foreign-field':
$result = $this->val->validateConstraintField($this->constraint['fields'], $this->field_name);
if (PEAR::isError($result)) {
$this->raiseError($result->getUserinfo(), 0, $xp, $result->getCode());
} else {
$this->constraint['fields'][$this->field_name] = '';
}
break;
case 'database-table-declaration-foreign-references-field':
$result = $this->val->validateConstraintReferencedField($this->constraint['references']['fields'], $this->field_name);
if (PEAR::isError($result)) {
$this->raiseError($result->getUserinfo(), 0, $xp, $result->getCode());
} else {
$this->constraint['references']['fields'][$this->field_name] = '';
}
break;
/* Sequence declaration */
case 'database-sequence':
$result = $this->val->validateSequence($this->database_definition['sequences'], $this->sequence, $this->sequence_name);
if (PEAR::isError($result)) {
$this->raiseError($result->getUserinfo(), 0, $xp, $result->getCode());
} else {
$this->database_definition['sequences'][$this->sequence_name] = $this->sequence;
}
break;
/* End of File */
case 'database':
$result = $this->val->validateDatabase($this->database_definition);
if (PEAR::isError($result)) {
$this->raiseError($result->getUserinfo(), 0, $xp, $result->getCode());
}
break;
}
unset($this->elements[--$this->count]);
$this->element = implode('-', $this->elements);
}
function raiseError($msg = null, $xmlecode = 0, $xp = null, $ecode = MDB2_SCHEMA_ERROR_PARSE,$a=null,$b=null,$c=null)
{
if (is_null($this->error)) {
$error = '';
if (is_resource($msg)) {
$error .= 'Parser error: '.xml_error_string(xml_get_error_code($msg));
$xp = $msg;
} else {
$error .= 'Parser error: '.$msg;
if (!is_resource($xp)) {
$xp = $this->parser;
}
}
if ($error_string = xml_error_string($xmlecode)) {
$error .= ' - '.$error_string;
}
if (is_resource($xp)) {
$byte = @xml_get_current_byte_index($xp);
$line = @xml_get_current_line_number($xp);
$column = @xml_get_current_column_number($xp);
$error .= " - Byte: $byte; Line: $line; Col: $column";
}
$error .= "\n";
$this->error =& MDB2_Schema::raiseError($ecode, null, null, $error);
}
return $this->error;
}
function cdataHandler($xp, $data)
{
if ($this->var_mode == true) {
if (!isset($this->variables[$data])) {
$this->raiseError('variable "'.$data.'" not found', null, $xp);
return;
}
$data = $this->variables[$data];
}
switch ($this->element) {
/* Initialization */
/* Insert */
case 'database-table-initialization-insert-select-table':
$this->init['data']['table'] = $data;
break;
/* Insert and Update */
case 'database-table-initialization-insert-field-name':
case 'database-table-initialization-insert-select-field-name':
case 'database-table-initialization-update-field-name':
$this->init_field['name'] .= $data;
break;
case 'database-table-initialization-insert-field-value':
case 'database-table-initialization-insert-select-field-value':
case 'database-table-initialization-update-field-value':
$this->init_field['group']['data'] .= $data;
break;
case 'database-table-initialization-insert-field-function-name':
case 'database-table-initialization-insert-select-field-function-name':
case 'database-table-initialization-update-field-function-name':
$this->init_function['name'] .= $data;
break;
case 'database-table-initialization-insert-field-function-value':
case 'database-table-initialization-insert-select-field-function-value':
case 'database-table-initialization-update-field-function-value':
$this->init_function['arguments'][] = array('type' => 'value', 'data' => $data);
break;
case 'database-table-initialization-insert-field-function-column':
case 'database-table-initialization-insert-select-field-function-column':
case 'database-table-initialization-update-field-function-column':
$this->init_function['arguments'][] = array('type' => 'column', 'data' => $data);
break;
case 'database-table-initialization-insert-field-column':
case 'database-table-initialization-insert-select-field-column':
case 'database-table-initialization-update-field-column':
$this->init_field['group'] = array('type' => 'column', 'data' => $data);
break;
/* All */
case 'database-table-initialization-insert-field-expression-operator':
case 'database-table-initialization-insert-select-field-expression-operator':
case 'database-table-initialization-insert-select-where-expression-operator':
case 'database-table-initialization-update-field-expression-operator':
case 'database-table-initialization-update-where-expression-operator':
case 'database-table-initialization-delete-where-expression-operator':
$this->init_expression['operator'] = $data;
break;
case 'database-table-initialization-insert-field-expression-value':
case 'database-table-initialization-insert-select-field-expression-value':
case 'database-table-initialization-insert-select-where-expression-value':
case 'database-table-initialization-update-field-expression-value':
case 'database-table-initialization-update-where-expression-value':
case 'database-table-initialization-delete-where-expression-value':
$this->init_expression['operants'][] = array('type' => 'value', 'data' => $data);
break;
case 'database-table-initialization-insert-field-expression-column':
case 'database-table-initialization-insert-select-field-expression-column':
case 'database-table-initialization-insert-select-where-expression-column':
case 'database-table-initialization-update-field-expression-column':
case 'database-table-initialization-update-where-expression-column':
case 'database-table-initialization-delete-where-expression-column':
$this->init_expression['operants'][] = array('type' => 'column', 'data' => $data);
break;
case 'database-table-initialization-insert-field-function-function':
case 'database-table-initialization-insert-field-function-expression':
case 'database-table-initialization-insert-field-expression-expression':
case 'database-table-initialization-update-field-function-function':
case 'database-table-initialization-update-field-function-expression':
case 'database-table-initialization-update-field-expression-expression':
case 'database-table-initialization-update-where-expression-expression':
case 'database-table-initialization-delete-where-expression-expression':
/* Recursion to be implemented yet */
break;
/* One level simulation of expression-function recursion */
case 'database-table-initialization-insert-field-expression-function-name':
case 'database-table-initialization-insert-select-field-expression-function-name':
case 'database-table-initialization-insert-select-where-expression-function-name':
case 'database-table-initialization-update-field-expression-function-name':
case 'database-table-initialization-update-where-expression-function-name':
case 'database-table-initialization-delete-where-expression-function-name':
$this->init_function['name'] .= $data;
break;
case 'database-table-initialization-insert-field-expression-function-value':
case 'database-table-initialization-insert-select-field-expression-function-value':
case 'database-table-initialization-insert-select-where-expression-function-value':
case 'database-table-initialization-update-field-expression-function-value':
case 'database-table-initialization-update-where-expression-function-value':
case 'database-table-initialization-delete-where-expression-function-value':
$this->init_function['arguments'][] = array('type' => 'value', 'data' => $data);
break;
case 'database-table-initialization-insert-field-expression-function-column':
case 'database-table-initialization-insert-select-field-expression-function-column':
case 'database-table-initialization-insert-select-where-expression-function-column':
case 'database-table-initialization-update-field-expression-function-column':
case 'database-table-initialization-update-where-expression-function-column':
case 'database-table-initialization-delete-where-expression-function-column':
$this->init_function['arguments'][] = array('type' => 'column', 'data' => $data);
break;
/* One level simulation of function-expression recursion */
case 'database-table-initialization-insert-field-function-expression-operator':
case 'database-table-initialization-insert-select-field-function-expression-operator':
case 'database-table-initialization-update-field-function-expression-operator':
$this->init_expression['operator'] = $data;
break;
case 'database-table-initialization-insert-field-function-expression-value':
case 'database-table-initialization-insert-select-field-function-expression-value':
case 'database-table-initialization-update-field-function-expression-value':
$this->init_expression['operants'][] = array('type' => 'value', 'data' => $data);
break;
case 'database-table-initialization-insert-field-function-expression-column':
case 'database-table-initialization-insert-select-field-function-expression-column':
case 'database-table-initialization-update-field-function-expression-column':
$this->init_expression['operants'][] = array('type' => 'column', 'data' => $data);
break;
/* Database */
case 'database-name':
$this->database_definition['name'] .= $data;
break;
case 'database-create':
$this->database_definition['create'] .= $data;
break;
case 'database-overwrite':
$this->database_definition['overwrite'] .= $data;
break;
case 'database-charset':
$this->database_definition['charset'] .= $data;
break;
case 'database-description':
$this->database_definition['description'] .= $data;
break;
case 'database-comments':
$this->database_definition['comments'] .= $data;
break;
/* Table declaration */
case 'database-table-name':
$this->table_name .= $data;
break;
case 'database-table-was':
$this->table['was'] .= $data;
break;
case 'database-table-description':
$this->table['description'] .= $data;
break;
case 'database-table-comments':
$this->table['comments'] .= $data;
break;
/* Field declaration */
case 'database-table-declaration-field-name':
$this->field_name .= $data;
break;
case 'database-table-declaration-field-was':
$this->field['was'] .= $data;
break;
case 'database-table-declaration-field-type':
$this->field['type'] .= $data;
break;
case 'database-table-declaration-field-fixed':
$this->field['fixed'] .= $data;
break;
case 'database-table-declaration-field-default':
$this->field['default'] .= $data;
break;
case 'database-table-declaration-field-notnull':
$this->field['notnull'] .= $data;
break;
case 'database-table-declaration-field-autoincrement':
$this->field['autoincrement'] .= $data;
break;
case 'database-table-declaration-field-unsigned':
$this->field['unsigned'] .= $data;
break;
case 'database-table-declaration-field-length':
$this->field['length'] .= $data;
break;
case 'database-table-declaration-field-description':
$this->field['description'] .= $data;
break;
case 'database-table-declaration-field-comments':
$this->field['comments'] .= $data;
break;
/* Index declaration */
case 'database-table-declaration-index-name':
$this->index_name .= $data;
break;
case 'database-table-declaration-index-was':
$this->index['was'] .= $data;
break;
case 'database-table-declaration-index-unique':
$this->index['unique'] .= $data;
break;
case 'database-table-declaration-index-primary':
$this->index['primary'] .= $data;
break;
case 'database-table-declaration-index-field-name':
$this->field_name .= $data;
break;
case 'database-table-declaration-index-field-sorting':
$this->field['sorting'] .= $data;
break;
/* Add by Leoncx */
case 'database-table-declaration-index-field-length':
$this->field['length'] .= $data;
break;
/* Foreign Key declaration */
case 'database-table-declaration-foreign-name':
$this->constraint_name .= $data;
break;
case 'database-table-declaration-foreign-was':
$this->constraint['was'] .= $data;
break;
case 'database-table-declaration-foreign-match':
$this->constraint['match'] .= $data;
break;
case 'database-table-declaration-foreign-ondelete':
$this->constraint['ondelete'] .= $data;
break;
case 'database-table-declaration-foreign-onupdate':
$this->constraint['onupdate'] .= $data;
break;
case 'database-table-declaration-foreign-deferrable':
$this->constraint['deferrable'] .= $data;
break;
case 'database-table-declaration-foreign-initiallydeferred':
$this->constraint['initiallydeferred'] .= $data;
break;
case 'database-table-declaration-foreign-field':
$this->field_name .= $data;
break;
case 'database-table-declaration-foreign-references-table':
$this->constraint['references']['table'] .= $data;
break;
case 'database-table-declaration-foreign-references-field':
$this->field_name .= $data;
break;
/* Sequence declaration */
case 'database-sequence-name':
$this->sequence_name .= $data;
break;
case 'database-sequence-was':
$this->sequence['was'] .= $data;
break;
case 'database-sequence-start':
$this->sequence['start'] .= $data;
break;
case 'database-sequence-description':
$this->sequence['description'] .= $data;
break;
case 'database-sequence-comments':
$this->sequence['comments'] .= $data;
break;
case 'database-sequence-on-table':
$this->sequence['on']['table'] .= $data;
break;
case 'database-sequence-on-field':
$this->sequence['on']['field'] .= $data;
break;
}
}
}
?>

624
3rdparty/MDB2/Schema/Parser2.php vendored Normal file
View File

@ -0,0 +1,624 @@
<?php
/**
* PHP versions 4 and 5
*
* Copyright (c) 1998-2008 Manuel Lemos, Tomas V.V.Cox,
* Stig. S. Bakken, Lukas Smith, Igor Feghali
* All rights reserved.
*
* MDB2_Schema enables users to maintain RDBMS independant schema files
* in XML that can be used to manipulate both data and database schemas
* This LICENSE is in the BSD license style.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken,
* Lukas Smith, Igor Feghali nor the names of his contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* Author: Igor Feghali <ifeghali@php.net>
*
* @category Database
* @package MDB2_Schema
* @author Igor Feghali <ifeghali@php.net>
* @license BSD http://www.opensource.org/licenses/bsd-license.php
* @version CVS: $Id: Parser2.php,v 1.12 2008/11/30 03:34:00 clockwerx Exp $
* @link http://pear.php.net/packages/MDB2_Schema
*/
require_once 'XML/Unserializer.php';
require_once 'MDB2/Schema/Validate.php';
/**
* Parses an XML schema file
*
* @category Database
* @package MDB2_Schema
* @author Lukas Smith <smith@pooteeweet.org>
* @author Igor Feghali <ifeghali@php.net>
* @license BSD http://www.opensource.org/licenses/bsd-license.php
* @link http://pear.php.net/packages/MDB2_Schema
*/
class MDB2_Schema_Parser2 extends XML_Unserializer
{
var $database_definition = array();
var $database_loaded = array();
var $variables = array();
var $error;
var $structure = false;
var $val;
var $options = array();
var $table = array();
var $table_name = '';
var $field = array();
var $field_name = '';
var $index = array();
var $index_name = '';
var $constraint = array();
var $constraint_name = '';
var $sequence = array();
var $sequence_name = '';
var $init = array();
function __construct($variables, $fail_on_invalid_names = true, $structure = false, $valid_types = array(), $force_defaults = true)
{
// force ISO-8859-1 due to different defaults for PHP4 and PHP5
// todo: this probably needs to be investigated some more and cleaned up
$this->options['encoding'] = 'ISO-8859-1';
$this->options['XML_UNSERIALIZER_OPTION_ATTRIBUTES_PARSE'] = true;
$this->options['XML_UNSERIALIZER_OPTION_ATTRIBUTES_ARRAYKEY'] = false;
$this->options['forceEnum'] = array('table', 'field', 'index', 'foreign', 'insert', 'update', 'delete', 'sequence');
/*
* todo: find a way to force the following items not to be parsed as arrays
* as it cause problems in functions with multiple arguments
*/
//$this->options['forceNEnum'] = array('value', 'column');
$this->variables = $variables;
$this->structure = $structure;
$this->val =& new MDB2_Schema_Validate($fail_on_invalid_names, $valid_types, $force_defaults);
parent::XML_Unserializer($this->options);
}
function MDB2_Schema_Parser2($variables, $fail_on_invalid_names = true, $structure = false, $valid_types = array(), $force_defaults = true)
{
$this->__construct($variables, $fail_on_invalid_names, $structure, $valid_types, $force_defaults);
}
function parse()
{
$result = $this->unserialize($this->filename, true);
if (PEAR::isError($result)) {
return $result;
} else {
$this->database_loaded = $this->getUnserializedData();
return $this->fixDatabaseKeys($this->database_loaded);
}
}
function setInputFile($filename)
{
$this->filename = $filename;
return MDB2_OK;
}
function renameKey(&$arr, $oKey, $nKey)
{
$arr[$nKey] = &$arr[$oKey];
unset($arr[$oKey]);
}
function fixDatabaseKeys($database)
{
$this->database_definition = array(
'name' => '',
'create' => '',
'overwrite' => '',
'charset' => '',
'description' => '',
'comments' => '',
'tables' => array(),
'sequences' => array()
);
if (!empty($database['name'])) {
$this->database_definition['name'] = $database['name'];
}
if (!empty($database['create'])) {
$this->database_definition['create'] = $database['create'];
}
if (!empty($database['overwrite'])) {
$this->database_definition['overwrite'] = $database['overwrite'];
}
if (!empty($database['charset'])) {
$this->database_definition['charset'] = $database['charset'];
}
if (!empty($database['description'])) {
$this->database_definition['description'] = $database['description'];
}
if (!empty($database['comments'])) {
$this->database_definition['comments'] = $database['comments'];
}
if (!empty($database['table']) && is_array($database['table'])) {
foreach ($database['table'] as $table) {
$this->fixTableKeys($table);
}
}
if (!empty($database['sequence']) && is_array($database['sequence'])) {
foreach ($database['sequence'] as $sequence) {
$this->fixSequenceKeys($sequence);
}
}
$result = $this->val->validateDatabase($this->database_definition);
if (PEAR::isError($result)) {
return $this->raiseError($result->getUserinfo());
}
return MDB2_OK;
}
function fixTableKeys($table)
{
$this->table = array(
'was' => '',
'description' => '',
'comments' => '',
'fields' => array(),
'indexes' => array(),
'constraints' => array(),
'initialization' => array()
);
if (!empty($table['name'])) {
$this->table_name = $table['name'];
} else {
$this->table_name = '';
}
if (!empty($table['was'])) {
$this->table['was'] = $table['was'];
}
if (!empty($table['description'])) {
$this->table['description'] = $table['description'];
}
if (!empty($table['comments'])) {
$this->table['comments'] = $table['comments'];
}
if (!empty($table['declaration']) && is_array($table['declaration'])) {
if (!empty($table['declaration']['field']) && is_array($table['declaration']['field'])) {
foreach ($table['declaration']['field'] as $field) {
$this->fixTableFieldKeys($field);
}
}
if (!empty($table['declaration']['index']) && is_array($table['declaration']['index'])) {
foreach ($table['declaration']['index'] as $index) {
$this->fixTableIndexKeys($index);
}
}
if (!empty($table['declaration']['foreign']) && is_array($table['declaration']['foreign'])) {
foreach ($table['declaration']['foreign'] as $constraint) {
$this->fixTableConstraintKeys($constraint);
}
}
}
if (!empty($table['initialization']) && is_array($table['initialization'])) {
if (!empty($table['initialization']['insert']) && is_array($table['initialization']['insert'])) {
foreach ($table['initialization']['insert'] as $init) {
$this->fixTableInitializationKeys($init, 'insert');
}
}
if (!empty($table['initialization']['update']) && is_array($table['initialization']['update'])) {
foreach ($table['initialization']['update'] as $init) {
$this->fixTableInitializationKeys($init, 'update');
}
}
if (!empty($table['initialization']['delete']) && is_array($table['initialization']['delete'])) {
foreach ($table['initialization']['delete'] as $init) {
$this->fixTableInitializationKeys($init, 'delete');
}
}
}
$result = $this->val->validateTable($this->database_definition['tables'], $this->table, $this->table_name);
if (PEAR::isError($result)) {
return $this->raiseError($result->getUserinfo());
} else {
$this->database_definition['tables'][$this->table_name] = $this->table;
}
return MDB2_OK;
}
function fixTableFieldKeys($field)
{
$this->field = array();
if (!empty($field['name'])) {
$this->field_name = $field['name'];
} else {
$this->field_name = '';
}
if (!empty($field['was'])) {
$this->field['was'] = $field['was'];
}
if (!empty($field['type'])) {
$this->field['type'] = $field['type'];
}
if (!empty($field['fixed'])) {
$this->field['fixed'] = $field['fixed'];
}
if (isset($field['default'])) {
$this->field['default'] = $field['default'];
}
if (!empty($field['notnull'])) {
$this->field['notnull'] = $field['notnull'];
}
if (!empty($field['autoincrement'])) {
$this->field['autoincrement'] = $field['autoincrement'];
}
if (!empty($field['unsigned'])) {
$this->field['unsigned'] = $field['unsigned'];
}
if (!empty($field['length'])) {
$this->field['length'] = $field['length'];
}
if (!empty($field['description'])) {
$this->field['description'] = $field['description'];
}
if (!empty($field['comments'])) {
$this->field['comments'] = $field['comments'];
}
$result = $this->val->validateField($this->table['fields'], $this->field, $this->field_name);
if (PEAR::isError($result)) {
return $this->raiseError($result->getUserinfo());
} else {
$this->table['fields'][$this->field_name] = $this->field;
}
return MDB2_OK;
}
function fixTableIndexKeys($index)
{
$this->index = array(
'was' => '',
'unique' =>'',
'primary' => '',
'fields' => array()
);
if (!empty($index['name'])) {
$this->index_name = $index['name'];
} else {
$this->index_name = '';
}
if (!empty($index['was'])) {
$this->index['was'] = $index['was'];
}
if (!empty($index['unique'])) {
$this->index['unique'] = $index['unique'];
}
if (!empty($index['primary'])) {
$this->index['primary'] = $index['primary'];
}
if (!empty($index['field'])) {
foreach ($index['field'] as $field) {
if (!empty($field['name'])) {
$this->field_name = $field['name'];
} else {
$this->field_name = '';
}
$this->field = array(
'sorting' => '',
'length' => ''
);
if (!empty($field['sorting'])) {
$this->field['sorting'] = $field['sorting'];
}
if (!empty($field['length'])) {
$this->field['length'] = $field['length'];
}
$result = $this->val->validateIndexField($this->index['fields'], $this->field, $this->field_name);
if (PEAR::isError($result)) {
return $this->raiseError($result->getUserinfo());
}
$this->index['fields'][$this->field_name] = $this->field;
}
}
$result = $this->val->validateIndex($this->table['indexes'], $this->index, $this->index_name);
if (PEAR::isError($result)) {
return $this->raiseError($result->getUserinfo());
} else {
$this->table['indexes'][$this->index_name] = $this->index;
}
return MDB2_OK;
}
function fixTableConstraintKeys($constraint)
{
$this->constraint = array(
'was' => '',
'match' => '',
'ondelete' => '',
'onupdate' => '',
'deferrable' => '',
'initiallydeferred' => '',
'foreign' => true,
'fields' => array(),
'references' => array('table' => '', 'fields' => array())
);
if (!empty($constraint['name'])) {
$this->constraint_name = $constraint['name'];
} else {
$this->constraint_name = '';
}
if (!empty($constraint['was'])) {
$this->constraint['was'] = $constraint['was'];
}
if (!empty($constraint['match'])) {
$this->constraint['match'] = $constraint['match'];
}
if (!empty($constraint['ondelete'])) {
$this->constraint['ondelete'] = $constraint['ondelete'];
}
if (!empty($constraint['onupdate'])) {
$this->constraint['onupdate'] = $constraint['onupdate'];
}
if (!empty($constraint['deferrable'])) {
$this->constraint['deferrable'] = $constraint['deferrable'];
}
if (!empty($constraint['initiallydeferred'])) {
$this->constraint['initiallydeferred'] = $constraint['initiallydeferred'];
}
if (!empty($constraint['field']) && is_array($constraint['field'])) {
foreach ($constraint['field'] as $field) {
$result = $this->val->validateConstraintField($this->constraint['fields'], $field);
if (PEAR::isError($result)) {
return $this->raiseError($result->getUserinfo());
}
$this->constraint['fields'][$field] = '';
}
}
if (!empty($constraint['references']) && is_array($constraint['references'])) {
/**
* As we forced 'table' to be enumerated
* we have to fix it on the foreign-references-table context
*/
if (!empty($constraint['references']['table']) && is_array($constraint['references']['table'])) {
$this->constraint['references']['table'] = $constraint['references']['table'][0];
}
if (!empty($constraint['references']['field']) && is_array($constraint['references']['field'])) {
foreach ($constraint['references']['field'] as $field) {
$result = $this->val->validateConstraintReferencedField($this->constraint['references']['fields'], $field);
if (PEAR::isError($result)) {
return $this->raiseError($result->getUserinfo());
}
$this->constraint['references']['fields'][$field] = '';
}
}
}
$result = $this->val->validateConstraint($this->table['constraints'], $this->constraint, $this->constraint_name);
if (PEAR::isError($result)) {
return $this->raiseError($result->getUserinfo());
} else {
$this->table['constraints'][$this->constraint_name] = $this->constraint;
}
return MDB2_OK;
}
function fixTableInitializationKeys($element, $type = '')
{
if (!empty($element['select']) && is_array($element['select'])) {
$this->fixTableInitializationDataKeys($element['select']);
$this->init = array( 'select' => $this->init );
} else {
$this->fixTableInitializationDataKeys($element);
}
$this->table['initialization'][] = array( 'type' => $type, 'data' => $this->init );
}
function fixTableInitializationDataKeys($element)
{
$this->init = array();
if (!empty($element['field']) && is_array($element['field'])) {
foreach ($element['field'] as $field) {
$name = $field['name'];
unset($field['name']);
$this->setExpression($field);
$this->init['field'][] = array( 'name' => $name, 'group' => $field );
}
}
/**
* As we forced 'table' to be enumerated
* we have to fix it on the insert-select context
*/
if (!empty($element['table']) && is_array($element['table'])) {
$this->init['table'] = $element['table'][0];
}
if (!empty($element['where']) && is_array($element['where'])) {
$this->init['where'] = $element['where'];
$this->setExpression($this->init['where']);
}
}
function setExpression(&$arr)
{
$element = each($arr);
$arr = array( 'type' => $element['key'] );
$element = $element['value'];
switch ($arr['type']) {
case 'null':
break;
case 'value':
case 'column':
$arr['data'] = $element;
break;
case 'function':
if (!empty($element)
&& is_array($element)
) {
$arr['data'] = array( 'name' => $element['name'] );
unset($element['name']);
foreach ($element as $type => $value) {
if (!empty($value)) {
if (is_array($value)) {
foreach ($value as $argument) {
$argument = array( $type => $argument );
$this->setExpression($argument);
$arr['data']['arguments'][] = $argument;
}
} else {
$arr['data']['arguments'][] = array( 'type' => $type, 'data' => $value );
}
}
}
}
break;
case 'expression':
$arr['data'] = array( 'operants' => array(), 'operator' => $element['operator'] );
unset($element['operator']);
foreach ($element as $k => $v) {
$argument = array( $k => $v );
$this->setExpression($argument);
$arr['data']['operants'][] = $argument;
}
break;
}
}
function fixSequenceKeys($sequence)
{
$this->sequence = array(
'was' => '',
'start' => '',
'description' => '',
'comments' => '',
'on' => array('table' => '', 'field' => '')
);
if (!empty($sequence['name'])) {
$this->sequence_name = $sequence['name'];
} else {
$this->sequence_name = '';
}
if (!empty($sequence['was'])) {
$this->sequence['was'] = $sequence['was'];
}
if (!empty($sequence['start'])) {
$this->sequence['start'] = $sequence['start'];
}
if (!empty($sequence['description'])) {
$this->sequence['description'] = $sequence['description'];
}
if (!empty($sequence['comments'])) {
$this->sequence['comments'] = $sequence['comments'];
}
if (!empty($sequence['on']) && is_array($sequence['on'])) {
/**
* As we forced 'table' to be enumerated
* we have to fix it on the sequence-on-table context
*/
if (!empty($sequence['on']['table']) && is_array($sequence['on']['table'])) {
$this->sequence['on']['table'] = $sequence['on']['table'][0];
}
/**
* As we forced 'field' to be enumerated
* we have to fix it on the sequence-on-field context
*/
if (!empty($sequence['on']['field']) && is_array($sequence['on']['field'])) {
$this->sequence['on']['field'] = $sequence['on']['field'][0];
}
}
$result = $this->val->validateSequence($this->database_definition['sequences'], $this->sequence, $this->sequence_name);
if (PEAR::isError($result)) {
return $this->raiseError($result->getUserinfo());
} else {
$this->database_definition['sequences'][$this->sequence_name] = $this->sequence;
}
return MDB2_OK;
}
function &raiseError($msg = null, $ecode = MDB2_SCHEMA_ERROR_PARSE)
{
if (is_null($this->error)) {
$error = 'Parser error: '.$msg."\n";
$this->error =& MDB2_Schema::raiseError($ecode, null, null, $error);
}
return $this->error;
}
}
?>

436
3rdparty/MDB2/Schema/Reserved/ibase.php vendored Normal file
View File

@ -0,0 +1,436 @@
<?php
// {{{ Disclaimer, Licence, copyrights
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. |
// | |
// | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions |
// | are met: |
// | |
// | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. |
// | |
// | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. |
// | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior|
// | written permission. |
// | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+
// | Author: Lorenzo Alberton <l.alberton@quipo.it> |
// +----------------------------------------------------------------------+
//
// }}}
// {{{ $GLOBALS['_MDB2_Schema_Reserved']['ibase']
/**
* Has a list of reserved words of Interbase/Firebird
*
* @package MDB2_Schema
* @category Database
* @access protected
* @author Lorenzo Alberton <l.alberton@quipo.it>
*/
$GLOBALS['_MDB2_Schema_Reserved']['ibase'] = array(
'ABS',
'ABSOLUTE',
'ACTION',
'ACTIVE',
'ADD',
'ADMIN',
'AFTER',
'ALL',
'ALLOCATE',
'ALTER',
'AND',
'ANY',
'ARE',
'AS',
'ASC',
'ASCENDING',
'ASSERTION',
'AT',
'AUTHORIZATION',
'AUTO',
'AUTODDL',
'AVG',
'BACKUP',
'BASE_NAME',
'BASED',
'BASENAME',
'BEFORE',
'BEGIN',
'BETWEEN',
'BIGINT',
'BIT',
'BIT_LENGTH',
'BLOB',
'BLOCK',
'BLOBEDIT',
'BOOLEAN',
'BOTH',
'BOTH',
'BREAK',
'BUFFER',
'BY',
'CACHE',
'CASCADE',
'CASCADED',
'CASE',
'CASE',
'CAST',
'CATALOG',
'CHAR',
'CHAR_LENGTH',
'CHARACTER',
'CHARACTER_LENGTH',
'CHECK',
'CHECK_POINT_LEN',
'CHECK_POINT_LENGTH',
'CLOSE',
'COALESCE',
'COLLATE',
'COLLATION',
'COLUMN',
'COMMENT',
'COMMIT',
'COMMITTED',
'COMPILETIME',
'COMPUTED',
'CONDITIONAL',
'CONNECT',
'CONNECTION',
'CONSTRAINT',
'CONSTRAINTS',
'CONTAINING',
'CONTINUE',
'CONVERT',
'CORRESPONDING',
'COUNT',
'CREATE',
'CROSS',
'CSTRING',
'CURRENT',
'CURRENT_CONNECTION',
'CURRENT_DATE',
'CURRENT_ROLE',
'CURRENT_TIME',
'CURRENT_TIMESTAMP',
'CURRENT_TRANSACTION',
'CURRENT_USER',
'DATABASE',
'DATE',
'DAY',
'DB_KEY',
'DEALLOCATE',
'DEBUG',
'DEC',
'DECIMAL',
'DECLARE',
'DEFAULT',
'DEFERRABLE',
'DEFERRED',
'DELETE',
'DELETING',
'DESC',
'DESCENDING',
'DESCRIBE',
'DESCRIPTOR',
'DIAGNOSTICS',
'DIFFERENCE',
'DISCONNECT',
'DISPLAY',
'DISTINCT',
'DO',
'DOMAIN',
'DOUBLE',
'DROP',
'ECHO',
'EDIT',
'ELSE',
'END',
'END-EXEC',
'ENTRY_POINT',
'ESCAPE',
'EVENT',
'EXCEPT',
'EXCEPTION',
'EXEC',
'EXECUTE',
'EXISTS',
'EXIT',
'EXTERN',
'EXTERNAL',
'EXTRACT',
'FALSE',
'FETCH',
'FILE',
'FILTER',
'FIRST',
'FLOAT',
'FOR',
'FOREIGN',
'FOUND',
'FREE_IT',
'FROM',
'FULL',
'FUNCTION',
'GDSCODE',
'GEN_ID',
'GENERATOR',
'GET',
'GLOBAL',
'GO',
'GOTO',
'GRANT',
'GROUP',
'GROUP_COMMIT_WAIT',
'GROUP_COMMIT_WAIT_TIME',
'HAVING',
'HELP',
'HOUR',
'IDENTITY',
'IF',
'IIF',
'IMMEDIATE',
'IN',
'INACTIVE',
'INDEX',
'INDICATOR',
'INIT',
'INITIALLY',
'INNER',
'INPUT',
'INPUT_TYPE',
'INSENSITIVE',
'INSERT',
'INSERTING',
'INT',
'INTEGER',
'INTERSECT',
'INTERVAL',
'INTO',
'IS',
'ISOLATION',
'ISQL',
'JOIN',
'KEY',
'LANGUAGE',
'LAST',
'LC_MESSAGES',
'LC_TYPE',
'LEADING',
'LEADING',
'LEADING',
'LEAVE',
'LEFT',
'LENGTH',
'LEV',
'LEVEL',
'LIKE',
'LOCAL',
'LOCK',
'LOG_BUF_SIZE',
'LOG_BUFFER_SIZE',
'LOGFILE',
'LONG',
'LOWER',
'MANUAL',
'MATCH',
'MAX',
'MAX_SEGMENT',
'MAXIMUM',
'MAXIMUM_SEGMENT',
'MERGE',
'MESSAGE',
'MIN',
'MINIMUM',
'MINUTE',
'MODULE',
'MODULE_NAME',
'MONTH',
'NAMES',
'NATIONAL',
'NATURAL',
'NCHAR',
'NEXT',
'NO',
'NOAUTO',
'NOT',
'NULL',
'NULLIF',
'NULLS',
'NUM_LOG_BUFFERS',
'NUM_LOG_BUFS',
'NUMERIC',
'OCTET_LENGTH',
'OF',
'ON',
'ONLY',
'OPEN',
'OPTION',
'OR',
'ORDER',
'OUTER',
'OUTPUT',
'OUTPUT_TYPE',
'OVERFLOW',
'OVERLAPS',
'PAD',
'PAGE',
'PAGE_SIZE',
'PAGELENGTH',
'PAGES',
'PARAMETER',
'PARTIAL',
'PASSWORD',
'PERCENT',
'PLAN',
'POSITION',
'POST_EVENT',
'PRECISION',
'PREPARE',
'PRESERVE',
'PRIMARY',
'PRIOR',
'PRIVILEGES',
'PROCEDURE',
'PUBLIC',
'QUIT',
'RAW_PARTITIONS',
'RDB$DB_KEY',
'READ',
'REAL',
'RECORD_VERSION',
'RECREATE',
'RECREATE ROW_COUNT',
'REFERENCES',
'RELATIVE',
'RELEASE',
'RESERV',
'RESERVING',
'RESTART',
'RESTRICT',
'RETAIN',
'RETURN',
'RETURNING',
'RETURNING_VALUES',
'RETURNS',
'REVOKE',
'RIGHT',
'ROLE',
'ROLLBACK',
'ROW_COUNT',
'ROWS',
'RUNTIME',
'SAVEPOINT',
'SCALAR_ARRAY',
'SCHEMA',
'SCROLL',
'SECOND',
'SECTION',
'SELECT',
'SEQUENCE',
'SESSION',
'SESSION_USER',
'SET',
'SHADOW',
'SHARED',
'SHELL',
'SHOW',
'SINGULAR',
'SIZE',
'SKIP',
'SMALLINT',
'SNAPSHOT',
'SOME',
'SORT',
'SPACE',
'SQL',
'SQLCODE',
'SQLERROR',
'SQLSTATE',
'SQLWARNING',
'STABILITY',
'STARTING',
'STARTS',
'STATEMENT',
'STATIC',
'STATISTICS',
'SUB_TYPE',
'SUBSTRING',
'SUM',
'SUSPEND',
'SYSTEM_USER',
'TABLE',
'TEMPORARY',
'TERMINATOR',
'THEN',
'TIES',
'TIME',
'TIMESTAMP',
'TIMEZONE_HOUR',
'TIMEZONE_MINUTE',
'TO',
'TRAILING',
'TRANSACTION',
'TRANSLATE',
'TRANSLATION',
'TRIGGER',
'TRIM',
'TRUE',
'TYPE',
'UNCOMMITTED',
'UNION',
'UNIQUE',
'UNKNOWN',
'UPDATE',
'UPDATING',
'UPPER',
'USAGE',
'USER',
'USING',
'VALUE',
'VALUES',
'VARCHAR',
'VARIABLE',
'VARYING',
'VERSION',
'VIEW',
'WAIT',
'WEEKDAY',
'WHEN',
'WHENEVER',
'WHERE',
'WHILE',
'WITH',
'WORK',
'WRITE',
'YEAR',
'YEARDAY',
'ZONE',
);
// }}}
?>

258
3rdparty/MDB2/Schema/Reserved/mssql.php vendored Normal file
View File

@ -0,0 +1,258 @@
<?php
// {{{ Disclaimer, Licence, copyrights
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. |
// | |
// | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions |
// | are met: |
// | |
// | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. |
// | |
// | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. |
// | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior|
// | written permission. |
// | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+
// | Author: David Coallier <davidc@php.net> |
// +----------------------------------------------------------------------+
// }}}
// {{{ $GLOBALS['_MDB2_Schema_Reserved']['mssql']
/**
* Has a list of all the reserved words for mssql.
*
* @package MDB2_Schema
* @category Database
* @access protected
* @author David Coallier <davidc@php.net>
*/
$GLOBALS['_MDB2_Schema_Reserved']['mssql'] = array(
'ADD',
'CURRENT_TIMESTAMP',
'GROUP',
'OPENQUERY',
'SERIALIZABLE',
'ALL',
'CURRENT_USER',
'HAVING',
'OPENROWSET',
'SESSION_USER',
'ALTER',
'CURSOR',
'HOLDLOCK',
'OPTION',
'SET',
'AND',
'DATABASE',
'IDENTITY',
'OR',
'SETUSER',
'ANY',
'DBCC',
'IDENTITYCOL',
'ORDER',
'SHUTDOWN',
'AS',
'DEALLOCATE',
'IDENTITY_INSERT',
'OUTER',
'SOME',
'ASC',
'DECLARE',
'IF',
'OVER',
'STATISTICS',
'AUTHORIZATION',
'DEFAULT',
'IN',
'PERCENT',
'SUM',
'AVG',
'DELETE',
'INDEX',
'PERM',
'SYSTEM_USER',
'BACKUP',
'DENY',
'INNER',
'PERMANENT',
'TABLE',
'BEGIN',
'DESC',
'INSERT',
'PIPE',
'TAPE',
'BETWEEN',
'DISK',
'INTERSECT',
'PLAN',
'TEMP',
'BREAK',
'DISTINCT',
'INTO',
'PRECISION',
'TEMPORARY',
'BROWSE',
'DISTRIBUTED',
'IS',
'PREPARE',
'TEXTSIZE',
'BULK',
'DOUBLE',
'ISOLATION',
'PRIMARY',
'THEN',
'BY',
'DROP',
'JOIN',
'PRINT',
'TO',
'CASCADE',
'DUMMY',
'KEY',
'PRIVILEGES',
'TOP',
'CASE',
'DUMP',
'KILL',
'PROC',
'TRAN',
'CHECK',
'ELSE',
'LEFT',
'PROCEDURE',
'TRANSACTION',
'CHECKPOINT',
'END',
'LEVEL',
'PROCESSEXIT',
'TRIGGER',
'CLOSE',
'ERRLVL',
'LIKE',
'PUBLIC',
'TRUNCATE',
'CLUSTERED',
'ERROREXIT',
'LINENO',
'RAISERROR',
'TSEQUAL',
'COALESCE',
'ESCAPE',
'LOAD',
'READ',
'UNCOMMITTED',
'COLUMN',
'EXCEPT',
'MAX',
'READTEXT',
'UNION',
'COMMIT',
'EXEC',
'MIN',
'RECONFIGURE',
'UNIQUE',
'COMMITTED',
'EXECUTE',
'MIRROREXIT',
'REFERENCES',
'UPDATE',
'COMPUTE',
'EXISTS',
'NATIONAL',
'REPEATABLE',
'UPDATETEXT',
'CONFIRM',
'EXIT',
'NOCHECK',
'REPLICATION',
'USE',
'CONSTRAINT',
'FETCH',
'NONCLUSTERED',
'RESTORE',
'USER',
'CONTAINS',
'FILE',
'NOT',
'RESTRICT',
'VALUES',
'CONTAINSTABLE',
'FILLFACTOR',
'NULL',
'RETURN',
'VARYING',
'CONTINUE',
'FLOPPY',
'NULLIF',
'REVOKE',
'VIEW',
'CONTROLROW',
'FOR',
'OF',
'RIGHT',
'WAITFOR',
'CONVERT',
'FOREIGN',
'OFF',
'ROLLBACK',
'WHEN',
'COUNT',
'FREETEXT',
'OFFSETS',
'ROWCOUNT',
'WHERE',
'CREATE',
'FREETEXTTABLE',
'ON',
'ROWGUIDCOL',
'WHILE',
'CROSS',
'FROM',
'ONCE',
'RULE',
'WITH',
'CURRENT',
'FULL',
'ONLY',
'SAVE',
'WORK',
'CURRENT_DATE',
'GOTO',
'OPEN',
'SCHEMA',
'WRITETEXT',
'CURRENT_TIME',
'GRANT',
'OPENDATASOURCE',
'SELECT',
);
//}}}
?>

284
3rdparty/MDB2/Schema/Reserved/mysql.php vendored Normal file
View File

@ -0,0 +1,284 @@
<?php
// {{{ Disclaimer, Licence, copyrights
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. |
// | |
// | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions |
// | are met: |
// | |
// | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. |
// | |
// | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. |
// | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior|
// | written permission. |
// | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+
// | Author: David Coallier <davidc@php.net> |
// +----------------------------------------------------------------------+
//
// $Id: mysql.php,v 1.3 2006/03/01 12:16:40 lsmith Exp $
// }}}
// {{{ $GLOBALS['_MDB2_Schema_Reserved']['mysql']
/**
* Has a list of reserved words of mysql
*
* @package MDB2_Schema
* @category Database
* @access protected
* @author David Coalier <davidc@php.net>
*/
$GLOBALS['_MDB2_Schema_Reserved']['mysql'] = array(
'ADD',
'ALL',
'ALTER',
'ANALYZE',
'AND',
'AS',
'ASC',
'ASENSITIVE',
'BEFORE',
'BETWEEN',
'BIGINT',
'BINARY',
'BLOB',
'BOTH',
'BY',
'CALL',
'CASCADE',
'CASE',
'CHANGE',
'CHAR',
'CHARACTER',
'CHECK',
'COLLATE',
'COLUMN',
'CONDITION',
'CONNECTION',
'CONSTRAINT',
'CONTINUE',
'CONVERT',
'CREATE',
'CROSS',
'CURRENT_DATE',
'CURRENT_TIME',
'CURRENT_TIMESTAMP',
'CURRENT_USER',
'CURSOR',
'DATABASE',
'DATABASES',
'DAY_HOUR',
'DAY_MICROSECOND',
'DAY_MINUTE',
'DAY_SECOND',
'DEC',
'DECIMAL',
'DECLARE',
'DEFAULT',
'DELAYED',
'DELETE',
'DESC',
'DESCRIBE',
'DETERMINISTIC',
'DISTINCT',
'DISTINCTROW',
'DIV',
'DOUBLE',
'DROP',
'DUAL',
'EACH',
'ELSE',
'ELSEIF',
'ENCLOSED',
'ESCAPED',
'EXISTS',
'EXIT',
'EXPLAIN',
'FALSE',
'FETCH',
'FLOAT',
'FLOAT4',
'FLOAT8',
'FOR',
'FORCE',
'FOREIGN',
'FROM',
'FULLTEXT',
'GOTO',
'GRANT',
'GROUP',
'HAVING',
'HIGH_PRIORITY',
'HOUR_MICROSECOND',
'HOUR_MINUTE',
'HOUR_SECOND',
'IF',
'IGNORE',
'IN',
'INDEX',
'INFILE',
'INNER',
'INOUT',
'INSENSITIVE',
'INSERT',
'INT',
'INT1',
'INT2',
'INT3',
'INT4',
'INT8',
'INTEGER',
'INTERVAL',
'INTO',
'IS',
'ITERATE',
'JOIN',
'KEY',
'KEYS',
'KILL',
'LABEL',
'LEADING',
'LEAVE',
'LEFT',
'LIKE',
'LIMIT',
'LINES',
'LOAD',
'LOCALTIME',
'LOCALTIMESTAMP',
'LOCK',
'LONG',
'LONGBLOB',
'LONGTEXT',
'LOOP',
'LOW_PRIORITY',
'MATCH',
'MEDIUMBLOB',
'MEDIUMINT',
'MEDIUMTEXT',
'MIDDLEINT',
'MINUTE_MICROSECOND',
'MINUTE_SECOND',
'MOD',
'MODIFIES',
'NATURAL',
'NOT',
'NO_WRITE_TO_BINLOG',
'NULL',
'NUMERIC',
'ON',
'OPTIMIZE',
'OPTION',
'OPTIONALLY',
'OR',
'ORDER',
'OUT',
'OUTER',
'OUTFILE',
'PRECISION',
'PRIMARY',
'PROCEDURE',
'PURGE',
'RAID0',
'READ',
'READS',
'REAL',
'REFERENCES',
'REGEXP',
'RELEASE',
'RENAME',
'REPEAT',
'REPLACE',
'REQUIRE',
'RESTRICT',
'RETURN',
'REVOKE',
'RIGHT',
'RLIKE',
'SCHEMA',
'SCHEMAS',
'SECOND_MICROSECOND',
'SELECT',
'SENSITIVE',
'SEPARATOR',
'SET',
'SHOW',
'SMALLINT',
'SONAME',
'SPATIAL',
'SPECIFIC',
'SQL',
'SQLEXCEPTION',
'SQLSTATE',
'SQLWARNING',
'SQL_BIG_RESULT',
'SQL_CALC_FOUND_ROWS',
'SQL_SMALL_RESULT',
'SSL',
'STARTING',
'STRAIGHT_JOIN',
'TABLE',
'TERMINATED',
'THEN',
'TINYBLOB',
'TINYINT',
'TINYTEXT',
'TO',
'TRAILING',
'TRIGGER',
'TRUE',
'UNDO',
'UNION',
'UNIQUE',
'UNLOCK',
'UNSIGNED',
'UPDATE',
'USAGE',
'USE',
'USING',
'UTC_DATE',
'UTC_TIME',
'UTC_TIMESTAMP',
'VALUES',
'VARBINARY',
'VARCHAR',
'VARCHARACTER',
'VARYING',
'WHEN',
'WHERE',
'WHILE',
'WITH',
'WRITE',
'X509',
'XOR',
'YEAR_MONTH',
'ZEROFILL',
);
// }}}
?>

171
3rdparty/MDB2/Schema/Reserved/oci8.php vendored Normal file
View File

@ -0,0 +1,171 @@
<?php
// {{{ Disclaimer, Licence, copyrights
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. |
// | |
// | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions |
// | are met: |
// | |
// | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. |
// | |
// | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. |
// | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior|
// | written permission. |
// | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+
// | Author: David Coallier <davidc@php.net> |
// +----------------------------------------------------------------------+
// }}}
// {{{ $GLOBALS['_MDB2_Schema_Reserved']['oci8']
/**
* Has a list of all the reserved words for oracle.
*
* @package MDB2_Schema
* @category Database
* @access protected
* @author David Coallier <davidc@php.net>
*/
$GLOBALS['_MDB2_Schema_Reserved']['oci8'] = array(
'ACCESS',
'ELSE',
'MODIFY',
'START',
'ADD',
'EXCLUSIVE',
'NOAUDIT',
'SELECT',
'ALL',
'EXISTS',
'NOCOMPRESS',
'SESSION',
'ALTER',
'FILE',
'NOT',
'SET',
'AND',
'FLOAT',
'NOTFOUND ',
'SHARE',
'ANY',
'FOR',
'NOWAIT',
'SIZE',
'ARRAYLEN',
'FROM',
'NULL',
'SMALLINT',
'AS',
'GRANT',
'NUMBER',
'SQLBUF',
'ASC',
'GROUP',
'OF',
'SUCCESSFUL',
'AUDIT',
'HAVING',
'OFFLINE ',
'SYNONYM',
'BETWEEN',
'IDENTIFIED',
'ON',
'SYSDATE',
'BY',
'IMMEDIATE',
'ONLINE',
'TABLE',
'CHAR',
'IN',
'OPTION',
'THEN',
'CHECK',
'INCREMENT',
'OR',
'TO',
'CLUSTER',
'INDEX',
'ORDER',
'TRIGGER',
'COLUMN',
'INITIAL',
'PCTFREE',
'UID',
'COMMENT',
'INSERT',
'PRIOR',
'UNION',
'COMPRESS',
'INTEGER',
'PRIVILEGES',
'UNIQUE',
'CONNECT',
'INTERSECT',
'PUBLIC',
'UPDATE',
'CREATE',
'INTO',
'RAW',
'USER',
'CURRENT',
'IS',
'RENAME',
'VALIDATE',
'DATE',
'LEVEL',
'RESOURCE',
'VALUES',
'DECIMAL',
'LIKE',
'REVOKE',
'VARCHAR',
'DEFAULT',
'LOCK',
'ROW',
'VARCHAR2',
'DELETE',
'LONG',
'ROWID',
'VIEW',
'DESC',
'MAXEXTENTS',
'ROWLABEL',
'WHENEVER',
'DISTINCT',
'MINUS',
'ROWNUM',
'WHERE',
'DROP',
'MODE',
'ROWS',
'WITH',
);
// }}}
?>

147
3rdparty/MDB2/Schema/Reserved/pgsql.php vendored Normal file
View File

@ -0,0 +1,147 @@
<?php
// {{{ Disclaimer, Licence, copyrights
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. |
// | |
// | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions |
// | are met: |
// | |
// | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. |
// | |
// | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. |
// | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior|
// | written permission. |
// | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+
// | Author: Marcelo Santos Araujo <msaraujo@php.net> |
// +----------------------------------------------------------------------+
//
// }}}
// {{{ $GLOBALS['_MDB2_Schema_Reserved']['pgsql']
/**
* Has a list of reserved words of pgsql
*
* @package MDB2_Schema
* @category Database
* @access protected
* @author Marcelo Santos Araujo <msaraujo@php.net>
*/
$GLOBALS['_MDB2_Schema_Reserved']['pgsql'] = array(
'ALL',
'ANALYSE',
'ANALYZE',
'AND',
'ANY',
'AS',
'ASC',
'AUTHORIZATION',
'BETWEEN',
'BINARY',
'BOTH',
'CASE',
'CAST',
'CHECK',
'COLLATE',
'COLUMN',
'CONSTRAINT',
'CREATE',
'CURRENT_DATE',
'CURRENT_TIME',
'CURRENT_TIMESTAMP',
'CURRENT_USER',
'DEFAULT',
'DEFERRABLE',
'DESC',
'DISTINCT',
'DO',
'ELSE',
'END',
'EXCEPT',
'FALSE',
'FOR',
'FOREIGN',
'FREEZE',
'FROM',
'FULL',
'GRANT',
'GROUP',
'HAVING',
'ILIKE',
'IN',
'INITIALLY',
'INNER',
'INTERSECT',
'INTO',
'IS',
'ISNULL',
'JOIN',
'LEADING',
'LEFT',
'LIKE',
'LIMIT',
'LOCALTIME',
'LOCALTIMESTAMP',
'NATURAL',
'NEW',
'NOT',
'NOTNULL',
'NULL',
'OFF',
'OFFSET',
'OLD',
'ON',
'ONLY',
'OR',
'ORDER',
'OUTER',
'OVERLAPS',
'PLACING',
'PRIMARY',
'REFERENCES',
'SELECT',
'SESSION_USER',
'SIMILAR',
'SOME',
'TABLE',
'THEN',
'TO',
'TRAILING',
'TRUE',
'UNION',
'UNIQUE',
'USER',
'USING',
'VERBOSE',
'WHEN',
'WHERE'
);
// }}}
?>

560
3rdparty/MDB2/Schema/Tool.php vendored Normal file
View File

@ -0,0 +1,560 @@
<?php
/**
* PHP versions 4 and 5
*
* Copyright (c) 1998-2008 Manuel Lemos, Tomas V.V.Cox,
* Stig. S. Bakken, Lukas Smith, Igor Feghali
* All rights reserved.
*
* MDB2_Schema enables users to maintain RDBMS independant schema files
* in XML that can be used to manipulate both data and database schemas
* This LICENSE is in the BSD license style.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken,
* Lukas Smith, Igor Feghali nor the names of his contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* Author: Christian Weiske <cweiske@php.net>
* $Id: Tool.php,v 1.6 2008/12/13 00:26:07 clockwerx Exp $
*
* @category Database
* @package MDB2_Schema
* @author Christian Weiske <cweiske@php.net>
* @license BSD http://www.opensource.org/licenses/bsd-license.php
* @version CVS: $Id: Tool.php,v 1.6 2008/12/13 00:26:07 clockwerx Exp $
* @link http://pear.php.net/packages/MDB2_Schema
*/
require_once 'MDB2/Schema.php';
require_once 'MDB2/Schema/Tool/ParameterException.php';
/**
* Command line tool to work with database schemas
*
* Functionality:
* - dump a database schema to stdout
* - import schema into database
* - create a diff between two schemas
* - apply diff to database
*
* @category Database
* @package MDB2_Schema
* @author Christian Weiske <cweiske@php.net>
* @license BSD http://www.opensource.org/licenses/bsd-license.php
* @link http://pear.php.net/packages/MDB2_Schema
*/
class MDB2_Schema_Tool
{
/**
* Run the schema tool
*
* @param array $args Array of command line arguments
*/
public function __construct($args)
{
$strAction = $this->getAction($args);
try {
$this->{'do' . ucfirst($strAction)}($args);
} catch (MDB2_Schema_Tool_ParameterException $e) {
$this->{'doHelp' . ucfirst($strAction)}($e->getMessage());
}
}//public function __construct($args)
/**
* Runs the tool with command line arguments
*
* @return void
*/
public static function run()
{
$args = $GLOBALS['argv'];
array_shift($args);
try {
$tool = new MDB2_Schema_Tool($args);
} catch (Exception $e) {
self::toStdErr($e->getMessage() . "\n");
}
}//public static function run()
/**
* Reads the first parameter from the argument array and
* returns the action.
*
* @param array &$args Command line parameters
*
* @return string Action to execute
*/
protected function getAction(&$args)
{
if (count($args) == 0) {
return 'help';
}
$arg = array_shift($args);
switch ($arg) {
case 'h':
case 'help':
case '-h':
case '--help':
return 'help';
case 'd':
case 'dump':
case '-d':
case '--dump':
return 'dump';
case 'l':
case 'load':
case '-l':
case '--load':
return 'load';
case 'i':
case 'diff':
case '-i':
case '--diff':
return 'diff';
case 'a':
case 'apply':
case '-a':
case '--apply':
return 'apply';
case 'n':
case 'init':
case '-i':
case '--init':
return 'init';
default:
throw new MDB2_Schema_Tool_ParameterException("Unknown mode \"$arg\"");
}
}//protected function getAction(&$args)
/**
* Writes the message to stderr
*
* @param string $msg Message to print
*
* @return void
*/
protected static function toStdErr($msg)
{
file_put_contents('php://stderr', $msg);
}//protected static function toStdErr($msg)
/**
* Displays generic help to stdout
*
* @return void
*/
protected function doHelp()
{
self::toStdErr(<<<EOH
Usage: mdb2_schematool mode parameters
Works with database schemas
mode: (- and -- are optional)
h, help Show this help screen
d, dump Dump a schema to stdout
l, load Load a schema into database
i, diff Create a diff between two schemas and dump it to stdout
a, apply Apply a diff to a database
n, init Initialize a database with data
EOH
);
}//protected function doHelp()
/**
* Displays the help screen for "dump" command
*
* @return void
*/
protected function doHelpDump()
{
self::toStdErr( <<<EOH
Usage: mdb2_schematool dump [all|data|schema] [-p] DSN
Dumps a database schema to stdout
If dump type is not specified, defaults to "schema".
DSN: Data source name in the form of
driver://user:password@host/database
User and password may be omitted.
Using -p reads password from stdin which is more secure than passing it in the parameter.
EOH
);
}//protected function doHelpDump()
/**
* Displays the help screen for "init" command
*
* @return void
*/
protected function doHelpInit()
{
self::toStdErr( <<<EOH
Usage: mdb2_schematool init source [-p] destination
Initializes a database with data
(Inserts data on a previous created database at destination)
source should be a schema file containing data,
destination should be a DSN
DSN: Data source name in the form of
driver://user:password@host/database
User and password may be omitted.
Using -p reads password from stdin which is more secure than passing it in the parameter.
EOH
);
}//protected function doHelpInit()
/**
* Displays the help screen for "load" command
*
* @return void
*/
protected function doHelpLoad()
{
self::toStdErr( <<<EOH
Usage: mdb2_schematool load [-p] source [-p] destination
Loads a database schema from source to destination
(Creates the database schema at destination)
source can be a DSN or a schema file,
destination should be a DSN
DSN: Data source name in the form of
driver://user:password@host/database
User and password may be omitted.
Using -p reads password from stdin which is more secure than passing it in the parameter.
EOH
);
}//protected function doHelpLoad()
/**
* Returns an array of options for MDB2_Schema constructor
*
* @return array Options for MDB2_Schema constructor
*/
protected function getSchemaOptions()
{
$options = array(
'log_line_break' => '<br>',
'idxname_format' => '%s',
'debug' => true,
'quote_identifier' => true,
'force_defaults' => false,
'portability' => true,
'use_transactions' => false,
);
return $options;
}//protected function getSchemaOptions()
/**
* Checks if the passed parameter is a PEAR_Error object
* and throws an exception in that case.
*
* @param mixed $object Some variable to check
* @param string $location Where the error occured
*
* @return void
*/
protected function throwExceptionOnError($object, $location = '')
{
if (PEAR::isError($object)) {
//FIXME: exception class
//debug_print_backtrace();
throw new Exception('Error ' . $location
. "\n" . $object->getMessage()
. "\n" . $object->getUserInfo()
);
}
}//protected function throwExceptionOnError($object, $location = '')
/**
* Loads a file or a dsn from the arguments
*
* @param array &$args Array of arguments to the program
*
* @return array Array of ('file'|'dsn', $value)
*/
protected function getFileOrDsn(&$args)
{
if (count($args) == 0) {
throw new MDB2_Schema_Tool_ParameterException('File or DSN expected');
}
$arg = array_shift($args);
if ($arg == '-p') {
$bAskPassword = true;
$arg = array_shift($args);
} else {
$bAskPassword = false;
}
if (strpos($arg, '://') === false) {
if (file_exists($arg)) {
//File
return array('file', $arg);
} else {
throw new Exception('Schema file does not exist');
}
}
//read password if necessary
if ($bAskPassword) {
$password = $this->readPasswordFromStdin($arg);
$arg = self::setPasswordIntoDsn($arg, $password);
self::toStdErr($arg);
}
return array('dsn', $arg);
}//protected function getFileOrDsn(&$args)
/**
* Takes a DSN data source name and integrates the given
* password into it.
*
* @param string $dsn Data source name
* @param string $password Password
*
* @return string DSN with password
*/
protected function setPasswordIntoDsn($dsn, $password)
{
//simple try to integrate password
if (strpos($dsn, '@') === false) {
//no @ -> no user and no password
return str_replace('://', '://:' . $password . '@', $dsn);
} else if (preg_match('|://[^:]+@|', $dsn)) {
//user only, no password
return str_replace('@', ':' . $password . '@', $dsn);
} else if (strpos($dsn, ':@') !== false) {
//abstract version
return str_replace(':@', ':' . $password . '@', $dsn);
}
return $dsn;
}//protected function setPasswordIntoDsn($dsn, $password)
/**
* Reads a password from stdin
*
* @param string $dsn DSN name to put into the message
*
* @return string Password
*/
protected function readPasswordFromStdin($dsn)
{
$stdin = fopen('php://stdin', 'r');
self::toStdErr('Please insert password for ' . $dsn . "\n");
$password = '';
$breakme = false;
while (false !== ($char = fgetc($stdin))) {
if (ord($char) == 10 || $char == "\n" || $char == "\r") {
break;
}
$password .= $char;
}
fclose($stdin);
return trim($password);
}//protected function readPasswordFromStdin()
/**
* Creates a database schema dump and sends it to stdout
*
* @param array $args Command line arguments
*
* @return void
*/
protected function doDump($args)
{
$dump_what = MDB2_SCHEMA_DUMP_STRUCTURE;
$arg = '';
if (count($args)) {
$arg = $args[0];
}
switch (strtolower($arg)) {
case 'all':
$dump_what = MDB2_SCHEMA_DUMP_ALL;
array_shift($args);
break;
case 'data':
$dump_what = MDB2_SCHEMA_DUMP_CONTENT;
array_shift($args);
break;
case 'schema':
array_shift($args);
}
list($type, $dsn) = $this->getFileOrDsn($args);
if ($type == 'file') {
throw new MDB2_Schema_Tool_ParameterException(
'Dumping a schema file as a schema file does not make much sense'
);
}
$schema = MDB2_Schema::factory($dsn, $this->getSchemaOptions());
$this->throwExceptionOnError($schema);
$definition = $schema->getDefinitionFromDatabase();
$this->throwExceptionOnError($definition);
$dump_options = array(
'output_mode' => 'file',
'output' => 'php://stdout',
'end_of_line' => "\r\n"
);
$op = $schema->dumpDatabase(
$definition, $dump_options, $dump_what
);
$this->throwExceptionOnError($op);
$schema->disconnect();
}//protected function doDump($args)
/**
* Loads a database schema
*
* @param array $args Command line arguments
*
* @return void
*/
protected function doLoad($args)
{
list($typeSource, $dsnSource) = $this->getFileOrDsn($args);
list($typeDest, $dsnDest) = $this->getFileOrDsn($args);
if ($typeDest == 'file') {
throw new MDB2_Schema_Tool_ParameterException(
'A schema can only be loaded into a database, not a file'
);
}
$schemaDest = MDB2_Schema::factory($dsnDest, $this->getSchemaOptions());
$this->throwExceptionOnError($schemaDest);
//load definition
if ($typeSource == 'file') {
$definition = $schemaDest->parseDatabaseDefinitionFile($dsnSource);
$where = 'loading schema file';
} else {
$schemaSource = MDB2_Schema::factory($dsnSource, $this->getSchemaOptions());
$this->throwExceptionOnError($schemaSource, 'connecting to source database');
$definition = $schemaSource->getDefinitionFromDatabase();
$where = 'loading definition from database';
}
$this->throwExceptionOnError($definition, $where);
//create destination database from definition
$simulate = false;
$op = $schemaDest->createDatabase($definition, array(), $simulate);
$this->throwExceptionOnError($op, 'creating the database');
}//protected function doLoad($args)
/**
* Initializes a database with data
*
* @param array $args Command line arguments
*
* @return void
*/
protected function doInit($args)
{
list($typeSource, $dsnSource) = $this->getFileOrDsn($args);
list($typeDest, $dsnDest) = $this->getFileOrDsn($args);
if ($typeSource != 'file') {
throw new MDB2_Schema_Tool_ParameterException(
'Data must come from a source file'
);
}
if ($typeDest != 'dsn') {
throw new MDB2_Schema_Tool_ParameterException(
'A schema can only be loaded into a database, not a file'
);
}
$schemaDest = MDB2_Schema::factory($dsnDest, $this->getSchemaOptions());
$this->throwExceptionOnError($schemaDest, 'connecting to destination database');
$definition = $schemaDest->getDefinitionFromDatabase();
$this->throwExceptionOnError($definition, 'loading definition from database');
$op = $schemaDest->writeInitialization($dsnSource, $definition);
$this->throwExceptionOnError($op, 'initializing database');
}//protected function doInit($args)
}//class MDB2_Schema_Tool
?>

View File

@ -0,0 +1,6 @@
<?php
class MDB2_Schema_Tool_ParameterException extends Exception
{}
?>

917
3rdparty/MDB2/Schema/Validate.php vendored Normal file
View File

@ -0,0 +1,917 @@
<?php
/**
* PHP versions 4 and 5
*
* Copyright (c) 1998-2008 Manuel Lemos, Tomas V.V.Cox,
* Stig. S. Bakken, Lukas Smith, Igor Feghali
* All rights reserved.
*
* MDB2_Schema enables users to maintain RDBMS independant schema files
* in XML that can be used to manipulate both data and database schemas
* This LICENSE is in the BSD license style.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken,
* Lukas Smith, Igor Feghali nor the names of his contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* Author: Christian Dickmann <dickmann@php.net>
* Author: Igor Feghali <ifeghali@php.net>
*
* @category Database
* @package MDB2_Schema
* @author Christian Dickmann <dickmann@php.net>
* @author Igor Feghali <ifeghali@php.net>
* @license BSD http://www.opensource.org/licenses/bsd-license.php
* @version CVS: $Id: Validate.php,v 1.42 2008/11/30 03:34:00 clockwerx Exp $
* @link http://pear.php.net/packages/MDB2_Schema
*/
/**
* Validates an XML schema file
*
* @category Database
* @package MDB2_Schema
* @author Igor Feghali <ifeghali@php.net>
* @license BSD http://www.opensource.org/licenses/bsd-license.php
* @link http://pear.php.net/packages/MDB2_Schema
*/
class MDB2_Schema_Validate
{
// {{{ properties
var $fail_on_invalid_names = true;
var $valid_types = array();
var $force_defaults = true;
// }}}
// {{{ constructor
function __construct($fail_on_invalid_names = true, $valid_types = array(), $force_defaults = true)
{
if (empty($GLOBALS['_MDB2_Schema_Reserved'])) {
$GLOBALS['_MDB2_Schema_Reserved'] = array();
}
if (is_array($fail_on_invalid_names)) {
$this->fail_on_invalid_names = array_intersect($fail_on_invalid_names,
array_keys($GLOBALS['_MDB2_Schema_Reserved']));
} elseif ($fail_on_invalid_names === true) {
$this->fail_on_invalid_names = array_keys($GLOBALS['_MDB2_Schema_Reserved']);
} else {
$this->fail_on_invalid_names = array();
}
$this->valid_types = $valid_types;
$this->force_defaults = $force_defaults;
}
// }}}
// {{{ raiseError()
function &raiseError($ecode, $msg = null)
{
$error =& MDB2_Schema::raiseError($ecode, null, null, $msg);
return $error;
}
// }}}
// {{{ isBoolean()
/**
* Verifies if a given value can be considered boolean. If yes, set value
* to true or false according to its actual contents and return true. If
* not, keep its contents untouched and return false.
*
* @param mixed &$value value to be checked
*
* @return bool
*
* @access public
* @static
*/
function isBoolean(&$value)
{
if (is_bool($value)) {
return true;
}
if ($value === 0 || $value === 1 || $value === '') {
$value = (bool)$value;
return true;
}
if (!is_string($value)) {
return false;
}
switch ($value) {
case '0':
case 'N':
case 'n':
case 'no':
case 'false':
$value = false;
break;
case '1':
case 'Y':
case 'y':
case 'yes':
case 'true':
$value = true;
break;
default:
return false;
}
return true;
}
// }}}
// {{{ validateTable()
/* Definition */
/**
* Checks whether the definition of a parsed table is valid. Modify table
* definition when necessary.
*
* @param array $tables multi dimensional array that contains the
* tables of current database.
* @param array &$table multi dimensional array that contains the
* structure and optional data of the table.
* @param string $table_name name of the parsed table
*
* @return bool|error object
*
* @access public
*/
function validateTable($tables, &$table, $table_name)
{
/* Have we got a name? */
if (!$table_name) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'a table has to have a name');
}
/* Table name duplicated? */
if (is_array($tables) && isset($tables[$table_name])) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'table "'.$table_name.'" already exists');
}
/* Table name reserved? */
if (is_array($this->fail_on_invalid_names)) {
$name = strtoupper($table_name);
foreach ($this->fail_on_invalid_names as $rdbms) {
if (in_array($name, $GLOBALS['_MDB2_Schema_Reserved'][$rdbms])) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'table name "'.$table_name.'" is a reserved word in: '.$rdbms);
}
}
}
/* Was */
if (empty($table['was'])) {
$table['was'] = $table_name;
}
/* Have we got fields? */
if (empty($table['fields']) || !is_array($table['fields'])) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'tables need one or more fields');
}
/* Autoincrement */
$autoinc = $primary = false;
foreach ($table['fields'] as $field_name => $field) {
if (!empty($field['autoincrement'])) {
if ($autoinc) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'there was already an autoincrement field in "'.$table_name.'" before "'.$field_name.'"');
}
$autoinc = $field_name;
}
}
/*
* Checking Indexes
* this have to be done here otherwise we can't
* guarantee that all table fields were already
* defined in the moment we are parsing indexes
*/
if (!empty($table['indexes']) && is_array($table['indexes'])) {
foreach ($table['indexes'] as $name => $index) {
$skip_index = false;
if (!empty($index['primary'])) {
/*
* Lets see if we should skip this index since there is
* already an auto increment on this field this implying
* a primary key index.
*/
if (count($index['fields']) == '1'
&& $autoinc
&& array_key_exists($autoinc, $index['fields'])) {
$skip_index = true;
} elseif ($autoinc || $primary) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'there was already an primary index or autoincrement field in "'.$table_name.'" before "'.$name.'"');
} else {
$primary = true;
}
}
if (!$skip_index && is_array($index['fields'])) {
foreach ($index['fields'] as $field_name => $field) {
if (!isset($table['fields'][$field_name])) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'index field "'.$field_name.'" does not exist');
}
if (!empty($index['primary'])
&& !$table['fields'][$field_name]['notnull']
) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'all primary key fields must be defined notnull in "'.$table_name.'"');
}
}
} else {
unset($table['indexes'][$name]);
}
}
}
return MDB2_OK;
}
// }}}
// {{{ validateField()
/**
* Checks whether the definition of a parsed field is valid. Modify field
* definition when necessary.
*
* @param array $fields multi dimensional array that contains the
* fields of current table.
* @param array &$field multi dimensional array that contains the
* structure of the parsed field.
* @param string $field_name name of the parsed field
*
* @return bool|error object
*
* @access public
*/
function validateField($fields, &$field, $field_name)
{
/* Have we got a name? */
if (!$field_name) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'field name missing');
}
/* Field name duplicated? */
if (is_array($fields) && isset($fields[$field_name])) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'field "'.$field_name.'" already exists');
}
/* Field name reserverd? */
if (is_array($this->fail_on_invalid_names)) {
$name = strtoupper($field_name);
foreach ($this->fail_on_invalid_names as $rdbms) {
if (in_array($name, $GLOBALS['_MDB2_Schema_Reserved'][$rdbms])) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'field name "'.$field_name.'" is a reserved word in: '.$rdbms);
}
}
}
/* Type check */
if (empty($field['type'])) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'no field type specified');
}
if (!empty($this->valid_types) && !array_key_exists($field['type'], $this->valid_types)) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'no valid field type ("'.$field['type'].'") specified');
}
/* Unsigned */
if (array_key_exists('unsigned', $field) && !$this->isBoolean($field['unsigned'])) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'unsigned has to be a boolean value');
}
/* Fixed */
if (array_key_exists('fixed', $field) && !$this->isBoolean($field['fixed'])) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'fixed has to be a boolean value');
}
/* Length */
if (array_key_exists('length', $field) && $field['length'] <= 0) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'length has to be an integer greater 0');
}
// if it's a DECIMAL datatype, check if a 'scale' value is provided:
// <length>8,4</length> should be translated to DECIMAL(8,4)
if (is_float($this->valid_types[$field['type']])
&& !empty($field['length'])
&& strpos($field['length'], ',') !== false
) {
list($field['length'], $field['scale']) = explode(',', $field['length']);
}
/* Was */
if (empty($field['was'])) {
$field['was'] = $field_name;
}
/* Notnull */
if (empty($field['notnull'])) {
$field['notnull'] = false;
}
if (!$this->isBoolean($field['notnull'])) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'field "notnull" has to be a boolean value');
}
/* Default */
if ($this->force_defaults
&& !array_key_exists('default', $field)
&& $field['type'] != 'clob' && $field['type'] != 'blob'
) {
$field['default'] = $this->valid_types[$field['type']];
}
if (array_key_exists('default', $field)) {
if ($field['type'] == 'clob' || $field['type'] == 'blob') {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'"'.$field['type'].'"-fields are not allowed to have a default value');
}
if ($field['default'] === '' && !$field['notnull']) {
$field['default'] = null;
}
}
if (isset($field['default'])
&& PEAR::isError($result = $this->validateDataFieldValue($field, $field['default'], $field_name))
) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'default value of "'.$field_name.'" is incorrect: '.$result->getUserinfo());
}
/* Autoincrement */
if (!empty($field['autoincrement'])) {
if (!$field['notnull']) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'all autoincrement fields must be defined notnull');
}
if (empty($field['default'])) {
$field['default'] = '0';
} elseif ($field['default'] !== '0' && $field['default'] !== 0) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'all autoincrement fields must be defined default "0"');
}
}
return MDB2_OK;
}
// }}}
// {{{ validateIndex()
/**
* Checks whether a parsed index is valid. Modify index definition when
* necessary.
*
* @param array $table_indexes multi dimensional array that contains the
* indexes of current table.
* @param array &$index multi dimensional array that contains the
* structure of the parsed index.
* @param string $index_name name of the parsed index
*
* @return bool|error object
*
* @access public
*/
function validateIndex($table_indexes, &$index, $index_name)
{
if (!$index_name) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'an index has to have a name');
}
if (is_array($table_indexes) && isset($table_indexes[$index_name])) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'index "'.$index_name.'" already exists');
}
if (array_key_exists('unique', $index) && !$this->isBoolean($index['unique'])) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'field "unique" has to be a boolean value');
}
if (array_key_exists('primary', $index) && !$this->isBoolean($index['primary'])) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'field "primary" has to be a boolean value');
}
/* Have we got fields? */
if (empty($index['fields']) || !is_array($index['fields'])) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'indexes need one or more fields');
}
if (empty($index['was'])) {
$index['was'] = $index_name;
}
return MDB2_OK;
}
// }}}
// {{{ validateIndexField()
/**
* Checks whether a parsed index-field is valid. Modify its definition when
* necessary.
*
* @param array $index_fields multi dimensional array that contains the
* fields of current index.
* @param array &$field multi dimensional array that contains the
* structure of the parsed index-field.
* @param string $field_name name of the parsed index-field
*
* @return bool|error object
*
* @access public
*/
function validateIndexField($index_fields, &$field, $field_name)
{
if (is_array($index_fields) && isset($index_fields[$field_name])) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'index field "'.$field_name.'" already exists');
}
if (!$field_name) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'the index-field-name is required');
}
if (empty($field['sorting'])) {
$field['sorting'] = 'ascending';
} elseif ($field['sorting'] !== 'ascending' && $field['sorting'] !== 'descending') {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'sorting type unknown');
}
return MDB2_OK;
}
// }}}
// {{{ validateConstraint()
/**
* Checks whether a parsed foreign key is valid. Modify its definition when
* necessary.
*
* @param array $table_constraints multi dimensional array that contains the
* constraints of current table.
* @param array &$constraint multi dimensional array that contains the
* structure of the parsed foreign key.
* @param string $constraint_name name of the parsed foreign key
*
* @return bool|error object
*
* @access public
*/
function validateConstraint($table_constraints, &$constraint, $constraint_name)
{
if (!$constraint_name) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'a foreign key has to have a name');
}
if (is_array($table_constraints) && isset($table_constraints[$constraint_name])) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'foreign key "'.$constraint_name.'" already exists');
}
/* Have we got fields? */
if (empty($constraint['fields']) || !is_array($constraint['fields'])) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'foreign key "'.$constraint_name.'" need one or more fields');
}
/* Have we got referenced fields? */
if (empty($constraint['references']) || !is_array($constraint['references'])) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'foreign key "'.$constraint_name.'" need to reference one or more fields');
}
/* Have we got referenced table? */
if (empty($constraint['references']['table'])) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'foreign key "'.$constraint_name.'" need to reference a table');
}
if (empty($constraint['was'])) {
$constraint['was'] = $constraint_name;
}
return MDB2_OK;
}
// }}}
// {{{ validateConstraintField()
/**
* Checks whether a foreign-field is valid.
*
* @param array $constraint_fields multi dimensional array that contains the
* fields of current foreign key.
* @param string $field_name name of the parsed foreign-field
*
* @return bool|error object
*
* @access public
*/
function validateConstraintField($constraint_fields, $field_name)
{
if (!$field_name) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'empty value for foreign-field');
}
if (is_array($constraint_fields) && isset($constraint_fields[$field_name])) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'foreign field "'.$field_name.'" already exists');
}
return MDB2_OK;
}
// }}}
// {{{ validateConstraintReferencedField()
/**
* Checks whether a foreign-referenced field is valid.
*
* @param array $referenced_fields multi dimensional array that contains the
* fields of current foreign key.
* @param string $field_name name of the parsed foreign-field
*
* @return bool|error object
*
* @access public
*/
function validateConstraintReferencedField($referenced_fields, $field_name)
{
if (!$field_name) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'empty value for referenced foreign-field');
}
if (is_array($referenced_fields) && isset($referenced_fields[$field_name])) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'foreign field "'.$field_name.'" already referenced');
}
return MDB2_OK;
}
// }}}
// {{{ validateSequence()
/**
* Checks whether the definition of a parsed sequence is valid. Modify
* sequence definition when necessary.
*
* @param array $sequences multi dimensional array that contains the
* sequences of current database.
* @param array &$sequence multi dimensional array that contains the
* structure of the parsed sequence.
* @param string $sequence_name name of the parsed sequence
*
* @return bool|error object
*
* @access public
*/
function validateSequence($sequences, &$sequence, $sequence_name)
{
if (!$sequence_name) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'a sequence has to have a name');
}
if (is_array($sequences) && isset($sequences[$sequence_name])) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'sequence "'.$sequence_name.'" already exists');
}
if (is_array($this->fail_on_invalid_names)) {
$name = strtoupper($sequence_name);
foreach ($this->fail_on_invalid_names as $rdbms) {
if (in_array($name, $GLOBALS['_MDB2_Schema_Reserved'][$rdbms])) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'sequence name "'.$sequence_name.'" is a reserved word in: '.$rdbms);
}
}
}
if (empty($sequence['was'])) {
$sequence['was'] = $sequence_name;
}
if (!empty($sequence['on'])
&& (empty($sequence['on']['table']) || empty($sequence['on']['field']))
) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'sequence "'.$sequence_name.'" on a table was not properly defined');
}
return MDB2_OK;
}
// }}}
// {{{ validateDatabase()
/**
* Checks whether a parsed database is valid. Modify its structure and
* data when necessary.
*
* @param array &$database multi dimensional array that contains the
* structure and optional data of the database.
*
* @return bool|error object
*
* @access public
*/
function validateDatabase(&$database)
{
/* Have we got a name? */
if (!is_array($database) || !isset($database['name']) || !$database['name']) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'a database has to have a name');
}
/* Database name reserved? */
if (is_array($this->fail_on_invalid_names)) {
$name = strtoupper($database['name']);
foreach ($this->fail_on_invalid_names as $rdbms) {
if (in_array($name, $GLOBALS['_MDB2_Schema_Reserved'][$rdbms])) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'database name "'.$database['name'].'" is a reserved word in: '.$rdbms);
}
}
}
/* Create */
if (isset($database['create'])
&& !$this->isBoolean($database['create'])
) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'field "create" has to be a boolean value');
}
/* Overwrite */
if (isset($database['overwrite'])
&& $database['overwrite'] !== ''
&& !$this->isBoolean($database['overwrite'])
) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'field "overwrite" has to be a boolean value');
}
/*
* This have to be done here otherwise we can't guarantee that all
* tables were already defined in the moment we are parsing constraints
*/
if (isset($database['tables'])) {
foreach ($database['tables'] as $table_name => $table) {
if (!empty($table['constraints'])) {
foreach ($table['constraints'] as $constraint_name => $constraint) {
$referenced_table_name = $constraint['references']['table'];
if (!isset($database['tables'][$referenced_table_name])) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'referenced table "'.$referenced_table_name.'" of foreign key "'.$constraint_name.'" of table "'.$table_name.'" does not exist');
}
if (empty($constraint['references']['fields'])) {
$referenced_table = $database['tables'][$referenced_table_name];
$primary = false;
if (!empty($referenced_table['indexes'])) {
foreach ($referenced_table['indexes'] as $index_name => $index) {
if (array_key_exists('primary', $index)
&& $index['primary']
) {
$primary = array();
foreach ($index['fields'] as $field_name => $field) {
$primary[$field_name] = '';
}
break;
}
}
}
if (!$primary) {
foreach ($referenced_table['fields'] as $field_name => $field) {
if (array_key_exists('autoincrement', $field)
&& $field['autoincrement']
) {
$primary = array( $field_name => '' );
break;
}
}
}
if (!$primary) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'referenced table "'.$referenced_table_name.'" has no primary key and no referenced field was specified for foreign key "'.$constraint_name.'" of table "'.$table_name.'"');
}
$constraint['references']['fields'] = $primary;
}
/* the same number of referencing and referenced fields ? */
if (count($constraint['fields']) != count($constraint['references']['fields'])) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'The number of fields in the referenced key must match those of the foreign key "'.$constraint_name.'"');
}
$database['tables'][$table_name]['constraints'][$constraint_name]['references']['fields'] = $constraint['references']['fields'];
}
}
}
}
/*
* This have to be done here otherwise we can't guarantee that all
* tables were already defined in the moment we are parsing sequences
*/
if (isset($database['sequences'])) {
foreach ($database['sequences'] as $seq_name => $seq) {
if (!empty($seq['on'])
&& empty($database['tables'][$seq['on']['table']]['fields'][$seq['on']['field']])
) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'sequence "'.$seq_name.'" was assigned on unexisting field/table');
}
}
}
return MDB2_OK;
}
// }}}
// {{{ validateDataField()
/* Data Manipulation */
/**
* Checks whether a parsed DML-field is valid. Modify its structure when
* necessary. This is called when validating INSERT and
* UPDATE.
*
* @param array $table_fields multi dimensional array that contains the
* definition for current table's fields.
* @param array $instruction_fields multi dimensional array that contains the
* parsed fields of the current DML instruction.
* @param string &$field array that contains the parsed instruction field
*
* @return bool|error object
*
* @access public
*/
function validateDataField($table_fields, $instruction_fields, &$field)
{
if (!$field['name']) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'field-name has to be specified');
}
if (is_array($instruction_fields) && isset($instruction_fields[$field['name']])) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'field "'.$field['name'].'" already initialized');
}
if (is_array($table_fields) && !isset($table_fields[$field['name']])) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'"'.$field['name'].'" is not defined');
}
if (!isset($field['group']['type'])) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'"'.$field['name'].'" has no initial value');
}
if (isset($field['group']['data'])
&& $field['group']['type'] == 'value'
&& $field['group']['data'] !== ''
&& PEAR::isError($result = $this->validateDataFieldValue($table_fields[$field['name']], $field['group']['data'], $field['name']))
) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'value of "'.$field['name'].'" is incorrect: '.$result->getUserinfo());
}
return MDB2_OK;
}
// }}}
// {{{ validateDataFieldValue()
/**
* Checks whether a given value is compatible with a table field. This is
* done when parsing a field for a INSERT or UPDATE instruction.
*
* @param array $field_def multi dimensional array that contains the
* definition for current table's fields.
* @param string &$field_value value to fill the parsed field
* @param string $field_name name of the parsed field
*
* @return bool|error object
*
* @access public
* @see MDB2_Schema_Validate::validateInsertField()
*/
function validateDataFieldValue($field_def, &$field_value, $field_name)
{
switch ($field_def['type']) {
case 'text':
case 'clob':
if (!empty($field_def['length']) && strlen($field_value) > $field_def['length']) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'"'.$field_value.'" is larger than "'.$field_def['length'].'"');
}
break;
case 'blob':
$field_value = pack('H*', $field_value);
if (!empty($field_def['length']) && strlen($field_value) > $field_def['length']) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'"'.$field_value.'" is larger than "'.$field_def['type'].'"');
}
break;
case 'integer':
if ($field_value != ((int)$field_value)) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'"'.$field_value.'" is not of type "'.$field_def['type'].'"');
}
//$field_value = (int)$field_value;
if (!empty($field_def['unsigned']) && $field_def['unsigned'] && $field_value < 0) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'"'.$field_value.'" signed instead of unsigned');
}
break;
case 'boolean':
if (!$this->isBoolean($field_value)) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'"'.$field_value.'" is not of type "'.$field_def['type'].'"');
}
break;
case 'date':
if (!preg_match('/([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})/', $field_value)
&& $field_value !== 'CURRENT_DATE'
) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'"'.$field_value.'" is not of type "'.$field_def['type'].'"');
}
break;
case 'timestamp':
if (!preg_match('/([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})/', $field_value)
&& strcasecmp($field_value, 'now()') != 0
&& $field_value !== 'CURRENT_TIMESTAMP'
) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'"'.$field_value.'" is not of type "'.$field_def['type'].'"');
}
break;
case 'time':
if (!preg_match("/([0-9]{2}):([0-9]{2}):([0-9]{2})/", $field_value)
&& $field_value !== 'CURRENT_TIME'
) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'"'.$field_value.'" is not of type "'.$field_def['type'].'"');
}
break;
case 'float':
case 'double':
if ($field_value != (double)$field_value) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
'"'.$field_value.'" is not of type "'.$field_def['type'].'"');
}
//$field_value = (double)$field_value;
break;
}
return MDB2_OK;
}
}
?>

581
3rdparty/MDB2/Schema/Writer.php vendored Normal file
View File

@ -0,0 +1,581 @@
<?php
/**
* PHP versions 4 and 5
*
* Copyright (c) 1998-2008 Manuel Lemos, Tomas V.V.Cox,
* Stig. S. Bakken, Lukas Smith, Igor Feghali
* All rights reserved.
*
* MDB2_Schema enables users to maintain RDBMS independant schema files
* in XML that can be used to manipulate both data and database schemas
* This LICENSE is in the BSD license style.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken,
* Lukas Smith, Igor Feghali nor the names of his contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* Author: Lukas Smith <smith@pooteeweet.org>
* Author: Igor Feghali <ifeghali@php.net>
*
* @category Database
* @package MDB2_Schema
* @author Lukas Smith <smith@pooteeweet.org>
* @author Igor Feghali <ifeghali@php.net>
* @license BSD http://www.opensource.org/licenses/bsd-license.php
* @version CVS: $Id: Writer.php,v 1.40 2008/11/30 03:34:00 clockwerx Exp $
* @link http://pear.php.net/packages/MDB2_Schema
*/
/**
* Writes an XML schema file
*
* @category Database
* @package MDB2_Schema
* @author Lukas Smith <smith@pooteeweet.org>
* @license BSD http://www.opensource.org/licenses/bsd-license.php
* @link http://pear.php.net/packages/MDB2_Schema
*/
class MDB2_Schema_Writer
{
// {{{ properties
var $valid_types = array();
// }}}
// {{{ constructor
function __construct($valid_types = array())
{
$this->valid_types = $valid_types;
}
function MDB2_Schema_Writer($valid_types = array())
{
$this->__construct($valid_types);
}
// }}}
// {{{ raiseError()
/**
* This method is used to communicate an error and invoke error
* callbacks etc. Basically a wrapper for PEAR::raiseError
* without the message string.
*
* @param int|PEAR_Error $code integer error code or and PEAR_Error instance
* @param int $mode error mode, see PEAR_Error docs
* error level (E_USER_NOTICE etc). If error mode is
* PEAR_ERROR_CALLBACK, this is the callback function,
* either as a function name, or as an array of an
* object and method name. For other error modes this
* parameter is ignored.
* @param string $options Extra debug information. Defaults to the last
* query and native error code.
*
* @return object a PEAR error object
* @access public
* @see PEAR_Error
*/
function &raiseError($code = null, $mode = null, $options = null, $userinfo = null)
{
$error =& MDB2_Schema::raiseError($code, $mode, $options, $userinfo);
return $error;
}
// }}}
// {{{ _escapeSpecialChars()
/**
* add escapecharacters to all special characters in a string
*
* @param string $string string that should be escaped
*
* @return string escaped string
* @access protected
*/
function _escapeSpecialChars($string)
{
if (!is_string($string)) {
$string = strval($string);
}
$escaped = '';
for ($char = 0, $count = strlen($string); $char < $count; $char++) {
switch ($string[$char]) {
case '&':
$escaped .= '&amp;';
break;
case '>':
$escaped .= '&gt;';
break;
case '<':
$escaped .= '&lt;';
break;
case '"':
$escaped .= '&quot;';
break;
case '\'':
$escaped .= '&apos;';
break;
default:
$code = ord($string[$char]);
if ($code < 32 || $code > 127) {
$escaped .= "&#$code;";
} else {
$escaped .= $string[$char];
}
break;
}
}
return $escaped;
}
// }}}
// {{{ _dumpBoolean()
/**
* dump the structure of a sequence
*
* @param string $boolean boolean value or variable definition
*
* @return string with xml boolea definition
* @access private
*/
function _dumpBoolean($boolean)
{
if (is_string($boolean)) {
if ($boolean !== 'true' || $boolean !== 'false'
|| preg_match('/<variable>.*</variable>/', $boolean)
) {
return $boolean;
}
}
return $boolean ? 'true' : 'false';
}
// }}}
// {{{ dumpSequence()
/**
* dump the structure of a sequence
*
* @param string $sequence_definition sequence definition
* @param string $sequence_name sequence name
* @param string $eol end of line characters
* @param integer $dump determines what data to dump
* MDB2_SCHEMA_DUMP_ALL : the entire db
* MDB2_SCHEMA_DUMP_STRUCTURE : only the structure of the db
* MDB2_SCHEMA_DUMP_CONTENT : only the content of the db
*
* @return mixed string xml sequence definition on success, or a error object
* @access public
*/
function dumpSequence($sequence_definition, $sequence_name, $eol, $dump = MDB2_SCHEMA_DUMP_ALL)
{
$buffer = "$eol <sequence>$eol <name>$sequence_name</name>$eol";
if ($dump == MDB2_SCHEMA_DUMP_ALL || $dump == MDB2_SCHEMA_DUMP_CONTENT) {
if (!empty($sequence_definition['start'])) {
$start = $sequence_definition['start'];
$buffer .= " <start>$start</start>$eol";
}
}
if (!empty($sequence_definition['on'])) {
$buffer .= " <on>$eol";
$buffer .= " <table>".$sequence_definition['on']['table'];
$buffer .= "</table>$eol <field>".$sequence_definition['on']['field'];
$buffer .= "</field>$eol </on>$eol";
}
$buffer .= " </sequence>$eol";
return $buffer;
}
// }}}
// {{{ dumpDatabase()
/**
* Dump a previously parsed database structure in the Metabase schema
* XML based format suitable for the Metabase parser. This function
* may optionally dump the database definition with initialization
* commands that specify the data that is currently present in the tables.
*
* @param array $database_definition unknown
* @param array $arguments associative array that takes pairs of tag
* names and values that define dump options.
* array (
* 'output_mode' => String
* 'file' : dump into a file
* default: dump using a function
* 'output' => String
* depending on the 'Output_Mode'
* name of the file
* name of the function
* 'end_of_line' => String
* end of line delimiter that should be used
* default: "\n"
* );
* @param integer $dump determines what data to dump
* MDB2_SCHEMA_DUMP_ALL : the entire db
* MDB2_SCHEMA_DUMP_STRUCTURE : only the structure of the db
* MDB2_SCHEMA_DUMP_CONTENT : only the content of the db
*
* @return mixed MDB2_OK on success, or a error object
* @access public
*/
function dumpDatabase($database_definition, $arguments, $dump = MDB2_SCHEMA_DUMP_ALL)
{
if (!empty($arguments['output'])) {
if (!empty($arguments['output_mode']) && $arguments['output_mode'] == 'file') {
$fp = fopen($arguments['output'], 'w');
if ($fp === false) {
return $this->raiseError(MDB2_SCHEMA_ERROR_WRITER, null, null,
'it was not possible to open output file');
}
$output = false;
} elseif (is_callable($arguments['output'])) {
$output = $arguments['output'];
} else {
return $this->raiseError(MDB2_SCHEMA_ERROR_WRITER, null, null,
'no valid output function specified');
}
} else {
return $this->raiseError(MDB2_SCHEMA_ERROR_WRITER, null, null,
'no output method specified');
}
$eol = isset($arguments['end_of_line']) ? $arguments['end_of_line'] : "\n";
$sequences = array();
if (!empty($database_definition['sequences'])
&& is_array($database_definition['sequences'])
) {
foreach ($database_definition['sequences'] as $sequence_name => $sequence) {
$table = !empty($sequence['on']) ? $sequence['on']['table'] :'';
$sequences[$table][] = $sequence_name;
}
}
$buffer = '<?xml version="1.0" encoding="ISO-8859-1" ?>'.$eol;
$buffer .= "<database>$eol$eol <name>".$database_definition['name']."</name>";
$buffer .= "$eol <create>".$this->_dumpBoolean($database_definition['create'])."</create>";
$buffer .= "$eol <overwrite>".$this->_dumpBoolean($database_definition['overwrite'])."</overwrite>$eol";
$buffer .= "$eol <charset>".$database_definition['charset']."</charset>$eol";
if ($output) {
call_user_func($output, $buffer);
} else {
fwrite($fp, $buffer);
}
if (!empty($database_definition['tables']) && is_array($database_definition['tables'])) {
foreach ($database_definition['tables'] as $table_name => $table) {
$buffer = "$eol <table>$eol$eol <name>$table_name</name>$eol";
if ($dump == MDB2_SCHEMA_DUMP_ALL || $dump == MDB2_SCHEMA_DUMP_STRUCTURE) {
$buffer .= "$eol <declaration>$eol";
if (!empty($table['fields']) && is_array($table['fields'])) {
foreach ($table['fields'] as $field_name => $field) {
if (empty($field['type'])) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE, null, null,
'it was not specified the type of the field "'.
$field_name.'" of the table "'.$table_name.'"');
}
if (!empty($this->valid_types) && !array_key_exists($field['type'], $this->valid_types)) {
return $this->raiseError(MDB2_SCHEMA_ERROR_UNSUPPORTED, null, null,
'type "'.$field['type'].'" is not yet supported');
}
$buffer .= "$eol <field>$eol <name>$field_name</name>$eol <type>";
$buffer .= $field['type']."</type>$eol";
if (!empty($field['fixed']) && $field['type'] === 'text') {
$buffer .= " <fixed>".$this->_dumpBoolean($field['fixed'])."</fixed>$eol";
}
if (array_key_exists('default', $field)
&& $field['type'] !== 'clob' && $field['type'] !== 'blob'
) {
$buffer .= ' <default>'.$this->_escapeSpecialChars($field['default'])."</default>$eol";
}
if (!empty($field['notnull'])) {
$buffer .= " <notnull>".$this->_dumpBoolean($field['notnull'])."</notnull>$eol";
} else {
$buffer .= " <notnull>false</notnull>$eol";
}
if (!empty($field['autoincrement'])) {
$buffer .= " <autoincrement>" . $field['autoincrement'] ."</autoincrement>$eol";
}
if (!empty($field['unsigned'])) {
$buffer .= " <unsigned>".$this->_dumpBoolean($field['unsigned'])."</unsigned>$eol";
}
if (!empty($field['length'])) {
$buffer .= ' <length>'.$field['length']."</length>$eol";
}
$buffer .= " </field>$eol";
}
}
if (!empty($table['indexes']) && is_array($table['indexes'])) {
foreach ($table['indexes'] as $index_name => $index) {
if (strtolower($index_name) === 'primary') {
$index_name = $table_name . '_pKey';
}
$buffer .= "$eol <index>$eol <name>$index_name</name>$eol";
if (!empty($index['unique'])) {
$buffer .= " <unique>".$this->_dumpBoolean($index['unique'])."</unique>$eol";
}
if (!empty($index['primary'])) {
$buffer .= " <primary>".$this->_dumpBoolean($index['primary'])."</primary>$eol";
}
foreach ($index['fields'] as $field_name => $field) {
$buffer .= " <field>$eol <name>$field_name</name>$eol";
if (!empty($field) && is_array($field)) {
$buffer .= ' <sorting>'.$field['sorting']."</sorting>$eol";
}
$buffer .= " </field>$eol";
}
$buffer .= " </index>$eol";
}
}
if (!empty($table['constraints']) && is_array($table['constraints'])) {
foreach ($table['constraints'] as $constraint_name => $constraint) {
$buffer .= "$eol <foreign>$eol <name>$constraint_name</name>$eol";
if (empty($constraint['fields']) || !is_array($constraint['fields'])) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE, null, null,
'it was not specified a field for the foreign key "'.
$constraint_name.'" of the table "'.$table_name.'"');
}
if (!is_array($constraint['references']) || empty($constraint['references']['table'])) {
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE, null, null,
'it was not specified the referenced table of the foreign key "'.
$constraint_name.'" of the table "'.$table_name.'"');
}
if (!empty($constraint['match'])) {
$buffer .= " <match>".$constraint['match']."</match>$eol";
}
if (!empty($constraint['ondelete'])) {
$buffer .= " <ondelete>".$constraint['ondelete']."</ondelete>$eol";
}
if (!empty($constraint['onupdate'])) {
$buffer .= " <onupdate>".$constraint['onupdate']."</onupdate>$eol";
}
if (!empty($constraint['deferrable'])) {
$buffer .= " <deferrable>".$constraint['deferrable']."</deferrable>$eol";
}
if (!empty($constraint['initiallydeferred'])) {
$buffer .= " <initiallydeferred>".$constraint['initiallydeferred']."</initiallydeferred>$eol";
}
foreach ($constraint['fields'] as $field_name => $field) {
$buffer .= " <field>$field_name</field>$eol";
}
$buffer .= " <references>$eol <table>".$constraint['references']['table']."</table>$eol";
foreach ($constraint['references']['fields'] as $field_name => $field) {
$buffer .= " <field>$field_name</field>$eol";
}
$buffer .= " </references>$eol";
$buffer .= " </foreign>$eol";
}
}
$buffer .= "$eol </declaration>$eol";
}
if ($output) {
call_user_func($output, $buffer);
} else {
fwrite($fp, $buffer);
}
$buffer = '';
if ($dump == MDB2_SCHEMA_DUMP_ALL || $dump == MDB2_SCHEMA_DUMP_CONTENT) {
if (!empty($table['initialization']) && is_array($table['initialization'])) {
$buffer = "$eol <initialization>$eol";
foreach ($table['initialization'] as $instruction) {
switch ($instruction['type']) {
case 'insert':
$buffer .= "$eol <insert>$eol";
foreach ($instruction['data']['field'] as $field) {
$field_name = $field['name'];
$buffer .= "$eol <field>$eol <name>$field_name</name>$eol";
$buffer .= $this->writeExpression($field['group'], 5, $arguments);
$buffer .= " </field>$eol";
}
$buffer .= "$eol </insert>$eol";
break;
case 'update':
$buffer .= "$eol <update>$eol";
foreach ($instruction['data']['field'] as $field) {
$field_name = $field['name'];
$buffer .= "$eol <field>$eol <name>$field_name</name>$eol";
$buffer .= $this->writeExpression($field['group'], 5, $arguments);
$buffer .= " </field>$eol";
}
if (!empty($instruction['data']['where'])
&& is_array($instruction['data']['where'])
) {
$buffer .= " <where>$eol";
$buffer .= $this->writeExpression($instruction['data']['where'], 5, $arguments);
$buffer .= " </where>$eol";
}
$buffer .= "$eol </update>$eol";
break;
case 'delete':
$buffer .= "$eol <delete>$eol$eol";
if (!empty($instruction['data']['where'])
&& is_array($instruction['data']['where'])
) {
$buffer .= " <where>$eol";
$buffer .= $this->writeExpression($instruction['data']['where'], 5, $arguments);
$buffer .= " </where>$eol";
}
$buffer .= "$eol </delete>$eol";
break;
}
}
$buffer .= "$eol </initialization>$eol";
}
}
$buffer .= "$eol </table>$eol";
if ($output) {
call_user_func($output, $buffer);
} else {
fwrite($fp, $buffer);
}
if (isset($sequences[$table_name])) {
foreach ($sequences[$table_name] as $sequence) {
$result = $this->dumpSequence($database_definition['sequences'][$sequence],
$sequence, $eol, $dump);
if (PEAR::isError($result)) {
return $result;
}
if ($output) {
call_user_func($output, $result);
} else {
fwrite($fp, $result);
}
}
}
}
}
if (isset($sequences[''])) {
foreach ($sequences[''] as $sequence) {
$result = $this->dumpSequence($database_definition['sequences'][$sequence],
$sequence, $eol, $dump);
if (PEAR::isError($result)) {
return $result;
}
if ($output) {
call_user_func($output, $result);
} else {
fwrite($fp, $result);
}
}
}
$buffer = "$eol</database>$eol";
if ($output) {
call_user_func($output, $buffer);
} else {
fwrite($fp, $buffer);
fclose($fp);
}
return MDB2_OK;
}
// }}}
// {{{ writeExpression()
/**
* Dumps the structure of an element. Elements can be value, column,
* function or expression.
*
* @param array $element multi dimensional array that represents the parsed element
* of a DML instruction.
* @param integer $offset base indentation width
* @param array $arguments associative array that takes pairs of tag
* names and values that define dump options.
*
* @return string
*
* @access public
* @see MDB2_Schema_Writer::dumpDatabase()
*/
function writeExpression($element, $offset = 0, $arguments = null)
{
$eol = isset($arguments['end_of_line']) ? $arguments['end_of_line'] : "\n";
$str = '';
$indent = str_repeat(' ', $offset);
$noffset = $offset + 1;
switch ($element['type']) {
case 'value':
$str .= "$indent<value>".$this->_escapeSpecialChars($element['data'])."</value>$eol";
break;
case 'column':
$str .= "$indent<column>".$this->_escapeSpecialChars($element['data'])."</column>$eol";
break;
case 'function':
$str .= "$indent<function>$eol$indent <name>".$this->_escapeSpecialChars($element['data']['name'])."</name>$eol";
if (!empty($element['data']['arguments'])
&& is_array($element['data']['arguments'])
) {
foreach ($element['data']['arguments'] as $v) {
$str .= $this->writeExpression($v, $noffset, $arguments);
}
}
$str .= "$indent</function>$eol";
break;
case 'expression':
$str .= "$indent<expression>$eol";
$str .= $this->writeExpression($element['data']['operants'][0], $noffset, $arguments);
$str .= "$indent <operator>".$element['data']['operator']."</operator>$eol";
$str .= $this->writeExpression($element['data']['operants'][1], $noffset, $arguments);
$str .= "$indent</expression>$eol";
break;
}
return $str;
}
// }}}
}
?>

1055
3rdparty/PEAR.php vendored Normal file

File diff suppressed because it is too large Load Diff

208
3rdparty/PEAR/Autoloader.php vendored Normal file
View File

@ -0,0 +1,208 @@
<?php
// /* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | 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: Stig Bakken <ssb@php.net> |
// | |
// +----------------------------------------------------------------------+
//
// $Id: Autoloader.php,v 1.11 2004/02/27 02:21:29 cellog Exp $
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@php.net>
*/
class PEAR_Autoloader extends PEAR
{
// {{{ properties
/**
* 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();
// }}}
// {{{ addAutoload()
/**
* 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)) {
array_walk($method, create_function('$a,&$b', '$b = strtolower($b);'));
$this->_autoload_map = array_merge($this->_autoload_map, $method);
} else {
$this->_autoload_map[strtolower($method)] = $classname;
}
}
// }}}
// {{{ removeAutoload()
/**
* 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)
{
$method = strtolower($method);
$ok = isset($this->_autoload_map[$method]);
unset($this->_autoload_map[$method]);
return $ok;
}
// }}}
// {{{ addAggregateObject()
/**
* 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;
}
}
}
// }}}
// {{{ removeAggregateObject()
/**
* 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 (is_a($obj, $classname)) {
unset($this->_method_map[$method]);
$ok = true;
}
}
return $ok;
}
// }}}
// {{{ __call()
/**
* 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)
{
$method = strtolower($method);
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");
?>

426
3rdparty/PEAR/Builder.php vendored Normal file
View File

@ -0,0 +1,426 @@
<?php
//
// +----------------------------------------------------------------------+
// | 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. |
// +----------------------------------------------------------------------+
// | Authors: Stig Sæther Bakken <ssb@php.net> |
// +----------------------------------------------------------------------+
//
// $Id: Builder.php,v 1.16.2.3 2005/02/17 17:55:01 cellog Exp $
require_once 'PEAR/Common.php';
/**
* Class to handle building (compiling) extensions.
*
* @author Stig Sæther Bakken <ssb@php.net>
*/
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;
}
// }}}
// {{{ _harventInstDir
/**
* @param string
* @param string
* @param array
* @access private
*/
function _harvestInstDir($dest_prefix, $dirname, &$built_files)
{
$d = opendir($dirname);
if (!$d)
return false;
$ret = true;
while (($ent = readdir($d)) !== false) {
if ($ent{0} == '.')
continue;
$full = $dirname . DIRECTORY_SEPARATOR . $ent;
if (is_dir($full)) {
if (!$this->_harvestInstDir(
$dest_prefix . DIRECTORY_SEPARATOR . $ent,
$full, $built_files)) {
$ret = false;
break;
}
} else {
$dest = $dest_prefix . DIRECTORY_SEPARATOR . $ent;
$built_files[] = array(
'file' => $full,
'dest' => $dest,
'php_api' => $this->php_api_version,
'zend_mod_api' => $this->zend_module_api_no,
'zend_ext_api' => $this->zend_extension_api_no,
);
}
}
closedir($d);
return $ret;
}
// }}}
// {{{ 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;
putenv('PATH=' . $this->config->get('bin_dir') . ':' . getenv('PATH'));
$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]=".trim($r);
}
}
}
// }}} end of interactive part
// FIXME make configurable
if(!$user=getenv('USER')){
$user='defaultuser';
}
$build_basedir = "/var/tmp/pear-build-$user";
$build_dir = "$build_basedir/$info[package]-$info[version]";
$inst_dir = "$build_basedir/install-$info[package]-$info[version]";
$this->log(1, "building in $build_dir");
if (is_dir($build_dir)) {
System::rm('-rf', $build_dir);
}
if (!System::mkDir(array('-p', $build_dir))) {
return $this->raiseError("could not create build dir: $build_dir");
}
$this->addTempFile($build_dir);
if (!System::mkDir(array('-p', $inst_dir))) {
return $this->raiseError("could not create temporary install dir: $inst_dir");
}
$this->addTempFile($inst_dir);
if (getenv('MAKE')) {
$make_command = getenv('MAKE');
} else {
$make_command = 'make';
}
$to_run = array(
$configure_command,
$make_command,
"$make_command INSTALL_ROOT=\"$inst_dir\" install",
"find \"$inst_dir\" -ls"
);
if (!@chdir($build_dir)) {
return $this->raiseError("could not chdir to $build_dir");
}
putenv('PHP_PEAR_VERSION=@PEAR-VER@');
foreach ($to_run as $cmd) {
$err = $this->_runCommand($cmd, $callback);
if (PEAR::isError($err)) {
chdir($old_cwd);
return $err;
}
if (!$err) {
chdir($old_cwd);
return $this->raiseError("`$cmd' failed");
}
}
if (!($dp = opendir("modules"))) {
chdir($old_cwd);
return $this->raiseError("no `modules' directory found");
}
$built_files = array();
$prefix = exec("php-config --prefix");
$this->_harvestInstDir($prefix, $inst_dir . DIRECTORY_SEPARATOR . $prefix, $built_files);
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(1, 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'");
}
if ($callback && $callback[0]->debug == 1) {
$olddbg = $callback[0]->debug;
$callback[0]->debug = 2;
}
while ($line = fgets($pp, 1024)) {
if ($callback) {
call_user_func($callback, 'cmdoutput', $line);
} else {
$this->log(2, rtrim($line));
}
}
if ($callback && isset($olddbg)) {
$callback[0]->debug = $olddbg;
}
$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);
}
// }}}
}
?>

398
3rdparty/PEAR/Command.php vendored Normal file
View File

@ -0,0 +1,398 @@
<?php
//
// +----------------------------------------------------------------------+
// | 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: Stig Bakken <ssb@php.net> |
// +----------------------------------------------------------------------+
//
// $Id: Command.php,v 1.24 2004/05/16 15:43:30 pajoye Exp $
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
{
// {{{ factory()
/**
* 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
* @static
*/
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];
}
if (!isset($GLOBALS['_PEAR_Command_commandlist'][$command])) {
return PEAR::raiseError("unknown command `$command'");
}
$class = $GLOBALS['_PEAR_Command_commandlist'][$command];
if (!class_exists($class)) {
return PEAR::raiseError("unknown command `$command'");
}
$ui =& PEAR_Command::getFrontendObject();
$obj = &new $class($ui, $config);
return $obj;
}
// }}}
// {{{ & getFrontendObject()
/**
* Get instance of frontend object.
*
* @return object
* @static
*/
function &getFrontendObject()
{
if (empty($GLOBALS['_PEAR_Command_uiobject'])) {
$GLOBALS['_PEAR_Command_uiobject'] = &new $GLOBALS['_PEAR_Command_uiclass'];
}
return $GLOBALS['_PEAR_Command_uiobject'];
}
// }}}
// {{{ & setFrontendClass()
/**
* Load current frontend class.
*
* @param string $uiclass Name of class implementing the frontend
*
* @return object the frontend object, or a PEAR error
* @static
*/
function &setFrontendClass($uiclass)
{
if (is_object($GLOBALS['_PEAR_Command_uiobject']) &&
is_a($GLOBALS['_PEAR_Command_uiobject'], $uiclass)) {
return $GLOBALS['_PEAR_Command_uiobject'];
}
if (!class_exists($uiclass)) {
$file = str_replace('_', '/', $uiclass) . '.php';
if (PEAR_Command::isIncludeable($file)) {
include_once $file;
}
}
if (class_exists($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 {
$err = PEAR::raiseError("not a frontend class: $uiclass");
return $err;
}
}
$err = PEAR::raiseError("no such class: $uiclass");
return $err;
}
// }}}
// {{{ setFrontendType()
// }}}
// {{{ isIncludeable()
/**
* @param string $path relative or absolute include path
* @return boolean
* @static
*/
function isIncludeable($path)
{
if (file_exists($path) && is_readable($path)) {
return true;
}
$ipath = explode(PATH_SEPARATOR, ini_get('include_path'));
foreach ($ipath as $include) {
$test = realpath($include . DIRECTORY_SEPARATOR . $path);
if (file_exists($test) && is_readable($test)) {
return true;
}
}
return false;
}
/**
* Set current frontend.
*
* @param string $uitype Name of the frontend type (for example "CLI")
*
* @return object the frontend object, or a PEAR error
* @static
*/
function setFrontendType($uitype)
{
$uiclass = 'PEAR_Frontend_' . $uitype;
return PEAR_Command::setFrontendClass($uiclass);
}
// }}}
// {{{ registerCommands()
/**
* 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
* @static
*/
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;
}
}
@closedir($dp);
return true;
}
// }}}
// {{{ getCommands()
/**
* Get the list of currently supported commands, and what
* classes implement them.
*
* @return array command => implementing class
*
* @access public
* @static
*/
function getCommands()
{
if (empty($GLOBALS['_PEAR_Command_commandlist'])) {
PEAR_Command::registerCommands();
}
return $GLOBALS['_PEAR_Command_commandlist'];
}
// }}}
// {{{ getShortcuts()
/**
* Get the list of command shortcuts.
*
* @return array shortcut => command
*
* @access public
* @static
*/
function getShortcuts()
{
if (empty($GLOBALS['_PEAR_Command_shortcuts'])) {
PEAR_Command::registerCommands();
}
return $GLOBALS['_PEAR_Command_shortcuts'];
}
// }}}
// {{{ getGetoptArgs()
/**
* 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
* @static
*/
function getGetoptArgs($command, &$short_args, &$long_args)
{
if (empty($GLOBALS['_PEAR_Command_commandlist'])) {
PEAR_Command::registerCommands();
}
if (!isset($GLOBALS['_PEAR_Command_commandlist'][$command])) {
return null;
}
$class = $GLOBALS['_PEAR_Command_commandlist'][$command];
$obj = &$GLOBALS['_PEAR_Command_objects'][$class];
return $obj->getGetoptArgs($command, $short_args, $long_args);
}
// }}}
// {{{ getDescription()
/**
* Get description for a command.
*
* @param string $command Name of the command
*
* @return string command description
*
* @access public
* @static
*/
function getDescription($command)
{
if (!isset($GLOBALS['_PEAR_Command_commanddesc'][$command])) {
return null;
}
return $GLOBALS['_PEAR_Command_commanddesc'][$command];
}
// }}}
// {{{ getHelp()
/**
* Get help for command.
*
* @param string $command Name of the command to return help for
*
* @access public
* @static
*/
function getHelp($command)
{
$cmds = PEAR_Command::getCommands();
if (isset($cmds[$command])) {
$class = $cmds[$command];
return $GLOBALS['_PEAR_Command_objects'][$class]->getHelp($command);
}
return false;
}
// }}}
}
?>

155
3rdparty/PEAR/Command/Auth.php vendored Normal file
View File

@ -0,0 +1,155 @@
<?php
//
// +----------------------------------------------------------------------+
// | 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: Stig Bakken <ssb@php.net> |
// +----------------------------------------------------------------------+
//
// $Id: Auth.php,v 1.15 2004/01/08 17:33:13 sniper Exp $
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
{
// {{{ properties
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.',
)
);
// }}}
// {{{ constructor
/**
* PEAR_Command_Auth constructor.
*
* @access public
*/
function PEAR_Command_Auth(&$ui, &$config)
{
parent::PEAR_Command_Common($ui, $config);
}
// }}}
// {{{ doLogin()
/**
* 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!");
}
}
// }}}
// {{{ doLogout()
/**
* 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();
}
// }}}
}
?>

89
3rdparty/PEAR/Command/Build.php vendored Normal file
View File

@ -0,0 +1,89 @@
<?php
//
// +----------------------------------------------------------------------+
// | 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: Stig Bakken <ssb@php.net> |
// | Tomas V.V.Cox <cox@idecnet.com> |
// | |
// +----------------------------------------------------------------------+
//
// $Id: Build.php,v 1.9 2004/01/08 17:33:13 sniper Exp $
require_once "PEAR/Command/Common.php";
require_once "PEAR/Builder.php";
/**
* PEAR commands for building extensions.
*
*/
class PEAR_Command_Build extends PEAR_Command_Common
{
// {{{ properties
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.'
),
);
// }}}
// {{{ constructor
/**
* PEAR_Command_Build constructor.
*
* @access public
*/
function PEAR_Command_Build(&$ui, &$config)
{
parent::PEAR_Command_Common($ui, $config);
}
// }}}
// {{{ doBuild()
function doBuild($command, $options, $params)
{
if (sizeof($params) < 1) {
$params[0] = 'package.xml';
}
$builder = &new PEAR_Builder($this->ui);
$this->debug = $this->config->get('verbose');
$err = $builder->build($params[0], array(&$this, 'buildCallback'));
if (PEAR::isError($err)) {
return $err;
}
return true;
}
// }}}
// {{{ buildCallback()
function buildCallback($what, $data)
{
if (($what == 'cmdoutput' && $this->debug > 1) ||
($what == 'output' && $this->debug > 0)) {
$this->ui->outputData(rtrim($data), 'build');
}
}
// }}}
}

249
3rdparty/PEAR/Command/Common.php vendored Normal file
View File

@ -0,0 +1,249 @@
<?php
//
// +----------------------------------------------------------------------+
// | 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: Stig Sæther Bakken <ssb@php.net> |
// +----------------------------------------------------------------------+
//
// $Id: Common.php,v 1.24 2004/01/08 17:33:13 sniper Exp $
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]";
}
} else {
$sapp = $lapp = "";
}
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);
}
// }}}
}
?>

225
3rdparty/PEAR/Command/Config.php vendored Normal file
View File

@ -0,0 +1,225 @@
<?php
//
// +----------------------------------------------------------------------+
// | 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: Stig Bakken <ssb@php.net> |
// | Tomas V.V.Cox <cox@idecnet.com> |
// | |
// +----------------------------------------------------------------------+
//
// $Id: Config.php,v 1.27 2004/06/15 16:48:49 pajoye Exp $
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
{
// {{{ properties
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' => '<parameter> [layer]
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' => '<parameter> <value> [layer]
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 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 in which layer to set the
configuration parameter. 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.
',
),
);
// }}}
// {{{ constructor
/**
* PEAR_Command_Config constructor.
*
* @access public
*/
function PEAR_Command_Config(&$ui, &$config)
{
parent::PEAR_Command_Common($ui, $config);
}
// }}}
// {{{ doConfigShow()
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;
}
// }}}
// {{{ doConfigGet()
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($this->config->get($params[0]), $command);
} else {
$data = $this->config->get($params[0], $params[1]);
$this->ui->outputData($data, $command);
}
return true;
}
// }}}
// {{{ doConfigSet()
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;
}
// }}}
// {{{ doConfigHelp()
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);
}
// }}}
// {{{ _checkLayer()
/**
* 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) && $layer != 'default') {
$layers = $this->config->getLayers();
if (!in_array($layer, $layers)) {
return " only the layers: \"" . implode('" or "', $layers) . "\" are supported";
}
}
return false;
}
// }}}
}
?>

470
3rdparty/PEAR/Command/Install.php vendored Normal file
View File

@ -0,0 +1,470 @@
<?php
//
// +----------------------------------------------------------------------+
// | 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: Stig Sæther Bakken <ssb@php.net> |
// +----------------------------------------------------------------------+
//
// $Id: Install.php,v 1.53.2.1 2004/10/19 04:08:42 cellog Exp $
require_once "PEAR/Command/Common.php";
require_once "PEAR/Installer.php";
/**
* PEAR commands for installation or deinstallation/upgrading of
* packages.
*
*/
class PEAR_Command_Install extends PEAR_Command_Common
{
// {{{ properties
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)',
),
'ignore-errors' => array(
'doc' => 'force install even if there were errors',
),
'alldeps' => array(
'shortopt' => 'a',
'doc' => 'install all required and optional dependencies',
),
'onlyreqdeps' => array(
'shortopt' => 'o',
'doc' => 'install all required dependencies',
),
),
'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)',
),
'ignore-errors' => array(
'doc' => 'force install even if there were errors',
),
'alldeps' => array(
'shortopt' => 'a',
'doc' => 'install all required and optional dependencies',
),
'onlyreqdeps' => array(
'shortopt' => 'o',
'doc' => 'install all required dependencies',
),
),
'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)',
),
'ignore-errors' => array(
'doc' => 'force install even if there were errors',
),
),
'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)',
),
'ignore-errors' => array(
'doc' => 'force install even if there were errors',
),
),
'doc' => '<package> ...
Uninstalls one or more PEAR packages. More than one package may be
specified at once.
'),
'bundle' => array(
'summary' => 'Unpacks a Pecl Package',
'function' => 'doBundle',
'shortcut' => 'bun',
'options' => array(
'destination' => array(
'shortopt' => 'd',
'arg' => 'DIR',
'doc' => 'Optional destination directory for unpacking (defaults to current path or "ext" if exists)',
),
'force' => array(
'shortopt' => 'f',
'doc' => 'Force the unpacking even if there were errors in the package',
),
),
'doc' => '<package>
Unpacks a Pecl Package into the selected location. It will download the
package if needed.
'),
);
// }}}
// {{{ constructor
/**
* PEAR_Command_Install constructor.
*
* @access public
*/
function PEAR_Command_Install(&$ui, &$config)
{
parent::PEAR_Command_Common($ui, $config);
}
// }}}
// {{{ doInstall()
function doInstall($command, $options, $params)
{
require_once 'PEAR/Downloader.php';
if (empty($this->installer)) {
$this->installer = &new PEAR_Installer($this->ui);
}
if ($command == 'upgrade') {
$options['upgrade'] = 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) {
$package = strtolower($package);
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(array('data' => "Will upgrade $package"), $command);
}
}
$this->downloader = &new PEAR_Downloader($this->ui, $options, $this->config);
$errors = array();
$downloaded = array();
$this->downloader->download($params);
$errors = $this->downloader->getErrorMsgs();
if (count($errors)) {
$err['data'] = array($errors);
$err['headline'] = 'Install Errors';
$this->ui->outputData($err);
return $this->raiseError("$command failed");
}
$downloaded = $this->downloader->getDownloadedPackages();
$this->installer->sortPkgDeps($downloaded);
foreach ($downloaded as $pkg) {
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
$info = $this->installer->install($pkg['file'], $options, $this->config);
PEAR::popErrorHandling();
if (PEAR::isError($info)) {
$this->ui->outputData('ERROR: ' .$info->getMessage());
continue;
}
if (is_array($info)) {
if ($this->config->get('verbose') > 0) {
$label = "$info[package] $info[version]";
$out = array('data' => "$command ok: $label");
if (isset($info['release_warnings'])) {
$out['release_warnings'] = $info['release_warnings'];
}
$this->ui->outputData($out, $command);
}
} else {
return $this->raiseError("$command failed");
}
}
return true;
}
// }}}
// {{{ doUninstall()
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");
}
include_once 'PEAR/Registry.php';
$reg = new PEAR_Registry($this->config->get('php_dir'));
$newparams = array();
$badparams = array();
foreach ($params as $pkg) {
$info = $reg->packageInfo($pkg);
if ($info === null) {
$badparams[] = $pkg;
} else {
$newparams[] = $info;
}
}
$this->installer->sortPkgDeps($newparams, true);
$params = array();
foreach($newparams as $info) {
$params[] = $info['info']['package'];
}
$params = array_merge($params, $badparams);
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;
}
// }}}
// }}}
// {{{ doBundle()
/*
(cox) It just downloads and untars the package, does not do
any check that the PEAR_Installer::_installFile() does.
*/
function doBundle($command, $options, $params)
{
if (empty($this->installer)) {
$this->installer = &new PEAR_Downloader($this->ui);
}
$installer = &$this->installer;
if (sizeof($params) < 1) {
return $this->raiseError("Please supply the package you want to bundle");
}
$pkgfile = $params[0];
$need_download = false;
if (preg_match('#^(http|ftp)://#', $pkgfile)) {
$need_download = true;
} elseif (!@is_file($pkgfile)) {
if ($installer->validPackageName($pkgfile)) {
$pkgfile = $installer->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 = $installer->config->get('download_dir');
if (empty($downloaddir)) {
if (PEAR::isError($downloaddir = System::mktemp('-d'))) {
return $downloaddir;
}
$installer->log(2, '+ tmp dir created at ' . $downloaddir);
}
$callback = $this->ui ? array(&$installer, '_downloadCallback') : null;
$file = $installer->downloadHttp($pkgfile, $this->ui, $downloaddir, $callback);
if (PEAR::isError($file)) {
return $this->raiseError($file);
}
$pkgfile = $file;
}
// Parse xml file -----------------------------------------------
$pkginfo = $installer->infoFromTgzFile($pkgfile);
if (PEAR::isError($pkginfo)) {
return $this->raiseError($pkginfo);
}
$installer->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:\n".
implode("\n", $errors));
} else {
$this->log(0, "warning : the following errors were found:\n".
implode("\n", $errors));
}
}
$pkgname = $pkginfo['package'];
// Unpacking -------------------------------------------------
if (isset($options['destination'])) {
if (!is_dir($options['destination'])) {
System::mkdir('-p ' . $options['destination']);
}
$dest = realpath($options['destination']);
} else {
$pwd = getcwd();
if (is_dir($pwd . DIRECTORY_SEPARATOR . 'ext')) {
$dest = $pwd . DIRECTORY_SEPARATOR . 'ext';
} else {
$dest = $pwd;
}
}
$dest .= DIRECTORY_SEPARATOR . $pkgname;
$orig = $pkgname . '-' . $pkginfo['version'];
$tar = new Archive_Tar($pkgfile);
if (!@$tar->extractModify($dest, $orig)) {
return $this->raiseError("unable to unpack $pkgfile");
}
$this->ui->outputData("Package ready at '$dest'");
// }}}
}
// }}}
}
?>

101
3rdparty/PEAR/Command/Mirror.php vendored Normal file
View File

@ -0,0 +1,101 @@
<?php
//
// +----------------------------------------------------------------------+
// | 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: Alexander Merz <alexmerz@php.net> |
// | |
// +----------------------------------------------------------------------+
//
// $Id: Mirror.php,v 1.5 2004/03/18 12:23:57 mj Exp $
require_once "PEAR/Command/Common.php";
require_once "PEAR/Command.php";
require_once "PEAR/Remote.php";
require_once "PEAR.php";
/**
* PEAR commands for providing file mirrors
*
*/
class PEAR_Command_Mirror extends PEAR_Command_Common
{
// {{{ properties
var $commands = array(
'download-all' => array(
'summary' => 'Downloads each available package from master_server',
'function' => 'doDownloadAll',
'shortcut' => 'da',
'options' => array(),
'doc' => '
Requests a list of available packages from the package server
(master_server) and downloads them to current working directory'
),
);
// }}}
// {{{ constructor
/**
* PEAR_Command_Mirror constructor.
*
* @access public
* @param object PEAR_Frontend a reference to an frontend
* @param object PEAR_Config a reference to the configuration data
*/
function PEAR_Command_Mirror(&$ui, &$config)
{
parent::PEAR_Command_Common($ui, $config);
}
// }}}
// {{{ doDownloadAll()
/**
* retrieves a list of avaible Packages from master server
* and downloads them
*
* @access public
* @param string $command the command
* @param array $options the command options before the command
* @param array $params the stuff after the command name
* @return bool true if succesful
* @throw PEAR_Error
*/
function doDownloadAll($command, $options, $params)
{
$this->config->set("php_dir", ".");
$remote = &new PEAR_Remote($this->config);
$remoteInfo = $remote->call("package.listAll");
if (PEAR::isError($remoteInfo)) {
return $remoteInfo;
}
$cmd = &PEAR_Command::factory("download", $this->config);
if (PEAR::isError($cmd)) {
return $cmd;
}
foreach ($remoteInfo as $pkgn => $pkg) {
/**
* Error handling not neccesary, because already done by
* the download command
*/
$cmd->run("download", array(), array($pkgn));
}
return true;
}
// }}}
}

819
3rdparty/PEAR/Command/Package.php vendored Normal file
View File

@ -0,0 +1,819 @@
<?php
//
// +----------------------------------------------------------------------+
// | 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. |
// +----------------------------------------------------------------------+
// | Authors: Stig Bakken <ssb@php.net> |
// | Martin Jansen <mj@php.net> |
// | Greg Beaver <cellog@php.net> |
// +----------------------------------------------------------------------+
//
// $Id: Package.php,v 1.61.2.7 2005/02/17 17:47:55 cellog Exp $
require_once 'PEAR/Common.php';
require_once 'PEAR/Command/Common.php';
class PEAR_Command_Package extends PEAR_Command_Common
{
// {{{ properties
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' => '
',
),
'cvsdiff' => array(
'summary' => 'Run a "cvs diff" for all files in a package',
'function' => 'doCvsDiff',
'shortcut' => 'cd',
'options' => array(
'quiet' => array(
'shortopt' => 'q',
'doc' => 'Be quiet',
),
'reallyquiet' => array(
'shortopt' => 'Q',
'doc' => 'Be really quiet',
),
'date' => array(
'shortopt' => 'D',
'doc' => 'Diff against revision of DATE',
'arg' => 'DATE',
),
'release' => array(
'shortopt' => 'R',
'doc' => 'Diff against tag for package release REL',
'arg' => 'REL',
),
'revision' => array(
'shortopt' => 'r',
'doc' => 'Diff against revision REV',
'arg' => 'REV',
),
'context' => array(
'shortopt' => 'c',
'doc' => 'Generate context diff',
),
'unified' => array(
'shortopt' => 'u',
'doc' => 'Generate unified diff',
),
'ignore-case' => array(
'shortopt' => 'i',
'doc' => 'Ignore case, consider upper- and lower-case letters equivalent',
),
'ignore-whitespace' => array(
'shortopt' => 'b',
'doc' => 'Ignore changes in amount of white space',
),
'ignore-blank-lines' => array(
'shortopt' => 'B',
'doc' => 'Ignore changes that insert or delete blank lines',
),
'brief' => array(
'doc' => 'Report only whether the files differ, no details',
),
'dry-run' => array(
'shortopt' => 'n',
'doc' => 'Don\'t do anything, just pretend',
),
),
'doc' => '<package.xml>
Compares all the files in a package. Without any options, this
command will compare the current code with the last checked-in code.
Using the -r or -R option you may compare the current code with that
of a specific release.
',
),
'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',
),
'dry-run' => array(
'shortopt' => 'n',
'doc' => 'Don\'t do anything, just pretend',
),
),
'doc' => '<package.xml>
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(
'recur' => array(
'shortopt' => 'r',
'doc' => 'Run tests in child directories, recursively. 4 dirs deep maximum',
),
'ini' => array(
'shortopt' => 'i',
'doc' => 'actual string of settings to pass to php in format " -d setting=blah"',
'arg' => 'SETTINGS'
),
'realtimelog' => array(
'shortopt' => 'l',
'doc' => 'Log test runs/results as they are run',
),
),
'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 spec file 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;
// }}}
// {{{ constructor
/**
* PEAR_Command_Package constructor.
*
* @access public
*/
function PEAR_Command_Package(&$ui, &$config)
{
parent::PEAR_Command_Common($ui, $config);
}
// }}}
// {{{ _displayValidationResults()
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;
}
// }}}
// {{{ doPackage()
function doPackage($command, $options, $params)
{
$this->output = '';
include_once 'PEAR/Packager.php';
if (sizeof($params) < 1) {
$params[0] = "package.xml";
}
$pkginfofile = isset($params[0]) ? $params[0] : 'package.xml';
$packager =& new PEAR_Packager();
$err = $warn = array();
$dir = dirname($pkginfofile);
$compress = empty($options['nocompress']) ? true : false;
$result = $packager->package($pkginfofile, $compress);
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;
}
if (PEAR::isError($result)) {
$this->output .= "Package failed: ".$result->getMessage();
}
$this->ui->outputData($this->output, $command);
return true;
}
// }}}
// {{{ doPackageValidate()
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;
}
// }}}
// {{{ doCvsTag()
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);
}
if ($this->config->get('verbose') > 1) {
$this->output .= "+ $command\n";
}
$this->output .= "+ $command\n";
if (empty($options['dry-run'])) {
$fp = popen($command, "r");
while ($line = fgets($fp, 1024)) {
$this->output .= rtrim($line)."\n";
}
pclose($fp);
}
$this->ui->outputData($this->output, $_cmd);
return true;
}
// }}}
// {{{ doCvsDiff()
function doCvsDiff($command, $options, $params)
{
$this->output = '';
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);
}
$files = array_keys($info['filelist']);
$cmd = "cvs";
if (isset($options['quiet'])) {
$cmd .= ' -q';
unset($options['quiet']);
}
if (isset($options['reallyquiet'])) {
$cmd .= ' -Q';
unset($options['reallyquiet']);
}
if (isset($options['release'])) {
$cvsversion = preg_replace('/[^a-z0-9]/i', '_', $options['release']);
$cvstag = "RELEASE_$cvsversion";
$options['revision'] = $cvstag;
unset($options['release']);
}
$execute = true;
if (isset($options['dry-run'])) {
$execute = false;
unset($options['dry-run']);
}
$cmd .= ' diff';
// the rest of the options are passed right on to "cvs diff"
foreach ($options as $option => $optarg) {
$arg = @$this->commands[$command]['options'][$option]['arg'];
$short = @$this->commands[$command]['options'][$option]['shortopt'];
$cmd .= $short ? " -$short" : " --$option";
if ($arg && $optarg) {
$cmd .= ($short ? '' : '=') . escapeshellarg($optarg);
}
}
foreach ($files as $file) {
$cmd .= ' ' . escapeshellarg($file);
}
if ($this->config->get('verbose') > 1) {
$this->output .= "+ $cmd\n";
}
if ($execute) {
$fp = popen($cmd, "r");
while ($line = fgets($fp, 1024)) {
$this->output .= rtrim($line)."\n";
}
pclose($fp);
}
$this->ui->outputData($this->output, $command);
return true;
}
// }}}
// {{{ doRunTests()
function doRunTests($command, $options, $params)
{
include_once 'PEAR/RunTest.php';
$log = new PEAR_Common;
$log->ui = &$this->ui; // slightly hacky, but it will work
$run = new PEAR_RunTest($log);
$tests = array();
if (isset($options['recur'])) {
$depth = 4;
} else {
$depth = 1;
}
if (!count($params)) {
$params[] = '.';
}
foreach ($params as $p) {
if (is_dir($p)) {
$dir = System::find(array($p, '-type', 'f',
'-maxdepth', $depth,
'-name', '*.phpt'));
$tests = array_merge($tests, $dir);
} else {
if (!@file_exists($p)) {
if (!preg_match('/\.phpt$/', $p)) {
$p .= '.phpt';
}
$dir = System::find(array(dirname($p), '-type', 'f',
'-maxdepth', $depth,
'-name', $p));
$tests = array_merge($tests, $dir);
} else {
$tests[] = $p;
}
}
}
$ini_settings = '';
if (isset($options['ini'])) {
$ini_settings .= $options['ini'];
}
if (isset($_ENV['TEST_PHP_INCLUDE_PATH'])) {
$ini_settings .= " -d include_path={$_ENV['TEST_PHP_INCLUDE_PATH']}";
}
if ($ini_settings) {
$this->ui->outputData('Using INI settings: "' . $ini_settings . '"');
}
$skipped = $passed = $failed = array();
$this->ui->outputData('Running ' . count($tests) . ' tests', $command);
$start = time();
if (isset($options['realtimelog'])) {
@unlink('run-tests.log');
}
foreach ($tests as $t) {
if (isset($options['realtimelog'])) {
$fp = @fopen('run-tests.log', 'a');
if ($fp) {
fwrite($fp, "Running test $t...");
fclose($fp);
}
}
$result = $run->run($t, $ini_settings);
if (OS_WINDOWS) {
for($i=0;$i<2000;$i++) {
$i = $i; // delay - race conditions on windows
}
}
if (isset($options['realtimelog'])) {
$fp = @fopen('run-tests.log', 'a');
if ($fp) {
fwrite($fp, "$result\n");
fclose($fp);
}
}
if ($result == 'FAILED') {
$failed[] = $t;
}
if ($result == 'PASSED') {
$passed[] = $t;
}
if ($result == 'SKIPPED') {
$skipped[] = $t;
}
}
$total = date('i:s', time() - $start);
if (count($failed)) {
$output = "TOTAL TIME: $total\n";
$output .= count($passed) . " PASSED TESTS\n";
$output .= count($skipped) . " SKIPPED TESTS\n";
$output .= count($failed) . " FAILED TESTS:\n";
foreach ($failed as $failure) {
$output .= $failure . "\n";
}
if (isset($options['realtimelog'])) {
$fp = @fopen('run-tests.log', 'a');
} else {
$fp = @fopen('run-tests.log', 'w');
}
if ($fp) {
fwrite($fp, $output, strlen($output));
fclose($fp);
$this->ui->outputData('wrote log to "' . realpath('run-tests.log') . '"', $command);
}
} elseif (@file_exists('run-tests.log') && !@is_dir('run-tests.log')) {
@unlink('run-tests.log');
}
$this->ui->outputData('TOTAL TIME: ' . $total);
$this->ui->outputData(count($passed) . ' PASSED TESTS', $command);
$this->ui->outputData(count($skipped) . ' SKIPPED TESTS', $command);
if (count($failed)) {
$this->ui->outputData(count($failed) . ' FAILED TESTS:', $command);
foreach ($failed as $failure) {
$this->ui->outputData($failure, $command);
}
}
return true;
}
// }}}
// {{{ doPackageDependencies()
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);
}
// }}}
// {{{ doSign()
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;
}
// }}}
// {{{ doMakeRPM()
/*
(cox)
TODO:
- Fill the rpm dependencies in the template file.
IDEAS:
- Instead of mapping the role to rpm vars, perhaps it's better
to use directly the pear cmd to install the files by itself
in %postrun so:
pear -d php_dir=%{_libdir}/php/pear -d test_dir=.. <package>
*/
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]";
$info['rpm_xml_dir'] = '/var/lib/pear';
$this->config->set('verbose', $tmp);
if (!$tar->extractList("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]");
}
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 (!isset($attr['role'])) {
continue;
}
$name = preg_replace('![/:\\\\]!', '/', $name);
if ($attr['role'] == 'doc') {
$info['doc_files'] .= " $name";
// Map role to the rpm vars
} else {
$c_prefix = '%{_libdir}/php/pear';
switch ($attr['role']) {
case 'php':
$prefix = $c_prefix; break;
case 'ext':
$prefix = '%{_libdir}/php'; break; // XXX good place?
case 'src':
$srcfiles++;
$prefix = '%{_includedir}/php'; break; // XXX good place?
case 'test':
$prefix = "$c_prefix/tests/" . $info['package']; break;
case 'data':
$prefix = "$c_prefix/data/" . $info['package']; break;
case 'script':
$prefix = '%{_bindir}'; break;
}
$name = str_replace('\\', '/', $name);
$info['files'] .= "$prefix/$name\n";
}
}
if ($srcfiles > 0) {
include_once "OS/Guess.php";
$os = new OS_Guess;
$arch = $os->getCpu();
} else {
$arch = 'noarch';
}
$cfg = array('master_server', 'php_dir', 'ext_dir', 'doc_dir',
'bin_dir', 'data_dir', 'test_dir');
foreach ($cfg as $k) {
$info[$k] = $this->config->get($k);
}
$info['arch'] = $arch;
$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, "wb");
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;
}
// }}}
}
?>

351
3rdparty/PEAR/Command/Registry.php vendored Normal file
View File

@ -0,0 +1,351 @@
<?php
// /* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | 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: Stig Bakken <ssb@php.net> |
// | |
// +----------------------------------------------------------------------+
//
// $Id: Registry.php,v 1.36 2004/01/08 17:33:13 sniper Exp $
require_once 'PEAR/Command/Common.php';
require_once 'PEAR/Registry.php';
require_once 'PEAR/Config.php';
class PEAR_Command_Registry extends PEAR_Command_Common
{
// {{{ properties
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' => 'in',
'options' => array(),
'doc' => '<package>
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->raiseError("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;
}
case 'provides' : {
$debug = $this->config->get('verbose');
if ($debug < 2) {
$pstr = 'Classes: ';
} else {
$pstr = '';
}
$i = 0;
foreach ($info[$key] as $p) {
if ($debug < 2 && $p['type'] != "class") {
continue;
}
// Only print classes when verbosity mode is < 2
if ($debug < 2) {
if ($i++ > 0) {
$pstr .= ", ";
}
$pstr .= $p['name'];
} else {
if ($i++ > 0) {
$pstr .= "\n";
}
$pstr .= ucfirst($p['type']) . " " . $p['name'];
if (isset($p['explicit']) && $p['explicit'] == 1) {
$pstr .= " (explicit)";
}
}
}
$info[$key] = $pstr;
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);
}
$data['raw'] = $info;
$this->ui->outputData($data, 'package-info');
}
// }}}
}
?>

435
3rdparty/PEAR/Command/Remote.php vendored Normal file
View File

@ -0,0 +1,435 @@
<?php
// /* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | 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: Stig Bakken <ssb@php.net> |
// | |
// +----------------------------------------------------------------------+
//
// $Id: Remote.php,v 1.39 2004/04/03 15:56:00 cellog Exp $
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 parameters (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.',
),
'clear-cache' => array(
'summary' => 'Clear XML-RPC Cache',
'function' => 'doClearCache',
'shortcut' => 'cc',
'options' => array(),
'doc' => '
Clear the XML-RPC cache. See also the cache_ttl configuration
parameter.
',
),
);
// }}}
// {{{ constructor
/**
* PEAR_Command_Remote constructor.
*
* @access public
*/
function PEAR_Command_Remote(&$ui, &$config)
{
parent::PEAR_Command_Common($ui, $config);
}
// }}}
// {{{ doRemoteInfo()
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;
}
// }}}
// {{{ doRemoteList()
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;
}
// }}}
// {{{ doListAll()
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);
}
if (!is_array($available)) {
return $this->raiseError('The package list could not be fetched from the remote server. Please try again. (Debug info: "'.$available.'")');
}
$data = array(
'caption' => 'All packages:',
'border' => true,
'headline' => array('Package', 'Latest', 'Local'),
);
$local_pkgs = $reg->listPackages();
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;
}
}
$pos = array_search(strtolower($name), $local_pkgs);
if ($pos !== false) {
unset($local_pkgs[$pos]);
}
$data['data'][$info['category']][] = array(
$name,
@$info['stable'],
@$installed['version'],
@$desc,
@$info['deps'],
);
}
foreach ($local_pkgs as $name) {
$info = $reg->packageInfo($name);
$data['data']['Local'][] = array(
$info['package'],
'',
$info['version'],
$info['summary'],
@$info['release_deps']
);
}
$this->ui->outputData($data, $command);
return true;
}
// }}}
// {{{ doSearch()
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, false);
if (PEAR::isError($available)) {
return $this->raiseError($available);
}
$data = array(
'caption' => 'Matched packages:',
'border' => true,
'headline' => array('Package', 'Stable/(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'];
$unstable = '';
if ($info['unstable']) {
$unstable = '/(' . $info['unstable'] . $info['state'] . ')';
}
if (!isset($info['stable']) || !$info['stable']) {
$info['stable'] = 'none';
}
$data['data'][$info['category']][] = array(
$name,
$info['stable'] . $unstable,
$installed['version'],
$desc,
);
}
if (!isset($data['data'])) {
return $this->raiseError('no packages found');
}
$this->ui->outputData($data, $command);
return true;
}
// }}}
// {{{ doDownload()
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])) {
$getoption = isset($options['nocompress'])&&$options['nocompress']==1?'?uncompress=on':'';
$pkgfile = "http://$server/get/$params[0]".$getoption;
} 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;
}
}
// }}}
// {{{ doListUpgrades()
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 .= ' (' . implode(', ', PEAR_Common::betterStates($state, true)) . ')';
}
$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', 'Local', 'Remote', 'Size'),
);
foreach ((array)$latest as $pkg => $info) {
$package = strtolower($pkg);
if (!isset($inst[$package])) {
// skip packages we don't have installed
continue;
}
extract($info);
$pkginfo = $reg->packageInfo($package);
$inst_version = $pkginfo['version'];
$inst_state = $pkginfo['release_state'];
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($pkg, "$inst_version ($inst_state)", "$version ($state)", $fs);
}
if (empty($data['data'])) {
$this->ui->outputData('No upgrades available');
} else {
$this->ui->outputData($data, $command);
}
return true;
}
// }}}
// {{{ doClearCache()
function doClearCache($command, $options, $params)
{
$cache_dir = $this->config->get('cache_dir');
$verbose = $this->config->get('verbose');
$output = '';
if (!($dp = @opendir($cache_dir))) {
return $this->raiseError("opendir($cache_dir) failed: $php_errormsg");
}
if ($verbose >= 1) {
$output .= "reading directory $cache_dir\n";
}
$num = 0;
while ($ent = readdir($dp)) {
if (preg_match('/^xmlrpc_cache_[a-z0-9]{32}$/', $ent)) {
$path = $cache_dir . DIRECTORY_SEPARATOR . $ent;
$ok = @unlink($path);
if ($ok) {
if ($verbose >= 2) {
$output .= "deleted $path\n";
}
$num++;
} elseif ($verbose >= 1) {
$output .= "failed to delete $path\n";
}
}
}
closedir($dp);
if ($verbose >= 1) {
$output .= "$num cache entries cleared\n";
}
$this->ui->outputData(rtrim($output), $command);
return $num;
}
// }}}
}
?>

2094
3rdparty/PEAR/Common.php vendored Normal file

File diff suppressed because it is too large Load Diff

1169
3rdparty/PEAR/Config.php vendored Normal file

File diff suppressed because it is too large Load Diff

487
3rdparty/PEAR/Dependency.php vendored Normal file
View File

@ -0,0 +1,487 @@
<?php
//
// +----------------------------------------------------------------------+
// | 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. |
// +----------------------------------------------------------------------+
// | Authors: Tomas V.V.Cox <cox@idecnet.com> |
// | Stig Bakken <ssb@php.net> |
// +----------------------------------------------------------------------+
//
// $Id: Dependency.php,v 1.36.4.1 2004/12/27 07:04:19 cellog Exp $
require_once "PEAR.php";
define('PEAR_DEPENDENCY_MISSING', -1);
define('PEAR_DEPENDENCY_CONFLICT', -2);
define('PEAR_DEPENDENCY_UPGRADE_MINOR', -3);
define('PEAR_DEPENDENCY_UPGRADE_MAJOR', -4);
define('PEAR_DEPENDENCY_BAD_DEPENDENCY', -5);
define('PEAR_DEPENDENCY_MISSING_OPTIONAL', -6);
define('PEAR_DEPENDENCY_CONFLICT_OPTIONAL', -7);
define('PEAR_DEPENDENCY_UPGRADE_MINOR_OPTIONAL', -8);
define('PEAR_DEPENDENCY_UPGRADE_MAJOR_OPTIONAL', -9);
/**
* Dependency check for PEAR packages
*
* The class is based on the dependency RFC that can be found at
* http://cvs.php.net/cvs.php/pearweb/rfc. It requires PHP >= 4.1
*
* @author Tomas V.V.Vox <cox@idecnet.com>
* @author Stig Bakken <ssb@php.net>
*/
class PEAR_Dependency
{
// {{{ constructor
/**
* Constructor
*
* @access public
* @param object Registry object
* @return void
*/
function PEAR_Dependency(&$registry)
{
$this->registry = &$registry;
}
// }}}
// {{{ callCheckMethod()
/**
* This method maps the XML dependency definition to the
* corresponding one from PEAR_Dependency
*
* <pre>
* $opts => Array
* (
* [type] => pkg
* [rel] => ge
* [version] => 3.4
* [name] => HTML_Common
* [optional] => false
* )
* </pre>
*
* @param string Error message
* @param array Options
* @return boolean
*/
function callCheckMethod(&$errmsg, $opts)
{
$rel = isset($opts['rel']) ? $opts['rel'] : 'has';
$req = isset($opts['version']) ? $opts['version'] : null;
$name = isset($opts['name']) ? $opts['name'] : null;
$opt = (isset($opts['optional']) && $opts['optional'] == 'yes') ?
$opts['optional'] : null;
$errmsg = '';
switch ($opts['type']) {
case 'pkg':
return $this->checkPackage($errmsg, $name, $req, $rel, $opt);
break;
case 'ext':
return $this->checkExtension($errmsg, $name, $req, $rel, $opt);
break;
case 'php':
return $this->checkPHP($errmsg, $req, $rel);
break;
case 'prog':
return $this->checkProgram($errmsg, $name);
break;
case 'os':
return $this->checkOS($errmsg, $name);
break;
case 'sapi':
return $this->checkSAPI($errmsg, $name);
break;
case 'zend':
return $this->checkZend($errmsg, $name);
break;
default:
return "'{$opts['type']}' dependency type not supported";
}
}
// }}}
// {{{ checkPackage()
/**
* Package dependencies check method
*
* @param string $errmsg Empty string, it will be populated with an error message, if any
* @param string $name Name of the package to test
* @param string $req The package version required
* @param string $relation How to compare versions with each other
* @param bool $opt Whether the relationship is optional
*
* @return mixed bool false if no error or the error string
*/
function checkPackage(&$errmsg, $name, $req = null, $relation = 'has',
$opt = false)
{
if (is_string($req) && substr($req, 0, 2) == 'v.') {
$req = substr($req, 2);
}
switch ($relation) {
case 'has':
if (!$this->registry->packageExists($name)) {
if ($opt) {
$errmsg = "package `$name' is recommended to utilize some features.";
return PEAR_DEPENDENCY_MISSING_OPTIONAL;
}
$errmsg = "requires package `$name'";
return PEAR_DEPENDENCY_MISSING;
}
return false;
case 'not':
if ($this->registry->packageExists($name)) {
$errmsg = "conflicts with package `$name'";
return PEAR_DEPENDENCY_CONFLICT;
}
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))
{
$code = $this->codeFromRelation($relation, $version, $req, $opt);
if ($opt) {
$errmsg = "package `$name' version " . $this->signOperator($relation) .
" $req is recommended to utilize some features.";
if ($version) {
$errmsg .= " Installed version is $version";
}
return $code;
}
$errmsg = "requires package `$name' " .
$this->signOperator($relation) . " $req";
return $code;
}
return false;
}
$errmsg = "relation '$relation' with requirement '$req' is not supported (name=$name)";
return PEAR_DEPENDENCY_BAD_DEPENDENCY;
}
// }}}
// {{{ checkPackageUninstall()
/**
* Check package dependencies on uninstall
*
* @param string $error The resultant error string
* @param string $warning The resultant warning string
* @param string $name Name of the package to test
*
* @return bool true if there were errors
*/
function checkPackageUninstall(&$error, &$warning, $package)
{
$error = null;
$packages = $this->registry->listPackages();
foreach ($packages as $pkg) {
if ($pkg == $package) {
continue;
}
$deps = $this->registry->packageInfo($pkg, 'release_deps');
if (empty($deps)) {
continue;
}
foreach ($deps as $dep) {
if ($dep['type'] == 'pkg' && strcasecmp($dep['name'], $package) == 0) {
if ($dep['rel'] == 'ne' || $dep['rel'] == 'not') {
continue;
}
if (isset($dep['optional']) && $dep['optional'] == 'yes') {
$warning .= "\nWarning: Package '$pkg' optionally depends on '$package'";
} else {
$error .= "Package '$pkg' depends on '$package'\n";
}
}
}
}
return ($error) ? true : false;
}
// }}}
// {{{ checkExtension()
/**
* 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
* @param bool $opt Whether the relationship is optional
*
* @return mixed bool false if no error or the error string
*/
function checkExtension(&$errmsg, $name, $req = null, $relation = 'has',
$opt = false)
{
if ($relation == 'not') {
if (extension_loaded($name)) {
$errmsg = "conflicts with PHP extension '$name'";
return PEAR_DEPENDENCY_CONFLICT;
} else {
return false;
}
}
if (!extension_loaded($name)) {
if ($relation == 'not') {
return false;
}
if ($opt) {
$errmsg = "'$name' PHP extension is recommended to utilize some features";
return PEAR_DEPENDENCY_MISSING_OPTIONAL;
}
$errmsg = "'$name' PHP extension is not installed";
return PEAR_DEPENDENCY_MISSING;
}
if ($relation == 'has') {
return false;
}
$code = false;
if (is_string($req) && substr($req, 0, 2) == 'v.') {
$req = substr($req, 2);
}
$ext_ver = phpversion($name);
$operator = $relation;
// Force params to be strings, otherwise the comparation will fail (ex. 0.9==0.90)
if (!version_compare("$ext_ver", "$req", $operator)) {
$errmsg = "'$name' PHP extension version " .
$this->signOperator($operator) . " $req is required";
$code = $this->codeFromRelation($relation, $ext_ver, $req, $opt);
if ($opt) {
$errmsg = "'$name' PHP extension version " . $this->signOperator($operator) .
" $req is recommended to utilize some features";
return $code;
}
}
return $code;
}
// }}}
// {{{ checkOS()
/**
* 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(&$errmsg, $os)
{
// XXX Fixme: Implement a more flexible way, like
// comma separated values or something similar to PEAR_OS
static $myos;
if (empty($myos)) {
include_once "OS/Guess.php";
$myos = new OS_Guess();
}
// only 'has' relation is currently supported
if ($myos->matchSignature($os)) {
return false;
}
$errmsg = "'$os' operating system not supported";
return PEAR_DEPENDENCY_CONFLICT;
}
// }}}
// {{{ checkPHP()
/**
* 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(&$errmsg, $req, $relation = 'ge')
{
// this would be a bit stupid, but oh well :)
if ($relation == 'has') {
return false;
}
if ($relation == 'not') {
$errmsg = 'Invalid dependency - "not" is not allowed for php dependencies, ' .
'php cannot conflict with itself';
return PEAR_DEPENDENCY_BAD_DEPENDENCY;
}
if (substr($req, 0, 2) == 'v.') {
$req = substr($req,2, strlen($req) - 2);
}
$php_ver = phpversion();
$operator = $relation;
if (!version_compare("$php_ver", "$req", $operator)) {
$errmsg = "PHP version " . $this->signOperator($operator) .
" $req is required";
return PEAR_DEPENDENCY_CONFLICT;
}
return false;
}
// }}}
// {{{ checkProgram()
/**
* 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(&$errmsg, $program)
{
// XXX FIXME honor safe mode
$exe_suffix = OS_WINDOWS ? '.exe' : '';
$path_elements = explode(PATH_SEPARATOR, getenv('PATH'));
foreach ($path_elements as $dir) {
$file = $dir . DIRECTORY_SEPARATOR . $program . $exe_suffix;
if (@file_exists($file) && @is_executable($file)) {
return false;
}
}
$errmsg = "'$program' program is not present in the PATH";
return PEAR_DEPENDENCY_MISSING;
}
// }}}
// {{{ checkSAPI()
/**
* 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(&$errmsg, $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;
}
$errmsg = "'$sapi_backend' SAPI backend not supported";
return PEAR_DEPENDENCY_CONFLICT;
}
// }}}
// {{{ checkZend()
/**
* 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(&$errmsg, $req, $relation = 'ge')
{
if (substr($req, 0, 2) == 'v.') {
$req = substr($req,2, strlen($req) - 2);
}
$zend_ver = zend_version();
$operator = substr($relation,0,2);
if (!version_compare("$zend_ver", "$req", $operator)) {
$errmsg = "Zend version " . $this->signOperator($operator) .
" $req is required";
return PEAR_DEPENDENCY_CONFLICT;
}
return false;
}
// }}}
// {{{ signOperator()
/**
* Converts text comparing operators to them sign equivalents
*
* Example: 'ge' to '>='
*
* @access public
* @param string Operator
* @return string Sign equivalent
*/
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;
}
}
// }}}
// {{{ codeFromRelation()
/**
* Convert relation into corresponding code
*
* @access public
* @param string Relation
* @param string Version
* @param string Requirement
* @param bool Optional dependency indicator
* @return integer
*/
function codeFromRelation($relation, $version, $req, $opt = false)
{
$code = PEAR_DEPENDENCY_BAD_DEPENDENCY;
switch ($relation) {
case 'gt': case 'ge': case 'eq':
// upgrade
$have_major = preg_replace('/\D.*/', '', $version);
$need_major = preg_replace('/\D.*/', '', $req);
if ($need_major > $have_major) {
$code = $opt ? PEAR_DEPENDENCY_UPGRADE_MAJOR_OPTIONAL :
PEAR_DEPENDENCY_UPGRADE_MAJOR;
} else {
$code = $opt ? PEAR_DEPENDENCY_UPGRADE_MINOR_OPTIONAL :
PEAR_DEPENDENCY_UPGRADE_MINOR;
}
break;
case 'lt': case 'le': case 'ne':
$code = $opt ? PEAR_DEPENDENCY_CONFLICT_OPTIONAL :
PEAR_DEPENDENCY_CONFLICT;
break;
}
return $code;
}
// }}}
}
?>

680
3rdparty/PEAR/Downloader.php vendored Normal file
View File

@ -0,0 +1,680 @@
<?php
//
// +----------------------------------------------------------------------+
// | 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. |
// +----------------------------------------------------------------------+
// | Authors: Stig Bakken <ssb@php.net> |
// | Tomas V.V.Cox <cox@idecnet.com> |
// | Martin Jansen <mj@php.net> |
// +----------------------------------------------------------------------+
//
// $Id: Downloader.php,v 1.17.2.1 2004/10/22 22:54:03 cellog Exp $
require_once 'PEAR/Common.php';
require_once 'PEAR/Registry.php';
require_once 'PEAR/Dependency.php';
require_once 'PEAR/Remote.php';
require_once 'System.php';
define('PEAR_INSTALLER_OK', 1);
define('PEAR_INSTALLER_FAILED', 0);
define('PEAR_INSTALLER_SKIPPED', -1);
define('PEAR_INSTALLER_ERROR_NO_PREF_STATE', 2);
/**
* Administration class used to download PEAR packages and maintain the
* installed package database.
*
* @since PEAR 1.4
* @author Greg Beaver <cellog@php.net>
*/
class PEAR_Downloader extends PEAR_Common
{
/**
* @var PEAR_Config
* @access private
*/
var $_config;
/**
* @var PEAR_Registry
* @access private
*/
var $_registry;
/**
* @var PEAR_Remote
* @access private
*/
var $_remote;
/**
* Preferred Installation State (snapshot, devel, alpha, beta, stable)
* @var string|null
* @access private
*/
var $_preferredState;
/**
* Options from command-line passed to Install.
*
* Recognized options:<br />
* - onlyreqdeps : install all required dependencies as well
* - alldeps : install all dependencies, including optional
* - installroot : base relative path to install files in
* - force : force a download even if warnings would prevent it
* @see PEAR_Command_Install
* @access private
* @var array
*/
var $_options;
/**
* Downloaded Packages after a call to download().
*
* Format of each entry:
*
* <code>
* array('pkg' => 'package_name', 'file' => '/path/to/local/file',
* 'info' => array() // parsed package.xml
* );
* </code>
* @access private
* @var array
*/
var $_downloadedPackages = array();
/**
* Packages slated for download.
*
* This is used to prevent downloading a package more than once should it be a dependency
* for two packages to be installed.
* Format of each entry:
*
* <pre>
* array('package_name1' => parsed package.xml, 'package_name2' => parsed package.xml,
* );
* </pre>
* @access private
* @var array
*/
var $_toDownload = array();
/**
* Array of every package installed, with names lower-cased.
*
* Format:
* <code>
* array('package1' => 0, 'package2' => 1, );
* </code>
* @var array
*/
var $_installed = array();
/**
* @var array
* @access private
*/
var $_errorStack = array();
// {{{ PEAR_Downloader()
function PEAR_Downloader(&$ui, $options, &$config)
{
$this->_options = $options;
$this->_config = &$config;
$this->_preferredState = $this->_config->get('preferred_state');
$this->ui = &$ui;
if (!$this->_preferredState) {
// don't inadvertantly use a non-set preferred_state
$this->_preferredState = null;
}
$php_dir = $this->_config->get('php_dir');
if (isset($this->_options['installroot'])) {
if (substr($this->_options['installroot'], -1) == DIRECTORY_SEPARATOR) {
$this->_options['installroot'] = substr($this->_options['installroot'], 0, -1);
}
$php_dir = $this->_prependPath($php_dir, $this->_options['installroot']);
}
$this->_registry = &new PEAR_Registry($php_dir);
$this->_remote = &new PEAR_Remote($config);
if (isset($this->_options['alldeps']) || isset($this->_options['onlyreqdeps'])) {
$this->_installed = $this->_registry->listPackages();
array_walk($this->_installed, create_function('&$v,$k','$v = strtolower($v);'));
$this->_installed = array_flip($this->_installed);
}
parent::PEAR_Common();
}
// }}}
// {{{ configSet()
function configSet($key, $value, $layer = 'user')
{
$this->_config->set($key, $value, $layer);
$this->_preferredState = $this->_config->get('preferred_state');
if (!$this->_preferredState) {
// don't inadvertantly use a non-set preferred_state
$this->_preferredState = null;
}
}
// }}}
// {{{ setOptions()
function setOptions($options)
{
$this->_options = $options;
}
// }}}
// {{{ _downloadFile()
/**
* @param string filename to download
* @param string version/state
* @param string original value passed to command-line
* @param string|null preferred state (snapshot/devel/alpha/beta/stable)
* Defaults to configuration preferred state
* @return null|PEAR_Error|string
* @access private
*/
function _downloadFile($pkgfile, $version, $origpkgfile, $state = null)
{
if (is_null($state)) {
$state = $this->_preferredState;
}
// {{{ check the package filename, and whether it's already installed
$need_download = false;
if (preg_match('#^(http|ftp)://#', $pkgfile)) {
$need_download = true;
} elseif (!@is_file($pkgfile)) {
if ($this->validPackageName($pkgfile)) {
if ($this->_registry->packageExists($pkgfile)) {
if (empty($this->_options['upgrade']) && empty($this->_options['force'])) {
$errors[] = "$pkgfile already installed";
return;
}
}
$pkgfile = $this->getPackageDownloadUrl($pkgfile, $version);
$need_download = true;
} else {
if (strlen($pkgfile)) {
$errors[] = "Could not open the package file: $pkgfile";
} else {
$errors[] = "No package file given";
}
return;
}
}
// }}}
// {{{ 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(3, '+ tmp dir created at ' . $downloaddir);
}
$callback = $this->ui ? array(&$this, '_downloadCallback') : null;
$this->pushErrorHandling(PEAR_ERROR_RETURN);
$file = $this->downloadHttp($pkgfile, $this->ui, $downloaddir, $callback);
$this->popErrorHandling();
if (PEAR::isError($file)) {
if ($this->validPackageName($origpkgfile)) {
if (!PEAR::isError($info = $this->_remote->call('package.info',
$origpkgfile))) {
if (!count($info['releases'])) {
return $this->raiseError('Package ' . $origpkgfile .
' has no releases');
} else {
return $this->raiseError('No releases of preferred state "'
. $state . '" exist for package ' . $origpkgfile .
'. Use ' . $origpkgfile . '-state to install another' .
' state (like ' . $origpkgfile .'-beta)',
PEAR_INSTALLER_ERROR_NO_PREF_STATE);
}
} else {
return $pkgfile;
}
} else {
return $this->raiseError($file);
}
}
$pkgfile = $file;
}
// }}}
return $pkgfile;
}
// }}}
// {{{ getPackageDownloadUrl()
function getPackageDownloadUrl($package, $version = null)
{
if ($version) {
$package .= "-$version";
}
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;
}
// }}}
// {{{ extractDownloadFileName($pkgfile, &$version)
function extractDownloadFileName($pkgfile, &$version)
{
if (@is_file($pkgfile)) {
return $pkgfile;
}
// regex defined in Common.php
if (preg_match(PEAR_COMMON_PACKAGE_DOWNLOAD_PREG, $pkgfile, $m)) {
$version = (isset($m[3])) ? $m[3] : null;
return $m[1];
}
$version = null;
return $pkgfile;
}
// }}}
// }}}
// {{{ getDownloadedPackages()
/**
* Retrieve a list of downloaded packages after a call to {@link download()}.
*
* Also resets the list of downloaded packages.
* @return array
*/
function getDownloadedPackages()
{
$ret = $this->_downloadedPackages;
$this->_downloadedPackages = array();
$this->_toDownload = array();
return $ret;
}
// }}}
// {{{ download()
/**
* Download any files and their dependencies, if necessary
*
* BC-compatible method name
* @param array a mixed list of package names, local files, or package.xml
*/
function download($packages)
{
return $this->doDownload($packages);
}
// }}}
// {{{ doDownload()
/**
* Download any files and their dependencies, if necessary
*
* @param array a mixed list of package names, local files, or package.xml
*/
function doDownload($packages)
{
$mywillinstall = array();
$state = $this->_preferredState;
// {{{ download files in this list if necessary
foreach($packages as $pkgfile) {
$need_download = false;
if (!is_file($pkgfile)) {
if (preg_match('#^(http|ftp)://#', $pkgfile)) {
$need_download = true;
}
$pkgfile = $this->_downloadNonFile($pkgfile);
if (PEAR::isError($pkgfile)) {
return $pkgfile;
}
if ($pkgfile === false) {
continue;
}
} // end is_file()
$tempinfo = $this->infoFromAny($pkgfile);
if ($need_download) {
$this->_toDownload[] = $tempinfo['package'];
}
if (isset($this->_options['alldeps']) || isset($this->_options['onlyreqdeps'])) {
// ignore dependencies if there are any errors
if (!PEAR::isError($tempinfo)) {
$mywillinstall[strtolower($tempinfo['package'])] = @$tempinfo['release_deps'];
}
}
$this->_downloadedPackages[] = array('pkg' => $tempinfo['package'],
'file' => $pkgfile, 'info' => $tempinfo);
} // end foreach($packages)
// }}}
// {{{ extract dependencies from downloaded files and then download
// them if necessary
if (isset($this->_options['alldeps']) || isset($this->_options['onlyreqdeps'])) {
$deppackages = array();
foreach ($mywillinstall as $package => $alldeps) {
if (!is_array($alldeps)) {
// there are no dependencies
continue;
}
$fail = false;
foreach ($alldeps as $info) {
if ($info['type'] != 'pkg') {
continue;
}
$ret = $this->_processDependency($package, $info, $mywillinstall);
if ($ret === false) {
continue;
}
if ($ret === 0) {
$fail = true;
continue;
}
if (PEAR::isError($ret)) {
return $ret;
}
$deppackages[] = $ret;
} // foreach($alldeps
if ($fail) {
$deppackages = array();
}
}
if (count($deppackages)) {
$this->doDownload($deppackages);
}
} // }}} if --alldeps or --onlyreqdeps
}
// }}}
// {{{ _downloadNonFile($pkgfile)
/**
* @return false|PEAR_Error|string false if loop should be broken out of,
* string if the file was downloaded,
* PEAR_Error on exception
* @access private
*/
function _downloadNonFile($pkgfile)
{
$origpkgfile = $pkgfile;
$state = null;
$pkgfile = $this->extractDownloadFileName($pkgfile, $version);
if (preg_match('#^(http|ftp)://#', $pkgfile)) {
return $this->_downloadFile($pkgfile, $version, $origpkgfile);
}
if (!$this->validPackageName($pkgfile)) {
return $this->raiseError("Package name '$pkgfile' not valid");
}
// ignore packages that are installed unless we are upgrading
$curinfo = $this->_registry->packageInfo($pkgfile);
if ($this->_registry->packageExists($pkgfile)
&& empty($this->_options['upgrade']) && empty($this->_options['force'])) {
$this->log(0, "Package '{$curinfo['package']}' already installed, skipping");
return false;
}
if (in_array($pkgfile, $this->_toDownload)) {
return false;
}
$releases = $this->_remote->call('package.info', $pkgfile, 'releases', true);
if (!count($releases)) {
return $this->raiseError("No releases found for package '$pkgfile'");
}
// Want a specific version/state
if ($version !== null) {
// Passed Foo-1.2
if ($this->validPackageVersion($version)) {
if (!isset($releases[$version])) {
return $this->raiseError("No release with version '$version' found for '$pkgfile'");
}
// Passed Foo-alpha
} elseif (in_array($version, $this->getReleaseStates())) {
$state = $version;
$version = 0;
foreach ($releases as $ver => $inf) {
if ($inf['state'] == $state && version_compare("$version", "$ver") < 0) {
$version = $ver;
break;
}
}
if ($version == 0) {
return $this->raiseError("No release with state '$state' found for '$pkgfile'");
}
// invalid suffix passed
} else {
return $this->raiseError("Invalid suffix '-$version', be sure to pass a valid PEAR ".
"version number or release state");
}
// Guess what to download
} else {
$states = $this->betterStates($this->_preferredState, true);
$possible = false;
$version = 0;
$higher_version = 0;
$prev_hi_ver = 0;
foreach ($releases as $ver => $inf) {
if (in_array($inf['state'], $states) && version_compare("$version", "$ver") < 0) {
$version = $ver;
break;
} else {
$ver = (string)$ver;
if (version_compare($prev_hi_ver, $ver) < 0) {
$prev_hi_ver = $higher_version = $ver;
}
}
}
if ($version === 0 && !isset($this->_options['force'])) {
return $this->raiseError('No release with state equal to: \'' . implode(', ', $states) .
"' found for '$pkgfile'");
} elseif ($version === 0) {
$this->log(0, "Warning: $pkgfile is state '" . $releases[$higher_version]['state'] . "' which is less stable " .
"than state '$this->_preferredState'");
}
}
// Check if we haven't already the version
if (empty($this->_options['force']) && !is_null($curinfo)) {
if ($curinfo['version'] == $version) {
$this->log(0, "Package '{$curinfo['package']}-{$curinfo['version']}' already installed, skipping");
return false;
} elseif (version_compare("$version", "{$curinfo['version']}") < 0) {
$this->log(0, "Package '{$curinfo['package']}' version '{$curinfo['version']}' " .
" is installed and {$curinfo['version']} is > requested '$version', skipping");
return false;
}
}
$this->_toDownload[] = $pkgfile;
return $this->_downloadFile($pkgfile, $version, $origpkgfile, $state);
}
// }}}
// {{{ _processDependency($package, $info, $mywillinstall)
/**
* Process a dependency, download if necessary
* @param array dependency information from PEAR_Remote call
* @param array packages that will be installed in this iteration
* @return false|string|PEAR_Error
* @access private
* @todo Add test for relation 'lt'/'le' -> make sure that the dependency requested is
* in fact lower than the required value. This will be very important for BC dependencies
*/
function _processDependency($package, $info, $mywillinstall)
{
$state = $this->_preferredState;
if (!isset($this->_options['alldeps']) && isset($info['optional']) &&
$info['optional'] == 'yes') {
// skip optional deps
$this->log(0, "skipping Package '$package' optional dependency '$info[name]'");
return false;
}
// {{{ get releases
$releases = $this->_remote->call('package.info', $info['name'], 'releases', true);
if (PEAR::isError($releases)) {
return $releases;
}
if (!count($releases)) {
if (!isset($this->_installed[strtolower($info['name'])])) {
$this->pushError("Package '$package' dependency '$info[name]' ".
"has no releases");
}
return false;
}
$found = false;
$save = $releases;
while(count($releases) && !$found) {
if (!empty($state) && $state != 'any') {
list($release_version, $release) = each($releases);
if ($state != $release['state'] &&
!in_array($release['state'], $this->betterStates($state)))
{
// drop this release - it ain't stable enough
array_shift($releases);
} else {
$found = true;
}
} else {
$found = true;
}
}
if (!count($releases) && !$found) {
$get = array();
foreach($save as $release) {
$get = array_merge($get,
$this->betterStates($release['state'], true));
}
$savestate = array_shift($get);
$this->pushError( "Release for '$package' dependency '$info[name]' " .
"has state '$savestate', requires '$state'");
return 0;
}
if (in_array(strtolower($info['name']), $this->_toDownload) ||
isset($mywillinstall[strtolower($info['name'])])) {
// skip upgrade check for packages we will install
return false;
}
if (!isset($this->_installed[strtolower($info['name'])])) {
// check to see if we can install the specific version required
if ($info['rel'] == 'eq') {
return $info['name'] . '-' . $info['version'];
}
// skip upgrade check for packages we don't have installed
return $info['name'];
}
// }}}
// {{{ see if a dependency must be upgraded
$inst_version = $this->_registry->packageInfo($info['name'], 'version');
if (!isset($info['version'])) {
// this is a rel='has' dependency, check against latest
if (version_compare($release_version, $inst_version, 'le')) {
return false;
} else {
return $info['name'];
}
}
if (version_compare($info['version'], $inst_version, 'le')) {
// installed version is up-to-date
return false;
}
return $info['name'];
}
// }}}
// {{{ _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;
case 'bytesread':
static $bytes;
if (empty($bytes)) {
$bytes = 0;
}
if (!($bytes % 10240)) {
$this->log(1, '.', false);
}
$bytes += $params;
break;
case 'start':
$this->log(1, "Starting to download {$params[0]} (".number_format($params[1], 0, '', ',')." bytes)");
break;
}
if (method_exists($this->ui, '_downloadCallback'))
$this->ui->_downloadCallback($msg, $params);
}
// }}}
// {{{ _prependPath($path, $prepend)
function _prependPath($path, $prepend)
{
if (strlen($prepend) > 0) {
if (OS_WINDOWS && preg_match('/^[a-z]:/i', $path)) {
$path = $prepend . substr($path, 2);
} else {
$path = $prepend . $path;
}
}
return $path;
}
// }}}
// {{{ pushError($errmsg, $code)
/**
* @param string
* @param integer
*/
function pushError($errmsg, $code = -1)
{
array_push($this->_errorStack, array($errmsg, $code));
}
// }}}
// {{{ getErrorMsgs()
function getErrorMsgs()
{
$msgs = array();
$errs = $this->_errorStack;
foreach ($errs as $err) {
$msgs[] = $err[0];
}
$this->_errorStack = array();
return $msgs;
}
// }}}
}
// }}}
?>

981
3rdparty/PEAR/ErrorStack.php vendored Normal file
View File

@ -0,0 +1,981 @@
<?php
//
// +----------------------------------------------------------------------+
// | 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: Gregory Beaver <cellog@php.net> |
// | |
// +----------------------------------------------------------------------+
//
// $Id: ErrorStack.php,v 1.7.2.5 2005/01/01 21:26:51 cellog Exp $
/**
* Error Stack Implementation
*
* This is an incredibly simple implementation of a very complex error handling
* facility. It contains the ability
* to track multiple errors from multiple packages simultaneously. In addition,
* it can track errors of many levels, save data along with the error, context
* information such as the exact file, line number, class and function that
* generated the error, and if necessary, it can raise a traditional PEAR_Error.
* It has built-in support for PEAR::Log, to log errors as they occur
*
* Since version 0.2alpha, it is also possible to selectively ignore errors,
* through the use of an error callback, see {@link pushCallback()}
*
* Since version 0.3alpha, it is possible to specify the exception class
* returned from {@link push()}
*
* Since version PEAR1.3.2, ErrorStack no longer instantiates an exception class. This can
* still be done quite handily in an error callback or by manipulating the returned array
* @author Greg Beaver <cellog@php.net>
* @version PEAR1.3.2 (beta)
* @package PEAR_ErrorStack
* @category Debugging
* @license http://www.php.net/license/3_0.txt PHP License v3.0
*/
/**
* Singleton storage
*
* Format:
* <pre>
* array(
* 'package1' => PEAR_ErrorStack object,
* 'package2' => PEAR_ErrorStack object,
* ...
* )
* </pre>
* @access private
* @global array $GLOBALS['_PEAR_ERRORSTACK_SINGLETON']
*/
$GLOBALS['_PEAR_ERRORSTACK_SINGLETON'] = array();
/**
* Global error callback (default)
*
* This is only used if set to non-false. * is the default callback for
* all packages, whereas specific packages may set a default callback
* for all instances, regardless of whether they are a singleton or not.
*
* To exclude non-singletons, only set the local callback for the singleton
* @see PEAR_ErrorStack::setDefaultCallback()
* @access private
* @global array $GLOBALS['_PEAR_ERRORSTACK_DEFAULT_CALLBACK']
*/
$GLOBALS['_PEAR_ERRORSTACK_DEFAULT_CALLBACK'] = array(
'*' => false,
);
/**
* Global Log object (default)
*
* This is only used if set to non-false. Use to set a default log object for
* all stacks, regardless of instantiation order or location
* @see PEAR_ErrorStack::setDefaultLogger()
* @access private
* @global array $GLOBALS['_PEAR_ERRORSTACK_DEFAULT_LOGGER']
*/
$GLOBALS['_PEAR_ERRORSTACK_DEFAULT_LOGGER'] = false;
/**
* Global Overriding Callback
*
* This callback will override any error callbacks that specific loggers have set.
* Use with EXTREME caution
* @see PEAR_ErrorStack::staticPushCallback()
* @access private
* @global array $GLOBALS['_PEAR_ERRORSTACK_DEFAULT_LOGGER']
*/
$GLOBALS['_PEAR_ERRORSTACK_OVERRIDE_CALLBACK'] = array();
/**#@+
* One of four possible return values from the error Callback
* @see PEAR_ErrorStack::_errorCallback()
*/
/**
* If this is returned, then the error will be both pushed onto the stack
* and logged.
*/
define('PEAR_ERRORSTACK_PUSHANDLOG', 1);
/**
* If this is returned, then the error will only be pushed onto the stack,
* and not logged.
*/
define('PEAR_ERRORSTACK_PUSH', 2);
/**
* If this is returned, then the error will only be logged, but not pushed
* onto the error stack.
*/
define('PEAR_ERRORSTACK_LOG', 3);
/**
* If this is returned, then the error is completely ignored.
*/
define('PEAR_ERRORSTACK_IGNORE', 4);
/**
* If this is returned, then the error is logged and die() is called.
*/
define('PEAR_ERRORSTACK_DIE', 5);
/**#@-*/
/**
* Error code for an attempt to instantiate a non-class as a PEAR_ErrorStack in
* the singleton method.
*/
define('PEAR_ERRORSTACK_ERR_NONCLASS', 1);
/**
* Error code for an attempt to pass an object into {@link PEAR_ErrorStack::getMessage()}
* that has no __toString() method
*/
define('PEAR_ERRORSTACK_ERR_OBJTOSTRING', 2);
/**
* Error Stack Implementation
*
* Usage:
* <code>
* // global error stack
* $global_stack = &PEAR_ErrorStack::singleton('MyPackage');
* // local error stack
* $local_stack = new PEAR_ErrorStack('MyPackage');
* </code>
* @copyright 2004 Gregory Beaver
* @package PEAR_ErrorStack
* @license http://www.php.net/license/3_0.txt PHP License
*/
class PEAR_ErrorStack {
/**
* Errors are stored in the order that they are pushed on the stack.
* @since 0.4alpha Errors are no longer organized by error level.
* This renders pop() nearly unusable, and levels could be more easily
* handled in a callback anyway
* @var array
* @access private
*/
var $_errors = array();
/**
* Storage of errors by level.
*
* Allows easy retrieval and deletion of only errors from a particular level
* @since PEAR 1.4.0dev
* @var array
* @access private
*/
var $_errorsByLevel = array();
/**
* Package name this error stack represents
* @var string
* @access protected
*/
var $_package;
/**
* Determines whether a PEAR_Error is thrown upon every error addition
* @var boolean
* @access private
*/
var $_compat = false;
/**
* If set to a valid callback, this will be used to generate the error
* message from the error code, otherwise the message passed in will be
* used
* @var false|string|array
* @access private
*/
var $_msgCallback = false;
/**
* If set to a valid callback, this will be used to generate the error
* context for an error. For PHP-related errors, this will be a file
* and line number as retrieved from debug_backtrace(), but can be
* customized for other purposes. The error might actually be in a separate
* configuration file, or in a database query.
* @var false|string|array
* @access protected
*/
var $_contextCallback = false;
/**
* If set to a valid callback, this will be called every time an error
* is pushed onto the stack. The return value will be used to determine
* whether to allow an error to be pushed or logged.
*
* The return value must be one an PEAR_ERRORSTACK_* constant
* @see PEAR_ERRORSTACK_PUSHANDLOG, PEAR_ERRORSTACK_PUSH, PEAR_ERRORSTACK_LOG
* @var false|string|array
* @access protected
*/
var $_errorCallback = array();
/**
* PEAR::Log object for logging errors
* @var false|Log
* @access protected
*/
var $_logger = false;
/**
* Error messages - designed to be overridden
* @var array
* @abstract
*/
var $_errorMsgs = array();
/**
* Set up a new error stack
*
* @param string $package name of the package this error stack represents
* @param callback $msgCallback callback used for error message generation
* @param callback $contextCallback callback used for context generation,
* defaults to {@link getFileLine()}
* @param boolean $throwPEAR_Error
*/
function PEAR_ErrorStack($package, $msgCallback = false, $contextCallback = false,
$throwPEAR_Error = false)
{
$this->_package = $package;
$this->setMessageCallback($msgCallback);
$this->setContextCallback($contextCallback);
$this->_compat = $throwPEAR_Error;
}
/**
* Return a single error stack for this package.
*
* Note that all parameters are ignored if the stack for package $package
* has already been instantiated
* @param string $package name of the package this error stack represents
* @param callback $msgCallback callback used for error message generation
* @param callback $contextCallback callback used for context generation,
* defaults to {@link getFileLine()}
* @param boolean $throwPEAR_Error
* @param string $stackClass class to instantiate
* @static
* @return PEAR_ErrorStack
*/
function &singleton($package, $msgCallback = false, $contextCallback = false,
$throwPEAR_Error = false, $stackClass = 'PEAR_ErrorStack')
{
if (isset($GLOBALS['_PEAR_ERRORSTACK_SINGLETON'][$package])) {
return $GLOBALS['_PEAR_ERRORSTACK_SINGLETON'][$package];
}
if (!class_exists($stackClass)) {
if (function_exists('debug_backtrace')) {
$trace = debug_backtrace();
}
PEAR_ErrorStack::staticPush('PEAR_ErrorStack', PEAR_ERRORSTACK_ERR_NONCLASS,
'exception', array('stackclass' => $stackClass),
'stack class "%stackclass%" is not a valid class name (should be like PEAR_ErrorStack)',
false, $trace);
}
return $GLOBALS['_PEAR_ERRORSTACK_SINGLETON'][$package] =
&new $stackClass($package, $msgCallback, $contextCallback, $throwPEAR_Error);
}
/**
* Internal error handler for PEAR_ErrorStack class
*
* Dies if the error is an exception (and would have died anyway)
* @access private
*/
function _handleError($err)
{
if ($err['level'] == 'exception') {
$message = $err['message'];
if (isset($_SERVER['REQUEST_URI'])) {
echo '<br />';
} else {
echo "\n";
}
var_dump($err['context']);
die($message);
}
}
/**
* Set up a PEAR::Log object for all error stacks that don't have one
* @param Log $log
* @static
*/
function setDefaultLogger(&$log)
{
if (is_object($log) && method_exists($log, 'log') ) {
$GLOBALS['_PEAR_ERRORSTACK_DEFAULT_LOGGER'] = &$log;
} elseif (is_callable($log)) {
$GLOBALS['_PEAR_ERRORSTACK_DEFAULT_LOGGER'] = &$log;
}
}
/**
* Set up a PEAR::Log object for this error stack
* @param Log $log
*/
function setLogger(&$log)
{
if (is_object($log) && method_exists($log, 'log') ) {
$this->_logger = &$log;
} elseif (is_callable($log)) {
$this->_logger = &$log;
}
}
/**
* Set an error code => error message mapping callback
*
* This method sets the callback that can be used to generate error
* messages for any instance
* @param array|string Callback function/method
*/
function setMessageCallback($msgCallback)
{
if (!$msgCallback) {
$this->_msgCallback = array(&$this, 'getErrorMessage');
} else {
if (is_callable($msgCallback)) {
$this->_msgCallback = $msgCallback;
}
}
}
/**
* Get an error code => error message mapping callback
*
* This method returns the current callback that can be used to generate error
* messages
* @return array|string|false Callback function/method or false if none
*/
function getMessageCallback()
{
return $this->_msgCallback;
}
/**
* Sets a default callback to be used by all error stacks
*
* This method sets the callback that can be used to generate error
* messages for a singleton
* @param array|string Callback function/method
* @param string Package name, or false for all packages
* @static
*/
function setDefaultCallback($callback = false, $package = false)
{
if (!is_callable($callback)) {
$callback = false;
}
$package = $package ? $package : '*';
$GLOBALS['_PEAR_ERRORSTACK_DEFAULT_CALLBACK'][$package] = $callback;
}
/**
* Set a callback that generates context information (location of error) for an error stack
*
* This method sets the callback that can be used to generate context
* information for an error. Passing in NULL will disable context generation
* and remove the expensive call to debug_backtrace()
* @param array|string|null Callback function/method
*/
function setContextCallback($contextCallback)
{
if ($contextCallback === null) {
return $this->_contextCallback = false;
}
if (!$contextCallback) {
$this->_contextCallback = array(&$this, 'getFileLine');
} else {
if (is_callable($contextCallback)) {
$this->_contextCallback = $contextCallback;
}
}
}
/**
* Set an error Callback
* If set to a valid callback, this will be called every time an error
* is pushed onto the stack. The return value will be used to determine
* whether to allow an error to be pushed or logged.
*
* The return value must be one of the ERRORSTACK_* constants.
*
* This functionality can be used to emulate PEAR's pushErrorHandling, and
* the PEAR_ERROR_CALLBACK mode, without affecting the integrity of
* the error stack or logging
* @see PEAR_ERRORSTACK_PUSHANDLOG, PEAR_ERRORSTACK_PUSH, PEAR_ERRORSTACK_LOG
* @see popCallback()
* @param string|array $cb
*/
function pushCallback($cb)
{
array_push($this->_errorCallback, $cb);
}
/**
* Remove a callback from the error callback stack
* @see pushCallback()
* @return array|string|false
*/
function popCallback()
{
if (!count($this->_errorCallback)) {
return false;
}
return array_pop($this->_errorCallback);
}
/**
* Set a temporary overriding error callback for every package error stack
*
* Use this to temporarily disable all existing callbacks (can be used
* to emulate the @ operator, for instance)
* @see PEAR_ERRORSTACK_PUSHANDLOG, PEAR_ERRORSTACK_PUSH, PEAR_ERRORSTACK_LOG
* @see staticPopCallback(), pushCallback()
* @param string|array $cb
* @static
*/
function staticPushCallback($cb)
{
array_push($GLOBALS['_PEAR_ERRORSTACK_OVERRIDE_CALLBACK'], $cb);
}
/**
* Remove a temporary overriding error callback
* @see staticPushCallback()
* @return array|string|false
* @static
*/
function staticPopCallback()
{
$ret = array_pop($GLOBALS['_PEAR_ERRORSTACK_OVERRIDE_CALLBACK']);
if (!is_array($GLOBALS['_PEAR_ERRORSTACK_OVERRIDE_CALLBACK'])) {
$GLOBALS['_PEAR_ERRORSTACK_OVERRIDE_CALLBACK'] = array();
}
return $ret;
}
/**
* Add an error to the stack
*
* If the message generator exists, it is called with 2 parameters.
* - the current Error Stack object
* - an array that is in the same format as an error. Available indices
* are 'code', 'package', 'time', 'params', 'level', and 'context'
*
* Next, if the error should contain context information, this is
* handled by the context grabbing method.
* Finally, the error is pushed onto the proper error stack
* @param int $code Package-specific error code
* @param string $level Error level. This is NOT spell-checked
* @param array $params associative array of error parameters
* @param string $msg Error message, or a portion of it if the message
* is to be generated
* @param array $repackage If this error re-packages an error pushed by
* another package, place the array returned from
* {@link pop()} in this parameter
* @param array $backtrace Protected parameter: use this to pass in the
* {@link debug_backtrace()} that should be used
* to find error context
* @return PEAR_Error|array|Exception
* if compatibility mode is on, a PEAR_Error is also
* thrown. If the class Exception exists, then one
* is returned to allow code like:
* <code>
* throw ($stack->push(MY_ERROR_CODE, 'error', array('username' => 'grob')));
* </code>
*
* The errorData property of the exception class will be set to the array
* that would normally be returned. If a PEAR_Error is returned, the userinfo
* property is set to the array
*
* Otherwise, an array is returned in this format:
* <code>
* array(
* 'code' => $code,
* 'params' => $params,
* 'package' => $this->_package,
* 'level' => $level,
* 'time' => time(),
* 'context' => $context,
* 'message' => $msg,
* //['repackage' => $err] repackaged error array/Exception class
* );
* </code>
*/
function push($code, $level = 'error', $params = array(), $msg = false,
$repackage = false, $backtrace = false)
{
$context = false;
// grab error context
if ($this->_contextCallback) {
if (!$backtrace) {
$backtrace = debug_backtrace();
}
$context = call_user_func($this->_contextCallback, $code, $params, $backtrace);
}
// save error
$time = explode(' ', microtime());
$time = $time[1] + $time[0];
$err = array(
'code' => $code,
'params' => $params,
'package' => $this->_package,
'level' => $level,
'time' => $time,
'context' => $context,
'message' => $msg,
);
// set up the error message, if necessary
if ($this->_msgCallback) {
$msg = call_user_func_array($this->_msgCallback,
array(&$this, $err));
$err['message'] = $msg;
}
if ($repackage) {
$err['repackage'] = $repackage;
}
$push = $log = true;
$die = false;
// try the overriding callback first
$callback = $this->staticPopCallback();
if ($callback) {
$this->staticPushCallback($callback);
}
if (!is_callable($callback)) {
// try the local callback next
$callback = $this->popCallback();
if (is_callable($callback)) {
$this->pushCallback($callback);
} else {
// try the default callback
$callback = isset($GLOBALS['_PEAR_ERRORSTACK_DEFAULT_CALLBACK'][$this->_package]) ?
$GLOBALS['_PEAR_ERRORSTACK_DEFAULT_CALLBACK'][$this->_package] :
$GLOBALS['_PEAR_ERRORSTACK_DEFAULT_CALLBACK']['*'];
}
}
if (is_callable($callback)) {
switch(call_user_func($callback, $err)){
case PEAR_ERRORSTACK_IGNORE:
return $err;
break;
case PEAR_ERRORSTACK_PUSH:
$log = false;
break;
case PEAR_ERRORSTACK_LOG:
$push = false;
break;
case PEAR_ERRORSTACK_DIE:
$die = true;
break;
// anything else returned has the same effect as pushandlog
}
}
if ($push) {
array_unshift($this->_errors, $err);
$this->_errorsByLevel[$err['level']][] = &$this->_errors[0];
}
if ($log) {
if ($this->_logger || $GLOBALS['_PEAR_ERRORSTACK_DEFAULT_LOGGER']) {
$this->_log($err);
}
}
if ($die) {
die();
}
if ($this->_compat && $push) {
return $this->raiseError($msg, $code, null, null, $err);
}
return $err;
}
/**
* Static version of {@link push()}
*
* @param string $package Package name this error belongs to
* @param int $code Package-specific error code
* @param string $level Error level. This is NOT spell-checked
* @param array $params associative array of error parameters
* @param string $msg Error message, or a portion of it if the message
* is to be generated
* @param array $repackage If this error re-packages an error pushed by
* another package, place the array returned from
* {@link pop()} in this parameter
* @param array $backtrace Protected parameter: use this to pass in the
* {@link debug_backtrace()} that should be used
* to find error context
* @return PEAR_Error|null|Exception
* if compatibility mode is on, a PEAR_Error is also
* thrown. If the class Exception exists, then one
* is returned to allow code like:
* <code>
* throw ($stack->push(MY_ERROR_CODE, 'error', array('username' => 'grob')));
* </code>
* @static
*/
function staticPush($package, $code, $level = 'error', $params = array(),
$msg = false, $repackage = false, $backtrace = false)
{
$s = &PEAR_ErrorStack::singleton($package);
if ($s->_contextCallback) {
if (!$backtrace) {
if (function_exists('debug_backtrace')) {
$backtrace = debug_backtrace();
}
}
}
return $s->push($code, $level, $params, $msg, $repackage, $backtrace);
}
/**
* Log an error using PEAR::Log
* @param array $err Error array
* @param array $levels Error level => Log constant map
* @access protected
*/
function _log($err)
{
if ($this->_logger) {
$logger = &$this->_logger;
} else {
$logger = &$GLOBALS['_PEAR_ERRORSTACK_DEFAULT_LOGGER'];
}
if (is_a($logger, 'Log')) {
$levels = array(
'exception' => PEAR_LOG_CRIT,
'alert' => PEAR_LOG_ALERT,
'critical' => PEAR_LOG_CRIT,
'error' => PEAR_LOG_ERR,
'warning' => PEAR_LOG_WARNING,
'notice' => PEAR_LOG_NOTICE,
'info' => PEAR_LOG_INFO,
'debug' => PEAR_LOG_DEBUG);
if (isset($levels[$err['level']])) {
$level = $levels[$err['level']];
} else {
$level = PEAR_LOG_INFO;
}
$logger->log($err['message'], $level, $err);
} else { // support non-standard logs
call_user_func($logger, $err);
}
}
/**
* Pop an error off of the error stack
*
* @return false|array
* @since 0.4alpha it is no longer possible to specify a specific error
* level to return - the last error pushed will be returned, instead
*/
function pop()
{
return @array_shift($this->_errors);
}
/**
* Determine whether there are any errors on the stack
* @param string|array Level name. Use to determine if any errors
* of level (string), or levels (array) have been pushed
* @return boolean
*/
function hasErrors($level = false)
{
if ($level) {
return isset($this->_errorsByLevel[$level]);
}
return count($this->_errors);
}
/**
* Retrieve all errors since last purge
*
* @param boolean set in order to empty the error stack
* @param string level name, to return only errors of a particular severity
* @return array
*/
function getErrors($purge = false, $level = false)
{
if (!$purge) {
if ($level) {
if (!isset($this->_errorsByLevel[$level])) {
return array();
} else {
return $this->_errorsByLevel[$level];
}
} else {
return $this->_errors;
}
}
if ($level) {
$ret = $this->_errorsByLevel[$level];
foreach ($this->_errorsByLevel[$level] as $i => $unused) {
// entries are references to the $_errors array
$this->_errorsByLevel[$level][$i] = false;
}
// array_filter removes all entries === false
$this->_errors = array_filter($this->_errors);
unset($this->_errorsByLevel[$level]);
return $ret;
}
$ret = $this->_errors;
$this->_errors = array();
$this->_errorsByLevel = array();
return $ret;
}
/**
* Determine whether there are any errors on a single error stack, or on any error stack
*
* The optional parameter can be used to test the existence of any errors without the need of
* singleton instantiation
* @param string|false Package name to check for errors
* @param string Level name to check for a particular severity
* @return boolean
* @static
*/
function staticHasErrors($package = false, $level = false)
{
if ($package) {
if (!isset($GLOBALS['_PEAR_ERRORSTACK_SINGLETON'][$package])) {
return false;
}
return $GLOBALS['_PEAR_ERRORSTACK_SINGLETON'][$package]->hasErrors($level);
}
foreach ($GLOBALS['_PEAR_ERRORSTACK_SINGLETON'] as $package => $obj) {
if ($obj->hasErrors($level)) {
return true;
}
}
return false;
}
/**
* Get a list of all errors since last purge, organized by package
* @since PEAR 1.4.0dev BC break! $level is now in the place $merge used to be
* @param boolean $purge Set to purge the error stack of existing errors
* @param string $level Set to a level name in order to retrieve only errors of a particular level
* @param boolean $merge Set to return a flat array, not organized by package
* @param array $sortfunc Function used to sort a merged array - default
* sorts by time, and should be good for most cases
* @static
* @return array
*/
function staticGetErrors($purge = false, $level = false, $merge = false,
$sortfunc = array('PEAR_ErrorStack', '_sortErrors'))
{
$ret = array();
if (!is_callable($sortfunc)) {
$sortfunc = array('PEAR_ErrorStack', '_sortErrors');
}
foreach ($GLOBALS['_PEAR_ERRORSTACK_SINGLETON'] as $package => $obj) {
$test = $GLOBALS['_PEAR_ERRORSTACK_SINGLETON'][$package]->getErrors($purge, $level);
if ($test) {
if ($merge) {
$ret = array_merge($ret, $test);
} else {
$ret[$package] = $test;
}
}
}
if ($merge) {
usort($ret, $sortfunc);
}
return $ret;
}
/**
* Error sorting function, sorts by time
* @access private
*/
function _sortErrors($a, $b)
{
if ($a['time'] == $b['time']) {
return 0;
}
if ($a['time'] < $b['time']) {
return 1;
}
return -1;
}
/**
* Standard file/line number/function/class context callback
*
* This function uses a backtrace generated from {@link debug_backtrace()}
* and so will not work at all in PHP < 4.3.0. The frame should
* reference the frame that contains the source of the error.
* @return array|false either array('file' => file, 'line' => line,
* 'function' => function name, 'class' => class name) or
* if this doesn't work, then false
* @param unused
* @param integer backtrace frame.
* @param array Results of debug_backtrace()
* @static
*/
function getFileLine($code, $params, $backtrace = null)
{
if ($backtrace === null) {
return false;
}
$frame = 0;
$functionframe = 1;
if (!isset($backtrace[1])) {
$functionframe = 0;
} else {
while (isset($backtrace[$functionframe]['function']) &&
$backtrace[$functionframe]['function'] == 'eval' &&
isset($backtrace[$functionframe + 1])) {
$functionframe++;
}
}
if (isset($backtrace[$frame])) {
if (!isset($backtrace[$frame]['file'])) {
$frame++;
}
$funcbacktrace = $backtrace[$functionframe];
$filebacktrace = $backtrace[$frame];
$ret = array('file' => $filebacktrace['file'],
'line' => $filebacktrace['line']);
// rearrange for eval'd code or create function errors
if (strpos($filebacktrace['file'], '(') &&
preg_match(';^(.*?)\((\d+)\) : (.*?)$;', $filebacktrace['file'],
$matches)) {
$ret['file'] = $matches[1];
$ret['line'] = $matches[2] + 0;
}
if (isset($funcbacktrace['function']) && isset($backtrace[1])) {
if ($funcbacktrace['function'] != 'eval') {
if ($funcbacktrace['function'] == '__lambda_func') {
$ret['function'] = 'create_function() code';
} else {
$ret['function'] = $funcbacktrace['function'];
}
}
}
if (isset($funcbacktrace['class']) && isset($backtrace[1])) {
$ret['class'] = $funcbacktrace['class'];
}
return $ret;
}
return false;
}
/**
* Standard error message generation callback
*
* This method may also be called by a custom error message generator
* to fill in template values from the params array, simply
* set the third parameter to the error message template string to use
*
* The special variable %__msg% is reserved: use it only to specify
* where a message passed in by the user should be placed in the template,
* like so:
*
* Error message: %msg% - internal error
*
* If the message passed like so:
*
* <code>
* $stack->push(ERROR_CODE, 'error', array(), 'server error 500');
* </code>
*
* The returned error message will be "Error message: server error 500 -
* internal error"
* @param PEAR_ErrorStack
* @param array
* @param string|false Pre-generated error message template
* @static
* @return string
*/
function getErrorMessage(&$stack, $err, $template = false)
{
if ($template) {
$mainmsg = $template;
} else {
$mainmsg = $stack->getErrorMessageTemplate($err['code']);
}
$mainmsg = str_replace('%__msg%', $err['message'], $mainmsg);
if (count($err['params'])) {
foreach ($err['params'] as $name => $val) {
if (is_array($val)) {
// @ is needed in case $val is a multi-dimensional array
$val = @implode(', ', $val);
}
if (is_object($val)) {
if (method_exists($val, '__toString')) {
$val = $val->__toString();
} else {
PEAR_ErrorStack::staticPush('PEAR_ErrorStack', PEAR_ERRORSTACK_ERR_OBJTOSTRING,
'warning', array('obj' => get_class($val)),
'object %obj% passed into getErrorMessage, but has no __toString() method');
$val = 'Object';
}
}
$mainmsg = str_replace('%' . $name . '%', $val, $mainmsg);
}
}
return $mainmsg;
}
/**
* Standard Error Message Template generator from code
* @return string
*/
function getErrorMessageTemplate($code)
{
if (!isset($this->_errorMsgs[$code])) {
return '%__msg%';
}
return $this->_errorMsgs[$code];
}
/**
* Set the Error Message Template array
*
* The array format must be:
* <pre>
* array(error code => 'message template',...)
* </pre>
*
* Error message parameters passed into {@link push()} will be used as input
* for the error message. If the template is 'message %foo% was %bar%', and the
* parameters are array('foo' => 'one', 'bar' => 'six'), the error message returned will
* be 'message one was six'
* @return string
*/
function setErrorMessageTemplate($template)
{
$this->_errorMsgs = $template;
}
/**
* emulate PEAR::raiseError()
*
* @return PEAR_Error
*/
function raiseError()
{
require_once 'PEAR.php';
$args = func_get_args();
return call_user_func_array(array('PEAR', 'raiseError'), $args);
}
}
$stack = &PEAR_ErrorStack::singleton('PEAR_ErrorStack');
$stack->pushCallback(array('PEAR_ErrorStack', '_handleError'));
?>

359
3rdparty/PEAR/Exception.php vendored Normal file
View File

@ -0,0 +1,359 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */
// +----------------------------------------------------------------------+
// | PEAR_Exception |
// +----------------------------------------------------------------------+
// | Copyright (c) 2004 The PEAR 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 at through the world-wide-web at |
// | http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Tomas V.V.Cox <cox@idecnet.com> |
// | Hans Lellelid <hans@velum.net> |
// | Bertrand Mansion <bmansion@mamasam.com> |
// | Greg Beaver <cellog@php.net> |
// +----------------------------------------------------------------------+
//
// $Id: Exception.php,v 1.4.2.2 2004/12/31 19:01:52 cellog Exp $
/**
* Base PEAR_Exception Class
*
* WARNING: This code should be considered stable, but the API is
* subject to immediate and drastic change, so API stability is
* at best alpha
*
* 1) Features:
*
* - Nestable exceptions (throw new PEAR_Exception($msg, $prev_exception))
* - Definable triggers, shot when exceptions occur
* - Pretty and informative error messages
* - Added more context info available (like class, method or cause)
* - cause can be a PEAR_Exception or an array of mixed
* PEAR_Exceptions/PEAR_ErrorStack warnings
* - callbacks for specific exception classes and their children
*
* 2) Ideas:
*
* - Maybe a way to define a 'template' for the output
*
* 3) Inherited properties from PHP Exception Class:
*
* protected $message
* protected $code
* protected $line
* protected $file
* private $trace
*
* 4) Inherited methods from PHP Exception Class:
*
* __clone
* __construct
* getMessage
* getCode
* getFile
* getLine
* getTraceSafe
* getTraceSafeAsString
* __toString
*
* 5) Usage example
*
* <code>
* require_once 'PEAR/Exception.php';
*
* class Test {
* function foo() {
* throw new PEAR_Exception('Error Message', ERROR_CODE);
* }
* }
*
* function myLogger($pear_exception) {
* echo $pear_exception->getMessage();
* }
* // each time a exception is thrown the 'myLogger' will be called
* // (its use is completely optional)
* PEAR_Exception::addObserver('myLogger');
* $test = new Test;
* try {
* $test->foo();
* } catch (PEAR_Exception $e) {
* print $e;
* }
* </code>
*
* @since PHP 5
* @package PEAR
* @version $Revision: 1.4.2.2 $
* @author Tomas V.V.Cox <cox@idecnet.com>
* @author Hans Lellelid <hans@velum.net>
* @author Bertrand Mansion <bmansion@mamasam.com>
*
*/
class PEAR_Exception extends Exception
{
const OBSERVER_PRINT = -2;
const OBSERVER_TRIGGER = -4;
const OBSERVER_DIE = -8;
protected $cause;
private static $_observers = array();
private static $_uniqueid = 0;
private $_trace;
/**
* Supported signatures:
* PEAR_Exception(string $message);
* PEAR_Exception(string $message, int $code);
* PEAR_Exception(string $message, Exception $cause);
* PEAR_Exception(string $message, Exception $cause, int $code);
* PEAR_Exception(string $message, array $causes);
* PEAR_Exception(string $message, array $causes, int $code);
*/
public function __construct($message, $p2 = null, $p3 = null)
{
if (is_int($p2)) {
$code = $p2;
$this->cause = null;
} elseif ($p2 instanceof Exception || is_array($p2)) {
$code = $p3;
if (is_array($p2) && isset($p2['message'])) {
// fix potential problem of passing in a single warning
$p2 = array($p2);
}
$this->cause = $p2;
} else {
$code = null;
$this->cause = null;
}
parent::__construct($message, $code);
$this->signal();
}
/**
* @param mixed $callback - A valid php callback, see php func is_callable()
* - A PEAR_Exception::OBSERVER_* constant
* - An array(const PEAR_Exception::OBSERVER_*,
* mixed $options)
* @param string $label The name of the observer. Use this if you want
* to remove it later with removeObserver()
*/
public static function addObserver($callback, $label = 'default')
{
self::$_observers[$label] = $callback;
}
public static function removeObserver($label = 'default')
{
unset(self::$_observers[$label]);
}
/**
* @return int unique identifier for an observer
*/
public static function getUniqueId()
{
return self::$_uniqueid++;
}
private function signal()
{
foreach (self::$_observers as $func) {
if (is_callable($func)) {
call_user_func($func, $this);
continue;
}
settype($func, 'array');
switch ($func[0]) {
case self::OBSERVER_PRINT :
$f = (isset($func[1])) ? $func[1] : '%s';
printf($f, $this->getMessage());
break;
case self::OBSERVER_TRIGGER :
$f = (isset($func[1])) ? $func[1] : E_USER_NOTICE;
trigger_error($this->getMessage(), $f);
break;
case self::OBSERVER_DIE :
$f = (isset($func[1])) ? $func[1] : '%s';
die(printf($f, $this->getMessage()));
break;
default:
trigger_error('invalid observer type', E_USER_WARNING);
}
}
}
/**
* Return specific error information that can be used for more detailed
* error messages or translation.
*
* This method may be overridden in child exception classes in order
* to add functionality not present in PEAR_Exception and is a placeholder
* to define API
*
* The returned array must be an associative array of parameter => value like so:
* <pre>
* array('name' => $name, 'context' => array(...))
* </pre>
* @return array
*/
public function getErrorData()
{
return array();
}
/**
* Returns the exception that caused this exception to be thrown
* @access public
* @return Exception|array The context of the exception
*/
public function getCause()
{
return $this->cause;
}
/**
* Function must be public to call on caused exceptions
* @param array
*/
public function getCauseMessage(&$causes)
{
$trace = $this->getTraceSafe();
$cause = array('class' => get_class($this),
'message' => $this->message,
'file' => 'unknown',
'line' => 'unknown');
if (isset($trace[0])) {
if (isset($trace[0]['file'])) {
$cause['file'] = $trace[0]['file'];
$cause['line'] = $trace[0]['line'];
}
}
if ($this->cause instanceof PEAR_Exception) {
$this->cause->getCauseMessage($causes);
}
if (is_array($this->cause)) {
foreach ($this->cause as $cause) {
if ($cause instanceof PEAR_Exception) {
$cause->getCauseMessage($causes);
} elseif (is_array($cause) && isset($cause['message'])) {
// PEAR_ErrorStack warning
$causes[] = array(
'class' => $cause['package'],
'message' => $cause['message'],
'file' => isset($cause['context']['file']) ?
$cause['context']['file'] :
'unknown',
'line' => isset($cause['context']['line']) ?
$cause['context']['line'] :
'unknown',
);
}
}
}
}
public function getTraceSafe()
{
if (!isset($this->_trace)) {
$this->_trace = $this->getTrace();
if (empty($this->_trace)) {
$backtrace = debug_backtrace();
$this->_trace = array($backtrace[count($backtrace)-1]);
}
}
return $this->_trace;
}
public function getErrorClass()
{
$trace = $this->getTraceSafe();
return $trace[0]['class'];
}
public function getErrorMethod()
{
$trace = $this->getTraceSafe();
return $trace[0]['function'];
}
public function __toString()
{
if (isset($_SERVER['REQUEST_URI'])) {
return $this->toHtml();
}
return $this->toText();
}
public function toHtml()
{
$trace = $this->getTraceSafe();
$causes = array();
$this->getCauseMessage($causes);
$html = '<table border="1" cellspacing="0">' . "\n";
foreach ($causes as $i => $cause) {
$html .= '<tr><td colspan="3" bgcolor="#ff9999">'
. str_repeat('-', $i) . ' <b>' . $cause['class'] . '</b>: '
. htmlspecialchars($cause['message']) . ' in <b>' . $cause['file'] . '</b> '
. 'on line <b>' . $cause['line'] . '</b>'
. "</td></tr>\n";
}
$html .= '<tr><td colspan="3" bgcolor="#aaaaaa" align="center"><b>Exception trace</b></td></tr>' . "\n"
. '<tr><td align="center" bgcolor="#cccccc" width="20"><b>#</b></td>'
. '<td align="center" bgcolor="#cccccc"><b>Function</b></td>'
. '<td align="center" bgcolor="#cccccc"><b>Location</b></td></tr>' . "\n";
foreach ($trace as $k => $v) {
$html .= '<tr><td align="center">' . $k . '</td>'
. '<td>';
if (!empty($v['class'])) {
$html .= $v['class'] . $v['type'];
}
$html .= $v['function'];
$args = array();
if (!empty($v['args'])) {
foreach ($v['args'] as $arg) {
if (is_null($arg)) $args[] = 'null';
elseif (is_array($arg)) $args[] = 'Array';
elseif (is_object($arg)) $args[] = 'Object('.get_class($arg).')';
elseif (is_bool($arg)) $args[] = $arg ? 'true' : 'false';
elseif (is_int($arg) || is_double($arg)) $args[] = $arg;
else {
$arg = (string)$arg;
$str = htmlspecialchars(substr($arg, 0, 16));
if (strlen($arg) > 16) $str .= '&hellip;';
$args[] = "'" . $str . "'";
}
}
}
$html .= '(' . implode(', ',$args) . ')'
. '</td>'
. '<td>' . $v['file'] . ':' . $v['line'] . '</td></tr>' . "\n";
}
$html .= '<tr><td align="center">' . ($k+1) . '</td>'
. '<td>{main}</td>'
. '<td>&nbsp;</td></tr>' . "\n"
. '</table>';
return $html;
}
public function toText()
{
$causes = array();
$this->getCauseMessage($causes);
$causeMsg = '';
foreach ($causes as $i => $cause) {
$causeMsg .= str_repeat(' ', $i) . $cause['class'] . ': '
. $cause['message'] . ' in ' . $cause['file']
. ' on line ' . $cause['line'] . "\n";
}
return $causeMsg . $this->getTraceAsString();
}
}
?>

509
3rdparty/PEAR/Frontend/CLI.php vendored Normal file
View File

@ -0,0 +1,509 @@
<?php
/*
+----------------------------------------------------------------------+
| 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: Stig Sæther Bakken <ssb@php.net> |
+----------------------------------------------------------------------+
$Id: CLI.php,v 1.41 2004/02/17 05:49:16 ssb Exp $
*/
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 $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 (function_exists('posix_isatty') && !posix_isatty(1)) {
// output is being redirected to a file or through a pipe
} elseif ($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("PEAR_Frontend_CLI::displayLine deprecated", E_USER_ERROR);
}
function _displayLine($text)
{
print "$this->lp$text\n";
}
// }}}
// {{{ display(text)
function display($text)
{
trigger_error("PEAR_Frontend_CLI::display deprecated", E_USER_ERROR);
}
function _display($text)
{
print $text;
}
// }}}
// {{{ displayError(eobj)
/**
* @param object PEAR_Error object
*/
function displayError($eobj)
{
return $this->_displayLine($eobj->getMessage());
}
// }}}
// {{{ displayFatalError(eobj)
/**
* @param object PEAR_Error object
*/
function displayFatalError($eobj)
{
$this->displayError($eobj);
exit(1);
}
// }}}
// {{{ displayHeading(title)
function displayHeading($title)
{
trigger_error("PEAR_Frontend_CLI::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("PEAR_Frontend_CLI::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("PEAR_Frontend_CLI::startTable deprecated", E_USER_ERROR);
}
function _startTable($params = array())
{
$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("PEAR_Frontend_CLI::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", 0);
}
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("PEAR_Frontend_CLI::endTable deprecated", E_USER_ERROR);
}
function _endTable()
{
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];
}
}
}
$border = false;
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]);
if (!is_array($rowparams)) {
$rowparams = array();
}
if (!is_array($colparams)) {
$colparams = array();
}
$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;
}
if (!$border) {
$rowtext = rtrim($rowtext);
}
$rowtext .= $rowend;
$this->_displayLine($rowtext);
}
}
if ($borderline) {
$this->_displayLine($borderline);
}
}
// }}}
// {{{ outputData()
function outputData($data, $command = '_default')
{
switch ($command) {
case 'install':
case 'upgrade':
case 'upgrade-all':
if (isset($data['release_warnings'])) {
$this->_displayLine('');
$this->_startTable(array(
'border' => false,
'caption' => 'Release Warnings'
));
$this->_tableRow(array($data['release_warnings']), null, array(1 => array('wrap' => 55)));
$this->_endTable();
$this->_displayLine('');
}
$this->_displayLine($data['data']);
break;
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'] = false;
$opts = array(0 => array('wrap' => 30),
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' => false,
'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' => 30),
1 => array('wrap' => 20),
2 => array('wrap' => 35)
);
} else {
$opts = null;
}
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, $append_crlf = true)
{
if ($append_crlf) {
return $this->_displayLine($text);
}
return $this->_display($text);
}
// }}}
// {{{ bold($text)
function bold($text)
{
if (empty($this->term['bold'])) {
return strtoupper($text);
}
return $this->term['bold'] . $text . $this->term['normal'];
}
// }}}
}
?>

1068
3rdparty/PEAR/Installer.php vendored Normal file

File diff suppressed because it is too large Load Diff

165
3rdparty/PEAR/Packager.php vendored Normal file
View File

@ -0,0 +1,165 @@
<?php
//
// +----------------------------------------------------------------------+
// | 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. |
// +----------------------------------------------------------------------+
// | Authors: Stig Bakken <ssb@php.net> |
// | Tomas V.V.Cox <cox@idecnet.com> |
// +----------------------------------------------------------------------+
//
// $Id: Packager.php,v 1.53 2004/06/13 14:06:01 pajoye Exp $
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@php.net>
*/
class PEAR_Packager extends PEAR_Common
{
// {{{ constructor
function PEAR_Packager()
{
parent::PEAR_Common();
}
// }}}
// {{{ destructor
function _PEAR_Packager()
{
parent::_PEAR_Common();
}
// }}}
// {{{ package()
function package($pkgfile = null, $compress = true)
{
// {{{ validate supplied package.xml file
if (empty($pkgfile)) {
$pkgfile = 'package.xml';
}
// $this->pkginfo gets populated inside
$pkginfo = $this->infoFromDescriptionFile($pkgfile);
if (PEAR::isError($pkginfo)) {
return $this->raiseError($pkginfo);
}
$pkgdir = dirname(realpath($pkgfile));
$pkgfile = basename($pkgfile);
$errors = $warnings = array();
$this->validatePackageInfo($pkginfo, $errors, $warnings, $pkgdir);
foreach ($warnings as $w) {
$this->log(1, "Warning: $w");
}
foreach ($errors as $e) {
$this->log(0, "Error: $e");
}
if (sizeof($errors) > 0) {
return $this->raiseError('Errors in package');
}
// }}}
$pkgver = $pkginfo['package'] . '-' . $pkginfo['version'];
// {{{ Create the package file list
$filelist = array();
$i = 0;
foreach ($pkginfo['filelist'] as $fname => $atts) {
$file = $pkgdir . DIRECTORY_SEPARATOR . $fname;
if (!file_exists($file)) {
return $this->raiseError("File does not exist: $fname");
} else {
$filelist[$i++] = $file;
if (empty($pkginfo['filelist'][$fname]['md5sum'])) {
$md5sum = md5_file($file);
$pkginfo['filelist'][$fname]['md5sum'] = $md5sum;
}
$this->log(2, "Adding file $fname");
}
}
// }}}
// {{{ regenerate package.xml
$new_xml = $this->xmlFromInfo($pkginfo);
if (PEAR::isError($new_xml)) {
return $this->raiseError($new_xml);
}
if (!($tmpdir = System::mktemp(array('-d')))) {
return $this->raiseError("PEAR_Packager: mktemp failed");
}
$newpkgfile = $tmpdir . DIRECTORY_SEPARATOR . 'package.xml';
$np = @fopen($newpkgfile, 'wb');
if (!$np) {
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 = getcwd() . 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(array($newpkgfile), '', $tmpdir);
if (PEAR::isError($ok)) {
return $this->raiseError($ok);
} elseif (!$ok) {
return $this->raiseError('PEAR_Packager: tarball creation failed');
}
// ----- Add the content of the package
if (!$tar->addModify($filelist, $pkgver, $pkgdir)) {
return $this->raiseError('PEAR_Packager: tarball creation failed');
}
$this->log(1, "Package $dest_package done");
if (file_exists("$pkgdir/CVS/Root")) {
$cvsversion = preg_replace('/[^a-z0-9]/i', '_', $pkginfo['version']);
$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)");
}
// }}}
return $dest_package;
}
// }}}
}
// {{{ md5_file() utility function
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;
}
}
// }}}
?>

538
3rdparty/PEAR/Registry.php vendored Normal file
View File

@ -0,0 +1,538 @@
<?php
//
// +----------------------------------------------------------------------+
// | 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: Stig Bakken <ssb@php.net> |
// | Tomas V.V.Cox <cox@idecnet.com> |
// | |
// +----------------------------------------------------------------------+
//
// $Id: Registry.php,v 1.50.4.3 2004/10/26 19:19:56 cellog Exp $
/*
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';
// XXX Compatibility code should be removed in the future
// rename all registry files if any to lowercase
if (!OS_WINDOWS && $handle = @opendir($this->statedir)) {
$dest = $this->statedir . DIRECTORY_SEPARATOR;
while (false !== ($file = readdir($handle))) {
if (preg_match('/^.*[A-Z].*\.reg$/', $file)) {
rename($dest . $file, $dest . strtolower($file));
}
}
closedir($handle);
}
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(array('-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 . DIRECTORY_SEPARATOR . strtolower($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, 'wb');
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);
$rt = get_magic_quotes_runtime();
set_magic_quotes_runtime(0);
$data = fread($fp, $fsize);
set_magic_quotes_runtime($rt);
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 || $mode === LOCK_UN) {
if (@!is_file($this->lockfile)) {
touch($this->lockfile);
}
$open_mode = 'r';
}
if (!is_resource($this->lock_fp)) {
$this->lock_fp = @fopen($this->lockfile, $open_mode);
}
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);
if (is_resource($this->lock_fp)) {
fclose($this->lock_fp);
}
$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;
}
$rt = get_magic_quotes_runtime();
set_magic_quotes_runtime(0);
$data = fread($fp, filesize($this->_packageFileName($package)));
set_magic_quotes_runtime($rt);
$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, 'wb');
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 (is_array($attrs) && 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 '';
}
// }}}
}
?>

394
3rdparty/PEAR/Remote.php vendored Normal file
View File

@ -0,0 +1,394 @@
<?php
//
// +----------------------------------------------------------------------+
// | 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: Stig Bakken <ssb@php.net> |
// +----------------------------------------------------------------------+
//
// $Id: Remote.php,v 1.50 2004/06/08 18:03:46 cellog Exp $
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;
}
// }}}
// {{{ getCache()
function getCache($args)
{
$id = md5(serialize($args));
$cachedir = $this->config->get('cache_dir');
$filename = $cachedir . DIRECTORY_SEPARATOR . 'xmlrpc_cache_' . $id;
if (!file_exists($filename)) {
return null;
};
$fp = fopen($filename, 'rb');
if (!$fp) {
return null;
}
$content = fread($fp, filesize($filename));
fclose($fp);
$result = array(
'age' => time() - filemtime($filename),
'lastChange' => filemtime($filename),
'content' => unserialize($content),
);
return $result;
}
// }}}
// {{{ saveCache()
function saveCache($args, $data)
{
$id = md5(serialize($args));
$cachedir = $this->config->get('cache_dir');
if (!file_exists($cachedir)) {
System::mkdir(array('-p', $cachedir));
}
$filename = $cachedir.'/xmlrpc_cache_'.$id;
$fp = @fopen($filename, "wb");
if ($fp) {
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);
if (!PEAR::isError($result)) {
$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 = @urldecode(@$proxy['user']);
$proxy_pass = @urldecode(@$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;
if ($http_proxy = $this->config->get('http_proxy')) {
$proxy = parse_url($http_proxy);
$proxy_host = $proxy_port = $proxy_user = $proxy_pass = '';
$proxy_host = @$proxy['host'];
$proxy_port = @$proxy['port'];
$proxy_user = @urldecode(@$proxy['user']);
$proxy_pass = @urldecode(@$proxy['pass']);
$fp = @fsockopen($proxy_host, $proxy_port);
$use_proxy = true;
} else {
$use_proxy = false;
$fp = @fsockopen($server_host, $server_port);
}
if (!$fp && $http_proxy) {
return $this->raiseError("PEAR_Remote::call: fsockopen(`$proxy_host', $proxy_port) failed");
} elseif (!$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 ($use_proxy && $proxy_host != '' && $proxy_user != '') {
$req_headers .= 'Proxy-Authorization: Basic '
.base64_encode($proxy_user.':'.$proxy_pass)
."\r\n";
}
if ($this->config->get('verbose') > 3) {
print "XMLRPC REQUEST HEADERS:\n";
var_dump($req_headers);
print "XMLRPC REQUEST BODY:\n";
var_dump($request);
}
if ($use_proxy && $proxy_host != '') {
$post_string = "POST http://".$server_host;
if ($proxy_port > '') {
$post_string .= ':'.$server_port;
}
} else {
$post_string = "POST ";
}
fwrite($fp, ($post_string."/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 && isset($ret[0])
&& 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_continuous = true;
reset($php_val);
$size = count($php_val);
for ($expect = 0; $expect < $size; $expect++, next($php_val)) {
if (key($php_val) !== $expect) {
$is_continuous = false;
break;
}
}
if ($is_continuous) {
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 continuous
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;
}
// }}}
}
?>

363
3rdparty/PEAR/RunTest.php vendored Normal file
View File

@ -0,0 +1,363 @@
<?php
//
// +----------------------------------------------------------------------+
// | 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. |
// +----------------------------------------------------------------------+
// | Authors: Tomas V.V.Cox <cox@idecnet.com> |
// | Greg Beaver <cellog@php.net> |
// | |
// +----------------------------------------------------------------------+
//
// $Id: RunTest.php,v 1.3.2.4 2005/02/17 17:47:55 cellog Exp $
//
/**
* Simplified version of PHP's test suite
* -- EXPERIMENTAL --
Try it with:
$ php -r 'include "../PEAR/RunTest.php"; $t=new PEAR_RunTest; $o=$t->run("./pear_system.phpt");print_r($o);'
TODO:
Actually finish the development and testing
*/
require_once 'PEAR.php';
require_once 'PEAR/Config.php';
define('DETAILED', 1);
putenv("PHP_PEAR_RUNTESTS=1");
class PEAR_RunTest
{
var $_logger;
/**
* An object that supports the PEAR_Common->log() signature, or null
* @param PEAR_Common|null
*/
function PEAR_RunTest($logger = null)
{
$this->_logger = $logger;
}
//
// Run an individual test case.
//
function run($file, $ini_settings = '')
{
$cwd = getcwd();
$conf = &PEAR_Config::singleton();
$php = $conf->get('php_bin');
//var_dump($php);exit;
global $log_format, $info_params, $ini_overwrites;
$info_params = '';
$log_format = 'LEOD';
// Load the sections of the test file.
$section_text = array(
'TEST' => '(unnamed test)',
'SKIPIF' => '',
'GET' => '',
'ARGS' => '',
);
if (!is_file($file) || !$fp = fopen($file, "r")) {
return PEAR::raiseError("Cannot open test file: $file");
}
$section = '';
while (!feof($fp)) {
$line = fgets($fp);
// Match the beginning of a section.
if (ereg('^--([A-Z]+)--',$line,$r)) {
$section = $r[1];
$section_text[$section] = '';
continue;
}
// Add to the section text.
$section_text[$section] .= $line;
}
fclose($fp);
$shortname = str_replace($cwd.'/', '', $file);
$tested = trim($section_text['TEST'])." [$shortname]";
$tmp = realpath(dirname($file));
$tmp_skipif = $tmp . uniqid('/phpt.');
$tmp_file = ereg_replace('\.phpt$','.php',$file);
$tmp_post = $tmp . uniqid('/phpt.');
@unlink($tmp_skipif);
@unlink($tmp_file);
@unlink($tmp_post);
// unlink old test results
@unlink(ereg_replace('\.phpt$','.diff',$file));
@unlink(ereg_replace('\.phpt$','.log',$file));
@unlink(ereg_replace('\.phpt$','.exp',$file));
@unlink(ereg_replace('\.phpt$','.out',$file));
// Check if test should be skipped.
$info = '';
$warn = false;
if (array_key_exists('SKIPIF', $section_text)) {
if (trim($section_text['SKIPIF'])) {
$this->save_text($tmp_skipif, $section_text['SKIPIF']);
//$extra = substr(PHP_OS, 0, 3) !== "WIN" ?
// "unset REQUEST_METHOD;": "";
//$output = `$extra $php $info_params -f $tmp_skipif`;
$output = `$php $info_params -f $tmp_skipif`;
unlink($tmp_skipif);
if (eregi("^skip", trim($output))) {
$skipreason = "SKIP $tested";
$reason = (eregi("^skip[[:space:]]*(.+)\$", trim($output))) ? eregi_replace("^skip[[:space:]]*(.+)\$", "\\1", trim($output)) : FALSE;
if ($reason) {
$skipreason .= " (reason: $reason)";
}
$this->_logger->log(0, $skipreason);
if (isset($old_php)) {
$php = $old_php;
}
return 'SKIPPED';
}
if (eregi("^info", trim($output))) {
$reason = (ereg("^info[[:space:]]*(.+)\$", trim($output))) ? ereg_replace("^info[[:space:]]*(.+)\$", "\\1", trim($output)) : FALSE;
if ($reason) {
$info = " (info: $reason)";
}
}
if (eregi("^warn", trim($output))) {
$reason = (ereg("^warn[[:space:]]*(.+)\$", trim($output))) ? ereg_replace("^warn[[:space:]]*(.+)\$", "\\1", trim($output)) : FALSE;
if ($reason) {
$warn = true; /* only if there is a reason */
$info = " (warn: $reason)";
}
}
}
}
// We've satisfied the preconditions - run the test!
$this->save_text($tmp_file,$section_text['FILE']);
$args = $section_text['ARGS'] ? ' -- '.$section_text['ARGS'] : '';
$cmd = "$php$ini_settings -f $tmp_file$args 2>&1";
if (isset($this->_logger)) {
$this->_logger->log(2, 'Running command "' . $cmd . '"');
}
$savedir = getcwd(); // in case the test moves us around
if (isset($section_text['RETURNS'])) {
ob_start();
system($cmd, $return_value);
$out = ob_get_contents();
ob_end_clean();
@unlink($tmp_post);
$section_text['RETURNS'] = (int) trim($section_text['RETURNS']);
$returnfail = ($return_value != $section_text['RETURNS']);
} else {
$out = `$cmd`;
$returnfail = false;
}
chdir($savedir);
// Does the output match what is expected?
$output = trim($out);
$output = preg_replace('/\r\n/', "\n", $output);
if (isset($section_text['EXPECTF']) || isset($section_text['EXPECTREGEX'])) {
if (isset($section_text['EXPECTF'])) {
$wanted = trim($section_text['EXPECTF']);
} else {
$wanted = trim($section_text['EXPECTREGEX']);
}
$wanted_re = preg_replace('/\r\n/',"\n",$wanted);
if (isset($section_text['EXPECTF'])) {
$wanted_re = preg_quote($wanted_re, '/');
// Stick to basics
$wanted_re = str_replace("%s", ".+?", $wanted_re); //not greedy
$wanted_re = str_replace("%i", "[+\-]?[0-9]+", $wanted_re);
$wanted_re = str_replace("%d", "[0-9]+", $wanted_re);
$wanted_re = str_replace("%x", "[0-9a-fA-F]+", $wanted_re);
$wanted_re = str_replace("%f", "[+\-]?\.?[0-9]+\.?[0-9]*(E-?[0-9]+)?", $wanted_re);
$wanted_re = str_replace("%c", ".", $wanted_re);
// %f allows two points "-.0.0" but that is the best *simple* expression
}
/* DEBUG YOUR REGEX HERE
var_dump($wanted_re);
print(str_repeat('=', 80) . "\n");
var_dump($output);
*/
if (!$returnfail && preg_match("/^$wanted_re\$/s", $output)) {
@unlink($tmp_file);
$this->_logger->log(0, "PASS $tested$info");
if (isset($old_php)) {
$php = $old_php;
}
return 'PASSED';
}
} else {
$wanted = trim($section_text['EXPECT']);
$wanted = preg_replace('/\r\n/',"\n",$wanted);
// compare and leave on success
$ok = (0 == strcmp($output,$wanted));
if (!$returnfail && $ok) {
@unlink($tmp_file);
$this->_logger->log(0, "PASS $tested$info");
if (isset($old_php)) {
$php = $old_php;
}
return 'PASSED';
}
}
// Test failed so we need to report details.
if ($warn) {
$this->_logger->log(0, "WARN $tested$info");
} else {
$this->_logger->log(0, "FAIL $tested$info");
}
if (isset($section_text['RETURNS'])) {
$GLOBALS['__PHP_FAILED_TESTS__'][] = array(
'name' => $file,
'test_name' => $tested,
'output' => ereg_replace('\.phpt$','.log', $file),
'diff' => ereg_replace('\.phpt$','.diff', $file),
'info' => $info,
'return' => $return_value
);
} else {
$GLOBALS['__PHP_FAILED_TESTS__'][] = array(
'name' => $file,
'test_name' => $tested,
'output' => ereg_replace('\.phpt$','.log', $file),
'diff' => ereg_replace('\.phpt$','.diff', $file),
'info' => $info,
);
}
// write .exp
if (strpos($log_format,'E') !== FALSE) {
$logname = ereg_replace('\.phpt$','.exp',$file);
if (!$log = fopen($logname,'w')) {
return PEAR::raiseError("Cannot create test log - $logname");
}
fwrite($log,$wanted);
fclose($log);
}
// write .out
if (strpos($log_format,'O') !== FALSE) {
$logname = ereg_replace('\.phpt$','.out',$file);
if (!$log = fopen($logname,'w')) {
return PEAR::raiseError("Cannot create test log - $logname");
}
fwrite($log,$output);
fclose($log);
}
// write .diff
if (strpos($log_format,'D') !== FALSE) {
$logname = ereg_replace('\.phpt$','.diff',$file);
if (!$log = fopen($logname,'w')) {
return PEAR::raiseError("Cannot create test log - $logname");
}
fwrite($log, $this->generate_diff($wanted, $output,
isset($section_text['RETURNS']) ? array(trim($section_text['RETURNS']),
$return_value) : null));
fclose($log);
}
// write .log
if (strpos($log_format,'L') !== FALSE) {
$logname = ereg_replace('\.phpt$','.log',$file);
if (!$log = fopen($logname,'w')) {
return PEAR::raiseError("Cannot create test log - $logname");
}
fwrite($log,"
---- EXPECTED OUTPUT
$wanted
---- ACTUAL OUTPUT
$output
---- FAILED
");
if ($returnfail) {
fwrite($log,"
---- EXPECTED RETURN
$section_text[RETURNS]
---- ACTUAL RETURN
$return_value
");
}
fclose($log);
//error_report($file,$logname,$tested);
}
if (isset($old_php)) {
$php = $old_php;
}
return $warn ? 'WARNED' : 'FAILED';
}
function generate_diff($wanted, $output, $return_value)
{
$w = explode("\n", $wanted);
$o = explode("\n", $output);
$w1 = array_diff_assoc($w,$o);
$o1 = array_diff_assoc($o,$w);
$w2 = array();
$o2 = array();
foreach($w1 as $idx => $val) $w2[sprintf("%03d<",$idx)] = sprintf("%03d- ", $idx+1).$val;
foreach($o1 as $idx => $val) $o2[sprintf("%03d>",$idx)] = sprintf("%03d+ ", $idx+1).$val;
$diff = array_merge($w2, $o2);
ksort($diff);
if ($return_value) {
$extra = "##EXPECTED: $return_value[0]\r\n##RETURNED: $return_value[1]";
} else {
$extra = '';
}
return implode("\r\n", $diff) . $extra;
}
//
// Write the given text to a temporary file, and return the filename.
//
function save_text($filename, $text)
{
if (!$fp = fopen($filename, 'w')) {
return PEAR::raiseError("Cannot open file '" . $filename . "' (save_text)");
}
fwrite($fp,$text);
fclose($fp);
if (1 < DETAILED) echo "
FILE $filename {{{
$text
}}}
";
}
}
?>

2
3rdparty/README vendored
View File

@ -1,2 +0,0 @@
the 3rdparty libraries are now located in a seperate repository. just copy https://gitorious.org/owncloud/3rdparty into this directory and everything will work

127
3rdparty/Sabre.includes.php vendored Normal file
View File

@ -0,0 +1,127 @@
<?php
/**
* Library include file
*
* This file contains all includes to the rest of the SabreDAV library
* Make sure the lib/ directory is in PHP's include_path
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2011 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
/* Utilities */
include 'Sabre/HTTP/Util.php';
include 'Sabre/HTTP/Response.php';
include 'Sabre/HTTP/Request.php';
include 'Sabre/HTTP/AbstractAuth.php';
include 'Sabre/HTTP/BasicAuth.php';
include 'Sabre/HTTP/DigestAuth.php';
include 'Sabre/HTTP/AWSAuth.php';
/* Version */
include 'Sabre/DAV/Version.php';
include 'Sabre/HTTP/Version.php';
/* Exceptions */
include 'Sabre/DAV/Exception.php';
include 'Sabre/DAV/Exception/BadRequest.php';
include 'Sabre/DAV/Exception/Conflict.php';
include 'Sabre/DAV/Exception/FileNotFound.php';
include 'Sabre/DAV/Exception/InsufficientStorage.php';
include 'Sabre/DAV/Exception/Locked.php';
include 'Sabre/DAV/Exception/LockTokenMatchesRequestUri.php';
include 'Sabre/DAV/Exception/MethodNotAllowed.php';
include 'Sabre/DAV/Exception/NotImplemented.php';
include 'Sabre/DAV/Exception/Forbidden.php';
include 'Sabre/DAV/Exception/PreconditionFailed.php';
include 'Sabre/DAV/Exception/RequestedRangeNotSatisfiable.php';
include 'Sabre/DAV/Exception/UnsupportedMediaType.php';
include 'Sabre/DAV/Exception/NotAuthenticated.php';
include 'Sabre/DAV/Exception/ConflictingLock.php';
include 'Sabre/DAV/Exception/ReportNotImplemented.php';
include 'Sabre/DAV/Exception/InvalidResourceType.php';
/* Properties */
include 'Sabre/DAV/Property.php';
include 'Sabre/DAV/Property/GetLastModified.php';
include 'Sabre/DAV/Property/ResourceType.php';
include 'Sabre/DAV/Property/SupportedLock.php';
include 'Sabre/DAV/Property/LockDiscovery.php';
include 'Sabre/DAV/Property/IHref.php';
include 'Sabre/DAV/Property/Href.php';
include 'Sabre/DAV/Property/HrefList.php';
include 'Sabre/DAV/Property/SupportedReportSet.php';
include 'Sabre/DAV/Property/Response.php';
include 'Sabre/DAV/Property/ResponseList.php';
/* Node interfaces */
include 'Sabre/DAV/INode.php';
include 'Sabre/DAV/IFile.php';
include 'Sabre/DAV/ICollection.php';
include 'Sabre/DAV/IProperties.php';
include 'Sabre/DAV/ILockable.php';
include 'Sabre/DAV/IQuota.php';
include 'Sabre/DAV/IExtendedCollection.php';
/* Node abstract implementations */
include 'Sabre/DAV/Node.php';
include 'Sabre/DAV/File.php';
include 'Sabre/DAV/Collection.php';
include 'Sabre/DAV/Directory.php';
/* Utilities */
include 'Sabre/DAV/SimpleCollection.php';
include 'Sabre/DAV/SimpleDirectory.php';
include 'Sabre/DAV/XMLUtil.php';
include 'Sabre/DAV/URLUtil.php';
/* Filesystem implementation */
include 'Sabre/DAV/FS/Node.php';
include 'Sabre/DAV/FS/File.php';
include 'Sabre/DAV/FS/Directory.php';
/* Advanced filesystem implementation */
include 'Sabre/DAV/FSExt/Node.php';
include 'Sabre/DAV/FSExt/File.php';
include 'Sabre/DAV/FSExt/Directory.php';
/* Trees */
include 'Sabre/DAV/Tree.php';
include 'Sabre/DAV/ObjectTree.php';
include 'Sabre/DAV/Tree/Filesystem.php';
/* Server */
include 'Sabre/DAV/Server.php';
include 'Sabre/DAV/ServerPlugin.php';
/* Browser */
include 'Sabre/DAV/Browser/Plugin.php';
include 'Sabre/DAV/Browser/MapGetToPropFind.php';
include 'Sabre/DAV/Browser/GuessContentType.php';
/* Locks */
include 'Sabre/DAV/Locks/LockInfo.php';
include 'Sabre/DAV/Locks/Plugin.php';
include 'Sabre/DAV/Locks/Backend/Abstract.php';
include 'Sabre/DAV/Locks/Backend/FS.php';
include 'Sabre/DAV/Locks/Backend/PDO.php';
/* Temporary File Filter plugin */
include 'Sabre/DAV/TemporaryFileFilterPlugin.php';
/* Authentication plugin */
include 'Sabre/DAV/Auth/Plugin.php';
include 'Sabre/DAV/Auth/IBackend.php';
include 'Sabre/DAV/Auth/Backend/AbstractDigest.php';
include 'Sabre/DAV/Auth/Backend/AbstractBasic.php';
include 'Sabre/DAV/Auth/Backend/File.php';
include 'Sabre/DAV/Auth/Backend/PDO.php';
/* DavMount plugin */
include 'Sabre/DAV/Mount/Plugin.php';

View File

@ -0,0 +1,163 @@
<?php
/**
* Abstract Calendaring backend. Extend this class to create your own backends.
*
* @package Sabre
* @subpackage CalDAV
* @copyright Copyright (C) 2007-2011 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
abstract class Sabre_CalDAV_Backend_Abstract {
/**
* Returns a list of calendars for a principal.
*
* Every project is an array with the following keys:
* * id, a unique id that will be used by other functions to modify the
* calendar. This can be the same as the uri or a database key.
* * uri, which the basename of the uri with which the calendar is
* accessed.
* * principalUri. The owner of the calendar. Almost always the same as
* principalUri passed to this method.
*
* Furthermore it can contain webdav properties in clark notation. A very
* common one is '{DAV:}displayname'.
*
* @param string $principalUri
* @return array
*/
abstract function getCalendarsForUser($principalUri);
/**
* Creates a new calendar for a principal.
*
* If the creation was a success, an id must be returned that can be used to reference
* this calendar in other methods, such as updateCalendar.
*
* @param string $principalUri
* @param string $calendarUri
* @param array $properties
* @return void
*/
abstract function createCalendar($principalUri,$calendarUri,array $properties);
/**
* Updates properties for a calendar.
*
* The mutations array uses the propertyName in clark-notation as key,
* and the array value for the property value. In the case a property
* should be deleted, the property value will be null.
*
* This method must be atomic. If one property cannot be changed, the
* entire operation must fail.
*
* If the operation was successful, true can be returned.
* If the operation failed, false can be returned.
*
* Deletion of a non-existant property is always succesful.
*
* Lastly, it is optional to return detailed information about any
* failures. In this case an array should be returned with the following
* structure:
*
* array(
* 403 => array(
* '{DAV:}displayname' => null,
* ),
* 424 => array(
* '{DAV:}owner' => null,
* )
* )
*
* In this example it was forbidden to update {DAV:}displayname.
* (403 Forbidden), which in turn also caused {DAV:}owner to fail
* (424 Failed Dependency) because the request needs to be atomic.
*
* @param string $calendarId
* @param array $mutations
* @return bool|array
*/
public function updateCalendar($calendarId, array $mutations) {
return false;
}
/**
* Delete a calendar and all it's objects
*
* @param string $calendarId
* @return void
*/
abstract function deleteCalendar($calendarId);
/**
* Returns all calendar objects within a calendar.
*
* Every item contains an array with the following keys:
* * id - unique identifier which will be used for subsequent updates
* * calendardata - The iCalendar-compatible calnedar data
* * uri - a unique key which will be used to construct the uri. This can be any arbitrary string.
* * lastmodified - a timestamp of the last modification time
* * etag - An arbitrary string, surrounded by double-quotes. (e.g.:
* ' "abcdef"')
* * calendarid - The calendarid as it was passed to this function.
*
* Note that the etag is optional, but it's highly encouraged to return for
* speed reasons.
*
* The calendardata is also optional. If it's not returned
* 'getCalendarObject' will be called later, which *is* expected to return
* calendardata.
*
* @param string $calendarId
* @return array
*/
abstract function getCalendarObjects($calendarId);
/**
* Returns information from a single calendar object, based on it's object
* uri.
*
* The returned array must have the same keys as getCalendarObjects. The
* 'calendardata' object is required here though, while it's not required
* for getCalendarObjects.
*
* @param string $calendarId
* @param string $objectUri
* @return array
*/
abstract function getCalendarObject($calendarId,$objectUri);
/**
* Creates a new calendar object.
*
* @param string $calendarId
* @param string $objectUri
* @param string $calendarData
* @return void
*/
abstract function createCalendarObject($calendarId,$objectUri,$calendarData);
/**
* Updates an existing calendarobject, based on it's uri.
*
* @param string $calendarId
* @param string $objectUri
* @param string $calendarData
* @return void
*/
abstract function updateCalendarObject($calendarId,$objectUri,$calendarData);
/**
* Deletes an existing calendar object.
*
* @param string $calendarId
* @param string $objectUri
* @return void
*/
abstract function deleteCalendarObject($calendarId,$objectUri);
}

386
3rdparty/Sabre/CalDAV/Backend/PDO.php vendored Normal file
View File

@ -0,0 +1,386 @@
<?php
/**
* PDO CalDAV backend
*
* This backend is used to store calendar-data in a PDO database, such as
* sqlite or MySQL
*
* @package Sabre
* @subpackage CalDAV
* @copyright Copyright (C) 2007-2011 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_CalDAV_Backend_PDO extends Sabre_CalDAV_Backend_Abstract {
/**
* pdo
*
* @var PDO
*/
protected $pdo;
/**
* The table name that will be used for calendars
*
* @var string
*/
protected $calendarTableName;
/**
* The table name that will be used for calendar objects
*
* @var string
*/
protected $calendarObjectTableName;
/**
* List of CalDAV properties, and how they map to database fieldnames
*
* Add your own properties by simply adding on to this array
*
* @var array
*/
public $propertyMap = array(
'{DAV:}displayname' => 'displayname',
'{urn:ietf:params:xml:ns:caldav}calendar-description' => 'description',
'{urn:ietf:params:xml:ns:caldav}calendar-timezone' => 'timezone',
'{http://apple.com/ns/ical/}calendar-order' => 'calendarorder',
'{http://apple.com/ns/ical/}calendar-color' => 'calendarcolor',
);
/**
* Creates the backend
*
* @param PDO $pdo
*/
public function __construct(PDO $pdo, $calendarTableName = 'calendars', $calendarObjectTableName = 'calendarobjects') {
$this->pdo = $pdo;
$this->calendarTableName = $calendarTableName;
$this->calendarObjectTableName = $calendarObjectTableName;
}
/**
* Returns a list of calendars for a principal.
*
* Every project is an array with the following keys:
* * id, a unique id that will be used by other functions to modify the
* calendar. This can be the same as the uri or a database key.
* * uri, which the basename of the uri with which the calendar is
* accessed.
* * principalUri. The owner of the calendar. Almost always the same as
* principalUri passed to this method.
*
* Furthermore it can contain webdav properties in clark notation. A very
* common one is '{DAV:}displayname'.
*
* @param string $principalUri
* @return array
*/
public function getCalendarsForUser($principalUri) {
$fields = array_values($this->propertyMap);
$fields[] = 'id';
$fields[] = 'uri';
$fields[] = 'ctag';
$fields[] = 'components';
$fields[] = 'principaluri';
// Making fields a comma-delimited list
$fields = implode(', ', $fields);
$stmt = $this->pdo->prepare("SELECT " . $fields . " FROM `".$this->calendarTableName."` WHERE principaluri = ?");
$stmt->execute(array($principalUri));
$calendars = array();
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$components = explode(',',$row['components']);
$calendar = array(
'id' => $row['id'],
'uri' => $row['uri'],
'principaluri' => $row['principaluri'],
'{' . Sabre_CalDAV_Plugin::NS_CALENDARSERVER . '}getctag' => $row['ctag']?$row['ctag']:'0',
'{' . Sabre_CalDAV_Plugin::NS_CALDAV . '}supported-calendar-component-set' => new Sabre_CalDAV_Property_SupportedCalendarComponentSet($components),
);
foreach($this->propertyMap as $xmlName=>$dbName) {
$calendar[$xmlName] = $row[$dbName];
}
$calendars[] = $calendar;
}
return $calendars;
}
/**
* Creates a new calendar for a principal.
*
* If the creation was a success, an id must be returned that can be used to reference
* this calendar in other methods, such as updateCalendar
*
* @param string $principalUri
* @param string $calendarUri
* @param array $properties
*/
public function createCalendar($principalUri,$calendarUri, array $properties) {
$fieldNames = array(
'principaluri',
'uri',
'ctag',
);
$values = array(
':principaluri' => $principalUri,
':uri' => $calendarUri,
':ctag' => 1,
);
// Default value
$sccs = '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set';
$fieldNames[] = 'components';
if (!isset($properties[$sccs])) {
$values[':components'] = 'VEVENT,VTODO';
} else {
if (!($properties[$sccs] instanceof Sabre_CalDAV_Property_SupportedCalendarComponentSet)) {
throw new Sabre_DAV_Exception('The ' . $sccs . ' property must be of type: Sabre_CalDAV_Property_SupportedCalendarComponentSet');
}
$values[':components'] = implode(',',$properties[$sccs]->getValue());
}
foreach($this->propertyMap as $xmlName=>$dbName) {
if (isset($properties[$xmlName])) {
$myValue = $properties[$xmlName];
$values[':' . $dbName] = $properties[$xmlName];
$fieldNames[] = $dbName;
}
}
$stmt = $this->pdo->prepare("INSERT INTO `".$this->calendarTableName."` (".implode(', ', $fieldNames).") VALUES (".implode(', ',array_keys($values)).")");
$stmt->execute($values);
return $this->pdo->lastInsertId();
}
/**
* Updates properties for a calendar.
*
* The mutations array uses the propertyName in clark-notation as key,
* and the array value for the property value. In the case a property
* should be deleted, the property value will be null.
*
* This method must be atomic. If one property cannot be changed, the
* entire operation must fail.
*
* If the operation was successful, true can be returned.
* If the operation failed, false can be returned.
*
* Deletion of a non-existant property is always succesful.
*
* Lastly, it is optional to return detailed information about any
* failures. In this case an array should be returned with the following
* structure:
*
* array(
* 403 => array(
* '{DAV:}displayname' => null,
* ),
* 424 => array(
* '{DAV:}owner' => null,
* )
* )
*
* In this example it was forbidden to update {DAV:}displayname.
* (403 Forbidden), which in turn also caused {DAV:}owner to fail
* (424 Failed Dependency) because the request needs to be atomic.
*
* @param string $calendarId
* @param array $mutations
* @return bool|array
*/
public function updateCalendar($calendarId, array $mutations) {
$newValues = array();
$result = array(
200 => array(), // Ok
403 => array(), // Forbidden
424 => array(), // Failed Dependency
);
$hasError = false;
foreach($mutations as $propertyName=>$propertyValue) {
// We don't know about this property.
if (!isset($this->propertyMap[$propertyName])) {
$hasError = true;
$result[403][$propertyName] = null;
unset($mutations[$propertyName]);
continue;
}
$fieldName = $this->propertyMap[$propertyName];
$newValues[$fieldName] = $propertyValue;
}
// If there were any errors we need to fail the request
if ($hasError) {
// Properties has the remaining properties
foreach($mutations as $propertyName=>$propertyValue) {
$result[424][$propertyName] = null;
}
// Removing unused statuscodes for cleanliness
foreach($result as $status=>$properties) {
if (is_array($properties) && count($properties)===0) unset($result[$status]);
}
return $result;
}
// Success
// Now we're generating the sql query.
$valuesSql = array();
foreach($newValues as $fieldName=>$value) {
$valuesSql[] = $fieldName . ' = ?';
}
$valuesSql[] = 'ctag = ctag + 1';
$stmt = $this->pdo->prepare("UPDATE `" . $this->calendarTableName . "` SET " . implode(', ',$valuesSql) . " WHERE id = ?");
$newValues['id'] = $calendarId;
$stmt->execute(array_values($newValues));
return true;
}
/**
* Delete a calendar and all it's objects
*
* @param string $calendarId
* @return void
*/
public function deleteCalendar($calendarId) {
$stmt = $this->pdo->prepare('DELETE FROM `'.$this->calendarObjectTableName.'` WHERE calendarid = ?');
$stmt->execute(array($calendarId));
$stmt = $this->pdo->prepare('DELETE FROM `'.$this->calendarTableName.'` WHERE id = ?');
$stmt->execute(array($calendarId));
}
/**
* Returns all calendar objects within a calendar.
*
* Every item contains an array with the following keys:
* * id - unique identifier which will be used for subsequent updates
* * calendardata - The iCalendar-compatible calnedar data
* * uri - a unique key which will be used to construct the uri. This can be any arbitrary string.
* * lastmodified - a timestamp of the last modification time
* * etag - An arbitrary string, surrounded by double-quotes. (e.g.:
* ' "abcdef"')
* * calendarid - The calendarid as it was passed to this function.
*
* Note that the etag is optional, but it's highly encouraged to return for
* speed reasons.
*
* The calendardata is also optional. If it's not returned
* 'getCalendarObject' will be called later, which *is* expected to return
* calendardata.
*
* @param string $calendarId
* @return array
*/
public function getCalendarObjects($calendarId) {
$stmt = $this->pdo->prepare('SELECT * FROM `'.$this->calendarObjectTableName.'` WHERE calendarid = ?');
$stmt->execute(array($calendarId));
return $stmt->fetchAll();
}
/**
* Returns information from a single calendar object, based on it's object
* uri.
*
* The returned array must have the same keys as getCalendarObjects. The
* 'calendardata' object is required here though, while it's not required
* for getCalendarObjects.
*
* @param string $calendarId
* @param string $objectUri
* @return array
*/
public function getCalendarObject($calendarId,$objectUri) {
$stmt = $this->pdo->prepare('SELECT * FROM `'.$this->calendarObjectTableName.'` WHERE calendarid = ? AND uri = ?');
$stmt->execute(array($calendarId, $objectUri));
return $stmt->fetch();
}
/**
* Creates a new calendar object.
*
* @param string $calendarId
* @param string $objectUri
* @param string $calendarData
* @return void
*/
public function createCalendarObject($calendarId,$objectUri,$calendarData) {
$stmt = $this->pdo->prepare('INSERT INTO `'.$this->calendarObjectTableName.'` (calendarid, uri, calendardata, lastmodified) VALUES (?,?,?,?)');
$stmt->execute(array($calendarId,$objectUri,$calendarData,time()));
$stmt = $this->pdo->prepare('UPDATE `'.$this->calendarTableName.'` SET ctag = ctag + 1 WHERE id = ?');
$stmt->execute(array($calendarId));
}
/**
* Updates an existing calendarobject, based on it's uri.
*
* @param string $calendarId
* @param string $objectUri
* @param string $calendarData
* @return void
*/
public function updateCalendarObject($calendarId,$objectUri,$calendarData) {
$stmt = $this->pdo->prepare('UPDATE `'.$this->calendarObjectTableName.'` SET calendardata = ?, lastmodified = ? WHERE calendarid = ? AND uri = ?');
$stmt->execute(array($calendarData,time(),$calendarId,$objectUri));
$stmt = $this->pdo->prepare('UPDATE `'.$this->calendarTableName.'` SET ctag = ctag + 1 WHERE id = ?');
$stmt->execute(array($calendarId));
}
/**
* Deletes an existing calendar object.
*
* @param string $calendarId
* @param string $objectUri
* @return void
*/
public function deleteCalendarObject($calendarId,$objectUri) {
$stmt = $this->pdo->prepare('DELETE FROM `'.$this->calendarObjectTableName.'` WHERE calendarid = ? AND uri = ?');
$stmt->execute(array($calendarId,$objectUri));
$stmt = $this->pdo->prepare('UPDATE `'. $this->calendarTableName .'` SET ctag = ctag + 1 WHERE id = ?');
$stmt->execute(array($calendarId));
}
}

318
3rdparty/Sabre/CalDAV/Calendar.php vendored Normal file
View File

@ -0,0 +1,318 @@
<?php
/**
* This object represents a CalDAV calendar.
*
* A calendar can contain multiple TODO and or Events. These are represented
* as Sabre_CalDAV_CalendarObject objects.
*
* @package Sabre
* @subpackage CalDAV
* @copyright Copyright (C) 2007-2011 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_CalDAV_Calendar implements Sabre_CalDAV_ICalendar, Sabre_DAV_IProperties, Sabre_DAVACL_IACL {
/**
* This is an array with calendar information
*
* @var array
*/
protected $calendarInfo;
/**
* CalDAV backend
*
* @var Sabre_CalDAV_Backend_Abstract
*/
protected $caldavBackend;
/**
* Principal backend
*
* @var Sabre_DAVACL_IPrincipalBackend
*/
protected $principalBackend;
/**
* Constructor
*
* @param Sabre_CalDAV_Backend_Abstract $caldavBackend
* @param array $calendarInfo
* @return void
*/
public function __construct(Sabre_DAVACL_IPrincipalBackend $principalBackend, Sabre_CalDAV_Backend_Abstract $caldavBackend, $calendarInfo) {
$this->caldavBackend = $caldavBackend;
$this->principalBackend = $principalBackend;
$this->calendarInfo = $calendarInfo;
}
/**
* Returns the name of the calendar
*
* @return string
*/
public function getName() {
return $this->calendarInfo['uri'];
}
/**
* Updates properties such as the display name and description
*
* @param array $mutations
* @return array
*/
public function updateProperties($mutations) {
return $this->caldavBackend->updateCalendar($this->calendarInfo['id'],$mutations);
}
/**
* Returns the list of properties
*
* @param array $properties
* @return array
*/
public function getProperties($requestedProperties) {
$response = array();
foreach($requestedProperties as $prop) switch($prop) {
case '{urn:ietf:params:xml:ns:caldav}supported-calendar-data' :
$response[$prop] = new Sabre_CalDAV_Property_SupportedCalendarData();
break;
case '{urn:ietf:params:xml:ns:caldav}supported-collation-set' :
$response[$prop] = new Sabre_CalDAV_Property_SupportedCollationSet();
break;
case '{DAV:}owner' :
$response[$prop] = new Sabre_DAVACL_Property_Principal(Sabre_DAVACL_Property_Principal::HREF,$this->calendarInfo['principaluri']);
break;
default :
if (isset($this->calendarInfo[$prop])) $response[$prop] = $this->calendarInfo[$prop];
break;
}
return $response;
}
/**
* Returns a calendar object
*
* The contained calendar objects are for example Events or Todo's.
*
* @param string $name
* @return Sabre_DAV_ICalendarObject
*/
public function getChild($name) {
$obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'],$name);
if (!$obj) throw new Sabre_DAV_Exception_FileNotFound('Calendar object not found');
return new Sabre_CalDAV_CalendarObject($this->caldavBackend,$this->calendarInfo,$obj);
}
/**
* Returns the full list of calendar objects
*
* @return array
*/
public function getChildren() {
$objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id']);
$children = array();
foreach($objs as $obj) {
$children[] = new Sabre_CalDAV_CalendarObject($this->caldavBackend,$this->calendarInfo,$obj);
}
return $children;
}
/**
* Checks if a child-node exists.
*
* @param string $name
* @return bool
*/
public function childExists($name) {
$obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'],$name);
if (!$obj)
return false;
else
return true;
}
/**
* Creates a new directory
*
* We actually block this, as subdirectories are not allowed in calendars.
*
* @param string $name
* @return void
*/
public function createDirectory($name) {
throw new Sabre_DAV_Exception_MethodNotAllowed('Creating collections in calendar objects is not allowed');
}
/**
* Creates a new file
*
* The contents of the new file must be a valid ICalendar string.
*
* @param string $name
* @param resource $calendarData
* @return void
*/
public function createFile($name,$calendarData = null) {
$calendarData = stream_get_contents($calendarData);
// Converting to UTF-8, if needed
$calendarData = Sabre_DAV_StringUtil::ensureUTF8($calendarData);
$supportedComponents = $this->calendarInfo['{' . Sabre_CalDAV_Plugin::NS_CALDAV . '}supported-calendar-component-set'];
if ($supportedComponents) {
$supportedComponents = $supportedComponents->getValue();
} else {
$supportedComponents = null;
}
Sabre_CalDAV_ICalendarUtil::validateICalendarObject($calendarData, $supportedComponents);
$this->caldavBackend->createCalendarObject($this->calendarInfo['id'],$name,$calendarData);
}
/**
* Deletes the calendar.
*
* @return void
*/
public function delete() {
$this->caldavBackend->deleteCalendar($this->calendarInfo['id']);
}
/**
* Renames the calendar. Note that most calendars use the
* {DAV:}displayname to display a name to display a name.
*
* @param string $newName
* @return void
*/
public function setName($newName) {
throw new Sabre_DAV_Exception_MethodNotAllowed('Renaming calendars is not yet supported');
}
/**
* Returns the last modification date as a unix timestamp.
*
* @return void
*/
public function getLastModified() {
return null;
}
/**
* Returns the owner principal
*
* This must be a url to a principal, or null if there's no owner
*
* @return string|null
*/
public function getOwner() {
return $this->calendarInfo['principaluri'];
}
/**
* Returns a group principal
*
* This must be a url to a principal, or null if there's no owner
*
* @return string|null
*/
public function getGroup() {
return null;
}
/**
* Returns a list of ACE's for this node.
*
* Each ACE has the following properties:
* * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
* currently the only supported privileges
* * 'principal', a url to the principal who owns the node
* * 'protected' (optional), indicating that this ACE is not allowed to
* be updated.
*
* @return array
*/
public function getACL() {
return array(
array(
'privilege' => '{DAV:}read',
'principal' => $this->calendarInfo['principaluri'],
'protected' => true,
),
array(
'privilege' => '{DAV:}write',
'principal' => $this->calendarInfo['principaluri'],
'protected' => true,
),
array(
'privilege' => '{DAV:}read',
'principal' => $this->calendarInfo['principaluri'] . '/calendar-proxy-write',
'protected' => true,
),
array(
'privilege' => '{DAV:}write',
'principal' => $this->calendarInfo['principaluri'] . '/calendar-proxy-write',
'protected' => true,
),
array(
'privilege' => '{DAV:}read',
'principal' => $this->calendarInfo['principaluri'] . '/calendar-proxy-read',
'protected' => true,
),
);
}
/**
* Updates the ACL
*
* This method will receive a list of new ACE's.
*
* @param array $acl
* @return void
*/
public function setACL(array $acl) {
throw new Sabre_DAV_Exception_MethodNotAllowed('Changing ACL is not yet supported');
}
}

260
3rdparty/Sabre/CalDAV/CalendarObject.php vendored Normal file
View File

@ -0,0 +1,260 @@
<?php
/**
* The CalendarObject represents a single VEVENT or VTODO within a Calendar.
*
* @package Sabre
* @subpackage CalDAV
* @copyright Copyright (C) 2007-2011 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_CalDAV_CalendarObject extends Sabre_DAV_File implements Sabre_CalDAV_ICalendarObject, Sabre_DAVACL_IACL {
/**
* Sabre_CalDAV_Backend_Abstract
*
* @var array
*/
protected $caldavBackend;
/**
* Array with information about this CalendarObject
*
* @var array
*/
protected $objectData;
/**
* Array with information about the containing calendar
*
* @var array
*/
protected $calendarInfo;
/**
* Constructor
*
* @param Sabre_CalDAV_Backend_Abstract $caldavBackend
* @param array $calendarInfo
* @param array $objectData
*/
public function __construct(Sabre_CalDAV_Backend_Abstract $caldavBackend,array $calendarInfo,array $objectData) {
$this->caldavBackend = $caldavBackend;
if (!isset($objectData['calendarid'])) {
throw new InvalidArgumentException('The objectData argument must contain a \'calendarid\' property');
}
if (!isset($objectData['uri'])) {
throw new InvalidArgumentException('The objectData argument must contain an \'uri\' property');
}
$this->calendarInfo = $calendarInfo;
$this->objectData = $objectData;
}
/**
* Returns the uri for this object
*
* @return string
*/
public function getName() {
return $this->objectData['uri'];
}
/**
* Returns the ICalendar-formatted object
*
* @return string
*/
public function get() {
// Pre-populating the 'calendardata' is optional, if we don't have it
// already we fetch it from the backend.
if (!isset($this->objectData['calendardata'])) {
$this->objectData = $this->caldavBackend->getCalendarObject($this->objectData['calendarid'], $this->objectData['uri']);
}
return $this->objectData['calendardata'];
}
/**
* Updates the ICalendar-formatted object
*
* @param string $calendarData
* @return void
*/
public function put($calendarData) {
if (is_resource($calendarData))
$calendarData = stream_get_contents($calendarData);
// Converting to UTF-8, if needed
$calendarData = Sabre_DAV_StringUtil::ensureUTF8($calendarData);
$supportedComponents = $this->calendarInfo['{' . Sabre_CalDAV_Plugin::NS_CALDAV . '}supported-calendar-component-set'];
if ($supportedComponents) {
$supportedComponents = $supportedComponents->getValue();
} else {
$supportedComponents = null;
}
Sabre_CalDAV_ICalendarUtil::validateICalendarObject($calendarData, $supportedComponents);
$this->caldavBackend->updateCalendarObject($this->calendarInfo['id'],$this->objectData['uri'],$calendarData);
$this->objectData['calendardata'] = $calendarData;
}
/**
* Deletes the calendar object
*
* @return void
*/
public function delete() {
$this->caldavBackend->deleteCalendarObject($this->calendarInfo['id'],$this->objectData['uri']);
}
/**
* Returns the mime content-type
*
* @return string
*/
public function getContentType() {
return 'text/calendar';
}
/**
* Returns an ETag for this object.
*
* The ETag is an arbritrary string, but MUST be surrounded by double-quotes.
*
* @return string
*/
public function getETag() {
if (isset($this->objectData['etag'])) {
return $this->objectData['etag'];
} else {
return '"' . md5($this->get()). '"';
}
}
/**
* Returns the last modification date as a unix timestamp
*
* @return time
*/
public function getLastModified() {
return $this->objectData['lastmodified'];
}
/**
* Returns the size of this object in bytes
*
* @return int
*/
public function getSize() {
return strlen($this->objectData['calendardata']);
}
/**
* Returns the owner principal
*
* This must be a url to a principal, or null if there's no owner
*
* @return string|null
*/
public function getOwner() {
return $this->calendarInfo['principaluri'];
}
/**
* Returns a group principal
*
* This must be a url to a principal, or null if there's no owner
*
* @return string|null
*/
public function getGroup() {
return null;
}
/**
* Returns a list of ACE's for this node.
*
* Each ACE has the following properties:
* * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
* currently the only supported privileges
* * 'principal', a url to the principal who owns the node
* * 'protected' (optional), indicating that this ACE is not allowed to
* be updated.
*
* @return array
*/
public function getACL() {
return array(
array(
'privilege' => '{DAV:}read',
'principal' => $this->calendarInfo['principaluri'],
'protected' => true,
),
array(
'privilege' => '{DAV:}write',
'principal' => $this->calendarInfo['principaluri'],
'protected' => true,
),
array(
'privilege' => '{DAV:}read',
'principal' => $this->calendarInfo['principaluri'] . '/calendar-proxy-write',
'protected' => true,
),
array(
'privilege' => '{DAV:}write',
'principal' => $this->calendarInfo['principaluri'] . '/calendar-proxy-write',
'protected' => true,
),
array(
'privilege' => '{DAV:}read',
'principal' => $this->calendarInfo['principaluri'] . '/calendar-proxy-read',
'protected' => true,
),
);
}
/**
* Updates the ACL
*
* This method will receive a list of new ACE's.
*
* @param array $acl
* @return void
*/
public function setACL(array $acl) {
throw new Sabre_DAV_Exception_MethodNotAllowed('Changing ACL is not yet supported');
}
}

View File

@ -0,0 +1,75 @@
<?php
/**
* Users collection
*
* This object is responsible for generating a collection of users.
*
* @package Sabre
* @subpackage CalDAV
* @copyright Copyright (C) 2007-2011 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_CalDAV_CalendarRootNode extends Sabre_DAVACL_AbstractPrincipalCollection {
/**
* CalDAV backend
*
* @var Sabre_CalDAV_Backend_Abstract
*/
protected $caldavBackend;
/**
* Constructor
*
* This constructor needs both an authentication and a caldav backend.
*
* By default this class will show a list of calendar collections for
* principals in the 'principals' collection. If your main principals are
* actually located in a different path, use the $principalPrefix argument
* to override this.
*
*
* @param Sabre_DAVACL_IPrincipalBackend $principalBackend
* @param Sabre_CalDAV_Backend_Abstract $caldavBackend
* @param string $principalPrefix
*/
public function __construct(Sabre_DAVACL_IPrincipalBackend $principalBackend,Sabre_CalDAV_Backend_Abstract $caldavBackend, $principalPrefix = 'principals') {
parent::__construct($principalBackend, $principalPrefix);
$this->caldavBackend = $caldavBackend;
}
/**
* Returns the nodename
*
* We're overriding this, because the default will be the 'principalPrefix',
* and we want it to be Sabre_CalDAV_Plugin::CALENDAR_ROOT
*
* @return void
*/
public function getName() {
return Sabre_CalDAV_Plugin::CALENDAR_ROOT;
}
/**
* This method returns a node for a principal.
*
* The passed array contains principal information, and is guaranteed to
* at least contain a uri item. Other properties may or may not be
* supplied by the authentication backend.
*
* @param array $principal
* @return Sabre_DAV_INode
*/
public function getChildForPrincipal(array $principal) {
return new Sabre_CalDAV_UserCalendars($this->principalBackend, $this->caldavBackend, $principal['uri']);
}
}

View File

@ -0,0 +1,18 @@
<?php
/**
* InvalidICalendarObject
*
* This exception is thrown when an attempt is made to create or update
* an invalid ICalendar object
*
* @package Sabre
* @subpackage CalDAV
* @copyright Copyright (C) 2007-2011 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_CalDAV_Exception_InvalidICalendarObject extends Sabre_DAV_Exception_PreconditionFailed {
}

View File

@ -0,0 +1,124 @@
<?php
/**
* ICS Exporter
*
* This plugin adds the ability to export entire calendars as .ics files.
* This is useful for clients that don't support CalDAV yet. They often do
* support ics files.
*
* @package Sabre
* @subpackage CalDAV
* @copyright Copyright (C) 2007-2011 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_CalDAV_ICSExportPlugin extends Sabre_DAV_ServerPlugin {
/**
* Reference to Server class
*
* @var Sabre_DAV_Server
*/
private $server;
/**
* Initializes the plugin and registers event handlers
*
* @param Sabre_DAV_Server $server
* @return void
*/
public function initialize(Sabre_DAV_Server $server) {
$this->server = $server;
$this->server->subscribeEvent('beforeMethod',array($this,'beforeMethod'), 90);
}
/**
* 'beforeMethod' event handles. This event handles intercepts GET requests ending
* with ?export
*
* @param string $method
* @param string $uri
* @return void
*/
public function beforeMethod($method, $uri) {
if ($method!='GET') return;
if ($this->server->httpRequest->getQueryString()!='export') return;
// splitting uri
list($uri) = explode('?',$uri,2);
$node = $this->server->tree->getNodeForPath($uri);
if (!($node instanceof Sabre_CalDAV_Calendar)) return;
$this->server->httpResponse->setHeader('Content-Type','text/calendar');
$this->server->httpResponse->sendStatus(200);
$this->server->httpResponse->sendBody($this->generateICS($this->server->tree->getChildren($uri)));
// Returning false to break the event chain
return false;
}
/**
* Merges all calendar objects, and builds one big ics export
*
* @param array $nodes
* @return void
*/
public function generateICS(array $nodes) {
$calendar = new Sabre_VObject_Component('vcalendar');
$calendar->version = '2.0';
$calendar->prodid = '-//SabreDAV//SabreDAV ' . Sabre_DAV_Version::VERSION . '//EN';
$calendar->calscale = 'GREGORIAN';
$collectedTimezones = array();
$timezones = array();
$objects = array();
foreach($nodes as $node) {
$nodeData = $node->get();
$nodeComp = Sabre_VObject_Reader::read($nodeData);
foreach($nodeComp->children() as $child) {
switch($child->name) {
case 'VEVENT' :
case 'VTODO' :
case 'VJOURNAL' :
$objects[] = $child;
break;
// VTIMEZONE is special, because we need to filter out the duplicates
case 'VTIMEZONE' :
// Naively just checking tzid.
if (in_array((string)$child->TZID, $collectedTimezones)) continue;
$timezones[] = $child;
$collectedTimezones[] = $child->TZID;
break;
}
}
}
foreach($timezones as $tz) $calendar->add($tz);
foreach($objects as $obj) $calendar->add($obj);
return $calendar->serialize();
}
}

18
3rdparty/Sabre/CalDAV/ICalendar.php vendored Normal file
View File

@ -0,0 +1,18 @@
<?php
/**
* Calendar interface
*
* Implement this interface to allow a node to be recognized as an calendar.
*
* @package Sabre
* @subpackage CalDAV
* @copyright Copyright (C) 2007-2011 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
interface Sabre_CalDAV_ICalendar extends Sabre_DAV_ICollection {
}

View File

@ -0,0 +1,20 @@
<?php
/**
* CalendarObject interface
/**
* Extend the ICalendarObject interface to allow your custom nodes to be picked up as
* CalendarObjects.
*
* Calendar objects are resources such as Events, Todo's or Journals.
*
* @package Sabre
* @subpackage CalDAV
* @copyright Copyright (C) 2007-2011 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
interface Sabre_CalDAV_ICalendarObject extends Sabre_DAV_IFile {
}

157
3rdparty/Sabre/CalDAV/ICalendarUtil.php vendored Normal file
View File

@ -0,0 +1,157 @@
<?php
/**
* This class contains several utilities related to the ICalendar (rfc2445) format
*
* This class is now deprecated, and won't be further maintained. Please use
* the Sabre_VObject package for your ics parsing needs.
*
* @package Sabre
* @subpackage CalDAV
* @copyright Copyright (C) 2007-2011 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
* @deprecated Use Sabre_VObject instead.
*/
class Sabre_CalDAV_ICalendarUtil {
/**
* Validates an ICalendar object
*
* This method makes sure this ICalendar object is properly formatted.
* If we can't parse it, we'll throw exceptions.
*
* @param string $icalData
* @param array $allowedComponents
* @return bool
*/
static function validateICalendarObject($icalData, array $allowedComponents = null) {
$xcal = simplexml_load_string(self::toXCal($icalData));
if (!$xcal) throw new Sabre_CalDAV_Exception_InvalidICalendarObject('Invalid calendarobject format');
$xcal->registerXPathNameSpace('cal','urn:ietf:params:xml:ns:xcal');
// Check if there's only 1 component
$components = array('vevent','vtodo','vjournal','vfreebusy');
$componentsFound = array();
foreach($components as $component) {
$test = $xcal->xpath('/cal:iCalendar/cal:vcalendar/cal:' . $component);
if (is_array($test)) $componentsFound = array_merge($componentsFound, $test);
}
if (count($componentsFound)<1) {
throw new Sabre_CalDAV_Exception_InvalidICalendarObject('One VEVENT, VTODO, VJOURNAL or VFREEBUSY must be specified. 0 found.');
}
$component = $componentsFound[0];
if (is_null($allowedComponents)) return true;
// Check if the component is allowed
$name = $component->getName();
if (!in_array(strtoupper($name),$allowedComponents)) {
throw new Sabre_CalDAV_Exception_InvalidICalendarObject(strtoupper($name) . ' is not allowed in this calendar.');
}
if (count($xcal->xpath('/cal:iCalendar/cal:vcalendar/cal:method'))>0) {
throw new Sabre_CalDAV_Exception_InvalidICalendarObject('The METHOD property is not allowed in calendar objects');
}
return true;
}
/**
* Converts ICalendar data to XML.
*
* Properties are converted to lowercase xml elements. Parameters are;
* converted to attributes. BEGIN:VEVENT is converted to <vevent> and
* END:VEVENT </vevent> as well as other components.
*
* It's a very loose parser. If any line does not conform to the spec, it
* will simply be ignored. It will try to detect if \r\n or \n line endings
* are used.
*
* @todo Currently quoted attributes are not parsed correctly.
* @see http://tools.ietf.org/html/draft-royer-calsch-xcal-03
* @param string $icalData
* @return string.
*/
static function toXCAL($icalData) {
// Detecting line endings
$lb="\r\n";
if (strpos($icalData,"\r\n")!==false) $lb = "\r\n";
elseif (strpos($icalData,"\n")!==false) $lb = "\n";
// Splitting up items per line
$lines = explode($lb,$icalData);
// Properties can be folded over 2 lines. In this case the second
// line will be preceeded by a space or tab.
$lines2 = array();
foreach($lines as $line) {
if (!$line) continue;
if ($line[0]===" " || $line[0]==="\t") {
$lines2[count($lines2)-1].=substr($line,1);
continue;
}
$lines2[]=$line;
}
$xml = '<?xml version="1.0"?>' . "\n";
$xml.= "<iCalendar xmlns=\"urn:ietf:params:xml:ns:xcal\">\n";
$spaces = 2;
foreach($lines2 as $line) {
$matches = array();
// This matches PROPERTYNAME;ATTRIBUTES:VALUE
if (!preg_match('/^([^:^;]*)(?:;([^:]*))?:(.*)$/',$line,$matches))
continue;
$propertyName = strtolower($matches[1]);
$attributes = $matches[2];
$value = $matches[3];
// If the line was in the format BEGIN:COMPONENT or END:COMPONENT, we need to special case it.
if ($propertyName === 'begin') {
$xml.=str_repeat(" ",$spaces);
$xml.='<' . strtolower($value) . ">\n";
$spaces+=2;
continue;
} elseif ($propertyName === 'end') {
$spaces-=2;
$xml.=str_repeat(" ",$spaces);
$xml.='</' . strtolower($value) . ">\n";
continue;
}
$xml.=str_repeat(" ",$spaces);
$xml.='<' . $propertyName;
if ($attributes) {
// There can be multiple attributes
$attributes = explode(';',$attributes);
foreach($attributes as $att) {
list($attName,$attValue) = explode('=',$att,2);
$attName = strtolower($attName);
if ($attName === 'language') $attName='xml:lang';
$xml.=' ' . $attName . '="' . htmlspecialchars($attValue) . '"';
}
}
$xml.='>'. htmlspecialchars(trim($value)) . '</' . $propertyName . ">\n";
}
$xml.="</iCalendar>";
return $xml;
}
}

788
3rdparty/Sabre/CalDAV/Plugin.php vendored Normal file
View File

@ -0,0 +1,788 @@
<?php
/**
* CalDAV plugin
*
* This plugin provides functionality added by CalDAV (RFC 4791)
* It implements new reports, and the MKCALENDAR method.
*
* @package Sabre
* @subpackage CalDAV
* @copyright Copyright (C) 2007-2011 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_CalDAV_Plugin extends Sabre_DAV_ServerPlugin {
/**
* This is the official CalDAV namespace
*/
const NS_CALDAV = 'urn:ietf:params:xml:ns:caldav';
/**
* This is the namespace for the proprietary calendarserver extensions
*/
const NS_CALENDARSERVER = 'http://calendarserver.org/ns/';
/**
* The following constants are used to differentiate
* the various filters for the calendar-query report
*/
const FILTER_COMPFILTER = 1;
const FILTER_TIMERANGE = 3;
const FILTER_PROPFILTER = 4;
const FILTER_PARAMFILTER = 5;
const FILTER_TEXTMATCH = 6;
/**
* The hardcoded root for calendar objects. It is unfortunate
* that we're stuck with it, but it will have to do for now
*/
const CALENDAR_ROOT = 'calendars';
/**
* Reference to server object
*
* @var Sabre_DAV_Server
*/
private $server;
/**
* Use this method to tell the server this plugin defines additional
* HTTP methods.
*
* This method is passed a uri. It should only return HTTP methods that are
* available for the specified uri.
*
* @param string $uri
* @return array
*/
public function getHTTPMethods($uri) {
// The MKCALENDAR is only available on unmapped uri's, whose
// parents extend IExtendedCollection
list($parent, $name) = Sabre_DAV_URLUtil::splitPath($uri);
$node = $this->server->tree->getNodeForPath($parent);
if ($node instanceof Sabre_DAV_IExtendedCollection) {
try {
$node->getChild($name);
} catch (Sabre_DAV_Exception_FileNotFound $e) {
return array('MKCALENDAR');
}
}
return array();
}
/**
* Returns a list of features for the DAV: HTTP header.
*
* @return array
*/
public function getFeatures() {
return array('calendar-access', 'calendar-proxy');
}
/**
* Returns a plugin name.
*
* Using this name other plugins will be able to access other plugins
* using Sabre_DAV_Server::getPlugin
*
* @return string
*/
public function getPluginName() {
return 'caldav';
}
/**
* Returns a list of reports this plugin supports.
*
* This will be used in the {DAV:}supported-report-set property.
* Note that you still need to subscribe to the 'report' event to actually
* implement them
*
* @param string $uri
* @return array
*/
public function getSupportedReportSet($uri) {
$node = $this->server->tree->getNodeForPath($uri);
if ($node instanceof Sabre_CalDAV_ICalendar || $node instanceof Sabre_CalDAV_ICalendarObject) {
return array(
'{' . self::NS_CALDAV . '}calendar-multiget',
'{' . self::NS_CALDAV . '}calendar-query',
);
}
return array();
}
/**
* Initializes the plugin
*
* @param Sabre_DAV_Server $server
* @return void
*/
public function initialize(Sabre_DAV_Server $server) {
$this->server = $server;
$server->subscribeEvent('unknownMethod',array($this,'unknownMethod'));
//$server->subscribeEvent('unknownMethod',array($this,'unknownMethod2'),1000);
$server->subscribeEvent('report',array($this,'report'));
$server->subscribeEvent('beforeGetProperties',array($this,'beforeGetProperties'));
$server->xmlNamespaces[self::NS_CALDAV] = 'cal';
$server->xmlNamespaces[self::NS_CALENDARSERVER] = 'cs';
$server->propertyMap['{' . self::NS_CALDAV . '}supported-calendar-component-set'] = 'Sabre_CalDAV_Property_SupportedCalendarComponentSet';
$server->resourceTypeMapping['Sabre_CalDAV_ICalendar'] = '{urn:ietf:params:xml:ns:caldav}calendar';
$server->resourceTypeMapping['Sabre_CalDAV_Principal_ProxyRead'] = '{http://calendarserver.org/ns/}calendar-proxy-read';
$server->resourceTypeMapping['Sabre_CalDAV_Principal_ProxyWrite'] = '{http://calendarserver.org/ns/}calendar-proxy-write';
array_push($server->protectedProperties,
'{' . self::NS_CALDAV . '}supported-calendar-component-set',
'{' . self::NS_CALDAV . '}supported-calendar-data',
'{' . self::NS_CALDAV . '}max-resource-size',
'{' . self::NS_CALDAV . '}min-date-time',
'{' . self::NS_CALDAV . '}max-date-time',
'{' . self::NS_CALDAV . '}max-instances',
'{' . self::NS_CALDAV . '}max-attendees-per-instance',
'{' . self::NS_CALDAV . '}calendar-home-set',
'{' . self::NS_CALDAV . '}supported-collation-set',
'{' . self::NS_CALDAV . '}calendar-data',
// scheduling extension
'{' . self::NS_CALDAV . '}calendar-user-address-set',
// CalendarServer extensions
'{' . self::NS_CALENDARSERVER . '}getctag',
'{' . self::NS_CALENDARSERVER . '}calendar-proxy-read-for',
'{' . self::NS_CALENDARSERVER . '}calendar-proxy-write-for'
);
}
/**
* This function handles support for the MKCALENDAR method
*
* @param string $method
* @return bool
*/
public function unknownMethod($method, $uri) {
if ($method!=='MKCALENDAR') return;
$this->httpMkCalendar($uri);
// false is returned to stop the unknownMethod event
return false;
}
/**
* This functions handles REPORT requests specific to CalDAV
*
* @param string $reportName
* @param DOMNode $dom
* @return bool
*/
public function report($reportName,$dom) {
switch($reportName) {
case '{'.self::NS_CALDAV.'}calendar-multiget' :
$this->calendarMultiGetReport($dom);
return false;
case '{'.self::NS_CALDAV.'}calendar-query' :
$this->calendarQueryReport($dom);
return false;
}
}
/**
* This function handles the MKCALENDAR HTTP method, which creates
* a new calendar.
*
* @param string $uri
* @return void
*/
public function httpMkCalendar($uri) {
// Due to unforgivable bugs in iCal, we're completely disabling MKCALENDAR support
// for clients matching iCal in the user agent
//$ua = $this->server->httpRequest->getHeader('User-Agent');
//if (strpos($ua,'iCal/')!==false) {
// throw new Sabre_DAV_Exception_Forbidden('iCal has major bugs in it\'s RFC3744 support. Therefore we are left with no other choice but disabling this feature.');
//}
$body = $this->server->httpRequest->getBody(true);
$properties = array();
if ($body) {
$dom = Sabre_DAV_XMLUtil::loadDOMDocument($body);
foreach($dom->firstChild->childNodes as $child) {
if (Sabre_DAV_XMLUtil::toClarkNotation($child)!=='{DAV:}set') continue;
foreach(Sabre_DAV_XMLUtil::parseProperties($child,$this->server->propertyMap) as $k=>$prop) {
$properties[$k] = $prop;
}
}
}
$resourceType = array('{DAV:}collection','{urn:ietf:params:xml:ns:caldav}calendar');
$this->server->createCollection($uri,$resourceType,$properties);
$this->server->httpResponse->sendStatus(201);
$this->server->httpResponse->setHeader('Content-Length',0);
}
/**
* beforeGetProperties
*
* This method handler is invoked before any after properties for a
* resource are fetched. This allows us to add in any CalDAV specific
* properties.
*
* @param string $path
* @param Sabre_DAV_INode $node
* @param array $requestedProperties
* @param array $returnedProperties
* @return void
*/
public function beforeGetProperties($path, Sabre_DAV_INode $node, &$requestedProperties, &$returnedProperties) {
if ($node instanceof Sabre_DAVACL_IPrincipal) {
// calendar-home-set property
$calHome = '{' . self::NS_CALDAV . '}calendar-home-set';
if (in_array($calHome,$requestedProperties)) {
$principalId = $node->getName();
$calendarHomePath = self::CALENDAR_ROOT . '/' . $principalId . '/';
unset($requestedProperties[$calHome]);
$returnedProperties[200][$calHome] = new Sabre_DAV_Property_Href($calendarHomePath);
}
// calendar-user-address-set property
$calProp = '{' . self::NS_CALDAV . '}calendar-user-address-set';
if (in_array($calProp,$requestedProperties)) {
$addresses = $node->getAlternateUriSet();
$addresses[] = $this->server->getBaseUri() . $node->getPrincipalUrl();
unset($requestedProperties[$calProp]);
$returnedProperties[200][$calProp] = new Sabre_DAV_Property_HrefList($addresses, false);
}
// These two properties are shortcuts for ical to easily find
// other principals this principal has access to.
$propRead = '{' . self::NS_CALENDARSERVER . '}calendar-proxy-read-for';
$propWrite = '{' . self::NS_CALENDARSERVER . '}calendar-proxy-write-for';
if (in_array($propRead,$requestedProperties) || in_array($propWrite,$requestedProperties)) {
$membership = $node->getGroupMembership();
$readList = array();
$writeList = array();
foreach($membership as $group) {
$groupNode = $this->server->tree->getNodeForPath($group);
// If the node is either ap proxy-read or proxy-write
// group, we grab the parent principal and add it to the
// list.
if ($groupNode instanceof Sabre_CalDAV_Principal_ProxyRead) {
list($readList[]) = Sabre_DAV_URLUtil::splitPath($group);
}
if ($groupNode instanceof Sabre_CalDAV_Principal_ProxyWrite) {
list($writeList[]) = Sabre_DAV_URLUtil::splitPath($group);
}
}
if (in_array($propRead,$requestedProperties)) {
unset($requestedProperties[$propRead]);
$returnedProperties[200][$propRead] = new Sabre_DAV_Property_HrefList($readList);
}
if (in_array($propWrite,$requestedProperties)) {
unset($requestedProperties[$propWrite]);
$returnedProperties[200][$propWrite] = new Sabre_DAV_Property_HrefList($writeList);
}
}
} // instanceof IPrincipal
if ($node instanceof Sabre_CalDAV_ICalendarObject) {
// The calendar-data property is not supposed to be a 'real'
// property, but in large chunks of the spec it does act as such.
// Therefore we simply expose it as a property.
$calDataProp = '{' . Sabre_CalDAV_Plugin::NS_CALDAV . '}calendar-data';
if (in_array($calDataProp, $requestedProperties)) {
unset($requestedProperties[$calDataProp]);
$val = $node->get();
if (is_resource($val))
$val = stream_get_contents($val);
// Taking out \r to not screw up the xml output
$returnedProperties[200][$calDataProp] = str_replace("\r","", $val);
}
}
}
/**
* This function handles the calendar-multiget REPORT.
*
* This report is used by the client to fetch the content of a series
* of urls. Effectively avoiding a lot of redundant requests.
*
* @param DOMNode $dom
* @return void
*/
public function calendarMultiGetReport($dom) {
$properties = array_keys(Sabre_DAV_XMLUtil::parseProperties($dom->firstChild));
$hrefElems = $dom->getElementsByTagNameNS('urn:DAV','href');
foreach($hrefElems as $elem) {
$uri = $this->server->calculateUri($elem->nodeValue);
list($objProps) = $this->server->getPropertiesForPath($uri,$properties);
$propertyList[]=$objProps;
}
$this->server->httpResponse->sendStatus(207);
$this->server->httpResponse->setHeader('Content-Type','application/xml; charset=utf-8');
$this->server->httpResponse->sendBody($this->server->generateMultiStatus($propertyList));
}
/**
* This function handles the calendar-query REPORT
*
* This report is used by clients to request calendar objects based on
* complex conditions.
*
* @param DOMNode $dom
* @return void
*/
public function calendarQueryReport($dom) {
$requestedProperties = array_keys(Sabre_DAV_XMLUtil::parseProperties($dom->firstChild));
$filterNode = $dom->getElementsByTagNameNS('urn:ietf:params:xml:ns:caldav','filter');
if ($filterNode->length!==1) {
throw new Sabre_DAV_Exception_BadRequest('The calendar-query report must have a filter element');
}
$filters = Sabre_CalDAV_XMLUtil::parseCalendarQueryFilters($filterNode->item(0));
$requestedCalendarData = true;
if (!in_array('{urn:ietf:params:xml:ns:caldav}calendar-data', $requestedProperties)) {
// We always retrieve calendar-data, as we need it for filtering.
$requestedProperties[] = '{urn:ietf:params:xml:ns:caldav}calendar-data';
// If calendar-data wasn't explicitly requested, we need to remove
// it after processing.
$requestedCalendarData = false;
}
// These are the list of nodes that potentially match the requirement
$candidateNodes = $this->server->getPropertiesForPath($this->server->getRequestUri(),$requestedProperties,$this->server->getHTTPDepth(0));
$verifiedNodes = array();
foreach($candidateNodes as $node) {
// If the node didn't have a calendar-data property, it must not be a calendar object
if (!isset($node[200]['{urn:ietf:params:xml:ns:caldav}calendar-data'])) continue;
if ($this->validateFilters($node[200]['{urn:ietf:params:xml:ns:caldav}calendar-data'],$filters)) {
if (!$requestedCalendarData) {
unset($node[200]['{urn:ietf:params:xml:ns:caldav}calendar-data']);
}
$verifiedNodes[] = $node;
}
}
$this->server->httpResponse->sendStatus(207);
$this->server->httpResponse->setHeader('Content-Type','application/xml; charset=utf-8');
$this->server->httpResponse->sendBody($this->server->generateMultiStatus($verifiedNodes));
}
/**
* Verify if a list of filters applies to the calendar data object
*
* The calendarData object must be a valid iCalendar blob. The list of
* filters must be formatted as parsed by Sabre_CalDAV_Plugin::parseCalendarQueryFilters
*
* @param string $calendarData
* @param array $filters
* @return bool
*/
public function validateFilters($calendarData,$filters) {
// We are converting the calendar object to an XML structure
// This makes it far easier to parse
$xCalendarData = Sabre_CalDAV_ICalendarUtil::toXCal($calendarData);
$xml = simplexml_load_string($xCalendarData);
$xml->registerXPathNamespace('c','urn:ietf:params:xml:ns:xcal');
foreach($filters as $xpath=>$filter) {
// if-not-defined comes first
if (isset($filter['is-not-defined'])) {
if (!$xml->xpath($xpath))
continue;
else
return false;
}
$elem = $xml->xpath($xpath);
if (!$elem) return false;
$elem = $elem[0];
if (isset($filter['time-range'])) {
switch($elem->getName()) {
case 'vevent' :
$result = $this->validateTimeRangeFilterForEvent($xml,$xpath,$filter);
if ($result===false) return false;
break;
case 'vtodo' :
$result = $this->validateTimeRangeFilterForTodo($xml,$xpath,$filter);
if ($result===false) return false;
break;
case 'vjournal' :
case 'vfreebusy' :
case 'valarm' :
// TODO: not implemented
break;
/*
case 'vjournal' :
$result = $this->validateTimeRangeFilterForJournal($xml,$xpath,$filter);
if ($result===false) return false;
break;
case 'vfreebusy' :
$result = $this->validateTimeRangeFilterForFreeBusy($xml,$xpath,$filter);
if ($result===false) return false;
break;
case 'valarm' :
$result = $this->validateTimeRangeFilterForAlarm($xml,$xpath,$filter);
if ($result===false) return false;
break;
*/
}
}
if (isset($filter['text-match'])) {
$currentString = (string)$elem;
$isMatching = Sabre_DAV_StringUtil::textMatch($currentString, $filter['text-match']['value'], $filter['text-match']['collation']);
if ($filter['text-match']['negate-condition'] && $isMatching) return false;
if (!$filter['text-match']['negate-condition'] && !$isMatching) return false;
}
}
return true;
}
/**
* Checks whether a time-range filter matches an event.
*
* @param SimpleXMLElement $xml Event as xml object
* @param string $currentXPath XPath to check
* @param array $currentFilter Filter information
* @return void
*/
private function validateTimeRangeFilterForEvent(SimpleXMLElement $xml,$currentXPath,array $currentFilter) {
// Grabbing the DTSTART property
$xdtstart = $xml->xpath($currentXPath.'/c:dtstart');
if (!count($xdtstart)) {
throw new Sabre_DAV_Exception_BadRequest('DTSTART property missing from calendar object');
}
// The dtstart can be both a date, or datetime property
if ((string)$xdtstart[0]['value']==='DATE' || strlen((string)$xdtstart[0])===8) {
$isDateTime = false;
} else {
$isDateTime = true;
}
// Determining the timezone
if ($tzid = (string)$xdtstart[0]['tzid']) {
$tz = new DateTimeZone($tzid);
} else {
$tz = null;
}
if ($isDateTime) {
$dtstart = Sabre_CalDAV_XMLUtil::parseICalendarDateTime((string)$xdtstart[0],$tz);
} else {
$dtstart = Sabre_CalDAV_XMLUtil::parseICalendarDate((string)$xdtstart[0]);
}
// Grabbing the DTEND property
$xdtend = $xml->xpath($currentXPath.'/c:dtend');
$dtend = null;
if (count($xdtend)) {
// Determining the timezone
if ($tzid = (string)$xdtend[0]['tzid']) {
$tz = new DateTimeZone($tzid);
} else {
$tz = null;
}
// Since the VALUE prameter of both DTSTART and DTEND must be the same
// we can assume we don't need to check the VALUE paramter of DTEND.
if ($isDateTime) {
$dtend = Sabre_CalDAV_XMLUtil::parseICalendarDateTime((string)$xdtend[0],$tz);
} else {
$dtend = Sabre_CalDAV_XMLUtil::parseICalendarDate((string)$xdtend[0],$tz);
}
}
if (is_null($dtend)) {
// The DTEND property was not found. We will first see if the event has a duration
// property
$xduration = $xml->xpath($currentXPath.'/c:duration');
if (count($xduration)) {
$duration = Sabre_CalDAV_XMLUtil::parseICalendarDuration((string)$xduration[0]);
// Making sure that the duration is bigger than 0 seconds.
$tempDT = clone $dtstart;
$tempDT->modify($duration);
if ($tempDT > $dtstart) {
// use DTEND = DTSTART + DURATION
$dtend = $tempDT;
} else {
// use DTEND = DTSTART
$dtend = $dtstart;
}
}
}
if (is_null($dtend)) {
if ($isDateTime) {
// DTEND = DTSTART
$dtend = $dtstart;
} else {
// DTEND = DTSTART + 1 DAY
$dtend = clone $dtstart;
$dtend->modify('+1 day');
}
}
// TODO: we need to properly parse RRULE's, but it's very difficult.
// For now, we're always returning events if they have an RRULE at all.
$rrule = $xml->xpath($currentXPath.'/c:rrule');
$hasRrule = (count($rrule))>0;
if (!is_null($currentFilter['time-range']['start']) && $currentFilter['time-range']['start'] >= $dtend) return false;
if (!is_null($currentFilter['time-range']['end']) && $currentFilter['time-range']['end'] <= $dtstart && !$hasRrule) return false;
return true;
}
private function validateTimeRangeFilterForTodo(SimpleXMLElement $xml,$currentXPath,array $filter) {
// Gathering all relevant elements
$dtStart = null;
$duration = null;
$due = null;
$completed = null;
$created = null;
$xdt = $xml->xpath($currentXPath.'/c:dtstart');
if (count($xdt)) {
// The dtstart can be both a date, or datetime property
if ((string)$xdt[0]['value']==='DATE') {
$isDateTime = false;
} else {
$isDateTime = true;
}
// Determining the timezone
if ($tzid = (string)$xdt[0]['tzid']) {
$tz = new DateTimeZone($tzid);
} else {
$tz = null;
}
if ($isDateTime) {
$dtStart = Sabre_CalDAV_XMLUtil::parseICalendarDateTime((string)$xdt[0],$tz);
} else {
$dtStart = Sabre_CalDAV_XMLUtil::parseICalendarDate((string)$xdt[0]);
}
}
// Only need to grab duration if dtStart is set
if (!is_null($dtStart)) {
$xduration = $xml->xpath($currentXPath.'/c:duration');
if (count($xduration)) {
$duration = Sabre_CalDAV_XMLUtil::parseICalendarDuration((string)$xduration[0]);
}
}
if (!is_null($dtStart) && !is_null($duration)) {
// Comparision from RFC 4791:
// (start <= DTSTART+DURATION) AND ((end > DTSTART) OR (end >= DTSTART+DURATION))
$end = clone $dtStart;
$end->modify($duration);
if( (is_null($filter['time-range']['start']) || $filter['time-range']['start'] <= $end) &&
(is_null($filter['time-range']['end']) || $filter['time-range']['end'] > $dtStart || $filter['time-range']['end'] >= $end) ) {
return true;
} else {
return false;
}
}
// Need to grab the DUE property
$xdt = $xml->xpath($currentXPath.'/c:due');
if (count($xdt)) {
// The due property can be both a date, or datetime property
if ((string)$xdt[0]['value']==='DATE') {
$isDateTime = false;
} else {
$isDateTime = true;
}
// Determining the timezone
if ($tzid = (string)$xdt[0]['tzid']) {
$tz = new DateTimeZone($tzid);
} else {
$tz = null;
}
if ($isDateTime) {
$due = Sabre_CalDAV_XMLUtil::parseICalendarDateTime((string)$xdt[0],$tz);
} else {
$due = Sabre_CalDAV_XMLUtil::parseICalendarDate((string)$xdt[0]);
}
}
if (!is_null($dtStart) && !is_null($due)) {
// Comparision from RFC 4791:
// ((start < DUE) OR (start <= DTSTART)) AND ((end > DTSTART) OR (end >= DUE))
if( (is_null($filter['time-range']['start']) || $filter['time-range']['start'] < $due || $filter['time-range']['start'] < $dtstart) &&
(is_null($filter['time-range']['end']) || $filter['time-range']['end'] >= $due) ) {
return true;
} else {
return false;
}
}
if (!is_null($dtStart)) {
// Comparision from RFC 4791
// (start <= DTSTART) AND (end > DTSTART)
if ( (is_null($filter['time-range']['start']) || $filter['time-range']['start'] <= $dtStart) &&
(is_null($filter['time-range']['end']) || $filter['time-range']['end'] > $dtStart) ) {
return true;
} else {
return false;
}
}
if (!is_null($due)) {
// Comparison from RFC 4791
// (start < DUE) AND (end >= DUE)
if ( (is_null($filter['time-range']['start']) || $filter['time-range']['start'] < $due) &&
(is_null($filter['time-range']['end']) || $filter['time-range']['end'] >= $due) ) {
return true;
} else {
return false;
}
}
// Need to grab the COMPLETED property
$xdt = $xml->xpath($currentXPath.'/c:completed');
if (count($xdt)) {
$completed = Sabre_CalDAV_XMLUtil::parseICalendarDateTime((string)$xdt[0]);
}
// Need to grab the CREATED property
$xdt = $xml->xpath($currentXPath.'/c:created');
if (count($xdt)) {
$created = Sabre_CalDAV_XMLUtil::parseICalendarDateTime((string)$xdt[0]);
}
if (!is_null($completed) && !is_null($created)) {
// Comparison from RFC 4791
// ((start <= CREATED) OR (start <= COMPLETED)) AND ((end >= CREATED) OR (end >= COMPLETED))
if( (is_null($filter['time-range']['start']) || $filter['time-range']['start'] <= $created || $filter['time-range']['start'] <= $completed) &&
(is_null($filter['time-range']['end']) || $filter['time-range']['end'] >= $created || $filter['time-range']['end'] >= $completed)) {
return true;
} else {
return false;
}
}
if (!is_null($completed)) {
// Comparison from RFC 4791
// (start <= COMPLETED) AND (end >= COMPLETED)
if( (is_null($filter['time-range']['start']) || $filter['time-range']['start'] <= $completed) &&
(is_null($filter['time-range']['end']) || $filter['time-range']['end'] >= $completed)) {
return true;
} else {
return false;
}
}
if (!is_null($created)) {
// Comparison from RFC 4791
// (end > CREATED)
if( (is_null($filter['time-range']['end']) || $filter['time-range']['end'] > $created) ) {
return true;
} else {
return false;
}
}
// Everything else is TRUE
return true;
}
}

View File

@ -0,0 +1,31 @@
<?php
/**
* Principal collection
*
* This is an alternative collection to the standard ACL principal collection.
* This collection adds support for the calendar-proxy-read and
* calendar-proxy-write sub-principals, as defined by the caldav-proxy
* specification.
*
* @package Sabre
* @subpackage CalDAV
* @copyright Copyright (C) 2007-2011 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_CalDAV_Principal_Collection extends Sabre_DAVACL_AbstractPrincipalCollection {
/**
* Returns a child object based on principal information
*
* @param array $principalInfo
* @return Sabre_CalDAV_Principal_User
*/
public function getChildForPrincipal(array $principalInfo) {
return new Sabre_CalDAV_Principal_User($this->principalBackend, $principalInfo);
}
}

View File

@ -0,0 +1,178 @@
<?php
/**
* ProxyRead principal
*
* This class represents a principal group, hosted under the main principal.
* This is needed to implement 'Calendar delegation' support. This class is
* instantiated by Sabre_CalDAV_Principal_User.
*
* @package Sabre
* @subpackage CalDAV
* @copyright Copyright (C) 2007-2011 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_CalDAV_Principal_ProxyRead implements Sabre_DAVACL_IPrincipal {
/**
* Principal information from the parent principal.
*
* @var array
*/
protected $principalInfo;
/**
* Principal backend
*
* @var Sabre_DAVACL_IPrincipalBackend
*/
protected $principalBackend;
/**
* Creates the object.
*
* Note that you MUST supply the parent principal information.
*
* @param Sabre_DAVACL_IPrincipalBackend $principalBackend
* @param array $principalInfo
*/
public function __construct(Sabre_DAVACL_IPrincipalBackend $principalBackend, array $principalInfo) {
$this->principalInfo = $principalInfo;
$this->principalBackend = $principalBackend;
}
/**
* Returns this principals name.
*
* @return string
*/
public function getName() {
return 'calendar-proxy-read';
}
/**
* Returns the last modification time
*
* @return null
*/
public function getLastModified() {
return null;
}
/**
* Deletes the current node
*
* @throws Sabre_DAV_Exception_Forbidden
* @return void
*/
public function delete() {
throw new Sabre_DAV_Exception_Forbidden('Permission denied to delete node');
}
/**
* Renames the node
*
* @throws Sabre_DAV_Exception_Forbidden
* @param string $name The new name
* @return void
*/
public function setName($name) {
throw new Sabre_DAV_Exception_Forbidden('Permission denied to rename file');
}
/**
* Returns a list of altenative urls for a principal
*
* This can for example be an email address, or ldap url.
*
* @return array
*/
public function getAlternateUriSet() {
return array();
}
/**
* Returns the full principal url
*
* @return string
*/
public function getPrincipalUrl() {
return $this->principalInfo['uri'] . '/' . $this->getName();
}
/**
* Returns the list of group members
*
* If this principal is a group, this function should return
* all member principal uri's for the group.
*
* @return array
*/
public function getGroupMemberSet() {
return $this->principalBackend->getGroupMemberSet($this->getPrincipalUrl());
}
/**
* Returns the list of groups this principal is member of
*
* If this principal is a member of a (list of) groups, this function
* should return a list of principal uri's for it's members.
*
* @return array
*/
public function getGroupMembership() {
return $this->principalBackend->getGroupMembership($this->getPrincipalUrl());
}
/**
* Sets a list of group members
*
* If this principal is a group, this method sets all the group members.
* The list of members is always overwritten, never appended to.
*
* This method should throw an exception if the members could not be set.
*
* @param array $principals
* @return void
*/
public function setGroupMemberSet(array $principals) {
$this->principalBackend->setGroupMemberSet($this->getPrincipalUrl(), $principals);
}
/**
* Returns the displayname
*
* This should be a human readable name for the principal.
* If none is available, return the nodename.
*
* @return string
*/
public function getDisplayName() {
return $this->getName();
}
}

View File

@ -0,0 +1,178 @@
<?php
/**
* ProxyWrite principal
*
* This class represents a principal group, hosted under the main principal.
* This is needed to implement 'Calendar delegation' support. This class is
* instantiated by Sabre_CalDAV_Principal_User.
*
* @package Sabre
* @subpackage CalDAV
* @copyright Copyright (C) 2007-2011 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_CalDAV_Principal_ProxyWrite implements Sabre_DAVACL_IPrincipal {
/**
* Parent principal information
*
* @var array
*/
protected $principalInfo;
/**
* Principal Backend
*
* @var Sabre_DAVACL_IPrincipalBackend
*/
protected $principalBackend;
/**
* Creates the object
*
* Note that you MUST supply the parent principal information.
*
* @param Sabre_DAVACL_IPrincipalBackend $principalBackend
* @param array $principalInfo
*/
public function __construct(Sabre_DAVACL_IPrincipalBackend $principalBackend, array $principalInfo) {
$this->principalInfo = $principalInfo;
$this->principalBackend = $principalBackend;
}
/**
* Returns this principals name.
*
* @return string
*/
public function getName() {
return 'calendar-proxy-write';
}
/**
* Returns the last modification time
*
* @return null
*/
public function getLastModified() {
return null;
}
/**
* Deletes the current node
*
* @throws Sabre_DAV_Exception_Forbidden
* @return void
*/
public function delete() {
throw new Sabre_DAV_Exception_Forbidden('Permission denied to delete node');
}
/**
* Renames the node
*
* @throws Sabre_DAV_Exception_Forbidden
* @param string $name The new name
* @return void
*/
public function setName($name) {
throw new Sabre_DAV_Exception_Forbidden('Permission denied to rename file');
}
/**
* Returns a list of altenative urls for a principal
*
* This can for example be an email address, or ldap url.
*
* @return array
*/
public function getAlternateUriSet() {
return array();
}
/**
* Returns the full principal url
*
* @return string
*/
public function getPrincipalUrl() {
return $this->principalInfo['uri'] . '/' . $this->getName();
}
/**
* Returns the list of group members
*
* If this principal is a group, this function should return
* all member principal uri's for the group.
*
* @return array
*/
public function getGroupMemberSet() {
return $this->principalBackend->getGroupMemberSet($this->getPrincipalUrl());
}
/**
* Returns the list of groups this principal is member of
*
* If this principal is a member of a (list of) groups, this function
* should return a list of principal uri's for it's members.
*
* @return array
*/
public function getGroupMembership() {
return $this->principalBackend->getGroupMembership($this->getPrincipalUrl());
}
/**
* Sets a list of group members
*
* If this principal is a group, this method sets all the group members.
* The list of members is always overwritten, never appended to.
*
* This method should throw an exception if the members could not be set.
*
* @param array $principals
* @return void
*/
public function setGroupMemberSet(array $principals) {
$this->principalBackend->setGroupMemberSet($this->getPrincipalUrl(), $principals);
}
/**
* Returns the displayname
*
* This should be a human readable name for the principal.
* If none is available, return the nodename.
*
* @return string
*/
public function getDisplayName() {
return $this->getName();
}
}

122
3rdparty/Sabre/CalDAV/Principal/User.php vendored Normal file
View File

@ -0,0 +1,122 @@
<?php
/**
* CalDAV principal
*
* This is a standard user-principal for CalDAV. This principal is also a
* collection and returns the caldav-proxy-read and caldav-proxy-write child
* principals.
*
* @package Sabre
* @subpackage CalDAV
* @copyright Copyright (C) 2007-2011 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_CalDAV_Principal_User extends Sabre_DAVACL_Principal implements Sabre_DAV_ICollection {
/**
* Creates a new file in the directory
*
* @param string $name Name of the file
* @param resource $data Initial payload, passed as a readable stream resource.
* @throws Sabre_DAV_Exception_Forbidden
* @return void
*/
public function createFile($name, $data = null) {
throw new Sabre_DAV_Exception_Forbidden('Permission denied to create file (filename ' . $name . ')');
}
/**
* Creates a new subdirectory
*
* @param string $name
* @throws Sabre_DAV_Exception_Forbidden
* @return void
*/
public function createDirectory($name) {
throw new Sabre_DAV_Exception_Forbidden('Permission denied to create directory');
}
/**
* Returns a specific child node, referenced by its name
*
* @param string $name
* @return Sabre_DAV_INode
*/
public function getChild($name) {
if ($name === 'calendar-proxy-read')
return new Sabre_CalDAV_Principal_ProxyRead($this->principalBackend, $this->principalProperties);
if ($name === 'calendar-proxy-write')
return new Sabre_CalDAV_Principal_ProxyWrite($this->principalBackend, $this->principalProperties);
throw new Sabre_DAV_Exception_FileNotFound('Node with name ' . $name . ' was not found');
}
/**
* Returns an array with all the child nodes
*
* @return Sabre_DAV_INode[]
*/
public function getChildren() {
return array(
new Sabre_CalDAV_Principal_ProxyRead($this->principalBackend, $this->principalProperties),
new Sabre_CalDAV_Principal_ProxyWrite($this->principalBackend, $this->principalProperties),
);
}
/**
* Checks if a child-node with the specified name exists
*
* @return bool
*/
public function childExists($name) {
return $name === 'calendar-proxy-read' || $name === 'calendar-proxy-write';
}
/**
* Returns a list of ACE's for this node.
*
* Each ACE has the following properties:
* * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
* currently the only supported privileges
* * 'principal', a url to the principal who owns the node
* * 'protected' (optional), indicating that this ACE is not allowed to
* be updated.
*
* @return array
*/
public function getACL() {
return array(
array(
'privilege' => '{DAV:}read',
'principal' => $this->principalProperties['uri'],
'protected' => true,
),
array(
'privilege' => '{DAV:}read',
'principal' => $this->principalProperties['uri'] . '/calendar-proxy-read',
'protected' => true,
),
array(
'privilege' => '{DAV:}read',
'principal' => $this->principalProperties['uri'] . '/calendar-proxy-write',
'protected' => true,
),
);
}
}

View File

@ -0,0 +1,85 @@
<?php
/**
* Supported component set property
*
* This property is a representation of the supported-calendar_component-set
* property in the CalDAV namespace. It simply requires an array of components,
* such as VEVENT, VTODO
*
* @package Sabre
* @subpackage CalDAV
* @copyright Copyright (C) 2007-2011 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_CalDAV_Property_SupportedCalendarComponentSet extends Sabre_DAV_Property {
/**
* List of supported components, such as "VEVENT, VTODO"
*
* @var array
*/
private $components;
/**
* Creates the property
*
* @param array $components
*/
public function __construct(array $components) {
$this->components = $components;
}
/**
* Returns the list of supported components
*
* @return array
*/
public function getValue() {
return $this->components;
}
/**
* Serializes the property in a DOMDocument
*
* @param Sabre_DAV_Server $server
* @param DOMElement $node
* @return void
*/
public function serialize(Sabre_DAV_Server $server,DOMElement $node) {
$doc = $node->ownerDocument;
foreach($this->components as $component) {
$xcomp = $doc->createElement('cal:comp');
$xcomp->setAttribute('name',$component);
$node->appendChild($xcomp);
}
}
/**
* Unserializes the DOMElement back into a Property class.
*
* @param DOMElement $node
* @return void
*/
static function unserialize(DOMElement $node) {
$components = array();
foreach($node->childNodes as $childNode) {
if (Sabre_DAV_XMLUtil::toClarkNotation($childNode)==='{' . Sabre_CalDAV_Plugin::NS_CALDAV . '}comp') {
$components[] = $childNode->getAttribute('name');
}
}
return new self($components);
}
}

View File

@ -0,0 +1,38 @@
<?php
/**
* Supported-calendar-data property
*
* This property is a representation of the supported-calendar-data property
* in the CalDAV namespace. SabreDAV only has support for text/calendar;2.0
* so the value is currently hardcoded.
*
* @package Sabre
* @subpackage CalDAV
* @copyright Copyright (C) 2007-2011 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_CalDAV_Property_SupportedCalendarData extends Sabre_DAV_Property {
/**
* Serializes the property in a DOMDocument
*
* @param Sabre_DAV_Server $server
* @param DOMElement $node
* @return void
*/
public function serialize(Sabre_DAV_Server $server,DOMElement $node) {
$doc = $node->ownerDocument;
$prefix = isset($server->xmlNamespaces[Sabre_CalDAV_Plugin::NS_CALDAV])?$server->xmlNamespaces[Sabre_CalDAV_Plugin::NS_CALDAV]:'cal';
$caldata = $doc->createElement($prefix . ':calendar-data');
$caldata->setAttribute('content-type','text/calendar');
$caldata->setAttribute('version','2.0');
$node->appendChild($caldata);
}
}

View File

@ -0,0 +1,44 @@
<?php
/**
* supported-collation-set property
*
* This property is a representation of the supported-collation-set property
* in the CalDAV namespace.
*
* @package Sabre
* @subpackage CalDAV
* @copyright Copyright (C) 2007-2011 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_CalDAV_Property_SupportedCollationSet extends Sabre_DAV_Property {
/**
* Serializes the property in a DOM document
*
* @param Sabre_DAV_Server $server
* @param DOMElement $node
* @return void
*/
public function serialize(Sabre_DAV_Server $server,DOMElement $node) {
$doc = $node->ownerDocument;
$prefix = $node->lookupPrefix('urn:ietf:params:xml:ns:caldav');
if (!$prefix) $prefix = 'cal';
$node->appendChild(
$doc->createElement($prefix . ':supported-collation','i;ascii-casemap')
);
$node->appendChild(
$doc->createElement($prefix . ':supported-collation','i;octet')
);
$node->appendChild(
$doc->createElement($prefix . ':supported-collation','i;unicode-casemap')
);
}
}

65
3rdparty/Sabre/CalDAV/Server.php vendored Normal file
View File

@ -0,0 +1,65 @@
<?php
/**
* CalDAV server
*
* This script is a convenience script. It quickly sets up a WebDAV server
* with caldav and ACL support, and it creates the root 'principals' and
* 'calendars' collections.
*
* Note that if you plan to do anything moderately complex, you are advised to
* not subclass this server, but use Sabre_DAV_Server directly instead. This
* class is nothing more than an 'easy setup'.
*
* @package Sabre
* @subpackage CalDAV
* @copyright Copyright (C) 2007-2011 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_CalDAV_Server extends Sabre_DAV_Server {
/**
* The authentication realm
*
* Note that if this changes, the hashes in the auth backend must also
* be recalculated.
*
* @var string
*/
public $authRealm = 'SabreDAV';
/**
* Sets up the object. A PDO object must be passed to setup all the backends.
*
* @param PDO $pdo
*/
public function __construct(PDO $pdo) {
/* Backends */
$authBackend = new Sabre_DAV_Auth_Backend_PDO($pdo);
$calendarBackend = new Sabre_CalDAV_Backend_PDO($pdo);
$principalBackend = new Sabre_DAVACL_PrincipalBackend_PDO($pdo);
/* Directory structure */
$tree = array(
new Sabre_CalDAV_Principal_Collection($principalBackend),
new Sabre_CalDAV_CalendarRootNode($principalBackend, $calendarBackend),
);
/* Initializing server */
parent::__construct($tree);
/* Server Plugins */
$authPlugin = new Sabre_DAV_Auth_Plugin($authBackend,$this->authRealm);
$this->addPlugin($authPlugin);
$aclPlugin = new Sabre_DAVACL_Plugin();
$this->addPlugin($aclPlugin);
$caldavPlugin = new Sabre_CalDAV_Plugin();
$this->addPlugin($caldavPlugin);
}
}

280
3rdparty/Sabre/CalDAV/UserCalendars.php vendored Normal file
View File

@ -0,0 +1,280 @@
<?php
/**
* The UserCalenders class contains all calendars associated to one user
*
* @package Sabre
* @subpackage CalDAV
* @copyright Copyright (C) 2007-2011 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_CalDAV_UserCalendars implements Sabre_DAV_IExtendedCollection, Sabre_DAVACL_IACL {
/**
* Principal backend
*
* @var Sabre_DAVACL_IPrincipalBackend
*/
protected $principalBackend;
/**
* CalDAV backend
*
* @var Sabre_CalDAV_Backend_Abstract
*/
protected $caldavBackend;
/**
* Principal information
*
* @var array
*/
protected $principalInfo;
/**
* Constructor
*
* @param Sabre_DAVACL_IPrincipalBackend $principalBackend
* @param Sabre_CalDAV_Backend_Abstract $caldavBackend
* @param mixed $userUri
*/
public function __construct(Sabre_DAVACL_IPrincipalBackend $principalBackend, Sabre_CalDAV_Backend_Abstract $caldavBackend, $userUri) {
$this->principalBackend = $principalBackend;
$this->caldavBackend = $caldavBackend;
$this->principalInfo = $principalBackend->getPrincipalByPath($userUri);
}
/**
* Returns the name of this object
*
* @return string
*/
public function getName() {
list(,$name) = Sabre_DAV_URLUtil::splitPath($this->principalInfo['uri']);
return $name;
}
/**
* Updates the name of this object
*
* @param string $name
* @return void
*/
public function setName($name) {
throw new Sabre_DAV_Exception_Forbidden();
}
/**
* Deletes this object
*
* @return void
*/
public function delete() {
throw new Sabre_DAV_Exception_Forbidden();
}
/**
* Returns the last modification date
*
* @return int
*/
public function getLastModified() {
return null;
}
/**
* Creates a new file under this object.
*
* This is currently not allowed
*
* @param string $filename
* @param resource $data
* @return void
*/
public function createFile($filename, $data=null) {
throw new Sabre_DAV_Exception_MethodNotAllowed('Creating new files in this collection is not supported');
}
/**
* Creates a new directory under this object.
*
* This is currently not allowed.
*
* @param string $filename
* @return void
*/
public function createDirectory($filename) {
throw new Sabre_DAV_Exception_MethodNotAllowed('Creating new collections in this collection is not supported');
}
/**
* Returns a single calendar, by name
*
* @param string $name
* @todo needs optimizing
* @return Sabre_CalDAV_Calendar
*/
public function getChild($name) {
foreach($this->getChildren() as $child) {
if ($name==$child->getName())
return $child;
}
throw new Sabre_DAV_Exception_FileNotFound('Calendar with name \'' . $name . '\' could not be found');
}
/**
* Checks if a calendar exists.
*
* @param string $name
* @todo needs optimizing
* @return bool
*/
public function childExists($name) {
foreach($this->getChildren() as $child) {
if ($name==$child->getName())
return true;
}
return false;
}
/**
* Returns a list of calendars
*
* @return array
*/
public function getChildren() {
$calendars = $this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']);
$objs = array();
foreach($calendars as $calendar) {
$objs[] = new Sabre_CalDAV_Calendar($this->principalBackend, $this->caldavBackend, $calendar);
}
return $objs;
}
/**
* Creates a new calendar
*
* @param string $name
* @param string $properties
* @return void
*/
public function createExtendedCollection($name, array $resourceType, array $properties) {
if (!in_array('{urn:ietf:params:xml:ns:caldav}calendar',$resourceType) || count($resourceType)!==2) {
throw new Sabre_DAV_Exception_InvalidResourceType('Unknown resourceType for this collection');
}
$this->caldavBackend->createCalendar($this->principalInfo['uri'], $name, $properties);
}
/**
* Returns the owner principal
*
* This must be a url to a principal, or null if there's no owner
*
* @return string|null
*/
public function getOwner() {
return $this->principalInfo['uri'];
}
/**
* Returns a group principal
*
* This must be a url to a principal, or null if there's no owner
*
* @return string|null
*/
public function getGroup() {
return null;
}
/**
* Returns a list of ACE's for this node.
*
* Each ACE has the following properties:
* * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
* currently the only supported privileges
* * 'principal', a url to the principal who owns the node
* * 'protected' (optional), indicating that this ACE is not allowed to
* be updated.
*
* @return array
*/
public function getACL() {
return array(
array(
'privilege' => '{DAV:}read',
'principal' => $this->principalInfo['uri'],
'protected' => true,
),
array(
'privilege' => '{DAV:}write',
'principal' => $this->principalInfo['uri'],
'protected' => true,
),
array(
'privilege' => '{DAV:}read',
'principal' => $this->principalInfo['uri'] . '/calendar-proxy-write',
'protected' => true,
),
array(
'privilege' => '{DAV:}write',
'principal' => $this->principalInfo['uri'] . '/calendar-proxy-write',
'protected' => true,
),
array(
'privilege' => '{DAV:}read',
'principal' => $this->principalInfo['uri'] . '/calendar-proxy-read',
'protected' => true,
),
);
}
/**
* Updates the ACL
*
* This method will receive a list of new ACE's.
*
* @param array $acl
* @return void
*/
public function setACL(array $acl) {
throw new Sabre_DAV_Exception_MethodNotAllowed('Changing ACL is not yet supported');
}
}

24
3rdparty/Sabre/CalDAV/Version.php vendored Normal file
View File

@ -0,0 +1,24 @@
<?php
/**
* This class contains the Sabre_CalDAV version constants.
*
* @package Sabre
* @subpackage CalDAV
* @copyright Copyright (C) 2007-2011 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_CalDAV_Version {
/**
* Full version number
*/
const VERSION = '1.5.3';
/**
* Stability : alpha, beta, stable
*/
const STABILITY = 'stable';
}

208
3rdparty/Sabre/CalDAV/XMLUtil.php vendored Normal file
View File

@ -0,0 +1,208 @@
<?php
/**
* XML utilities for CalDAV
*
* This class contains a few static methods used for parsing certain CalDAV
* requests.
*
* @package Sabre
* @subpackage CalDAV
* @copyright Copyright (C) 2007-2011 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_CalDAV_XMLUtil {
/**
* This function parses the calendar-query report request body
*
* The body is quite complicated, so we're turning it into a PHP
* array.
*
* The resulting associative array has xpath expressions as keys.
* By default the xpath expressions should simply be checked for existance
* The xpath expressions can point to elements or attributes.
*
* The array values can contain a number of items, which alters the query
* filter.
*
* * time-range. Must also check if the todo or event falls within the
* specified timerange. How this is interpreted depends on
* the type of object (VTODO, VEVENT, VJOURNAL, etc)
* * is-not-defined
* Instead of checking if the attribute or element exist,
* we must check if it doesn't.
* * text-match
* Checks if the value of the attribute or element matches
* the specified value. This is actually another array with
* the 'collation', 'value' and 'negate-condition' items.
*
* Refer to the CalDAV spec for more information.
*
* @param DOMNode $domNode
* @param string $basePath used for recursive calls.
* @param array $filters used for recursive calls.
* @return array
*/
static public function parseCalendarQueryFilters($domNode,$basePath = '/c:iCalendar', &$filters = array()) {
foreach($domNode->childNodes as $child) {
switch(Sabre_DAV_XMLUtil::toClarkNotation($child)) {
case '{urn:ietf:params:xml:ns:caldav}comp-filter' :
case '{urn:ietf:params:xml:ns:caldav}prop-filter' :
$filterName = $basePath . '/' . 'c:' . strtolower($child->getAttribute('name'));
$filters[$filterName] = array();
self::parseCalendarQueryFilters($child, $filterName,$filters);
break;
case '{urn:ietf:params:xml:ns:caldav}time-range' :
if ($start = $child->getAttribute('start')) {
$start = self::parseICalendarDateTime($start);
} else {
$start = null;
}
if ($end = $child->getAttribute('end')) {
$end = self::parseICalendarDateTime($end);
} else {
$end = null;
}
if (!is_null($start) && !is_null($end) && $end <= $start) {
throw new Sabre_DAV_Exception_BadRequest('The end-date must be larger than the start-date in the time-range filter');
}
$filters[$basePath]['time-range'] = array(
'start' => $start,
'end' => $end
);
break;
case '{urn:ietf:params:xml:ns:caldav}is-not-defined' :
$filters[$basePath]['is-not-defined'] = true;
break;
case '{urn:ietf:params:xml:ns:caldav}param-filter' :
$filterName = $basePath . '/@' . strtolower($child->getAttribute('name'));
$filters[$filterName] = array();
self::parseCalendarQueryFilters($child, $filterName, $filters);
break;
case '{urn:ietf:params:xml:ns:caldav}text-match' :
$collation = $child->getAttribute('collation');
if (!$collation) $collation = 'i;ascii-casemap';
$filters[$basePath]['text-match'] = array(
'collation' => ($collation == 'default'?'i;ascii-casemap':$collation),
'negate-condition' => $child->getAttribute('negate-condition')==='yes',
'value' => $child->nodeValue,
);
break;
}
}
return $filters;
}
/**
* Parses an iCalendar (rfc5545) formatted datetime and returns a DateTime object
*
* Specifying a reference timezone is optional. It will only be used
* if the non-UTC format is used. The argument is used as a reference, the
* returned DateTime object will still be in the UTC timezone.
*
* @param string $dt
* @param DateTimeZone $tz
* @return DateTime
*/
static public function parseICalendarDateTime($dt,DateTimeZone $tz = null) {
// Format is YYYYMMDD + "T" + hhmmss
$result = preg_match('/^([1-3][0-9]{3})([0-1][0-9])([0-3][0-9])T([0-2][0-9])([0-5][0-9])([0-5][0-9])([Z]?)$/',$dt,$matches);
if (!$result) {
throw new Sabre_DAV_Exception_BadRequest('The supplied iCalendar datetime value is incorrect: ' . $dt);
}
if ($matches[7]==='Z' || is_null($tz)) {
$tz = new DateTimeZone('UTC');
}
$date = new DateTime($matches[1] . '-' . $matches[2] . '-' . $matches[3] . ' ' . $matches[4] . ':' . $matches[5] .':' . $matches[6], $tz);
// Still resetting the timezone, to normalize everything to UTC
$date->setTimeZone(new DateTimeZone('UTC'));
return $date;
}
/**
* Parses an iCalendar (rfc5545) formatted datetime and returns a DateTime object
*
* @param string $date
* @param DateTimeZone $tz
* @return DateTime
*/
static public function parseICalendarDate($date) {
// Format is YYYYMMDD
$result = preg_match('/^([1-3][0-9]{3})([0-1][0-9])([0-3][0-9])$/',$date,$matches);
if (!$result) {
throw new Sabre_DAV_Exception_BadRequest('The supplied iCalendar date value is incorrect: ' . $date);
}
$date = new DateTime($matches[1] . '-' . $matches[2] . '-' . $matches[3], new DateTimeZone('UTC'));
return $date;
}
/**
* Parses an iCalendar (RFC5545) formatted duration and returns a string suitable
* for strtotime or DateTime::modify.
*
* NOTE: When we require PHP 5.3 this can be replaced by the DateTimeInterval object, which
* supports ISO 8601 Intervals, which is a superset of ICalendar durations.
*
* For now though, we're just gonna live with this messy system
*
* @param string $duration
* @return string
*/
static public function parseICalendarDuration($duration) {
$result = preg_match('/^(?P<plusminus>\+|-)?P((?P<week>\d+)W)?((?P<day>\d+)D)?(T((?P<hour>\d+)H)?((?P<minute>\d+)M)?((?P<second>\d+)S)?)?$/', $duration, $matches);
if (!$result) {
throw new Sabre_DAV_Exception_BadRequest('The supplied iCalendar duration value is incorrect: ' . $duration);
}
$parts = array(
'week',
'day',
'hour',
'minute',
'second',
);
$newDur = '';
foreach($parts as $part) {
if (isset($matches[$part]) && $matches[$part]) {
$newDur.=' '.$matches[$part] . ' ' . $part . 's';
}
}
$newDur = ($matches['plusminus']==='-'?'-':'+') . trim($newDur);
return $newDur;
}
}

293
3rdparty/Sabre/CardDAV/AddressBook.php vendored Normal file
View File

@ -0,0 +1,293 @@
<?php
/**
* The AddressBook class represents a CardDAV addressbook, owned by a specific user
*
* The AddressBook can contain multiple vcards
*
* @package Sabre
* @subpackage CardDAV
* @copyright Copyright (C) 2007-2011 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_CardDAV_AddressBook extends Sabre_DAV_Collection implements Sabre_CardDAV_IAddressBook, Sabre_DAV_IProperties, Sabre_DAVACL_IACL {
/**
* This is an array with addressbook information
*
* @var array
*/
private $addressBookInfo;
/**
* CardDAV backend
*
* @var Sabre_CardDAV_Backend_Abstract
*/
private $carddavBackend;
/**
* Constructor
*
* @param Sabre_CardDAV_Backend_Abstract $carddavBackend
* @param array $addressBookInfo
* @return void
*/
public function __construct(Sabre_CardDAV_Backend_Abstract $carddavBackend,array $addressBookInfo) {
$this->carddavBackend = $carddavBackend;
$this->addressBookInfo = $addressBookInfo;
}
/**
* Returns the name of the addressbook
*
* @return string
*/
public function getName() {
return $this->addressBookInfo['uri'];
}
/**
* Returns a card
*
* @param string $name
* @return Sabre_DAV_Card
*/
public function getChild($name) {
$obj = $this->carddavBackend->getCard($this->addressBookInfo['id'],$name);
if (!$obj) throw new Sabre_DAV_Exception_FileNotFound('Card not found');
return new Sabre_CardDAV_Card($this->carddavBackend,$this->addressBookInfo,$obj);
}
/**
* Returns the full list of cards
*
* @return array
*/
public function getChildren() {
$objs = $this->carddavBackend->getCards($this->addressBookInfo['id']);
$children = array();
foreach($objs as $obj) {
$children[] = new Sabre_CardDAV_Card($this->carddavBackend,$this->addressBookInfo,$obj);
}
return $children;
}
/**
* Creates a new directory
*
* We actually block this, as subdirectories are not allowed in addressbooks.
*
* @param string $name
* @return void
*/
public function createDirectory($name) {
throw new Sabre_DAV_Exception_MethodNotAllowed('Creating collections in addressbooks is not allowed');
}
/**
* Creates a new file
*
* The contents of the new file must be a valid VCARD
*
* @param string $name
* @param resource $vcardData
* @return void
*/
public function createFile($name,$vcardData = null) {
$vcardData = stream_get_contents($vcardData);
// Converting to UTF-8, if needed
$vcardData = Sabre_DAV_StringUtil::ensureUTF8($vcardData);
$this->carddavBackend->createCard($this->addressBookInfo['id'],$name,$vcardData);
}
/**
* Deletes the entire addressbook.
*
* @return void
*/
public function delete() {
$this->carddavBackend->deleteAddressBook($this->addressBookInfo['id']);
}
/**
* Renames the addressbook
*
* @param string $newName
* @return void
*/
public function setName($newName) {
throw new Sabre_DAV_Exception_MethodNotAllowed('Renaming addressbooks is not yet supported');
}
/**
* Returns the last modification date as a unix timestamp.
*
* @return void
*/
public function getLastModified() {
return null;
}
/**
* Updates properties on this node,
*
* The properties array uses the propertyName in clark-notation as key,
* and the array value for the property value. In the case a property
* should be deleted, the property value will be null.
*
* This method must be atomic. If one property cannot be changed, the
* entire operation must fail.
*
* If the operation was successful, true can be returned.
* If the operation failed, false can be returned.
*
* Deletion of a non-existant property is always succesful.
*
* Lastly, it is optional to return detailed information about any
* failures. In this case an array should be returned with the following
* structure:
*
* array(
* 403 => array(
* '{DAV:}displayname' => null,
* ),
* 424 => array(
* '{DAV:}owner' => null,
* )
* )
*
* In this example it was forbidden to update {DAV:}displayname.
* (403 Forbidden), which in turn also caused {DAV:}owner to fail
* (424 Failed Dependency) because the request needs to be atomic.
*
* @param array $mutations
* @return bool|array
*/
public function updateProperties($mutations) {
return $this->carddavBackend->updateAddressBook($this->addressBookInfo['id'], $mutations);
}
/**
* Returns a list of properties for this nodes.
*
* The properties list is a list of propertynames the client requested,
* encoded in clark-notation {xmlnamespace}tagname
*
* If the array is empty, it means 'all properties' were requested.
*
* @param array $properties
* @return void
*/
public function getProperties($properties) {
$response = array();
foreach($properties as $propertyName) {
if (isset($this->addressBookInfo[$propertyName])) {
$response[$propertyName] = $this->addressBookInfo[$propertyName];
}
}
return $response;
}
/**
* Returns the owner principal
*
* This must be a url to a principal, or null if there's no owner
*
* @return string|null
*/
public function getOwner() {
return $this->addressBookInfo['principaluri'];
}
/**
* Returns a group principal
*
* This must be a url to a principal, or null if there's no owner
*
* @return string|null
*/
public function getGroup() {
return null;
}
/**
* Returns a list of ACE's for this node.
*
* Each ACE has the following properties:
* * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
* currently the only supported privileges
* * 'principal', a url to the principal who owns the node
* * 'protected' (optional), indicating that this ACE is not allowed to
* be updated.
*
* @return array
*/
public function getACL() {
return array(
array(
'privilege' => '{DAV:}read',
'principal' => $this->addressBookInfo['principaluri'],
'protected' => true,
),
array(
'privilege' => '{DAV:}write',
'principal' => $this->addressBookInfo['principaluri'],
'protected' => true,
),
);
}
/**
* Updates the ACL
*
* This method will receive a list of new ACE's.
*
* @param array $acl
* @return void
*/
public function setACL(array $acl) {
throw new Sabre_DAV_Exception_MethodNotAllowed('Changing ACL is not yet supported');
}
}

View File

@ -0,0 +1,211 @@
<?php
/**
* Parses the addressbook-query report request body.
*
* Whoever designed this format, and the CalDAV equavalent even more so,
* has no feel for design.
*
* @package Sabre
* @subpackage CardDAV
* @copyright Copyright (C) 2007-2011 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_CardDAV_AddressBookQueryParser {
const TEST_ANYOF = 'anyof';
const TEST_ALLOF = 'allof';
/**
* List of requested properties the client wanted
*
* @var array
*/
public $requestedProperties;
/**
* The number of results the client wants
*
* null means it wasn't specified, which in most cases means 'all results'.
*
* @var int|null
*/
public $limit;
/**
* List of property filters.
*
* @var array
*/
public $filters;
/**
* Either TEST_ANYOF or TEST_ALLOF
*
* @var string
*/
public $test;
/**
* DOM Document
*
* @var DOMDocument
*/
protected $dom;
/**
* DOM XPath object
*
* @var DOMXPath
*/
protected $xpath;
/**
* Creates the parser
*
* @param DOMNode $dom
* @return void
*/
public function __construct(DOMDocument $dom) {
$this->dom = $dom;
$this->xpath = new DOMXPath($dom);
$this->xpath->registerNameSpace('card',Sabre_CardDAV_Plugin::NS_CARDDAV);
}
/**
* Parses the request.
*
* @param DOMNode $dom
* @return void
*/
public function parse() {
$filterNode = null;
$limit = $this->xpath->evaluate('number(/card:addressbook-query/card:limit/card:nresults)');
if (is_nan($limit)) $limit = null;
$filter = $this->xpath->query('/card:addressbook-query/card:filter');
if ($filter->length !== 1) {
throw new Sabre_DAV_Exception_BadRequest('Only one filter element is allowed');
}
$filter = $filter->item(0);
$test = $this->xpath->evaluate('string(@test)', $filter);
if (!$test) $test = self::TEST_ANYOF;
if ($test !== self::TEST_ANYOF && $test !== self::TEST_ALLOF) {
throw new Sabre_DAV_Exception_BadRequest('The test attribute must either hold "anyof" or "allof"');
}
$propFilters = array();
$propFilterNodes = $this->xpath->query('card:prop-filter', $filter);
for($ii=0; $ii < $propFilterNodes->length; $ii++) {
$propFilters[] = $this->parsePropFilterNode($propFilterNodes->item($ii));
}
$this->filters = $propFilters;
$this->limit = $limit;
$this->requestedProperties = array_keys(Sabre_DAV_XMLUtil::parseProperties($this->dom->firstChild));
$this->test = $test;
}
/**
* Parses the prop-filter xml element
*
* @param DOMElement $propFilterNode
* @return array
*/
protected function parsePropFilterNode(DOMElement $propFilterNode) {
$propFilter = array();
$propFilter['name'] = $propFilterNode->getAttribute('name');
$propFilter['test'] = $propFilterNode->getAttribute('test');
if (!$propFilter['test']) $propFilter['test'] = 'anyof';
$propFilter['is-not-defined'] = $this->xpath->query('card:is-not-defined', $propFilterNode)->length>0;
$paramFilterNodes = $this->xpath->query('card:param-filter', $propFilterNode);
$propFilter['param-filters'] = array();
for($ii=0;$ii<$paramFilterNodes->length;$ii++) {
$propFilter['param-filters'][] = $this->parseParamFilterNode($paramFilterNodes->item($ii));
}
$propFilter['text-matches'] = array();
$textMatchNodes = $this->xpath->query('card:text-match', $propFilterNode);
for($ii=0;$ii<$textMatchNodes->length;$ii++) {
$propFilter['text-matches'][] = $this->parseTextMatchNode($textMatchNodes->item($ii));
}
return $propFilter;
}
/**
* Parses the param-filter element
*
* @param DOMElement $paramFilterNode
* @return array
*/
public function parseParamFilterNode(DOMElement $paramFilterNode) {
$paramFilter = array();
$paramFilter['name'] = $paramFilterNode->getAttribute('name');
$paramFilter['is-not-defined'] = $this->xpath->query('card:is-not-defined', $paramFilterNode)->length>0;
$paramFilter['text-match'] = null;
$textMatch = $this->xpath->query('card:text-match', $paramFilterNode);
if ($textMatch->length>0) {
$paramFilter['text-match'] = $this->parseTextMatchNode($textMatch->item(0));
}
return $paramFilter;
}
/**
* Text match
*
* @param DOMElement $textMatchNode
* @return void
*/
public function parseTextMatchNode(DOMElement $textMatchNode) {
$matchType = $textMatchNode->getAttribute('match-type');
if (!$matchType) $matchType = 'contains';
if (!in_array($matchType, array('contains', 'equals', 'starts-with', 'ends-with'))) {
throw new Sabre_DAV_Exception_BadRequest('Unknown match-type: ' . $matchType);
}
$negateCondition = $textMatchNode->getAttribute('negate-condition');
$negateCondition = $negateCondition==='yes';
$collation = $textMatchNode->getAttribute('collation');
if (!$collation) $collation = 'i;unicode-casemap';
return array(
'negate-condition' => $negateCondition,
'collation' => $collation,
'match-type' => $matchType,
'value' => $textMatchNode->nodeValue
);
}
}

View File

@ -0,0 +1,78 @@
<?php
/**
* AddressBook rootnode
*
* This object lists a collection of users, which can contain addressbooks.
*
* @package Sabre
* @subpackage CardDAV
* @copyright Copyright (C) 2007-2011 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_CardDAV_AddressBookRoot extends Sabre_DAVACL_AbstractPrincipalCollection {
/**
* Principal Backend
*
* @var Sabre_DAVACL_IPrincipalBackend
*/
protected $principalBackend;
/**
* CardDAV backend
*
* @var Sabre_CardDAV_Backend_Abstract
*/
protected $carddavBackend;
/**
* Constructor
*
* This constructor needs both a principal and a carddav backend.
*
* By default this class will show a list of addressbook collections for
* principals in the 'principals' collection. If your main principals are
* actually located in a different path, use the $principalPrefix argument
* to override this.
*
* @param Sabre_DAVACL_IPrincipalBackend $principalBackend
* @param Sabre_CardDAV_Backend_Abstract $carddavBackend
* @param string $principalPrefix
*/
public function __construct(Sabre_DAVACL_IPrincipalBackend $principalBackend,Sabre_CardDAV_Backend_Abstract $carddavBackend, $principalPrefix = 'principals') {
$this->carddavBackend = $carddavBackend;
parent::__construct($principalBackend, $principalPrefix);
}
/**
* Returns the name of the node
*
* @return string
*/
public function getName() {
return Sabre_CardDAV_Plugin::ADDRESSBOOK_ROOT;
}
/**
* This method returns a node for a principal.
*
* The passed array contains principal information, and is guaranteed to
* at least contain a uri item. Other properties may or may not be
* supplied by the authentication backend.
*
* @param array $principal
* @return Sabre_DAV_INode
*/
public function getChildForPrincipal(array $principal) {
return new Sabre_CardDAV_UserAddressBooks($this->carddavBackend, $principal['uri']);
}
}

View File

@ -0,0 +1,121 @@
<?php
/**
* Abstract Backend class
*
* This class serves as a base-class for addressbook backends
*
* Note that there are references to 'addressBookId' scattered throughout the
* class. The value of the addressBookId is completely up to you, it can be any
* arbitrary value you can use as an unique identifier.
*
* @package Sabre
* @subpackage CardDAV
* @copyright Copyright (C) 2007-2011 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
abstract class Sabre_CardDAV_Backend_Abstract {
/**
* Returns the list of addressbooks for a specific user.
*
* Every addressbook should have the following properties:
* id - an arbitrary unique id
* uri - the 'basename' part of the url
* principaluri - Same as the passed parameter
*
* Any additional clark-notation property may be passed besides this. Some
* common ones are :
* {DAV:}displayname
* {urn:ietf:params:xml:ns:carddav}addressbook-description
* {http://calendarserver.org/ns/}getctag
*
* @param string $principalUri
* @return array
*/
public abstract function getAddressBooksForUser($principalUri);
/**
* Updates an addressbook's properties
*
* See Sabre_DAV_IProperties for a description of the mutations array, as
* well as the return value.
*
* @param mixed $addressBookId
* @param array $mutations
* @see Sabre_DAV_IProperties::updateProperties
* @return bool|array
*/
public abstract function updateAddressBook($addressBookId, array $mutations);
/**
* Creates a new address book
*
* @param string $principalUri
* @param string $url Just the 'basename' of the url.
* @param array $properties
* @return void
*/
abstract public function createAddressBook($principalUri, $url, array $properties);
/**
* Deletes an entire addressbook and all its contents
*
* @param mixed $addressBookId
* @return void
*/
abstract public function deleteAddressBook($addressBookId);
/**
* Returns all cards for a specific addressbook id.
*
* This method should return the following properties for each card:
* * carddata - raw vcard data
* * uri - Some unique url
* * lastmodified - A unix timestamp
* @param mixed $addressbookId
* @return array
*/
public abstract function getCards($addressbookId);
/**
* Returns a specfic card
*
* @param mixed $addressBookId
* @param string $cardUri
* @return void
*/
public abstract function getCard($addressBookId, $cardUri);
/**
* Creates a new card
*
* @param mixed $addressBookId
* @param string $cardUri
* @param string $cardData
* @return bool
*/
abstract public function createCard($addressBookId, $cardUri, $cardData);
/**
* Updates a card
*
* @param mixed $addressBookId
* @param string $cardUri
* @param string $cardData
* @return bool
*/
abstract public function updateCard($addressBookId, $cardUri, $cardData);
/**
* Deletes a card
*
* @param mixed $addressBookId
* @param string $cardUri
* @return bool
*/
abstract public function deleteCard($addressBookId, $cardUri);
}

277
3rdparty/Sabre/CardDAV/Backend/PDO.php vendored Normal file
View File

@ -0,0 +1,277 @@
<?php
/**
* PDO CardDAV backend
*
* This CardDAV backend uses PDO to store addressbooks
*
* @package Sabre
* @subpackage CardDAV
* @copyright Copyright (C) 2007-2011 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_CardDAV_Backend_PDO extends Sabre_CardDAV_Backend_Abstract {
/**
* PDO connection
*
* @var PDO
*/
protected $pdo;
/**
* The PDO table name used to store addressbooks
*/
protected $addressBooksTableName;
/**
* The PDO table name used to store cards
*/
protected $cardsTableName;
/**
* Sets up the object
*
* @param PDO $pdo
*/
public function __construct(PDO $pdo, $addressBooksTableName = 'addressbooks', $cardsTableName = 'cards') {
$this->pdo = $pdo;
$this->addressBooksTableName = $addressBooksTableName;
$this->cardsTableName = $cardsTableName;
}
/**
* Returns the list of addressbooks for a specific user.
*
* @param string $principalUri
* @return array
*/
public function getAddressBooksForUser($principalUri) {
$stmt = $this->pdo->prepare('SELECT id, uri, displayname, principaluri, description, ctag FROM `'.$this->addressBooksTableName.'` WHERE principaluri = ?');
$result = $stmt->execute(array($principalUri));
$addressBooks = array();
foreach($stmt->fetchAll() as $row) {
$addressBooks[] = array(
'id' => $row['id'],
'uri' => $row['uri'],
'principaluri' => $row['principaluri'],
'{DAV:}displayname' => $row['displayname'],
'{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description' => $row['description'],
'{http://calendarserver.org/ns/}getctag' => $row['ctag'],
'{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}supported-address-data' =>
new Sabre_CardDAV_Property_SupportedAddressData(),
);
}
return $addressBooks;
}
/**
* Updates an addressbook's properties
*
* See Sabre_DAV_IProperties for a description of the mutations array, as
* well as the return value.
*
* @param mixed $addressBookId
* @param array $mutations
* @see Sabre_DAV_IProperties::updateProperties
* @return bool|array
*/
public function updateAddressBook($addressBookId, array $mutations) {
$updates = array();
foreach($mutations as $property=>$newValue) {
switch($property) {
case '{DAV:}displayname' :
$updates['displayname'] = $newValue;
break;
case '{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description' :
$updates['description'] = $newValue;
break;
default :
// If any unsupported values were being updated, we must
// let the entire request fail.
return false;
}
}
// No values are being updated?
if (!$updates) {
return false;
}
$query = 'UPDATE `' . $this->addressBooksTableName . '` SET ctag = ctag + 1 ';
foreach($updates as $key=>$value) {
$query.=', `' . $key . '` = :' . $key . ' ';
}
$query.=' WHERE id = :addressbookid';
$stmt = $this->pdo->prepare($query);
$updates['addressbookid'] = $addressBookId;
$stmt->execute($updates);
return true;
}
/**
* Creates a new address book
*
* @param string $principalUri
* @param string $url Just the 'basename' of the url.
* @param array $properties
* @return void
*/
public function createAddressBook($principalUri, $url, array $properties) {
$values = array(
'displayname' => null,
'description' => null,
'principaluri' => $principalUri,
'uri' => $url,
);
foreach($properties as $property=>$newValue) {
switch($property) {
case '{DAV:}displayname' :
$values['displayname'] = $newValue;
break;
case '{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description' :
$values['description'] = $newValue;
break;
default :
throw new Sabre_DAV_Exception_BadRequest('Unknown property: ' . $property);
}
}
$query = 'INSERT INTO `' . $this->addressBooksTableName . '` (uri, displayname, description, principaluri, ctag) VALUES (:uri, :displayname, :description, :principaluri, 1)';
$stmt = $this->pdo->prepare($query);
$stmt->execute($values);
}
/**
* Deletes an entire addressbook and all its contents
*
* @param int $addressBookId
* @return void
*/
public function deleteAddressBook($addressBookId) {
$stmt = $this->pdo->prepare('DELETE FROM `' . $this->cardsTableName . '` WHERE addressbookid = ?');
$stmt->execute(array($addressBookId));
$stmt = $this->pdo->prepare('DELETE FROM `' . $this->addressBooksTableName . '` WHERE id = ?');
$stmt->execute(array($addressBookId));
}
/**
* Returns all cards for a specific addressbook id.
*
* @param mixed $addressbookId
* @return array
*/
public function getCards($addressbookId) {
$stmt = $this->pdo->prepare('SELECT id, carddata, uri, lastmodified FROM `' . $this->cardsTableName . '` WHERE addressbookid = ?');
$stmt->execute(array($addressbookId));
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}
/**
* Returns a specfic card
*
* @param mixed $addressBookId
* @param string $cardUri
* @return array
*/
public function getCard($addressBookId, $cardUri) {
$stmt = $this->pdo->prepare('SELECT id, carddata, uri, lastmodified FROM `' . $this->cardsTableName . '` WHERE addressbookid = ? AND uri = ? LIMIT 1');
$stmt->execute(array($addressBookId, $cardUri));
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
return (count($result)>0?$result[0]:false);
}
/**
* Creates a new card
*
* @param mixed $addressBookId
* @param string $cardUri
* @param string $cardData
* @return bool
*/
public function createCard($addressBookId, $cardUri, $cardData) {
$stmt = $this->pdo->prepare('INSERT INTO `' . $this->cardsTableName . '` (carddata, uri, lastmodified, addressbookid) VALUES (?, ?, ?, ?)');
$result = $stmt->execute(array($cardData, $cardUri, time(), $addressBookId));
$stmt2 = $this->pdo->prepare('UPDATE `' . $this->addressBooksTableName . '` SET ctag = ctag + 1 WHERE id = ?');
$stmt2->execute(array($addressBookId));
return $result;
}
/**
* Updates a card
*
* @param mixed $addressBookId
* @param string $cardUri
* @param string $cardData
* @return bool
*/
public function updateCard($addressBookId, $cardUri, $cardData) {
$stmt = $this->pdo->prepare('UPDATE `' . $this->cardsTableName . '` SET carddata = ?, lastmodified = ? WHERE uri = ? AND addressbookid =?');
$result = $stmt->execute(array($cardData, time(), $cardUri, $addressBookId));
$stmt2 = $this->pdo->prepare('UPDATE `' . $this->addressBooksTableName . '` SET ctag = ctag + 1 WHERE id = ?');
$stmt2->execute(array($addressBookId));
return $stmt->rowCount()===1;
}
/**
* Deletes a card
*
* @param mixed $addressBookId
* @param string $cardUri
* @return bool
*/
public function deleteCard($addressBookId, $cardUri) {
$stmt = $this->pdo->prepare('DELETE FROM `' . $this->cardsTableName . '` WHERE addressbookid = ? AND uri = ?');
$stmt->execute(array($addressBookId, $cardUri));
$stmt2 = $this->pdo->prepare('UPDATE `' . $this->addressBooksTableName . '` SET ctag = ctag + 1 WHERE id = ?');
$stmt2->execute(array($addressBookId));
return $stmt->rowCount()===1;
}
}

220
3rdparty/Sabre/CardDAV/Card.php vendored Normal file
View File

@ -0,0 +1,220 @@
<?php
/**
* The Card object represents a single Card from an addressbook
*
* @package Sabre
* @subpackage CardDAV
* @copyright Copyright (C) 2007-2011 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_CardDAV_Card extends Sabre_DAV_File implements Sabre_CardDAV_ICard, Sabre_DAVACL_IACL {
/**
* CardDAV backend
*
* @var Sabre_CardDAV_Backend_Abstract
*/
private $carddavBackend;
/**
* Array with information about this Card
*
* @var array
*/
private $cardData;
/**
* Array with information about the containing addressbook
*
* @var array
*/
private $addressBookInfo;
/**
* Constructor
*
* @param Sabre_CardDAV_Backend_Abstract $carddavBackend
* @param array $addressBookInfo
* @param array $cardData
*/
public function __construct(Sabre_CardDAV_Backend_Abstract $carddavBackend,array $addressBookInfo,array $cardData) {
$this->carddavBackend = $carddavBackend;
$this->addressBookInfo = $addressBookInfo;
$this->cardData = $cardData;
}
/**
* Returns the uri for this object
*
* @return string
*/
public function getName() {
return $this->cardData['uri'];
}
/**
* Returns the VCard-formatted object
*
* @return string
*/
public function get() {
$cardData = $this->cardData['carddata'];
$s = fopen('php://temp','r+');
fwrite($s, $cardData);
rewind($s);
return $s;
}
/**
* Updates the VCard-formatted object
*
* @param string $cardData
* @return void
*/
public function put($cardData) {
if (is_resource($cardData))
$cardData = stream_get_contents($cardData);
// Converting to UTF-8, if needed
$cardData = Sabre_DAV_StringUtil::ensureUTF8($cardData);
$this->carddavBackend->updateCard($this->addressBookInfo['id'],$this->cardData['uri'],$cardData);
$this->cardData['carddata'] = $cardData;
}
/**
* Deletes the card
*
* @return void
*/
public function delete() {
$this->carddavBackend->deleteCard($this->addressBookInfo['id'],$this->cardData['uri']);
}
/**
* Returns the mime content-type
*
* @return string
*/
public function getContentType() {
return 'text/x-vcard';
}
/**
* Returns an ETag for this object
*
* @return string
*/
public function getETag() {
return '"' . md5($this->cardData['carddata']) . '"';
}
/**
* Returns the last modification date as a unix timestamp
*
* @return time
*/
public function getLastModified() {
return isset($this->cardData['lastmodified'])?$this->cardData['lastmodified']:null;
}
/**
* Returns the size of this object in bytes
*
* @return int
*/
public function getSize() {
return strlen($this->cardData['carddata']);
}
/**
* Returns the owner principal
*
* This must be a url to a principal, or null if there's no owner
*
* @return string|null
*/
public function getOwner() {
return $this->addressBookInfo['principaluri'];
}
/**
* Returns a group principal
*
* This must be a url to a principal, or null if there's no owner
*
* @return string|null
*/
public function getGroup() {
return null;
}
/**
* Returns a list of ACE's for this node.
*
* Each ACE has the following properties:
* * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
* currently the only supported privileges
* * 'principal', a url to the principal who owns the node
* * 'protected' (optional), indicating that this ACE is not allowed to
* be updated.
*
* @return array
*/
public function getACL() {
return array(
array(
'privilege' => '{DAV:}read',
'principal' => $this->addressBookInfo['principaluri'],
'protected' => true,
),
array(
'privilege' => '{DAV:}write',
'principal' => $this->addressBookInfo['principaluri'],
'protected' => true,
),
);
}
/**
* Updates the ACL
*
* This method will receive a list of new ACE's.
*
* @param array $acl
* @return void
*/
public function setACL(array $acl) {
throw new Sabre_DAV_Exception_MethodNotAllowed('Changing ACL is not yet supported');
}
}

18
3rdparty/Sabre/CardDAV/IAddressBook.php vendored Normal file
View File

@ -0,0 +1,18 @@
<?php
/**
* AddressBook interface
*
* Implement this interface to allow a node to be recognized as an addressbook.
*
* @package Sabre
* @subpackage CardDAV
* @copyright Copyright (C) 2007-2011 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
interface Sabre_CardDAV_IAddressBook extends Sabre_DAV_ICollection {
}

18
3rdparty/Sabre/CardDAV/ICard.php vendored Normal file
View File

@ -0,0 +1,18 @@
<?php
/**
* Card interface
*
* Extend the ICard interface to allow your custom nodes to be picked up as
* 'Cards'.
*
* @package Sabre
* @subpackage CardDAV
* @copyright Copyright (C) 2007-2011 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
interface Sabre_CardDAV_ICard extends Sabre_DAV_IFile {
}

Some files were not shown because too many files have changed in this diff Show More