1
0
mirror of https://github.com/dg/dibi.git synced 2025-07-31 19:30:30 +02:00

some stuff is deprecated and throws E_USER_WARNING: dibi::datetime(), dibi::date(), dibi::addSubst(), dibi::removeSubst(), dibi::setSubstFallback(), DibiResult::rowCount(), DibiResult::getColumnNames(), DibiVariable

This commit is contained in:
David Grudl
2011-01-25 17:47:31 +01:00
parent 08099816d5
commit 0dc9db1d77
4 changed files with 18 additions and 23 deletions

View File

@@ -88,6 +88,7 @@ class DibiVariable extends DibiDateTime
function __construct($val)
{
parent::__construct($val);
trigger_error(__CLASS__ . ' is deprecated; use class DateTime instead.', E_USER_WARNING);
}
}
@@ -584,11 +585,12 @@ class dibi
/**
* @deprecated
* @return DibiDateTime
*/
public static function datetime($time = NULL)
{
return new DibiDateTime(is_numeric($time) ? date('Y-m-d H:i:s', $time) : $time);
trigger_error(__METHOD__ . '() is deprecated; create DibiDateTime object instead.', E_USER_WARNING);
return new DibiDateTime($time);
}
@@ -598,7 +600,8 @@ class dibi
*/
public static function date($date = NULL)
{
return new DibiDateTime(is_numeric($date) ? date('Y-m-d', $date) : $date);
trigger_error(__METHOD__ . '() is deprecated; create DibiDateTime object instead.', E_USER_WARNING);
return new DibiDateTime($date);
}
@@ -618,26 +621,19 @@ class dibi
/**
* Create a new substitution pair for indentifiers.
* @param string from
* @param string to
* @return void
*/
/** @deprecated */
public static function addSubst($expr, $subst)
{
trigger_error(__METHOD__ . '() is deprecated; use dibi::getSubstitutes()->expr = val; instead.', E_USER_WARNING);
self::getSubstitutes()->$expr = $subst;
}
/**
* Remove substitution pair.
* @param mixed from or TRUE
* @return void
*/
/** @deprecated */
public static function removeSubst($expr)
{
trigger_error(__METHOD__ . '() is deprecated; use unset(dibi::getSubstitutes()->expr) instead.', E_USER_WARNING);
$substitutes = self::getSubstitutes();
if ($expr === TRUE) {
foreach ($substitutes as $expr => $foo) {
@@ -650,13 +646,10 @@ class dibi
/**
* Sets substitution fallback handler.
* @param callback
* @return void
*/
/** @deprecated */
public static function setSubstFallback($callback)
{
trigger_error(__METHOD__ . '() is deprecated; use dibi::getSubstitutes()->setCallback() instead.', E_USER_WARNING);
self::getSubstitutes()->setCallback($callback);
}

View File

@@ -164,6 +164,7 @@ class DibiResult extends DibiObject implements IDataSource
*/
final public function rowCount()
{
trigger_error(__METHOD__ . '() is deprecated; use count($res) or $res->getRowCount() instead.', E_USER_WARNING);
return $this->getDriver()->getRowCount();
}
@@ -633,6 +634,7 @@ class DibiResult extends DibiObject implements IDataSource
*/
public function getColumnNames($fullNames = FALSE)
{
trigger_error(__METHOD__ . '() is deprecated; use $res->getInfo()->getColumnNames() instead.', E_USER_WARNING);
return $this->getInfo()->getColumnNames($fullNames);
}

View File

@@ -24,7 +24,7 @@ dibi::test('
SELECT COUNT(*) as [count]
FROM [comments]
WHERE [ip] LIKE %s', $ipMask, '
AND [date] > ', dibi::date($timestamp)
AND [date] > ', new DibiDateTime($timestamp)
);
// -> SELECT COUNT(*) as [count] FROM [comments] WHERE [ip] LIKE '192.168.%' AND [date] > 876693600

View File

@@ -17,7 +17,7 @@ dibi::connect(array(
// create new substitution :blog: ==> wp_
dibi::addSubst('blog', 'wp_');
dibi::getSubstitutes()->blog = 'wp_';
dibi::test("SELECT * FROM [:blog:items]");
// -> SELECT * FROM [wp_items]
@@ -27,7 +27,7 @@ dibi::test("SELECT * FROM [:blog:items]");
// create new substitution :: (empty) ==> my_
dibi::addSubst('', 'my_');
dibi::getSubstitutes()->{''} = 'my_';
dibi::test("UPDATE ::table SET [text]='Hello World'");
// -> UPDATE my_table SET [text]='Hello World'
@@ -48,7 +48,7 @@ function substFallBack($expr)
}
// define callback
dibi::setSubstFallBack('substFallBack');
dibi::getSubstitutes()->setCallback('substFallBack');
// define substitutes as constants
define('SUBST_ACCOUNT', 'eshop_');