Skip to content

Commit

Permalink
Merge branch 'master' of github.com:nette/dibi
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakub Vrana committed Apr 21, 2010
2 parents d7b312d + 550be3b commit 18455aa
Show file tree
Hide file tree
Showing 36 changed files with 1,694 additions and 1,422 deletions.
54 changes: 54 additions & 0 deletions dibi/Nette/DateTime53.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

/**
* Nette Framework
*
* @copyright Copyright (c) 2004, 2010 David Grudl
* @license http://nettephp.com/license Nette license
* @link http://nettephp.com
* @category Nette
* @package Nette
*/

// no namespace



/**
* DateTime with serialization and timestamp support for PHP 5.2.
*
* @copyright Copyright (c) 2004, 2010 David Grudl
* @package Nette
*/
class DateTime53 extends DateTime
{

public function __sleep()
{
$this->fix = array($this->format('Y-m-d H:i:s'), $this->getTimezone()->getName());
return array('fix');
}



public function __wakeup()
{
$this->__construct($this->fix[0], new DateTimeZone($this->fix[1]));
unset($this->fix);
}



public function getTimestamp()
{
return (int) $this->format('U');
}



public function setTimestamp($timestamp)
{
return $this->__construct(date('Y-m-d H:i:s', $timestamp), new DateTimeZone($this->getTimezone()->getName())); // getTimeZone() crashes in PHP 5.2.6
}

}
44 changes: 44 additions & 0 deletions dibi/Nette/IDebugPanel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

/**
* Nette Framework
*
* @copyright Copyright (c) 2004, 2010 David Grudl
* @license http://nettephp.com/license Nette license
* @link http://nettephp.com
* @category Nette
* @package Nette
*/

/*namespace Nette;*/



/**
* Custom output for Nette\Debug.
*
* @copyright Copyright (c) 2004, 2010 David Grudl
* @package Nette
*/
interface IDebugPanel
{

/**
* Renders HTML code for custom tab.
* @return void
*/
function getTab();

/**
* Renders HTML code for custom panel.
* @return void
*/
function getPanel();

/**
* Returns panel ID.
* @return string
*/
function getId();

}
40 changes: 0 additions & 40 deletions dibi/Nette/IDebuggable.php

This file was deleted.

93 changes: 41 additions & 52 deletions dibi/dibi.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
* dibi - tiny'n'smart database abstraction layer
* ----------------------------------------------
*
* Copyright (c) 2005, 2009 David Grudl (http://davidgrudl.com)
* Copyright (c) 2005, 2010 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.
* with this package in the file license.txt, and/or GPL license.
*
* For more information please see http://dibiphp.com
*
* @copyright Copyright (c) 2005, 2009 David Grudl
* @copyright Copyright (c) 2005, 2010 David Grudl
* @license http://dibiphp.com/license dibi license
* @link http://dibiphp.com
* @package dibi
Expand All @@ -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 @
Expand All @@ -33,33 +33,58 @@
* Compatibility with Nette
*/
if (!class_exists('NotImplementedException', FALSE)) {
/** @package exceptions */
class NotImplementedException extends LogicException {}
}

if (!class_exists('NotSupportedException', FALSE)) {
/** @package exceptions */
class NotSupportedException extends LogicException {}
}

if (!class_exists('MemberAccessException', FALSE)) {
/** @package exceptions */
class MemberAccessException extends LogicException {}
}

if (!class_exists('InvalidStateException', FALSE)) {
/** @package exceptions */
class InvalidStateException extends RuntimeException {}
}

if (!class_exists('IOException', FALSE)) {
/** @package exceptions */
class IOException extends RuntimeException {}
}

if (!class_exists('FileNotFoundException', FALSE)) {
/** @package exceptions */
class FileNotFoundException extends IOException {}
}

if (!interface_exists(/*Nette\*/'IDebuggable', FALSE)) {
require_once dirname(__FILE__) . '/Nette/IDebuggable.php';
if (!interface_exists(/*Nette\*/'IDebugPanel', FALSE)) {
require_once dirname(__FILE__) . '/Nette/IDebugPanel.php';
}

if (!class_exists('DateTime53', FALSE)) {
require_once dirname(__FILE__) . '/Nette/DateTime53.php';
}



/**
* @deprecated
*/
class DibiVariable extends DateTime53
{
function __construct($val)
{
parent::__construct($val);
}
}



// dibi libraries
require_once dirname(__FILE__) . '/libs/interfaces.php';
require_once dirname(__FILE__) . '/libs/DibiObject.php';
Expand All @@ -69,7 +94,6 @@ class FileNotFoundException extends IOException {}
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';
Expand All @@ -85,8 +109,7 @@ class FileNotFoundException extends IOException {}
* This class is static container class for creating DB objects and
* store connections info.
*
* @author David Grudl
* @copyright Copyright (c) 2005, 2009 David Grudl
* @copyright Copyright (c) 2005, 2010 David Grudl
* @package dibi
*/
class dibi
Expand Down Expand Up @@ -121,15 +144,15 @@ class dibi
/**#@+
* dibi version
*/
const VERSION = '1.2-dev';
const VERSION = '1.3-dev';
const REVISION = '$WCREV$ released on $WCDATE$';
/**#@-*/

/**#@+
* Configuration options
*/
const RESULT_WITH_TABLES = 'resultWithTables'; // for MySQL
const ROW_CLASS = 'rowClass';
const RESULT_DETECT_TYPES = 'resultDetectTypes';
const RESULT_DATE_TIME = 'resultDateTime';
const ASC = 'ASC', DESC = 'DESC';
/**#@-*/

Expand Down Expand Up @@ -597,36 +620,21 @@ public static function delete($table)


/**
* 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 DateTime53(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 DateTime53(is_numeric($date) ? date('Y-m-d', $date) : $date);
}


Expand Down Expand Up @@ -724,7 +732,7 @@ public static function dump($sql = NULL, $return = FALSE)

$sql = wordwrap($sql, 100);
$sql = htmlSpecialChars($sql);
$sql = preg_replace("#\n{2,}#", "\n", $sql);
$sql = preg_replace("#([ \t]*\r?\n){2,}#", "\n", $sql);

// syntax highlight
$sql = preg_replace_callback("#(/\\*.+?\\*/)|(\\*\\*.+?\\*\\*)|(?<=[\\s,(])($keywords1)(?=[\\s,)])|(?<=[\\s,(=])($keywords2)(?=[\\s,)=])#is", array('dibi', 'highlightCallback'), $sql);
Expand Down Expand Up @@ -756,23 +764,4 @@ private static function highlightCallback($matches)
return '<strong style="color:green">' . $matches[4] . '</strong>';
}



/**
* Returns brief descriptions.
* @return string
* @return array
*/
public static function getColophon($sender = NULL)
{
$arr = array(
'Number of SQL queries: ' . dibi::$numOfQueries
. (dibi::$totalTime === NULL ? '' : ', elapsed time: ' . sprintf('%0.3f', dibi::$totalTime * 1000) . ' ms'),
);
if ($sender === 'bluescreen') {
$arr[] = 'dibi ' . dibi::VERSION . ' (revision ' . dibi::REVISION . ')';
}
return $arr;
}

}
Loading

0 comments on commit 18455aa

Please sign in to comment.