mirror of
https://github.com/dg/dibi.git
synced 2025-08-06 14:16:39 +02:00
removed PHP 5.1 support; removed DibiVariable & IDibiVariable
This commit is contained in:
@@ -21,8 +21,8 @@
|
||||
/**
|
||||
* Check PHP configuration.
|
||||
*/
|
||||
if (version_compare(PHP_VERSION, '5.1.0', '<')) {
|
||||
throw new Exception('dibi needs PHP 5.1.0 or newer.');
|
||||
if (version_compare(PHP_VERSION, '5.2.0', '<')) {
|
||||
throw new Exception('dibi needs PHP 5.2.0 or newer.');
|
||||
}
|
||||
|
||||
@set_magic_quotes_runtime(FALSE); // intentionally @
|
||||
@@ -60,6 +60,21 @@ if (!interface_exists(/*Nette\*/'IDebuggable', FALSE)) {
|
||||
require_once dirname(__FILE__) . '/Nette/IDebuggable.php';
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Back-compatibility
|
||||
*/
|
||||
class DibiVariable extends DateTime
|
||||
{
|
||||
function __construct($val)
|
||||
{
|
||||
parent::__construct($val);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// dibi libraries
|
||||
require_once dirname(__FILE__) . '/libs/interfaces.php';
|
||||
require_once dirname(__FILE__) . '/libs/DibiObject.php';
|
||||
@@ -69,7 +84,6 @@ require_once dirname(__FILE__) . '/libs/DibiResult.php';
|
||||
require_once dirname(__FILE__) . '/libs/DibiResultIterator.php';
|
||||
require_once dirname(__FILE__) . '/libs/DibiRow.php';
|
||||
require_once dirname(__FILE__) . '/libs/DibiTranslator.php';
|
||||
require_once dirname(__FILE__) . '/libs/DibiVariable.php';
|
||||
require_once dirname(__FILE__) . '/libs/DibiDataSource.php';
|
||||
require_once dirname(__FILE__) . '/libs/DibiFluent.php';
|
||||
require_once dirname(__FILE__) . '/libs/DibiDatabaseInfo.php';
|
||||
@@ -570,36 +584,21 @@ class dibi
|
||||
|
||||
|
||||
/**
|
||||
* Pseudotype for timestamp representation.
|
||||
* @param mixed datetime
|
||||
* @return DibiVariable
|
||||
* @deprecated
|
||||
*/
|
||||
public static function datetime($time = NULL)
|
||||
{
|
||||
if ($time === NULL) {
|
||||
$time = time(); // current time
|
||||
|
||||
} elseif (is_numeric($time)) {
|
||||
$time = (int) $time; // timestamp
|
||||
|
||||
} elseif (is_string($time)) {
|
||||
$time = class_exists('DateTime', FALSE) ? new DateTime($time) : strtotime($time); // DateTime is since PHP 5.2
|
||||
}
|
||||
return new DibiVariable($time, dibi::DATETIME);
|
||||
return new DateTime(is_numeric($time) ? date('Y-m-d H:i:s', $time) : $time);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Pseudotype for date representation.
|
||||
* @param mixed date
|
||||
* @return DibiVariable
|
||||
* @deprecated
|
||||
*/
|
||||
public static function date($date = NULL)
|
||||
{
|
||||
$var = self::datetime($date);
|
||||
$var->modifier = dibi::DATE;
|
||||
return $var;
|
||||
return new DateTime(is_numeric($date) ? date('Y-m-d', $date) : $date);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -636,12 +636,9 @@ class DibiResult extends DibiObject implements IDataSource
|
||||
} elseif (is_numeric($value)) { // single timestamp
|
||||
return date($format, $value);
|
||||
|
||||
} elseif (class_exists('DateTime', FALSE)) { // since PHP 5.2
|
||||
} else {
|
||||
$value = new DateTime($value);
|
||||
return $value->format($format);
|
||||
|
||||
} else {
|
||||
return date($format, strtotime($value));
|
||||
}
|
||||
|
||||
case dibi::BOOL:
|
||||
|
@@ -60,12 +60,9 @@ class DibiRow extends ArrayObject
|
||||
} elseif (is_numeric($time)) { // single timestamp
|
||||
return date($format, $time);
|
||||
|
||||
} elseif (class_exists('DateTime', FALSE)) { // since PHP 5.2
|
||||
} else {
|
||||
$time = new DateTime($time);
|
||||
return $time->format($format);
|
||||
|
||||
} else {
|
||||
return date($format, strtotime($time));
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -326,10 +326,7 @@ final class DibiTranslator extends DibiObject
|
||||
|
||||
// with modifier procession
|
||||
if ($modifier) {
|
||||
if ($value instanceof IDibiVariable) {
|
||||
return $value->toSql($this, $modifier);
|
||||
|
||||
} elseif ($value !== NULL && !is_scalar($value) && !($value instanceof DateTime)) { // array is already processed
|
||||
if ($value !== NULL && !is_scalar($value) && !($value instanceof DateTime)) { // array is already processed
|
||||
$this->hasError = TRUE;
|
||||
return '**Unexpected type ' . gettype($value) . '**';
|
||||
}
|
||||
@@ -373,7 +370,7 @@ final class DibiTranslator extends DibiObject
|
||||
$value = (int) $value; // timestamp
|
||||
|
||||
} elseif (is_string($value)) {
|
||||
$value = class_exists('DateTime', FALSE) ? new DateTime($value) : strtotime($value);
|
||||
$value = new DateTime($value);
|
||||
}
|
||||
return $this->driver->escape($value, $modifier);
|
||||
}
|
||||
@@ -429,9 +426,6 @@ final class DibiTranslator extends DibiObject
|
||||
} elseif ($value === NULL) {
|
||||
return 'NULL';
|
||||
|
||||
} elseif ($value instanceof IDibiVariable) {
|
||||
return $value->toSql($this, NULL);
|
||||
|
||||
} elseif ($value instanceof DateTime) {
|
||||
return $this->driver->escape($value, dibi::DATETIME);
|
||||
|
||||
|
@@ -1,48 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* dibi - tiny'n'smart database abstraction layer
|
||||
* ----------------------------------------------
|
||||
*
|
||||
* Copyright (c) 2005, 2009 David Grudl (http://davidgrudl.com)
|
||||
*
|
||||
* This source file is subject to the "dibi license" that is bundled
|
||||
* with this package in the file license.txt.
|
||||
*
|
||||
* For more information please see http://dibiphp.com
|
||||
*
|
||||
* @copyright Copyright (c) 2005, 2009 David Grudl
|
||||
* @license http://dibiphp.com/license dibi license
|
||||
* @link http://dibiphp.com
|
||||
* @package dibi
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Default implemenation of IDibiVariable.
|
||||
* @package dibi
|
||||
*/
|
||||
class DibiVariable extends DibiObject implements IDibiVariable
|
||||
{
|
||||
/** @var mixed */
|
||||
public $value;
|
||||
|
||||
/** @var string */
|
||||
public $modifier;
|
||||
|
||||
|
||||
public function __construct($value, $modifier)
|
||||
{
|
||||
$this->value = $value;
|
||||
$this->modifier = $modifier;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function toSql(DibiTranslator $translator, $modifier)
|
||||
{
|
||||
return $translator->formatValue($this->value, $this->modifier);
|
||||
}
|
||||
|
||||
}
|
@@ -19,25 +19,6 @@
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Interface for user variable, used for generating SQL.
|
||||
* @package dibi
|
||||
*/
|
||||
interface IDibiVariable
|
||||
{
|
||||
/**
|
||||
* Format for SQL.
|
||||
* @param DibiTranslator
|
||||
* @param string optional modifier
|
||||
* @return string SQL code
|
||||
*/
|
||||
function toSql(DibiTranslator $translator, $modifier);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Provides an interface between a dataset and data-aware components.
|
||||
* @package dibi
|
||||
|
@@ -1,28 +0,0 @@
|
||||
<h1>IDibiVariable example</h1>
|
||||
<?php
|
||||
|
||||
require_once 'Nette/Debug.php';
|
||||
require_once '../dibi/dibi.php';
|
||||
|
||||
date_default_timezone_set('Europe/Prague');
|
||||
|
||||
|
||||
|
||||
// CHANGE TO REAL PARAMETERS!
|
||||
dibi::connect(array(
|
||||
'driver' => 'sqlite',
|
||||
'database' => 'sample.sdb',
|
||||
'formatDate' => "'Y-m-d'",
|
||||
'formatDateTime' => "'Y-m-d H-i-s'",
|
||||
));
|
||||
|
||||
|
||||
|
||||
// generate and dump SQL
|
||||
dibi::test("
|
||||
INSERT INTO [mytable]", array(
|
||||
'id' => 123,
|
||||
'date' => dibi::date('12.3.2007'),
|
||||
'stamp' => dibi::dateTime('23.1.2007 10:23'),
|
||||
));
|
||||
// -> INSERT INTO [mytable] ([id], [date], [stamp]) VALUES (123, '2007-03-12', '2007-01-23 10-23-00')
|
@@ -33,7 +33,7 @@ $array = array(
|
||||
'title' => 'Super Product',
|
||||
'price' => 12,
|
||||
'brand' => NULL,
|
||||
'created' => dibi::datetime(),
|
||||
'created' => new DateTime,
|
||||
);
|
||||
dibi::test("INSERT INTO [products]", $array, $array, $array);
|
||||
// -> INSERT INTO [products] ([title], [price], [brand], [created]) VALUES ('Super Product', ...) , (...) , (...)
|
||||
|
Reference in New Issue
Block a user