Update RedbeanPHP and Slim Framework.
This commit is contained in:
parent
2399f2628a
commit
13b163a0c9
@ -89,7 +89,7 @@ class PrettyExceptions extends \Slim\Middleware
|
||||
$message = $exception->getMessage();
|
||||
$file = $exception->getFile();
|
||||
$line = $exception->getLine();
|
||||
$trace = str_replace(array('#', '\n'), array('<div>#', '</div>'), $exception->getTraceAsString());
|
||||
$trace = str_replace(array('#', "\n"), array('<div>#', '</div>'), $exception->getTraceAsString());
|
||||
$html = sprintf('<h1>%s</h1>', $title);
|
||||
$html .= '<p>The application could not run because of the following error:</p>';
|
||||
$html .= '<h2>Details</h2>';
|
||||
|
@ -288,6 +288,9 @@ class Route
|
||||
public function appendHttpMethods()
|
||||
{
|
||||
$args = func_get_args();
|
||||
if(count($args) && is_array($args[0])){
|
||||
$args = $args[0];
|
||||
}
|
||||
$this->methods = array_merge($this->methods, $args);
|
||||
}
|
||||
|
||||
@ -298,6 +301,9 @@ class Route
|
||||
public function via()
|
||||
{
|
||||
$args = func_get_args();
|
||||
if(count($args) && is_array($args[0])){
|
||||
$args = $args[0];
|
||||
}
|
||||
$this->methods = array_merge($this->methods, $args);
|
||||
|
||||
return $this;
|
||||
|
@ -1099,6 +1099,18 @@ class Slim
|
||||
$this->response->redirect($url, $status);
|
||||
$this->halt($status);
|
||||
}
|
||||
|
||||
/**
|
||||
* RedirectTo
|
||||
*
|
||||
* Redirects to a specific named route
|
||||
*
|
||||
* @param string $route The route name
|
||||
* @param array $params Associative array of URL parameters and replacement values
|
||||
*/
|
||||
public function redirectTo($route, $params = array(), $status = 302){
|
||||
$this->redirect($this->urlFor($route, $params), $status);
|
||||
}
|
||||
|
||||
/********************************************************************************
|
||||
* Flash Messages
|
||||
|
@ -108,7 +108,7 @@ class View
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function keep($key, Closure $value)
|
||||
public function keep($key, \Closure $value)
|
||||
{
|
||||
$this->data->keep($key, $value);
|
||||
}
|
||||
|
214
api/lib/rb.php
214
api/lib/rb.php
@ -194,6 +194,11 @@ class Debug extends RDefault implements Logger
|
||||
*/
|
||||
private function writeQuery( $newSql, $newBindings )
|
||||
{
|
||||
//avoid str_replace collisions: slot1 and slot10 (issue 407).
|
||||
uksort( $newBindings, function( $a, $b ) {
|
||||
return ( strlen( $b ) - strlen( $a ) );
|
||||
} );
|
||||
|
||||
$newStr = $newSql;
|
||||
foreach( $newBindings as $slot => $value ) {
|
||||
if ( strpos( $slot, ':' ) === 0 ) {
|
||||
@ -698,6 +703,8 @@ class RPDO implements Driver
|
||||
//PHP 5.3 PDO SQLite has a bug with large numbers:
|
||||
if ( strpos( $this->dsn, 'sqlite' ) === 0 && PHP_MAJOR_VERSION === 5 && PHP_MINOR_VERSION === 3) {
|
||||
$this->max = 2147483647; //otherwise you get -2147483648 ?! demonstrated in build #603 on Travis.
|
||||
} elseif ( strpos( $this->dsn, 'cubrid' ) === 0 ) {
|
||||
$this->max = 2147483647; //bindParam in pdo_cubrid also fails...
|
||||
} else {
|
||||
$this->max = PHP_INT_MAX; //the normal value of course (makes it possible to use large numbers in LIMIT clause)
|
||||
}
|
||||
@ -736,14 +743,14 @@ class RPDO implements Driver
|
||||
$this->pdo = new\PDO(
|
||||
$this->dsn,
|
||||
$user,
|
||||
$pass,
|
||||
array(\PDO::ATTR_ERRMODE =>\PDO::ERRMODE_EXCEPTION,
|
||||
\PDO::ATTR_DEFAULT_FETCH_MODE =>\PDO::FETCH_ASSOC,
|
||||
)
|
||||
$pass
|
||||
);
|
||||
|
||||
$this->setEncoding();
|
||||
$this->pdo->setAttribute(\PDO::ATTR_STRINGIFY_FETCHES, TRUE );
|
||||
//cant pass these as argument to constructor, CUBRID driver does not understand...
|
||||
$this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
|
||||
$this->pdo->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE,\PDO::FETCH_ASSOC);
|
||||
|
||||
$this->isConnected = TRUE;
|
||||
} catch (\PDOException $exception ) {
|
||||
@ -1021,6 +1028,78 @@ use RedBeanPHP\OODBBean as OODBBean;
|
||||
*/
|
||||
class OODBBean implements\IteratorAggregate,\ArrayAccess,\Countable
|
||||
{
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
protected static $errorHandlingFUSE = FALSE;
|
||||
|
||||
/**
|
||||
* @var callable|NULL
|
||||
*/
|
||||
protected static $errorHandler = NULL;
|
||||
|
||||
/**
|
||||
* FUSE error modes.
|
||||
*/
|
||||
const C_ERR_IGNORE = FALSE;
|
||||
const C_ERR_LOG = 1;
|
||||
const C_ERR_NOTICE = 2;
|
||||
const C_ERR_WARN = 3;
|
||||
const C_ERR_EXCEPTION = 4;
|
||||
const C_ERR_FUNC = 5;
|
||||
const C_ERR_FATAL = 6;
|
||||
|
||||
/**
|
||||
* Sets the error mode for FUSE.
|
||||
* What to do if a FUSE model method does not exist?
|
||||
* You can set the following options:
|
||||
*
|
||||
* OODBBean::C_ERR_IGNORE (default), ignores the call, returns NULL
|
||||
* OODBBean::C_ERR_LOG, logs the incident using error_log
|
||||
* OODBBean::C_ERR_NOTICE, triggers a E_USER_NOTICE
|
||||
* OODBBean::C_ERR_WARN, triggers a E_USER_WARNING
|
||||
* OODBBean::C_ERR_EXCEPTION, throws an exception
|
||||
* OODBBean::C_ERR_FUNC, allows you to specify a custom handler (function)
|
||||
* OODBBean::C_ERR_FATAL, triggers a E_USER_ERROR
|
||||
*
|
||||
* Custom handler method signature: handler( array (
|
||||
* 'message' => string
|
||||
* 'bean' => OODBBean
|
||||
* 'method' => string
|
||||
* ) )
|
||||
*
|
||||
* This method returns the old mode and handler as an array.
|
||||
*
|
||||
* @param integer $mode mode
|
||||
* @param callable|NULL $func custom handler
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function setErrorHandlingFUSE($mode, $func = NULL) {
|
||||
if (
|
||||
$mode !== self::C_ERR_IGNORE
|
||||
&& $mode !== self::C_ERR_LOG
|
||||
&& $mode !== self::C_ERR_NOTICE
|
||||
&& $mode !== self::C_ERR_WARN
|
||||
&& $mode !== self::C_ERR_EXCEPTION
|
||||
&& $mode !== self::C_ERR_FUNC
|
||||
&& $mode !== self::C_ERR_FATAL
|
||||
) throw new \Exception( 'Invalid error mode selected' );
|
||||
|
||||
if ( $mode === self::C_ERR_FUNC && !is_callable( $func ) ) {
|
||||
throw new \Exception( 'Invalid error handler' );
|
||||
}
|
||||
|
||||
$old = array( self::$errorHandlingFUSE, self::$errorHandler );
|
||||
self::$errorHandlingFUSE = $mode;
|
||||
if ( is_callable( $func ) ) {
|
||||
self::$errorHandler = $func;
|
||||
} else {
|
||||
self::$errorHandler = NULL;
|
||||
}
|
||||
return $old;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is where the real properties of the bean live. They are stored and retrieved
|
||||
* by the magic getter and setter (__get and __set).
|
||||
@ -1433,6 +1512,7 @@ class OODBBean implements\IteratorAggregate,\ArrayAccess,\Countable
|
||||
$vn = array();
|
||||
|
||||
foreach ( $value as $i => $b ) {
|
||||
if ( !( $b instanceof OODBBean ) ) continue;
|
||||
$vn[] = $b->export( $meta, FALSE, FALSE, $filters );
|
||||
$value = $vn;
|
||||
}
|
||||
@ -2034,6 +2114,39 @@ class OODBBean implements\IteratorAggregate,\ArrayAccess,\Countable
|
||||
$this->__info['model'] = $model;
|
||||
}
|
||||
if ( !method_exists( $this->__info['model'], $method ) ) {
|
||||
|
||||
if ( self::$errorHandlingFUSE === FALSE ) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ( in_array( $method, array( 'update', 'open', 'delete', 'after_delete', 'after_update', 'dispense' ), TRUE ) ) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$message = "FUSE: method does not exist in model: $method";
|
||||
if ( self::$errorHandlingFUSE === self::C_ERR_LOG ) {
|
||||
error_log( $message );
|
||||
return NULL;
|
||||
} elseif ( self::$errorHandlingFUSE === self::C_ERR_NOTICE ) {
|
||||
trigger_error( $message, E_USER_NOTICE );
|
||||
return NULL;
|
||||
} elseif ( self::$errorHandlingFUSE === self::C_ERR_WARN ) {
|
||||
trigger_error( $message, E_USER_WARNING );
|
||||
return NULL;
|
||||
} elseif ( self::$errorHandlingFUSE === self::C_ERR_EXCEPTION ) {
|
||||
throw new \Exception( $message );
|
||||
} elseif ( self::$errorHandlingFUSE === self::C_ERR_FUNC ) {
|
||||
if ( is_callable( self::$errorHandler ) ) {
|
||||
$func = self::$errorHandler;
|
||||
return $func(array(
|
||||
'message' => $message,
|
||||
'method' => $method,
|
||||
'args' => $args,
|
||||
'bean' => $this
|
||||
));
|
||||
}
|
||||
}
|
||||
trigger_error( $message, E_USER_ERROR );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -2431,13 +2544,15 @@ class OODBBean implements\IteratorAggregate,\ArrayAccess,\Countable
|
||||
$firstKey = key( $this->withParams );
|
||||
}
|
||||
|
||||
$joinSql = $this->parseJoin( $type );
|
||||
|
||||
if ( !is_numeric( $firstKey ) || $firstKey === NULL ) {
|
||||
$bindings = $this->withParams;
|
||||
$bindings[':slot0'] = $this->getID();
|
||||
$count = $this->beanHelper->getToolbox()->getWriter()->queryRecordCount( $type, array(), " $myFieldLink = :slot0 " . $this->withSql, $bindings );
|
||||
$count = $this->beanHelper->getToolbox()->getWriter()->queryRecordCount( $type, array(), " {$joinSql} $myFieldLink = :slot0 " . $this->withSql, $bindings );
|
||||
} else {
|
||||
$bindings = array_merge( array( $this->getID() ), $this->withParams );
|
||||
$count = $this->beanHelper->getToolbox()->getWriter()->queryRecordCount( $type, array(), " $myFieldLink = ? " . $this->withSql, $bindings );
|
||||
$count = $this->beanHelper->getToolbox()->getWriter()->queryRecordCount( $type, array(), " {$joinSql} $myFieldLink = ? " . $this->withSql, $bindings );
|
||||
}
|
||||
|
||||
}
|
||||
@ -3802,10 +3917,13 @@ abstract class AQueryWriter { //bracket must be here - otherwise coverage softwa
|
||||
* A cache tag is used to make sure the cache remains consistent. In most cases the cache tag
|
||||
* will be the bean type, this makes sure queries associated with a certain reference type will
|
||||
* never contain conflicting data.
|
||||
* You can only store one item under a cache tag. Why not use the cache tag as a key? Well
|
||||
* Why not use the cache tag as a key? Well
|
||||
* we need to make sure the cache contents fits the key (and key is based on the cache values).
|
||||
* Otherwise it would be possible to store two different result sets under the same key (the cache tag).
|
||||
*
|
||||
* In previous versions you could only store one key-entry, I have changed this to
|
||||
* improve caching efficiency (issue #400).
|
||||
*
|
||||
* @param string $cacheTag cache tag (secondary key)
|
||||
* @param string $key key
|
||||
* @param array $values content to be stored
|
||||
@ -3814,9 +3932,8 @@ abstract class AQueryWriter { //bracket must be here - otherwise coverage softwa
|
||||
*/
|
||||
private function putResultInCache( $cacheTag, $key, $values )
|
||||
{
|
||||
$this->cache[$cacheTag] = array(
|
||||
$key => $values
|
||||
);
|
||||
if (!isset($this->cache[$cacheTag])) $this->cache[$cacheTag] = array();
|
||||
$this->cache[$cacheTag][$key] = $values;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -4611,9 +4728,10 @@ class MySQL extends AQueryWriter implements QueryWriter
|
||||
const C_DATATYPE_BOOL = 0;
|
||||
const C_DATATYPE_UINT32 = 2;
|
||||
const C_DATATYPE_DOUBLE = 3;
|
||||
const C_DATATYPE_TEXT8 = 4;
|
||||
const C_DATATYPE_TEXT16 = 5;
|
||||
const C_DATATYPE_TEXT32 = 6;
|
||||
const C_DATATYPE_TEXT7 = 4; //InnoDB cant index varchar(255) utf8mb4 - so keep 191 as long as possible
|
||||
const C_DATATYPE_TEXT8 = 5;
|
||||
const C_DATATYPE_TEXT16 = 6;
|
||||
const C_DATATYPE_TEXT32 = 7;
|
||||
const C_DATATYPE_SPECIAL_DATE = 80;
|
||||
const C_DATATYPE_SPECIAL_DATETIME = 81;
|
||||
const C_DATATYPE_SPECIAL_POINT = 90;
|
||||
@ -4704,7 +4822,8 @@ class MySQL extends AQueryWriter implements QueryWriter
|
||||
MySQL::C_DATATYPE_BOOL => ' TINYINT(1) UNSIGNED ',
|
||||
MySQL::C_DATATYPE_UINT32 => ' INT(11) UNSIGNED ',
|
||||
MySQL::C_DATATYPE_DOUBLE => ' DOUBLE ',
|
||||
MySQL::C_DATATYPE_TEXT8 => ' VARCHAR(255) ',
|
||||
MySQL::C_DATATYPE_TEXT7 => ' VARCHAR(191) ',
|
||||
MYSQL::C_DATATYPE_TEXT8 => ' VARCHAR(255) ',
|
||||
MySQL::C_DATATYPE_TEXT16 => ' TEXT ',
|
||||
MySQL::C_DATATYPE_TEXT32 => ' LONGTEXT ',
|
||||
MySQL::C_DATATYPE_SPECIAL_DATE => ' DATE ',
|
||||
@ -4780,6 +4899,7 @@ class MySQL extends AQueryWriter implements QueryWriter
|
||||
$this->svalue = $value;
|
||||
|
||||
if ( is_null( $value ) ) return MySQL::C_DATATYPE_BOOL;
|
||||
if ( $value === INF ) return MySQL::C_DATATYPE_TEXT8;
|
||||
|
||||
if ( $flagSpecial ) {
|
||||
if ( preg_match( '/^\d{4}\-\d\d-\d\d$/', $value ) ) {
|
||||
@ -4815,6 +4935,10 @@ class MySQL extends AQueryWriter implements QueryWriter
|
||||
}
|
||||
}
|
||||
|
||||
if ( mb_strlen( $value, 'UTF-8' ) <= 191 ) {
|
||||
return MySQL::C_DATATYPE_TEXT7;
|
||||
}
|
||||
|
||||
if ( mb_strlen( $value, 'UTF-8' ) <= 255 ) {
|
||||
return MySQL::C_DATATYPE_TEXT8;
|
||||
}
|
||||
@ -5243,6 +5367,7 @@ class SQLiteT extends AQueryWriter implements QueryWriter
|
||||
$this->svalue = $value;
|
||||
|
||||
if ( $value === NULL ) return self::C_DATATYPE_INTEGER;
|
||||
if ( $value === INF ) return self::C_DATATYPE_TEXT;
|
||||
|
||||
if ( $this->startsWithZeros( $value ) ) return self::C_DATATYPE_TEXT;
|
||||
|
||||
@ -5250,7 +5375,7 @@ class SQLiteT extends AQueryWriter implements QueryWriter
|
||||
|
||||
if ( is_numeric( $value ) && ( intval( $value ) == $value ) && $value < 2147483648 && $value > -2147483648 ) return self::C_DATATYPE_INTEGER;
|
||||
|
||||
if ( ( is_numeric( $value ) && $value < 2147483648 )
|
||||
if ( ( is_numeric( $value ) && $value < 2147483648 && $value > -2147483648)
|
||||
|| preg_match( '/\d{4}\-\d\d\-\d\d/', $value )
|
||||
|| preg_match( '/\d{4}\-\d\d\-\d\d\s\d\d:\d\d:\d\d/', $value )
|
||||
) {
|
||||
@ -5625,6 +5750,8 @@ class PostgreSQL extends AQueryWriter implements QueryWriter
|
||||
{
|
||||
$this->svalue = $value;
|
||||
|
||||
if ( $value === INF ) return self::C_DATATYPE_TEXT;
|
||||
|
||||
if ( $flagSpecial && $value ) {
|
||||
if ( preg_match( '/^\d{4}\-\d\d-\d\d$/', $value ) ) {
|
||||
return PostgreSQL::C_DATATYPE_SPECIAL_DATE;
|
||||
@ -5650,7 +5777,7 @@ class PostgreSQL extends AQueryWriter implements QueryWriter
|
||||
return PostgreSQL::C_DATATYPE_SPECIAL_POLYGON;
|
||||
}
|
||||
|
||||
if ( preg_match( '/^\-?\$[\d,\.]+$/', $value ) ) {
|
||||
if ( preg_match( '/^\-?(\$|€|¥|£)[\d,\.]+$/', $value ) ) {
|
||||
return PostgreSQL::C_DATATYPE_SPECIAL_MONEY;
|
||||
}
|
||||
}
|
||||
@ -9092,12 +9219,12 @@ class Facade
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $toolboxes = array();
|
||||
public static $toolboxes = array();
|
||||
|
||||
/**
|
||||
* @var ToolBox
|
||||
*/
|
||||
private static $toolbox;
|
||||
public static $toolbox;
|
||||
|
||||
/**
|
||||
* @var OODB
|
||||
@ -9142,13 +9269,18 @@ class Facade
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private static $currentDB = '';
|
||||
public static $currentDB = '';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $plugins = array();
|
||||
|
||||
/**
|
||||
* Not in use (backward compatibility SQLHelper)
|
||||
*/
|
||||
public static $f;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
@ -9353,10 +9485,13 @@ class Facade
|
||||
|
||||
$adapter = new DBAdapter( $db );
|
||||
|
||||
$writers = array('pgsql' => 'PostgreSQL',
|
||||
'sqlite' => 'SQLiteT',
|
||||
'cubrid' => 'CUBRID',
|
||||
'mysql' => 'MySQL');
|
||||
$writers = array(
|
||||
'pgsql' => 'PostgreSQL',
|
||||
'sqlite' => 'SQLiteT',
|
||||
'cubrid' => 'CUBRID',
|
||||
'mysql' => 'MySQL',
|
||||
'sqlsrv' => 'SQLServer',
|
||||
);
|
||||
|
||||
$wkey = trim( strtolower( $dbType ) );
|
||||
if ( !isset( $writers[$wkey] ) ) trigger_error( 'Unsupported DSN: '.$wkey );
|
||||
@ -10572,6 +10707,37 @@ class Facade
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the error mode for FUSE.
|
||||
* What to do if a FUSE model method does not exist?
|
||||
* You can set the following options:
|
||||
*
|
||||
* OODBBean::C_ERR_IGNORE (default), ignores the call, returns NULL
|
||||
* OODBBean::C_ERR_LOG, logs the incident using error_log
|
||||
* OODBBean::C_ERR_NOTICE, triggers a E_USER_NOTICE
|
||||
* OODBBean::C_ERR_WARN, triggers a E_USER_WARNING
|
||||
* OODBBean::C_ERR_EXCEPTION, throws an exception
|
||||
* OODBBean::C_ERR_FUNC, allows you to specify a custom handler (function)
|
||||
* OODBBean::C_ERR_FATAL, triggers a E_USER_ERROR
|
||||
*
|
||||
* Custom handler method signature: handler( array (
|
||||
* 'message' => string
|
||||
* 'bean' => OODBBean
|
||||
* 'method' => string
|
||||
* ) )
|
||||
*
|
||||
* This method returns the old mode and handler as an array.
|
||||
*
|
||||
* @param integer $mode mode
|
||||
* @param callable|NULL $func custom handler
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function setErrorHandlingFUSE( $mode, $func = NULL )
|
||||
{
|
||||
return OODBBean::setErrorHandlingFUSE( $mode, $func );
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple but effective debug function.
|
||||
@ -11051,7 +11217,7 @@ class DuplicationManager
|
||||
}
|
||||
}
|
||||
|
||||
$rs = $this->duplicate( clone( $bean ), $trail, $preserveIDs );
|
||||
$rs = $this->duplicate( ( clone $bean ), $trail, $preserveIDs );
|
||||
|
||||
if ( !$this->cacheTables ) {
|
||||
$this->tables = array();
|
||||
|
Reference in New Issue
Block a user