Created
May 29, 2011 11:20
-
-
Save komapa/997663 to your computer and use it in GitHub Desktop.
Propel runtime phpDoc optimisations - connection/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: connection/DebugPDO.php | |
=================================================================== | |
--- connection/DebugPDO.php (revision 2294) | |
+++ connection/DebugPDO.php (working copy) | |
@@ -13,90 +13,90 @@ | |
* | |
* This class is ONLY intended for development use. This class is also a work in-progress | |
* and, as such, it should be expected that this class' API may change. | |
- * | |
+ * | |
* The following runtime configuration items affect the behaviour of this class: | |
- * | |
+ * | |
* - debugpdo.logging.enabled (default: true) | |
* Should any logging take place | |
- * | |
+ * | |
* - debugpdo.logging.innerglue (default: ": ") | |
* String to use for combining the title of a detail and its value | |
- * | |
+ * | |
* - debugpdo.logging.outerglue (default: " | ") | |
* String to use for combining details together on a log line | |
- * | |
+ * | |
* - debugpdo.logging.realmemoryusage (default: false) | |
- * Parameter to memory_get_usage() and memory_get_peak_usage() calls | |
- * | |
+ * Parameter to memory_get_usage() and memory_get_peak_usage() calls | |
+ * | |
* - debugpdo.logging.methods (default: DebugPDO::$defaultLogMethods) | |
* An array of method names ("Class::method") to be included in method call logging | |
- * | |
+ * | |
* - debugpdo.logging.onlyslow (default: false) | |
* Suppress logging of non-slow queries. | |
- * | |
+ * | |
* - debugpdo.logging.details.slow.enabled (default: false) | |
* Enables flagging of slow method calls | |
- * | |
+ * | |
* - debugpdo.logging.details.slow.threshold (default: 0.1) | |
- * Method calls taking more seconds than this threshold are considered slow | |
- * | |
+ * Method calls taking more seconds than this threshold are considered slow | |
+ * | |
* - debugpdo.logging.details.time.enabled (default: false) | |
* Enables logging of method execution times | |
- * | |
+ * | |
* - debugpdo.logging.details.time.precision (default: 3) | |
* Determines the precision of the execution time logging | |
- * | |
+ * | |
* - debugpdo.logging.details.time.pad (default: 10) | |
* How much horizontal space to reserve for the execution time on a log line | |
- * | |
+ * | |
* - debugpdo.logging.details.mem.enabled (default: false) | |
* Enables logging of the instantaneous PHP memory consumption | |
- * | |
+ * | |
* - debugpdo.logging.details.mem.precision (default: 1) | |
* Determines the precision of the memory consumption logging | |
- * | |
+ * | |
* - debugpdo.logging.details.mem.pad (default: 9) | |
* How much horizontal space to reserve for the memory consumption on a log line | |
- * | |
+ * | |
* - debugpdo.logging.details.memdelta.enabled (default: false) | |
* Enables logging differences in memory consumption before and after the method call | |
- * | |
+ * | |
* - debugpdo.logging.details.memdelta.precision (default: 1) | |
* Determines the precision of the memory difference logging | |
- * | |
+ * | |
* - debugpdo.logging.details.memdelta.pad (default: 10) | |
* How much horizontal space to reserve for the memory difference on a log line | |
- * | |
+ * | |
* - debugpdo.logging.details.mempeak.enabled (default: false) | |
* Enables logging the peak memory consumption thus far by the currently executing PHP script | |
- * | |
+ * | |
* - debugpdo.logging.details.mempeak.precision (default: 1) | |
* Determines the precision of the memory peak logging | |
- * | |
+ * | |
* - debugpdo.logging.details.mempeak.pad (default: 9) | |
* How much horizontal space to reserve for the memory peak on a log line | |
- * | |
+ * | |
* - debugpdo.logging.details.querycount.enabled (default: false) | |
* Enables logging of the number of queries performed by the DebugPDO instance thus far | |
- * | |
+ * | |
* - debugpdo.logging.details.querycount.pad (default: 2) | |
* How much horizontal space to reserve for the query count on a log line | |
- * | |
+ * | |
* - debugpdo.logging.details.method.enabled (default: false) | |
* Enables logging of the name of the method call | |
- * | |
+ * | |
* - debugpdo.logging.details.method.pad (default: 28) | |
* How much horizontal space to reserve for the method name on a log line | |
- * | |
+ * | |
* The order in which the logging details are enabled is significant, since it determines the order in | |
* which they will appear in the log file. | |
- * | |
+ * | |
* @example // Enable simple query profiling, flagging calls taking over 1.5 seconds as slow: | |
* $config = Propel::getConfiguration(PropelConfiguration::TYPE_OBJECT); | |
* $config->setParameter('debugpdo.logging.details.slow.enabled', true); | |
* $config->setParameter('debugpdo.logging.details.slow.threshold', 1.5); | |
* $config->setParameter('debugpdo.logging.details.time.enabled', true); | |
- * | |
+ * | |
* @author Francois Zaninotto | |
* @author Cameron Brunner <[email protected]> | |
* @author Hans Lellelid <[email protected]> | |
@@ -107,5 +107,8 @@ | |
*/ | |
class DebugPDO extends PropelPDO | |
{ | |
- public $useDebug = true; | |
+ /** | |
+ * @var boolean | |
+ */ | |
+ public $useDebug = true; | |
} | |
Index: connection/DebugPDOStatement.php | |
=================================================================== | |
--- connection/DebugPDOStatement.php (revision 2294) | |
+++ connection/DebugPDOStatement.php (working copy) | |
@@ -20,21 +20,19 @@ | |
*/ | |
class DebugPDOStatement extends PDOStatement | |
{ | |
- | |
/** | |
* The PDO connection from which this instance was created. | |
- * | |
- * @var PropelPDO | |
+ * | |
+ * @var PropelPDO | |
*/ | |
protected $pdo; | |
- | |
+ | |
/** | |
* Hashmap for resolving the PDO::PARAM_* class constants to their human-readable names. | |
- * | |
* This is only used in logging the binding of variables. | |
- * | |
- * @see self::bindValue() | |
- * @var array | |
+ * | |
+ * @see self::bindValue() | |
+ * @var array | |
*/ | |
protected static $typeMap = array( | |
PDO::PARAM_BOOL => "PDO::PARAM_BOOL", | |
@@ -44,22 +42,26 @@ | |
PDO::PARAM_NULL => "PDO::PARAM_NULL", | |
); | |
- /** | |
- * @var array The values that have been bound | |
- */ | |
- protected $boundValues = array(); | |
+ /** | |
+ * @var array The values that have been bound | |
+ */ | |
+ protected $boundValues = array(); | |
/** | |
* Construct a new statement class with reference to main DebugPDO object from | |
* which this instance was created. | |
- * | |
- * @param DebugPDO $pdo Reference to the parent PDO instance. | |
+ * | |
+ * @param PropelPDO $pdo Reference to the parent PDO instance. | |
+ * @return DebugPDOStatement | |
*/ | |
protected function __construct(PropelPDO $pdo) | |
{ | |
$this->pdo = $pdo; | |
} | |
+ /** | |
+ * @return string | |
+ */ | |
public function getExecutedQueryString() | |
{ | |
$sql = $this->queryString; | |
@@ -71,38 +73,39 @@ | |
$sql = str_replace($pos, $this->boundValues[$pos], $sql); | |
} | |
} | |
- | |
+ | |
return $sql; | |
} | |
/** | |
* Executes a prepared statement. Returns a boolean value indicating success. | |
- * | |
* Overridden for query counting and logging. | |
- * | |
- * @return bool | |
+ * | |
+ * @param string $input_parameters | |
+ * @return boolean | |
*/ | |
public function execute($input_parameters = null) | |
{ | |
$debug = $this->pdo->getDebugSnapshot(); | |
$return = parent::execute($input_parameters); | |
- | |
+ | |
$sql = $this->getExecutedQueryString(); | |
$this->pdo->log($sql, null, __METHOD__, $debug); | |
$this->pdo->setLastExecutedQuery($sql); | |
$this->pdo->incrementQueryCount(); | |
- | |
+ | |
return $return; | |
} | |
/** | |
* Binds a value to a corresponding named or question mark placeholder in the SQL statement | |
- * that was use to prepare the statement. Returns a boolean value indicating success. | |
+ * that was use to prepare the statement. Returns a boolean value indicating success. | |
* | |
- * @param int $pos Parameter identifier (for determining what to replace in the query). | |
- * @param mixed $value The value to bind to the parameter. | |
- * @param int $type Explicit data type for the parameter using the PDO::PARAM_* constants. Defaults to PDO::PARAM_STR. | |
- * @return boolean | |
+ * @param integer $pos Parameter identifier (for determining what to replace in the query). | |
+ * @param mixed $value The value to bind to the parameter. | |
+ * @param integer $type Explicit data type for the parameter using the PDO::PARAM_* constants. Defaults to PDO::PARAM_STR. | |
+ * | |
+ * @return boolean | |
*/ | |
public function bindValue($pos, $value, $type = PDO::PARAM_STR) | |
{ | |
@@ -113,9 +116,9 @@ | |
$msg = sprintf('Binding %s at position %s w/ PDO type %s', $valuestr, $pos, $typestr); | |
$this->boundValues[$pos] = $valuestr; | |
- | |
+ | |
$this->pdo->log($msg, null, __METHOD__, $debug); | |
- | |
+ | |
return $return; | |
} | |
@@ -125,11 +128,13 @@ | |
* as a reference and will only be evaluated at the time that PDOStatement::execute() is called. | |
* Returns a boolean value indicating success. | |
* | |
- * @param int $pos Parameter identifier (for determining what to replace in the query). | |
- * @param mixed $value The value to bind to the parameter. | |
- * @param int $type Explicit data type for the parameter using the PDO::PARAM_* constants. Defaults to PDO::PARAM_STR. | |
- * @param int $length Length of the data type. To indicate that a parameter is an OUT parameter from a stored procedure, you must explicitly set the length. | |
- * @return boolean | |
+ * @param integer $pos Parameter identifier (for determining what to replace in the query). | |
+ * @param mixed $value The value to bind to the parameter. | |
+ * @param integer $type Explicit data type for the parameter using the PDO::PARAM_* constants. Defaults to PDO::PARAM_STR. | |
+ * @param integer $length Length of the data type. To indicate that a parameter is an OUT parameter from a stored procedure, you must explicitly set the length. | |
+ * @param mixed $driver_options | |
+ * | |
+ * @return boolean | |
*/ | |
public function bindParam($pos, &$value, $type = PDO::PARAM_STR, $length = 0, $driver_options = null) | |
{ | |
@@ -140,7 +145,7 @@ | |
$msg = sprintf('Binding %s at position %s w/ PDO type %s', $valuestr, $pos, $typestr); | |
$this->boundValues[$pos] = $valuestr; | |
- | |
+ | |
$this->pdo->log($msg, null, __METHOD__, $debug); | |
return $return; | |
Index: connection/PropelPDO.php | |
=================================================================== | |
--- connection/PropelPDO.php (revision 2294) | |
+++ connection/PropelPDO.php (working copy) | |
@@ -34,82 +34,82 @@ | |
* Attribute to use to set whether to cache prepared statements. | |
*/ | |
const PROPEL_ATTR_CACHE_PREPARES = -1; | |
- | |
+ | |
const DEFAULT_SLOW_THRESHOLD = 0.1; | |
const DEFAULT_ONLYSLOW_ENABLED = false; | |
/** | |
* The current transaction depth. | |
- * @var int | |
+ * @var integer | |
*/ | |
protected $nestedTransactionCount = 0; | |
/** | |
* Cache of prepared statements (PDOStatement) keyed by md5 of SQL. | |
* | |
- * @var array [md5(sql) => PDOStatement] | |
+ * @var array [md5(sql) => PDOStatement] | |
*/ | |
protected $preparedStatements = array(); | |
/** | |
* Whether to cache prepared statements. | |
* | |
- * @var boolean | |
+ * @var boolean | |
*/ | |
protected $cachePreparedStatements = false; | |
- | |
+ | |
/** | |
* Whether the final commit is possible | |
* Is false if a nested transaction is rolled back | |
*/ | |
protected $isUncommitable = false; | |
- | |
+ | |
/** | |
* Count of queries performed. | |
- * | |
- * @var int | |
+ * | |
+ * @var integer | |
*/ | |
protected $queryCount = 0; | |
- | |
+ | |
/** | |
* SQL code of the latest performed query. | |
- * | |
- * @var string | |
+ * | |
+ * @var string | |
*/ | |
protected $lastExecutedQuery; | |
- | |
+ | |
/** | |
* Whether or not the debug is enabled | |
- * | |
- * @var boolean | |
+ * | |
+ * @var boolean | |
*/ | |
public $useDebug = false; | |
- | |
+ | |
/** | |
* Configured BasicLogger (or compatible) logger. | |
* | |
- * @var BasicLogger | |
+ * @var BasicLogger | |
*/ | |
protected $logger; | |
/** | |
* The log level to use for logging. | |
* | |
- * @var int | |
+ * @var integer | |
*/ | |
private $logLevel = Propel::LOG_DEBUG; | |
- | |
+ | |
/** | |
* The runtime configuration | |
* | |
- * @var PropelConfiguration | |
+ * @var PropelConfiguration | |
*/ | |
protected $configuration; | |
- | |
+ | |
/** | |
* The default value for runtime config item "debugpdo.logging.methods". | |
* | |
- * @var array | |
+ * @var array | |
*/ | |
protected static $defaultLogMethods = array( | |
'PropelPDO::exec', | |
@@ -124,40 +124,43 @@ | |
* to the log with the state of this object just after its initialization. | |
* Add PropelPDO::__construct to $defaultLogMethods to see this message | |
* | |
- * @param string $dsn Connection DSN. | |
- * @param string $username (optional) The user name for the DSN string. | |
- * @param string $password (optional) The password for the DSN string. | |
- * @param array $driver_options (optional) A key=>value array of driver-specific connection options. | |
+ * @param string $dsn Connection DSN. | |
+ * @param string $username The user name for the DSN string. | |
+ * @param string $password The password for the DSN string. | |
+ * @param array $driver_options A key=>value array of driver-specific connection options. | |
+ * | |
* @throws PDOException if there is an error during connection initialization. | |
*/ | |
public function __construct($dsn, $username = null, $password = null, $driver_options = array()) | |
{ | |
+ $debug = null; | |
+ | |
if ($this->useDebug) { | |
$debug = $this->getDebugSnapshot(); | |
} | |
- | |
+ | |
parent::__construct($dsn, $username, $password, $driver_options); | |
- | |
+ | |
if ($this->useDebug) { | |
- $this->configureStatementClass('DebugPDOStatement', $suppress = true); | |
+ $this->configureStatementClass('DebugPDOStatement', true); | |
$this->log('Opening connection', null, __METHOD__, $debug); | |
} | |
} | |
- | |
+ | |
/** | |
* Inject the runtime configuration | |
- * | |
- * @param PropelConfiguration $configuration | |
+ * | |
+ * @param PropelConfiguration $configuration | |
*/ | |
public function setConfiguration($configuration) | |
{ | |
$this->configuration = $configuration; | |
} | |
- | |
+ | |
/** | |
* Get the runtime configuration | |
* | |
- * @return PropelConfiguration | |
+ * @return PropelConfiguration | |
*/ | |
public function getConfiguration() | |
{ | |
@@ -166,10 +169,11 @@ | |
} | |
return $this->configuration; | |
} | |
- | |
+ | |
/** | |
* Gets the current transaction depth. | |
- * @return int | |
+ * | |
+ * @return integer | |
*/ | |
public function getNestedTransactionCount() | |
{ | |
@@ -178,7 +182,7 @@ | |
/** | |
* Set the current transaction depth. | |
- * @param int $v The new depth. | |
+ * @param int $v The new depth. | |
*/ | |
protected function setNestedTransactionCount($v) | |
{ | |
@@ -187,28 +191,30 @@ | |
/** | |
* Is this PDO connection currently in-transaction? | |
- * This is equivalent to asking whether the current nested transaction count | |
- * is greater than 0. | |
- * @return boolean | |
+ * This is equivalent to asking whether the current nested transaction count is greater than 0. | |
+ * | |
+ * @return boolean | |
*/ | |
public function isInTransaction() | |
{ | |
return ($this->getNestedTransactionCount() > 0); | |
} | |
- | |
+ | |
/** | |
* Check whether the connection contains a transaction that can be committed. | |
* To be used in an evironment where Propelexceptions are caught. | |
* | |
- * @return boolean True if the connection is in a committable transaction | |
+ * @return boolean True if the connection is in a committable transaction | |
*/ | |
public function isCommitable() | |
{ | |
return $this->isInTransaction() && !$this->isUncommitable; | |
} | |
- | |
+ | |
/** | |
* Overrides PDO::beginTransaction() to prevent errors due to already-in-progress transaction. | |
+ * | |
+ * @return boolean | |
*/ | |
public function beginTransaction() | |
{ | |
@@ -221,17 +227,21 @@ | |
$this->isUncommitable = false; | |
} | |
$this->nestedTransactionCount++; | |
+ | |
return $return; | |
} | |
/** | |
* Overrides PDO::commit() to only commit the transaction if we are in the outermost | |
* transaction nesting level. | |
+ * | |
+ * @return boolean | |
*/ | |
public function commit() | |
{ | |
$return = true; | |
$opcount = $this->nestedTransactionCount; | |
+ | |
if ($opcount > 0) { | |
if ($opcount === 1) { | |
if ($this->isUncommitable) { | |
@@ -239,24 +249,28 @@ | |
} else { | |
$return = parent::commit(); | |
if ($this->useDebug) { | |
- $this->log('Commit transaction', null, __METHOD__); | |
+ $this->log('Commit transaction', null, __METHOD__); | |
} | |
} | |
} | |
- $this->nestedTransactionCount--; | |
+ | |
+ $this->nestedTransactionCount--; | |
} | |
+ | |
return $return; | |
} | |
/** | |
* Overrides PDO::rollBack() to only rollback the transaction if we are in the outermost | |
* transaction nesting level | |
- * @return boolean Whether operation was successful. | |
+ * | |
+ * @return boolean Whether operation was successful. | |
*/ | |
public function rollBack() | |
{ | |
$return = true; | |
$opcount = $this->nestedTransactionCount; | |
+ | |
if ($opcount > 0) { | |
if ($opcount === 1) { | |
$return = parent::rollBack(); | |
@@ -266,19 +280,23 @@ | |
} else { | |
$this->isUncommitable = true; | |
} | |
+ | |
$this->nestedTransactionCount--; | |
} | |
+ | |
return $return; | |
} | |
/** | |
* Rollback the whole transaction, even if this is a nested rollback | |
* and reset the nested transaction count to 0. | |
- * @return boolean Whether operation was successful. | |
+ * | |
+ * @return boolean Whether operation was successful. | |
*/ | |
public function forceRollBack() | |
{ | |
$return = true; | |
+ | |
if ($this->nestedTransactionCount) { | |
// If we're in a transaction, always roll it back | |
// regardless of nesting level. | |
@@ -292,17 +310,17 @@ | |
$this->log('Rollback transaction', null, __METHOD__); | |
} | |
} | |
+ | |
return $return; | |
} | |
- | |
+ | |
/** | |
* Sets a connection attribute. | |
* | |
- * This is overridden here to provide support for setting Propel-specific attributes | |
- * too. | |
+ * This is overridden here to provide support for setting Propel-specific attributes too. | |
* | |
- * @param int $attribute The attribute to set (e.g. PropelPDO::PROPEL_ATTR_CACHE_PREPARES). | |
- * @param mixed $value The attribute value. | |
+ * @param integer $attribute The attribute to set (e.g. PropelPDO::PROPEL_ATTR_CACHE_PREPARES). | |
+ * @param mixed $value The attribute value. | |
*/ | |
public function setAttribute($attribute, $value) | |
{ | |
@@ -318,10 +336,10 @@ | |
/** | |
* Gets a connection attribute. | |
* | |
- * This is overridden here to provide support for setting Propel-specific attributes | |
- * too. | |
+ * This is overridden here to provide support for setting Propel-specific attributes too. | |
* | |
- * @param int $attribute The attribute to get (e.g. PropelPDO::PROPEL_ATTR_CACHE_PREPARES). | |
+ * @param integer $attribute The attribute to get (e.g. PropelPDO::PROPEL_ATTR_CACHE_PREPARES). | |
+ * @return mixed | |
*/ | |
public function getAttribute($attribute) | |
{ | |
@@ -336,22 +354,25 @@ | |
/** | |
* Prepares a statement for execution and returns a statement object. | |
- * | |
+ * | |
* Overrides PDO::prepare() in order to: | |
* - Add logging and query counting if logging is true. | |
* - Add query caching support if the PropelPDO::PROPEL_ATTR_CACHE_PREPARES was set to true. | |
- * | |
- * @param string $sql This must be a valid SQL statement for the target database server. | |
- * @param array One or more key => value pairs to set attribute values | |
- * for the PDOStatement object that this method returns. | |
- * @return PDOStatement | |
+ * | |
+ * @param string $sql This must be a valid SQL statement for the target database server. | |
+ * @param array $driver_options One $array or more key => value pairs to set attribute values | |
+ * for the PDOStatement object that this method returns. | |
+ * | |
+ * @return PDOStatement | |
*/ | |
public function prepare($sql, $driver_options = array()) | |
{ | |
+ $debug = null; | |
+ | |
if ($this->useDebug) { | |
$debug = $this->getDebugSnapshot(); | |
} | |
- | |
+ | |
if ($this->cachePreparedStatements) { | |
if (!isset($this->preparedStatements[$sql])) { | |
$return = parent::prepare($sql, $driver_options); | |
@@ -362,70 +383,75 @@ | |
} else { | |
$return = parent::prepare($sql, $driver_options); | |
} | |
- | |
+ | |
if ($this->useDebug) { | |
$this->log($sql, null, __METHOD__, $debug); | |
} | |
- | |
+ | |
return $return; | |
} | |
/** | |
* Execute an SQL statement and return the number of affected rows. | |
- * | |
* Overrides PDO::exec() to log queries when required | |
- * | |
- * @return int | |
+ * | |
+ * @param string $sql | |
+ * @return integer | |
*/ | |
public function exec($sql) | |
{ | |
- if ($this->useDebug) { | |
+ $debug = null; | |
+ | |
+ if ($this->useDebug) { | |
$debug = $this->getDebugSnapshot(); | |
} | |
- | |
+ | |
$return = parent::exec($sql); | |
- | |
+ | |
if ($this->useDebug) { | |
$this->log($sql, null, __METHOD__, $debug); | |
$this->setLastExecutedQuery($sql); | |
$this->incrementQueryCount(); | |
} | |
- | |
+ | |
return $return; | |
} | |
/** | |
* Executes an SQL statement, returning a result set as a PDOStatement object. | |
* Despite its signature here, this method takes a variety of parameters. | |
- * | |
+ * | |
* Overrides PDO::query() to log queries when required | |
- * | |
- * @see http://php.net/manual/en/pdo.query.php for a description of the possible parameters. | |
- * @return PDOStatement | |
+ * | |
+ * @see http://php.net/manual/en/pdo.query.php for a description of the possible parameters. | |
+ * | |
+ * @return PDOStatement | |
*/ | |
public function query() | |
{ | |
- if ($this->useDebug) { | |
+ $debug = null; | |
+ | |
+ if ($this->useDebug) { | |
$debug = $this->getDebugSnapshot(); | |
} | |
- | |
+ | |
$args = func_get_args(); | |
if (version_compare(PHP_VERSION, '5.3', '<')) { | |
$return = call_user_func_array(array($this, 'parent::query'), $args); | |
} else { | |
$return = call_user_func_array('parent::query', $args); | |
} | |
- | |
+ | |
if ($this->useDebug) { | |
$sql = $args[0]; | |
$this->log($sql, null, __METHOD__, $debug); | |
$this->setLastExecutedQuery($sql); | |
$this->incrementQueryCount(); | |
} | |
- | |
+ | |
return $return; | |
} | |
- | |
+ | |
/** | |
* Clears any stored prepared statements for this connection. | |
*/ | |
@@ -436,9 +462,11 @@ | |
/** | |
* Configures the PDOStatement class for this connection. | |
- * | |
- * @param boolean $suppressError Whether to suppress an exception if the statement class cannot be set. | |
- * @throws PropelException if the statement class cannot be set (and $suppressError is false). | |
+ * | |
+ * @param string $class | |
+ * @param boolean $suppressError Whether to suppress an exception if the statement class cannot be set. | |
+ * | |
+ * @throws PropelException if the statement class cannot be set (and $suppressError is false). | |
*/ | |
protected function configureStatementClass($class = 'PDOStatement', $suppressError = true) | |
{ | |
@@ -452,12 +480,12 @@ | |
/** | |
* Returns the number of queries this DebugPDO instance has performed on the database connection. | |
- * | |
+ * | |
* When using DebugPDOStatement as the statement class, any queries by DebugPDOStatement instances | |
* are counted as well. | |
- * | |
- * @return int | |
+ * | |
* @throws PropelException if persistent connection is used (since unable to override PDOStatement in that case). | |
+ * @return integer | |
*/ | |
public function getQueryCount() | |
{ | |
@@ -470,10 +498,10 @@ | |
/** | |
* Increments the number of queries performed by this DebugPDO instance. | |
- * | |
+ * | |
* Returns the original number of queries (ie the value of $this->queryCount before calling this method). | |
- * | |
- * @return int | |
+ * | |
+ * @return integer | |
*/ | |
public function incrementQueryCount() | |
{ | |
@@ -482,33 +510,33 @@ | |
/** | |
* Get the SQL code for the latest query executed by Propel | |
- * | |
+ * | |
* @return string Executable SQL code | |
*/ | |
public function getLastExecutedQuery() | |
{ | |
return $this->lastExecutedQuery; | |
} | |
- | |
+ | |
/** | |
* Set the SQL code for the latest query executed by Propel | |
- * | |
- * @param string $query Executable SQL code | |
+ * | |
+ * @param string $query Executable SQL code | |
*/ | |
public function setLastExecutedQuery($query) | |
{ | |
$this->lastExecutedQuery = $query; | |
} | |
- | |
+ | |
/** | |
* Enable or disable the query debug features | |
* | |
- * @var boolean $value True to enable debug (default), false to disable it | |
+ * @param boolean $value True to enable debug (default), false to disable it | |
*/ | |
public function useDebug($value = true) | |
{ | |
if ($value) { | |
- $this->configureStatementClass('DebugPDOStatement', $suppress = true); | |
+ $this->configureStatementClass('DebugPDOStatement', true); | |
} else { | |
// reset query logging | |
$this->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('PDOStatement')); | |
@@ -518,11 +546,11 @@ | |
$this->clearStatementCache(); | |
$this->useDebug = $value; | |
} | |
- | |
+ | |
/** | |
* Sets the logging level to use for logging method calls and SQL statements. | |
* | |
- * @param int $level Value of one of the Propel::LOG_* class constants. | |
+ * @param integer $level Value of one of the Propel::LOG_* class constants. | |
*/ | |
public function setLogLevel($level) | |
{ | |
@@ -531,10 +559,10 @@ | |
/** | |
* Sets a logger to use. | |
- * | |
+ * | |
* The logger will be used by this class to log various method calls and their properties. | |
- * | |
- * @param BasicLogger $logger A Logger with an API compatible with BasicLogger (or PEAR Log). | |
+ * | |
+ * @param BasicLogger $logger A Logger with an API compatible with BasicLogger (or PEAR Log). | |
*/ | |
public function setLogger($logger) | |
{ | |
@@ -543,8 +571,8 @@ | |
/** | |
* Gets the logger in use. | |
- * | |
- * @return BasicLogger $logger A Logger with an API compatible with BasicLogger (or PEAR Log). | |
+ * | |
+ * @return BasicLogger A Logger with an API compatible with BasicLogger (or PEAR Log). | |
*/ | |
public function getLogger() | |
{ | |
@@ -553,14 +581,14 @@ | |
/** | |
* Logs the method call or SQL using the Propel::log() method or a registered logger class. | |
- * | |
- * @uses self::getLogPrefix() | |
- * @see self::setLogger() | |
- * | |
- * @param string $msg Message to log. | |
- * @param int $level (optional) Log level to use; will use self::setLogLevel() specified level by default. | |
- * @param string $methodName (optional) Name of the method whose execution is being logged. | |
- * @param array $debugSnapshot (optional) Previous return value from self::getDebugSnapshot(). | |
+ * | |
+ * @uses self::getLogPrefix() | |
+ * @see self::setLogger() | |
+ * | |
+ * @param string $msg Message to log. | |
+ * @param integer $level Log level to use; will use self::setLogLevel() specified level by default. | |
+ * @param string $methodName Name of the method whose execution is being logged. | |
+ * @param array $debugSnapshot Previous return value from self::getDebugSnapshot(). | |
*/ | |
public function log($msg, $level = null, $methodName = null, array $debugSnapshot = null) | |
{ | |
@@ -568,12 +596,12 @@ | |
if (!$this->getLoggingConfig('enabled', true)) { | |
return; | |
} | |
- | |
+ | |
// If the method being logged isn't one of the ones to be logged, bail | |
if (!in_array($methodName, $this->getLoggingConfig('methods', self::$defaultLogMethods))) { | |
return; | |
} | |
- | |
+ | |
// If a logging level wasn't provided, use the default one | |
if ($level === null) { | |
$level = $this->logLevel; | |
@@ -584,17 +612,17 @@ | |
$now = $this->getDebugSnapshot(); | |
if ($now['microtime'] - $debugSnapshot['microtime'] < $this->getLoggingConfig("details.slow.threshold", self::DEFAULT_SLOW_THRESHOLD)) return; | |
} | |
- | |
+ | |
// If the necessary additional parameters were given, get the debug log prefix for the log line | |
if ($methodName && $debugSnapshot) { | |
$msg = $this->getLogPrefix($methodName, $debugSnapshot) . $msg; | |
} | |
- | |
+ | |
// We won't log empty messages | |
if (!$msg) { | |
return; | |
} | |
- | |
+ | |
// Delegate the actual logging forward | |
if ($this->logger) { | |
$this->logger->log($msg, $level); | |
@@ -602,51 +630,53 @@ | |
Propel::log($msg, $level); | |
} | |
} | |
- | |
+ | |
/** | |
* Returns a snapshot of the current values of some functions useful in debugging. | |
* | |
- * @return array | |
+ * @return array | |
*/ | |
public function getDebugSnapshot() | |
{ | |
- if ($this->useDebug) { | |
+ if ($this->useDebug) { | |
return array( | |
'microtime' => microtime(true), | |
'memory_get_usage' => memory_get_usage($this->getLoggingConfig('realmemoryusage', false)), | |
'memory_get_peak_usage' => memory_get_peak_usage($this->getLoggingConfig('realmemoryusage', false)), | |
); | |
} else { | |
- throw new PropelException('Should not get debug snapshot when not debugging'); | |
+ throw new PropelException('Should not get debug snapshot when not debugging'); | |
} | |
} | |
- | |
+ | |
/** | |
* Returns a named configuration item from the Propel runtime configuration, from under the | |
* 'debugpdo.logging' prefix. If such a configuration setting hasn't been set, the given default | |
- * value will be returned. | |
+ * value will be returned. | |
* | |
- * @param string $key Key for which to return the value. | |
- * @param mixed $defaultValue Default value to apply if config item hasn't been set. | |
- * @return mixed | |
+ * @param string $key Key for which to return the value. | |
+ * @param mixed $defaultValue Default value to apply if config item hasn't been set. | |
+ * | |
+ * @return mixed | |
*/ | |
protected function getLoggingConfig($key, $defaultValue) | |
{ | |
return $this->getConfiguration()->getParameter("debugpdo.logging.$key", $defaultValue); | |
} | |
- | |
+ | |
/** | |
* Returns a prefix that may be prepended to a log line, containing debug information according | |
* to the current configuration. | |
- * | |
+ * | |
* Uses a given $debugSnapshot to calculate how much time has passed since the call to self::getDebugSnapshot(), | |
* how much the memory consumption by PHP has changed etc. | |
* | |
- * @see self::getDebugSnapshot() | |
- * | |
- * @param string $methodName Name of the method whose execution is being logged. | |
- * @param array $debugSnapshot A previous return value from self::getDebugSnapshot(). | |
- * @return string | |
+ * @see self::getDebugSnapshot() | |
+ * | |
+ * @param string $methodName Name of the method whose execution is being logged. | |
+ * @param array $debugSnapshot A previous return value from self::getDebugSnapshot(). | |
+ * | |
+ * @return string | |
*/ | |
protected function getLogPrefix($methodName, $debugSnapshot) | |
{ | |
@@ -659,91 +689,91 @@ | |
$now = $this->getDebugSnapshot(); | |
$innerGlue = $this->getLoggingConfig('innerglue', ': '); | |
$outerGlue = $this->getLoggingConfig('outerglue', ' | '); | |
- | |
+ | |
// Iterate through each detail that has been configured to be enabled | |
foreach ($logDetails as $detailName => $details) { | |
- | |
+ | |
if (!$this->getLoggingConfig("details.$detailName.enabled", false)) { | |
continue; | |
} | |
- | |
+ | |
switch ($detailName) { | |
- | |
+ | |
case 'slow'; | |
$value = $now['microtime'] - $debugSnapshot['microtime'] >= $this->getLoggingConfig('details.slow.threshold', self::DEFAULT_SLOW_THRESHOLD) ? 'YES' : ' NO'; | |
break; | |
- | |
+ | |
case 'time': | |
$value = number_format($now['microtime'] - $debugSnapshot['microtime'], $this->getLoggingConfig('details.time.precision', 3)) . ' sec'; | |
$value = str_pad($value, $this->getLoggingConfig('details.time.pad', 10), ' ', STR_PAD_LEFT); | |
break; | |
- | |
+ | |
case 'mem': | |
$value = self::getReadableBytes($now['memory_get_usage'], $this->getLoggingConfig('details.mem.precision', 1)); | |
$value = str_pad($value, $this->getLoggingConfig('details.mem.pad', 9), ' ', STR_PAD_LEFT); | |
break; | |
- | |
+ | |
case 'memdelta': | |
$value = $now['memory_get_usage'] - $debugSnapshot['memory_get_usage']; | |
$value = ($value > 0 ? '+' : '') . self::getReadableBytes($value, $this->getLoggingConfig('details.memdelta.precision', 1)); | |
$value = str_pad($value, $this->getLoggingConfig('details.memdelta.pad', 10), ' ', STR_PAD_LEFT); | |
break; | |
- | |
+ | |
case 'mempeak': | |
$value = self::getReadableBytes($now['memory_get_peak_usage'], $this->getLoggingConfig('details.mempeak.precision', 1)); | |
$value = str_pad($value, $this->getLoggingConfig('details.mempeak.pad', 9), ' ', STR_PAD_LEFT); | |
break; | |
- | |
+ | |
case 'querycount': | |
$value = str_pad($this->getQueryCount(), $this->getLoggingConfig('details.querycount.pad', 2), ' ', STR_PAD_LEFT); | |
break; | |
- | |
+ | |
case 'method': | |
$value = str_pad($methodName, $this->getLoggingConfig('details.method.pad', 28), ' ', STR_PAD_RIGHT); | |
break; | |
- | |
+ | |
default: | |
$value = 'n/a'; | |
break; | |
- | |
+ | |
} | |
- | |
+ | |
$prefix .= $detailName . $innerGlue . $value . $outerGlue; | |
- | |
+ | |
} | |
- | |
+ | |
return $prefix; | |
} | |
- | |
+ | |
/** | |
* Returns a human-readable representation of the given byte count. | |
* | |
- * @param int $bytes Byte count to convert. | |
- * @param int $precision How many decimals to include. | |
- * @return string | |
+ * @param integer $bytes Byte count to convert. | |
+ * @param integer $precision How many decimals to include. | |
+ * | |
+ * @return string | |
*/ | |
protected function getReadableBytes($bytes, $precision) | |
{ | |
$suffix = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); | |
- $total = count($suffix); | |
- | |
- for ($i = 0; $bytes > 1024 && $i < $total; $i++) | |
- $bytes /= 1024; | |
- | |
- return number_format($bytes, $precision) . ' ' . $suffix[$i]; | |
+ $total = count($suffix); | |
+ | |
+ for ($i = 0; $bytes > 1024 && $i < $total; $i++) | |
+ $bytes /= 1024; | |
+ | |
+ return number_format($bytes, $precision) . ' ' . $suffix[$i]; | |
} | |
- | |
+ | |
/** | |
* If so configured, makes an entry to the log of the state of this object just prior to its destruction. | |
* Add PropelPDO::__destruct to $defaultLogMethods to see this message | |
* | |
- * @see self::log() | |
+ * @see self::log() | |
*/ | |
public function __destruct() | |
{ | |
- if ($this->useDebug) { | |
+ if ($this->useDebug) { | |
$this->log('Closing connection', null, __METHOD__, $this->getDebugSnapshot()); | |
} | |
} | |
- | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment