diff --git a/dibi/dibi.php b/dibi/dibi.php index f9af1b60..50a82bff 100644 --- a/dibi/dibi.php +++ b/dibi/dibi.php @@ -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); } diff --git a/dibi/libs/DibiResult.php b/dibi/libs/DibiResult.php index 8d805280..903bfe43 100644 --- a/dibi/libs/DibiResult.php +++ b/dibi/libs/DibiResult.php @@ -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: diff --git a/dibi/libs/DibiRow.php b/dibi/libs/DibiRow.php index 56a5febe..36985676 100644 --- a/dibi/libs/DibiRow.php +++ b/dibi/libs/DibiRow.php @@ -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)); } } diff --git a/dibi/libs/DibiTranslator.php b/dibi/libs/DibiTranslator.php index 4c998ab2..4f9a549a 100644 --- a/dibi/libs/DibiTranslator.php +++ b/dibi/libs/DibiTranslator.php @@ -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); diff --git a/dibi/libs/DibiVariable.php b/dibi/libs/DibiVariable.php deleted file mode 100644 index c32eecab..00000000 --- a/dibi/libs/DibiVariable.php +++ /dev/null @@ -1,48 +0,0 @@ -value = $value; - $this->modifier = $modifier; - } - - - - public function toSql(DibiTranslator $translator, $modifier) - { - return $translator->formatValue($this->value, $this->modifier); - } - -} \ No newline at end of file diff --git a/dibi/libs/interfaces.php b/dibi/libs/interfaces.php index 1b31bfdf..165996aa 100644 --- a/dibi/libs/interfaces.php +++ b/dibi/libs/interfaces.php @@ -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 diff --git a/examples/datetime.demo.php b/examples/datetime.demo.php deleted file mode 100644 index d50c61ee..00000000 --- a/examples/datetime.demo.php +++ /dev/null @@ -1,28 +0,0 @@ -