[limb-svn] r6367 - in 3.x/trunk/limb/dbal/src: . toolkit
svn at limb-project.com
svn at limb-project.com
Wed Oct 3 03:02:58 MSD 2007
Author: pachanga
Date: 2007-10-03 03:02:58 +0400 (Wed, 03 Oct 2007)
New Revision: 6367
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6367
Modified:
3.x/trunk/limb/dbal/src/lmbDBAL.class.php
3.x/trunk/limb/dbal/src/toolkit/lmbDbTools.class.php
Log:
-- more efficient factory class existence check
Modified: 3.x/trunk/limb/dbal/src/lmbDBAL.class.php
===================================================================
--- 3.x/trunk/limb/dbal/src/lmbDBAL.class.php 2007-10-02 22:13:23 UTC (rev 6366)
+++ 3.x/trunk/limb/dbal/src/lmbDBAL.class.php 2007-10-02 23:02:58 UTC (rev 6367)
@@ -1,94 +1,94 @@
-<?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com
- * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
- * @license LGPL http://www.gnu.org/copyleft/lesser.html
- */
-lmb_require('limb/dbal/toolkit.inc.php');
-lmb_require('limb/dbal/src/lmbSimpleDb.class.php');
-lmb_require('limb/dbal/src/query/lmbSelectQuery.class.php');
-lmb_require('limb/dbal/src/query/lmbUpdateQuery.class.php');
-lmb_require('limb/dbal/src/query/lmbDeleteQuery.class.php');
-
-/**
- * class lmbDBAL.
- *
- * @package dbal
- * @version $Id$
- */
-class lmbDBAL
-{
- static function setDefaultDSN($dsn)
- {
- lmbToolkit :: instance()->setDefaultDbDSN($dsn);
- }
-
- static function setEnvironment($env)
- {
- lmbToolkit :: instance()->setDbEnvironment($env);
- }
-
- static function newConnection($dsn)
- {
- return lmbToolkit :: instance()->createDbConnection($dsn);
- }
-
- static function defaultConnection()
- {
- return lmbToolkit :: instance()->getDefaultDbConnection();
- }
-
- static function newStatement($sql, $conn = null)
- {
- if(!$conn)
- $conn = lmbToolkit :: instance()->getDefaultDbConnection();
- return $conn->newStatement($sql);
- }
-
- static function db($conn = null)
- {
- if(!$conn)
- $conn = lmbToolkit :: instance()->getDefaultDbConnection();
-
- return new lmbSimpleDb($conn);
- }
-
- static function table($table, $conn = null)
- {
- return lmbToolkit :: instance()->createTableGateway($table, $conn);
- }
-
- static function selectQuery($table, $conn = null)
- {
- return new lmbSelectQuery($table, $conn);
- }
-
- static function updateQuery($table, $conn = null)
- {
- return new lmbUpdateQuery($table, $conn);
- }
-
- static function deleteQuery($table, $conn = null)
- {
- return new lmbDeleteQuery($table, $conn);
- }
-
- static function fetch($sql, $conn = null)
- {
- if(!$conn)
- $conn = lmbToolkit :: instance()->getDefaultDbConnection();
- $stmt = $conn->newStatement($sql);
- return $stmt->getRecordSet();
- }
-
- static function execute($sql, $conn = null)
- {
- if(!$conn)
- $conn = lmbToolkit :: instance()->getDefaultDbConnection();
- $conn->execute($sql);
- }
-}
-
-
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+lmb_require('limb/dbal/toolkit.inc.php');
+lmb_require('limb/dbal/src/lmbSimpleDb.class.php');
+lmb_require('limb/dbal/src/query/lmbSelectQuery.class.php');
+lmb_require('limb/dbal/src/query/lmbUpdateQuery.class.php');
+lmb_require('limb/dbal/src/query/lmbDeleteQuery.class.php');
+
+/**
+ * class lmbDBAL.
+ *
+ * @package dbal
+ * @version $Id$
+ */
+class lmbDBAL
+{
+ static function setDefaultDSN($dsn)
+ {
+ lmbToolkit :: instance()->setDefaultDbDSN($dsn);
+ }
+
+ static function setEnvironment($env)
+ {
+ lmbToolkit :: instance()->setDbEnvironment($env);
+ }
+
+ static function newConnection($dsn)
+ {
+ return lmbToolkit :: instance()->createDbConnection($dsn);
+ }
+
+ static function defaultConnection()
+ {
+ return lmbToolkit :: instance()->getDefaultDbConnection();
+ }
+
+ static function newStatement($sql, $conn = null)
+ {
+ if(!$conn)
+ $conn = lmbToolkit :: instance()->getDefaultDbConnection();
+ return $conn->newStatement($sql);
+ }
+
+ static function db($conn = null)
+ {
+ if(!$conn)
+ $conn = lmbToolkit :: instance()->getDefaultDbConnection();
+
+ return new lmbSimpleDb($conn);
+ }
+
+ static function table($table, $conn = null)
+ {
+ return lmbToolkit :: instance()->createTableGateway($table, $conn);
+ }
+
+ static function selectQuery($table, $conn = null)
+ {
+ return new lmbSelectQuery($table, $conn);
+ }
+
+ static function updateQuery($table, $conn = null)
+ {
+ return new lmbUpdateQuery($table, $conn);
+ }
+
+ static function deleteQuery($table, $conn = null)
+ {
+ return new lmbDeleteQuery($table, $conn);
+ }
+
+ static function fetch($sql, $conn = null)
+ {
+ if(!$conn)
+ $conn = lmbToolkit :: instance()->getDefaultDbConnection();
+ $stmt = $conn->newStatement($sql);
+ return $stmt->getRecordSet();
+ }
+
+ static function execute($sql, $conn = null)
+ {
+ if(!$conn)
+ $conn = lmbToolkit :: instance()->getDefaultDbConnection();
+ $conn->execute($sql);
+ }
+}
+
+
Modified: 3.x/trunk/limb/dbal/src/toolkit/lmbDbTools.class.php
===================================================================
--- 3.x/trunk/limb/dbal/src/toolkit/lmbDbTools.class.php 2007-10-02 22:13:23 UTC (rev 6366)
+++ 3.x/trunk/limb/dbal/src/toolkit/lmbDbTools.class.php 2007-10-02 23:02:58 UTC (rev 6367)
@@ -1,150 +1,154 @@
-<?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com
- * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
- * @license LGPL http://www.gnu.org/copyleft/lesser.html
- */
-lmb_require('limb/toolkit/src/lmbAbstractTools.class.php');
-lmb_require('limb/dbal/src/lmbDBAL.class.php');
-lmb_require('limb/dbal/src/lmbDbDSN.class.php');
-lmb_require('limb/dbal/src/drivers/lmbDbCachedInfo.class.php');
-lmb_require('limb/dbal/src/lmbTableGateway.class.php');
-
-/**
- * class lmbDbTools.
- *
- * @package dbal
- * @version $Id$
- */
-class lmbDbTools extends lmbAbstractTools
-{
- protected $default_connection;
- protected $default_db_config;
- protected $cache_db_info = true;
- protected $db_info = array();
- protected $db_tables = array();
- protected $db_env = 'devel';
-
- function setDbEnvironment($env)
- {
- $this->db_env = $env;
- $this->default_db_config = null;
- $this->default_connection = null;
- }
-
- function getDbEnvironment()
- {
- return $this->db_env;
- }
-
- function setDefaultDbDSN($conf)
- {
- if(is_object($conf))
- $this->default_db_config = $conf;
- else
- $this->default_db_config = new lmbDbDSN($conf);
- }
-
- function getDefaultDbDSN()
- {
- if(is_object($this->default_db_config))
- return $this->default_db_config;
-
- $conf = $this->toolkit->getConf('db');
-
- //for BC 'dsn' overrides other db environments
- if($dsn = $conf->get('dsn'))
- {
- $this->default_db_config = new lmbDbDSN($dsn);
- }
- else
- {
- $env = $conf->get($this->db_env);
- if(!is_array($env) || !isset($env['dsn']))
- throw new lmbException("Could not find database connection settings for environment '{$this->db_env}'");
-
- $this->default_db_config = new lmbDbDSN($env['dsn']);
- }
-
- return $this->default_db_config;
- }
-
- function getDbDSN($env)
- {
- $conf = $this->toolkit->getConf('db');
- $array = $conf->get($env);
-
- if(!is_array($array) || !isset($array['dsn']))
- throw new lmbException("Could not find database connection settings for environment '{$env}'");
-
- return new lmbDbDSN($array['dsn']);
- }
-
- function getDefaultDbConnection()
- {
- if(is_object($this->default_connection))
- return $this->default_connection;
-
- if(!is_object($dsn = $this->toolkit->getDefaultDbDSN()))
- throw new lmbException('Default database DSN is not valid');
-
- $this->default_connection = $this->toolkit->createDbConnection($dsn);
- return $this->default_connection;
- }
-
- function createDbConnection($dsn)
- {
- $driver = $dsn->getDriver();
- $class = 'lmb' . ucfirst($driver) . 'Connection';
- $file = dirname(__FILE__) . '/../drivers/' . $driver . '/' . $class . '.class.php';
- if(!file_exists($file))
- throw new lmbException("Driver '$driver' file not found for DSN '" . $dsn->toString() . "'!");
-
- lmb_require($file);
- return new $class($dsn);
- }
-
- function cacheDbInfo($flag = true)
- {
- $this->cache_db_info = $flag;
- }
-
- function getDbInfo($conn)
- {
- $id = $conn->getHash();
-
- if(isset($this->db_info[$id]))
- return $this->db_info[$id];
-
- if($this->cache_db_info && defined('LIMB_VAR_DIR'))
- $db_info = new lmbDbCachedInfo($conn, LIMB_VAR_DIR);
- else
- $db_info = $conn->getDatabaseInfo();
-
- $this->db_info[$id] = $db_info;
- return $this->db_info[$id];
- }
-
- function setDefaultDbConnection($conn)
- {
- $this->default_connection = $conn;
- }
-
- function createTableGateway($table_name, $conn = null)
- {
- if(!$conn)
- $cache_key = $table_name;
- else
- $cache_key = $table_name . $conn->getHash();
-
- if(isset($this->db_tables[$cache_key]))
- return $this->db_tables[$cache_key];
-
- $db_table = new lmbTableGateway($table_name, $conn);
- $this->db_tables[$cache_key] = $db_table;
- return $db_table;
- }
-}
-
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+lmb_require('limb/toolkit/src/lmbAbstractTools.class.php');
+lmb_require('limb/dbal/src/lmbDBAL.class.php');
+lmb_require('limb/dbal/src/lmbDbDSN.class.php');
+lmb_require('limb/dbal/src/drivers/lmbDbCachedInfo.class.php');
+lmb_require('limb/dbal/src/lmbTableGateway.class.php');
+
+/**
+ * class lmbDbTools.
+ *
+ * @package dbal
+ * @version $Id$
+ */
+class lmbDbTools extends lmbAbstractTools
+{
+ protected $default_connection;
+ protected $default_db_config;
+ protected $cache_db_info = true;
+ protected $db_info = array();
+ protected $db_tables = array();
+ protected $db_env = 'devel';
+
+ function setDbEnvironment($env)
+ {
+ $this->db_env = $env;
+ $this->default_db_config = null;
+ $this->default_connection = null;
+ }
+
+ function getDbEnvironment()
+ {
+ return $this->db_env;
+ }
+
+ function setDefaultDbDSN($conf)
+ {
+ if(is_object($conf))
+ $this->default_db_config = $conf;
+ else
+ $this->default_db_config = new lmbDbDSN($conf);
+ }
+
+ function getDefaultDbDSN()
+ {
+ if(is_object($this->default_db_config))
+ return $this->default_db_config;
+
+ $conf = $this->toolkit->getConf('db');
+
+ //for BC 'dsn' overrides other db environments
+ if($dsn = $conf->get('dsn'))
+ {
+ $this->default_db_config = new lmbDbDSN($dsn);
+ }
+ else
+ {
+ $env = $conf->get($this->db_env);
+ if(!is_array($env) || !isset($env['dsn']))
+ throw new lmbException("Could not find database connection settings for environment '{$this->db_env}'");
+
+ $this->default_db_config = new lmbDbDSN($env['dsn']);
+ }
+
+ return $this->default_db_config;
+ }
+
+ function getDbDSN($env)
+ {
+ $conf = $this->toolkit->getConf('db');
+ $array = $conf->get($env);
+
+ if(!is_array($array) || !isset($array['dsn']))
+ throw new lmbException("Could not find database connection settings for environment '{$env}'");
+
+ return new lmbDbDSN($array['dsn']);
+ }
+
+ function getDefaultDbConnection()
+ {
+ if(is_object($this->default_connection))
+ return $this->default_connection;
+
+ if(!is_object($dsn = $this->toolkit->getDefaultDbDSN()))
+ throw new lmbException('Default database DSN is not valid');
+
+ $this->default_connection = $this->toolkit->createDbConnection($dsn);
+ return $this->default_connection;
+ }
+
+ function createDbConnection($dsn)
+ {
+ $driver = $dsn->getDriver();
+ $class = 'lmb' . ucfirst($driver) . 'Connection';
+
+ if(!class_exists($class))
+ {
+ $file = dirname(__FILE__) . '/../drivers/' . $driver . '/' . $class . '.class.php';
+ if(!file_exists($file))
+ throw new lmbException("Driver '$driver' file not found for DSN '" . $dsn->toString() . "'!");
+
+ lmb_require($file);
+ }
+ return new $class($dsn);
+ }
+
+ function cacheDbInfo($flag = true)
+ {
+ $this->cache_db_info = $flag;
+ }
+
+ function getDbInfo($conn)
+ {
+ $id = $conn->getHash();
+
+ if(isset($this->db_info[$id]))
+ return $this->db_info[$id];
+
+ if($this->cache_db_info && defined('LIMB_VAR_DIR'))
+ $db_info = new lmbDbCachedInfo($conn, LIMB_VAR_DIR);
+ else
+ $db_info = $conn->getDatabaseInfo();
+
+ $this->db_info[$id] = $db_info;
+ return $this->db_info[$id];
+ }
+
+ function setDefaultDbConnection($conn)
+ {
+ $this->default_connection = $conn;
+ }
+
+ function createTableGateway($table_name, $conn = null)
+ {
+ if(!$conn)
+ $cache_key = $table_name;
+ else
+ $cache_key = $table_name . $conn->getHash();
+
+ if(isset($this->db_tables[$cache_key]))
+ return $this->db_tables[$cache_key];
+
+ $db_table = new lmbTableGateway($table_name, $conn);
+ $this->db_tables[$cache_key] = $db_table;
+ return $db_table;
+ }
+}
+
More information about the limb-svn
mailing list