Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Code Formatting

  • Loading branch information...
commit 655c981bd51b068423f019abff8b3ad7ff975a20 1 parent 0fe4c30
@gabordemooij authored
View
16 RedBean/Adapter.php
@@ -13,21 +13,18 @@
*
*/
interface RedBean_Adapter {
-
/**
* Returns the latest SQL statement
*
* @return string $SQLString SQLString
*/
public function getSQL();
-
/**
* Escapes a value for usage in an SQL statement
*
* @param string $sqlvalue value
*/
public function escape( $sqlvalue );
-
/**
* Executes an SQL Statement using an array of values to bind
* If $noevent is TRUE then this function will not signal its
@@ -39,7 +36,6 @@ public function escape( $sqlvalue );
* @param boolean $noevent no event firing
*/
public function exec( $sql , $aValues=array(), $noevent=false);
-
/**
* Executes an SQL Query and returns a resultset.
* This method returns a multi dimensional resultset similar to getAll
@@ -50,7 +46,6 @@ public function exec( $sql , $aValues=array(), $noevent=false);
* @param array $aValues values
*/
public function get( $sql, $aValues = array() );
-
/**
* Executes an SQL Query and returns a resultset.
* This method returns a single row (one array) resultset.
@@ -63,7 +58,6 @@ public function get( $sql, $aValues = array() );
* @return array $aMultiDimArray row
*/
public function getRow( $sql, $aValues = array() );
-
/**
* Executes an SQL Query and returns a resultset.
* This method returns a single column (one array) resultset.
@@ -76,7 +70,6 @@ public function getRow( $sql, $aValues = array() );
* @return array $aSingleDimArray column
*/
public function getCol( $sql, $aValues = array() );
-
/**
* Executes an SQL Query and returns a resultset.
* This method returns a single cell, a scalar value as the resultset.
@@ -89,7 +82,6 @@ public function getCol( $sql, $aValues = array() );
* @return string $sSingleValue value from cell
*/
public function getCell( $sql, $aValues = array() );
-
/**
* Executes the SQL query specified in $sql and takes
* the first two columns of the resultset. This function transforms the
@@ -104,14 +96,12 @@ public function getCell( $sql, $aValues = array() );
* @return array $associativeArray associative array result set
*/
public function getAssoc( $sql, $values = array() );
-
/**
* Returns the latest insert ID.
*
* @return integer $id primary key ID
*/
public function getInsertID();
-
/**
* Returns the number of rows that have been
* affected by the last update statement.
@@ -119,7 +109,6 @@ public function getInsertID();
* @return integer $count number of rows affected
*/
public function getAffectedRows();
-
/**
* Returns the original database resource. This is useful if you want to
* perform operations on the driver directly instead of working with the
@@ -129,31 +118,26 @@ public function getAffectedRows();
* @return object $driver driver
*/
public function getDatabase();
-
/**
* This method is part of the RedBean Transaction Management
* mechanisms.
* Starts a transaction.
*/
public function startTransaction();
-
/**
* This method is part of the RedBean Transaction Management
* mechanisms.
* Commits the transaction.
*/
public function commit();
-
/**
* This method is part of the RedBean Transaction Management
* mechanisms.
* Rolls back the transaction.
*/
public function rollback();
-
/**
* Closes database connection.
*/
public function close();
-
}
View
24 RedBean/Adapter/DBAdapter.php
@@ -11,20 +11,16 @@
* with this source code in the file license.txt.
*/
class RedBean_Adapter_DBAdapter extends RedBean_Observable implements RedBean_Adapter {
-
/**
* ADODB compatible class
* @var RedBean_Driver
*/
private $db = null;
-
/**
* Contains SQL snippet
* @var string
*/
private $sql = '';
-
-
/**
* Constructor.
* Creates an instance of the RedBean Adapter Class.
@@ -36,7 +32,6 @@ class RedBean_Adapter_DBAdapter extends RedBean_Observable implements RedBean_Ad
public function __construct($database) {
$this->db = $database;
}
-
/**
* Returns the latest SQL Statement.
* This method returns the most recently executed SQL statement string.
@@ -47,7 +42,6 @@ public function __construct($database) {
public function getSQL() {
return $this->sql;
}
-
/**
* Escapes a string for use in a Query.
* This method escapes the value argument using the native
@@ -60,7 +54,6 @@ public function getSQL() {
public function escape( $sqlvalue ) {
return $this->db->Escape($sqlvalue);
}
-
/**
* Executes SQL code; any query without
* returning a resultset.
@@ -85,7 +78,6 @@ public function exec( $sql , $aValues=array(), $noevent=false) {
}
return $this->db->Execute( $sql, $aValues );
}
-
/**
* Multi array SQL fetch. Fetches a multi dimensional array.
* This function allows you to provide an array with values to bind
@@ -106,7 +98,6 @@ public function get( $sql, $aValues = array() ) {
$this->signal('sql_exec', $this);
return $this->db->GetAll( $sql,$aValues );
}
-
/**
* Executes SQL and fetches a single row.
* This function allows you to provide an array with values to bind
@@ -127,7 +118,6 @@ public function getRow( $sql, $aValues = array() ) {
$this->signal('sql_exec', $this);
return $this->db->GetRow( $sql,$aValues );
}
-
/**
* Executes SQL and returns a one dimensional array result set.
* This function rotates the result matrix to obtain a column result set.
@@ -149,8 +139,6 @@ public function getCol( $sql, $aValues = array() ) {
$this->signal('sql_exec', $this);
return $this->db->GetCol( $sql,$aValues );
}
-
-
/**
* Executes an SQL Query and fetches the first two columns only.
* Then this function builds an associative array using the first
@@ -192,8 +180,6 @@ public function getAssoc( $sql, $aValues = array() ) {
}
return $assoc;
}
-
-
/**
* Retrieves a single cell.
* This function allows you to provide an array with values to bind
@@ -209,14 +195,12 @@ public function getAssoc( $sql, $aValues = array() ) {
*
* @return array $result scalar result set
*/
-
public function getCell( $sql, $aValues = array(), $noSignal = null ) {
$this->sql = $sql;
if (!$noSignal) $this->signal('sql_exec', $this);
$arr = $this->db->getCol( $sql, $aValues );
if ($arr && is_array($arr)) return ($arr[0]); else return false;
}
-
/**
* Returns latest insert id, most recently inserted id.
* Following an insert-SQL statement this method will return the most recently
@@ -227,7 +211,6 @@ public function getCell( $sql, $aValues = array(), $noSignal = null ) {
public function getInsertID() {
return $this->db->getInsertID();
}
-
/**
* Returns number of affected rows.
* Returns the number of rows that have been affected by the most recent
@@ -238,7 +221,6 @@ public function getInsertID() {
public function getAffectedRows() {
return $this->db->Affected_Rows();
}
-
/**
* Unwrap the original database object.
* Returns the database driver instance. For instance this can be
@@ -249,7 +231,6 @@ public function getAffectedRows() {
public function getDatabase() {
return $this->db;
}
-
/**
* Transactions.
* Part of the transaction management infrastructure of RedBeanPHP.
@@ -260,7 +241,6 @@ public function getDatabase() {
public function startTransaction() {
return $this->db->StartTrans();
}
-
/**
* Transactions.
* Part of the transaction management infrastructure of RedBeanPHP.
@@ -271,7 +251,6 @@ public function startTransaction() {
public function commit() {
return $this->db->CommitTrans();
}
-
/**
* Transactions.
* Part of the transaction management infrastructure of RedBeanPHP.
@@ -283,11 +262,10 @@ public function commit() {
public function rollback() {
return $this->db->FailTrans();
}
-
/**
* Closes the database connection.
*/
public function close() {
$this->db->close();
}
-}
+}
View
29 RedBean/AssociationManager.php
@@ -17,20 +17,16 @@ class RedBean_AssociationManager extends RedBean_Observable {
* @var RedBean_OODB
*/
protected $oodb;
-
/**
* Contains a reference to the Database Adapter
* @var RedBean_Adapter_DBAdapter
*/
protected $adapter;
-
/**
* Contains a reference to the Query Writer
* @var RedBean_QueryWriter
*/
protected $writer;
-
-
/**
* Constructor
*
@@ -42,7 +38,6 @@ public function __construct( RedBean_ToolBox $tools ) {
$this->writer = $tools->getWriter();
$this->toolbox = $tools;
}
-
/**
* Creates a table name based on a types array.
* Manages the get the correct name for the linking table for the
@@ -76,8 +71,6 @@ public function associate($beans1, $beans2) {
}
return (count($results)>1) ? $results : reset($results);
}
-
-
/**
* Associates a pair of beans. This method associates two beans, no matter
* what types.Accepts a base bean that contains data for the linking record.
@@ -89,7 +82,6 @@ public function associate($beans1, $beans2) {
* @return mixed $id either the link ID or null
*/
protected function associateBeans(RedBean_OODBBean $bean1, RedBean_OODBBean $bean2, RedBean_OODBBean $bean) {
-
$property1 = $bean1->getMeta('type') . '_id';
$property2 = $bean2->getMeta('type') . '_id';
if ($property1==$property2) $property2 = $bean2->getMeta('type').'2_id';
@@ -115,16 +107,11 @@ protected function associateBeans(RedBean_OODBBean $bean1, RedBean_OODBBean $bea
$this->writer->addConstraint( $bean1, $bean2 );
}
$results[] = $id;
- }
- catch(RedBean_Exception_SQL $e) {
+ } catch(RedBean_Exception_SQL $e) {
if (!$this->writer->sqlStateIn($e->getSQLState(),
- array(
- RedBean_QueryWriter::C_SQLSTATE_INTEGRITY_CONSTRAINT_VIOLATION
- ))) throw $e;
+ array( RedBean_QueryWriter::C_SQLSTATE_INTEGRITY_CONSTRAINT_VIOLATION ))) throw $e;
}
-
}
-
/**
* Returns all ids of beans of type $type that are related to $bean. If the
* $getLinks parameter is set to boolean TRUE this method will return the ids
@@ -166,7 +153,6 @@ public function related( $bean, $type, $getLinks=false, $sql=false) {
}
else $cross=0;
if (!$getLinks) $targetproperty = $type.'_id'; else $targetproperty='id';
-
$property = $bean->getMeta('type').'_id';
try {
$sqlFetchKeys = $this->writer->selectRecord(
@@ -204,7 +190,6 @@ public function related( $bean, $type, $getLinks=false, $sql=false) {
return array();
}
}
-
/**
* Breaks the association between two beans. This method unassociates two beans. If the
* method succeeds the beans will no longer form an association. In the database
@@ -263,7 +248,6 @@ public function unassociate($beans1, $beans2, $fast=null) {
}
}
}
-
/**
* Removes all relations for a bean. This method breaks every connection between
* a certain bean $bean and every other bean of type $type. Warning: this method
@@ -298,7 +282,6 @@ public function clearRelations(RedBean_OODBBean $bean, $type) {
)) throw $e;
}
}
-
/**
* Given two beans this function returns TRUE if they are associated using a
* many-to-many association, FALSE otherwise.
@@ -317,8 +300,7 @@ public function areRelated(RedBean_OODBBean $bean1, RedBean_OODBBean $bean2) {
if ($type==$bean2->getMeta('type')) {
$type .= '2';
$cross = 1;
- }
- else $cross = 0;
+ } else $cross = 0;
$property1 = $type.'_id';
$property2 = $bean2->getMeta('type').'_id';
$value1 = (int) $bean1->id;
@@ -343,7 +325,6 @@ public function areRelated(RedBean_OODBBean $bean1, RedBean_OODBBean $bean2) {
}
return (count($rows)>0);
}
-
/**
* Given an array of two beans and a property, this method
* swaps the value of the property.
@@ -362,7 +343,6 @@ public function swap( $beans, $property ) {
$this->oodb->store($bean1);
$this->oodb->store($bean2);
}
-
/**
* Returns all the beans associated with $bean.
* This method will return an array containing all the beans that have
@@ -392,7 +372,6 @@ public function relatedSimple($bean, $type, $sql=null, $values=array()) {
$rows = $this->writer->selectRecord( $type, array('id'=>$keys),array($sql,$values),false );
return $this->oodb->convertToBeans($type,$rows);
}
-
/**
* Returns only single associated bean.
*
@@ -409,8 +388,6 @@ public function relatedOne( RedBean_OODBBean $bean, $type, $sql=null, $values=ar
if (count($beans)==0 || !is_array($beans)) return null;
return reset( $beans );
}
-
-
/**
* The opposite of related(). Returns all the beans that are not
* associated with the bean provided.
View
6 RedBean/AssociationManager/ExtAssociationManager.php
@@ -12,7 +12,6 @@
* with this source code in the file license.txt.
*/
class RedBean_AssociationManager_ExtAssociationManager extends RedBean_AssociationManager {
-
/**
* Associates two beans with eachother. This method connects two beans with eachother, just
* like the other associate() method in the Association Manager. The difference is however
@@ -31,8 +30,6 @@ public function extAssociate(RedBean_OODBBean $bean1, RedBean_OODBBean $bean2, R
$baseBean->setMeta('type', $table );
return $this->associateBeans( $bean1, $bean2, $baseBean );
}
-
-
/**
* Deprecated
*
@@ -45,8 +42,7 @@ public function extAssociateSimple( $beans1, $beans2, $extra = null) {
if (!is_array($extra)) {
$info = json_decode($extra,true);
if (!$info) $info = array('extra'=>$extra);
- }
- else {
+ } else {
$info = $extra;
}
$bean = $this->oodb->dispense('xtypeless');
View
7 RedBean/BeanHelper.php
@@ -16,13 +16,10 @@
*
*/
interface RedBean_BeanHelper {
-
/**
* @abstract
* @return RedBean_Toolbox $toolbox toolbox
*/
public function getToolbox();
-
- public function getModelForBean(RedBean_OODBBean $bean);
-
-}
+ public function getModelForBean(RedBean_OODBBean $bean);
+}
View
2  RedBean/BeanHelper/Facade.php
@@ -12,7 +12,6 @@
* with this source code in the file license.txt.
*/
class RedBean_BeanHelper_Facade implements RedBean_BeanHelper {
-
/**
* Returns a reference to the toolbox. This method returns a toolbox
* for beans that need to use toolbox functions. Since beans can contain
@@ -23,7 +22,6 @@ class RedBean_BeanHelper_Facade implements RedBean_BeanHelper {
public function getToolbox() {
return RedBean_Facade::$toolbox;
}
-
/**
* Fuse connector.
* Gets the model for a bean $bean.
View
3  RedBean/DependencyInjector.php
@@ -17,13 +17,11 @@
*
*/
class RedBean_DependencyInjector {
-
/**
* List of dependencies.
* @var array
*/
protected $dependencies = array();
-
/**
* Adds a dependency to the list.
* You can add dependencies using this method. Pass both the key of the
@@ -39,7 +37,6 @@ class RedBean_DependencyInjector {
public function addDependency($dependencyID,$dependency) {
$this->dependencies[$dependencyID] = $dependency;
}
-
/**
* Returns an instance of the class $modelClassName completely
* configured as far as possible with all the available
View
35 RedBean/Driver.php
@@ -23,7 +23,6 @@
* @return array $results result
*/
public function GetAll( $sql, $aValues=array() );
-
/**
* Runs a query and fetches results as a column.
*
@@ -32,7 +31,6 @@ public function GetAll( $sql, $aValues=array() );
* @return array $results Resultset
*/
public function GetCol( $sql, $aValues=array() );
-
/**
* Runs a query an returns results as a single cell.
*
@@ -41,7 +39,6 @@ public function GetCol( $sql, $aValues=array() );
* @return mixed $cellvalue result cell
*/
public function GetCell( $sql, $aValues=array() );
-
/**
* Runs a query and returns a flat array containing the values of
* one row.
@@ -51,7 +48,6 @@ public function GetCell( $sql, $aValues=array() );
* @return array $row result row
*/
public function GetRow( $sql, $aValues=array() );
-
/**
* Executes SQL code and allows key-value binding.
* This function allows you to provide an array with values to bind
@@ -68,7 +64,6 @@ public function GetRow( $sql, $aValues=array() );
* @return void
*/
public function Execute( $sql, $aValues=array() );
-
/**
* Escapes a string for use in SQL using the currently selected
* driver driver.
@@ -78,7 +73,6 @@ public function Execute( $sql, $aValues=array() );
* @return string $string escaped string
*/
public function Escape( $str );
-
/**
* Returns the latest insert ID if driver does support this
* feature.
@@ -86,8 +80,6 @@ public function Escape( $str );
* @return integer $id primary key ID
*/
public function GetInsertID();
-
-
/**
* Returns the number of rows affected by the most recent query
* if the currently selected driver driver supports this feature.
@@ -95,7 +87,6 @@ public function GetInsertID();
* @return integer $numOfRows number of rows affected
*/
public function Affected_Rows();
-
/**
* Toggles debug mode. In debug mode the driver will print all
* SQL to the screen together with some information about the
@@ -108,43 +99,19 @@ public function Affected_Rows();
* @return void
*/
public function setDebugMode( $tf );
-
/**
* Starts a transaction.
- * This method is part of the transaction mechanism of
- * RedBeanPHP. All queries in a transaction are executed together.
- * In case of an error all commands will be rolled back so none of the
- * SQL in the transaction will affect the DB. Using transactions is
- * considered best practice.
- * This method has no return value.
- *
* @return void
*/
public function CommitTrans();
-
/**
* Commits a transaction.
- * This method is part of the transaction mechanism of
- * RedBeanPHP. All queries in a transaction are executed together.
- * In case of an error all commands will be rolled back so none of the
- * SQL in the transaction will affect the DB. Using transactions is
- * considered best practice.
- * This method has no return value.
- *
* @return void
*/
public function StartTrans();
-
/**
* Rolls back a transaction.
- * This method is part of the transaction mechanism of
- * RedBeanPHP. All queries in a transaction are executed together.
- * In case of an error all commands will be rolled back so none of the
- * SQL in the transaction will affect the DB. Using transactions is
- * considered best practice.
- * This method has no return value.
- *
* @return void
*/
public function FailTrans();
-}
+}
View
68 RedBean/Driver/PDO.php
@@ -14,59 +14,48 @@
*
*/
class RedBean_Driver_PDO implements RedBean_Driver {
-
/**
* Contains database DSN for connecting to database.
* @var string
*/
protected $dsn;
-
/**
* Whether we are in debugging mode or not.
* @var boolean
*/
protected $debug = false;
-
/**
* Holds an instance of Logger implementation.
* @var RedBean_Logger
*/
protected $logger = NULL;
-
/**
* Holds the PDO instance.
* @var PDO
*/
protected $pdo;
-
/**
* Holds integer number of affected rows from latest query
* if driver supports this feature.
* @var integer
*/
protected $affected_rows;
-
/**
* Holds result resource.
* @var integer
*/
protected $rs;
-
-
/**
* Contains arbitrary connection data.
* @var array
*/
protected $connectInfo = array();
-
-
/**
* Whether you want to use classic String Only binding -
* backward compatibility.
* @var bool
*/
public $flagUseStringOnlyBinding = false;
-
/**
* Whether we are currently connected or not.
* This flag is being used to delay the connection until necessary.
@@ -76,7 +65,6 @@ class RedBean_Driver_PDO implements RedBean_Driver {
* @var boolean
*/
protected $isConnected = false;
-
/**
* Constructor. You may either specify dsn, user and password or
* just give an existing PDO connection.
@@ -104,7 +92,6 @@ public function __construct($dsn, $user = null, $pass = null) {
$this->connectInfo = array( 'pass'=>$pass, 'user'=>$user );
}
}
-
/**
* Establishes a connection to the database using PHP PDO
* functionality. If a connection has already been established this
@@ -132,12 +119,10 @@ public function connect() {
);
$this->pdo->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
$this->isConnected = true;
- }
- catch(PDOException $e) {
+ } catch(PDOException $e) {
throw new PDOException('Could not connect to database.');
}
}
-
/**
* Binds parameters. This method binds parameters to a PDOStatement for
* Query Execution. This method binds parameters as NULL, INTEGER or STRING
@@ -151,32 +136,24 @@ public function connect() {
protected function bindParams($s,$aValues) {
foreach($aValues as $key=>&$value) {
if (is_integer($key)) {
-
if (is_null($value)){
$s->bindValue($key+1,null,PDO::PARAM_NULL);
- }
- elseif (!$this->flagUseStringOnlyBinding && RedBean_QueryWriter_AQueryWriter::canBeTreatedAsInt($value) && $value < 2147483648) {
+ } elseif (!$this->flagUseStringOnlyBinding && RedBean_QueryWriter_AQueryWriter::canBeTreatedAsInt($value) && $value < 2147483648) {
$s->bindParam($key+1,$value,PDO::PARAM_INT);
- }
- else {
+ } else {
$s->bindParam($key+1,$value,PDO::PARAM_STR);
}
- }
- else {
+ } else {
if (is_null($value)){
$s->bindValue($key,null,PDO::PARAM_NULL);
- }
- elseif (!$this->flagUseStringOnlyBinding && RedBean_QueryWriter_AQueryWriter::canBeTreatedAsInt($value) && $value < 2147483648) {
+ } elseif (!$this->flagUseStringOnlyBinding && RedBean_QueryWriter_AQueryWriter::canBeTreatedAsInt($value) && $value < 2147483648) {
$s->bindParam($key,$value,PDO::PARAM_INT);
- }
- else {
+ } else {
$s->bindParam($key,$value,PDO::PARAM_STR);
}
}
-
}
}
-
/**
* Runs a query. Internal function, available for subclasses. This method
* runs the actual SQL query and binds a list of parameters to the query.
@@ -198,8 +175,7 @@ protected function runQuery($sql,$aValues) {
try {
if (strpos('pgsql',$this->dsn)===0) {
$s = $this->pdo->prepare($sql, array(PDO::PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT => true));
- }
- else {
+ } else {
$s = $this->pdo->prepare($sql);
}
$this->bindParams( $s, $aValues );
@@ -208,8 +184,7 @@ protected function runQuery($sql,$aValues) {
if ($s->columnCount()) {
$this->rs = $s->fetchAll();
if ($this->debug && $this->logger) $this->logger->log('resultset: ' . count($this->rs) . ' rows');
- }
- else {
+ } else {
$this->rs = array();
}
}catch(PDOException $e) {
@@ -222,8 +197,6 @@ protected function runQuery($sql,$aValues) {
throw $x;
}
}
-
-
/**
* Runs a query and fetches results as a multi dimensional array.
*
@@ -235,7 +208,6 @@ public function GetAll( $sql, $aValues=array() ) {
$this->runQuery($sql,$aValues);
return $this->rs;
}
-
/**
* Runs a query and fetches results as a column.
*
@@ -253,7 +225,6 @@ public function GetCol($sql, $aValues=array()) {
}
return $cols;
}
-
/**
* Runs a query an returns results as a single cell.
*
@@ -267,7 +238,6 @@ public function GetCell($sql, $aValues=array()) {
$col1 = array_shift($row1);
return $col1;
}
-
/**
* Runs a query and returns a flat array containing the values of
* one row.
@@ -280,9 +250,6 @@ public function GetRow($sql, $aValues=array()) {
$arr = $this->GetAll($sql, $aValues);
return array_shift($arr);
}
-
-
-
/**
* Executes SQL code and allows key-value binding.
* This function allows you to provide an array with values to bind
@@ -302,7 +269,6 @@ public function Execute( $sql, $aValues=array() ) {
$this->runQuery($sql,$aValues);
return $this->affected_rows;
}
-
/**
* Escapes a string for use in SQL using the currently selected
* PDO driver.
@@ -326,7 +292,6 @@ public function GetInsertID() {
$this->connect();
return (int) $this->pdo->lastInsertId();
}
-
/**
* Returns the number of rows affected by the most recent query
* if the currently selected PDO driver supports this feature.
@@ -337,7 +302,6 @@ public function Affected_Rows() {
$this->connect();
return (int) $this->affected_rows;
}
-
/**
* Toggles debug mode. In debug mode the driver will print all
* SQL to the screen together with some information about the
@@ -359,8 +323,6 @@ public function setDebugMode( $tf, $logger = NULL ) {
if ($this->debug and !$logger) $logger = new RedBean_Logger_Default();
$this->setLogger($logger);
}
-
-
/**
* Injects RedBean_Logger object.
*
@@ -369,7 +331,6 @@ public function setDebugMode( $tf, $logger = NULL ) {
public function setLogger( RedBean_Logger $logger ) {
$this->logger = $logger;
}
-
/**
* Gets RedBean_Logger object.
*
@@ -378,7 +339,6 @@ public function setLogger( RedBean_Logger $logger ) {
public function getLogger() {
return $this->logger;
}
-
/**
* Starts a transaction.
* This method is part of the transaction mechanism of
@@ -394,7 +354,6 @@ public function StartTrans() {
$this->connect();
$this->pdo->beginTransaction();
}
-
/**
* Commits a transaction.
* This method is part of the transaction mechanism of
@@ -410,7 +369,6 @@ public function CommitTrans() {
$this->connect();
$this->pdo->commit();
}
-
/**
* Rolls back a transaction.
* This method is part of the transaction mechanism of
@@ -426,7 +384,6 @@ public function FailTrans() {
$this->connect();
$this->pdo->rollback();
}
-
/**
* Returns the name of the database type/brand: i.e. mysql, db2 etc.
*
@@ -436,7 +393,6 @@ public function getDatabaseType() {
$this->connect();
return $this->pdo->getAttribute(PDO::ATTR_DRIVER_NAME);
}
-
/**
* Returns the version number of the database.
*
@@ -446,7 +402,6 @@ public function getDatabaseVersion() {
$this->connect();
return $this->pdo->getAttribute(PDO::ATTR_CLIENT_VERSION);
}
-
/**
* Returns the underlying PHP PDO instance.
*
@@ -456,7 +411,6 @@ public function getPDO() {
$this->connect();
return $this->pdo;
}
-
/**
* Closes database connection by destructing PDO.
*/
@@ -464,7 +418,6 @@ public function close() {
$this->pdo = null;
$this->isConnected = false;
}
-
/**
* Returns TRUE if the current PDO instance is connected.
*
@@ -474,7 +427,4 @@ public function isConnected() {
if (!$this->isConnected && !$this->pdo) return false;
return true;
}
-
-
-}
-
+}
View
21 RedBean/DuplicationManager.php
@@ -1,6 +1,6 @@
<?php
/**
- * RedBean Duplication Manager
+ * Duplication Manager
*
* @file RedBean/DuplicationManager.php
* @desc Creates deep copies of beans
@@ -13,26 +13,21 @@
*
*/
class RedBean_DuplicationManager {
-
-
/**
* The Dup Manager requires a toolbox
* @var RedBean_Toolbox
*/
protected $toolbox;
-
/**
* Association Manager
* @var RedBean_AssociationManager
*/
protected $associationManager;
-
/**
* RedBeanPHP OODB instance
* @var RedBean_OODBBean
*/
protected $redbean;
-
protected $tables = array();
protected $columns = array();
protected $filters = array();
@@ -47,7 +42,6 @@ public function __construct( RedBean_Toolbox $toolbox ) {
$this->redbean = $toolbox->getRedBean();
$this->associationManager = $this->redbean->getAssociationManager();
}
-
/**
* For better performance you can pass the tables in an array to this method.
* If the tables are available the duplication manager will not query them so
@@ -59,15 +53,13 @@ public function setTables($tables) {
foreach($tables as $key=>$value) {
if (is_numeric($key)) {
$this->tables[] = $value;
- }
- else {
+ } else {
$this->tables[] = $key;
$this->columns[$key] = $value;
}
}
$this->cacheTables = true;
}
-
/**
* Returns a schema array for cache.
*
@@ -76,7 +68,6 @@ public function setTables($tables) {
public function getSchema() {
return $this->columns;
}
-
/**
* Indicates whether you want the duplication manager to cache the database schema.
* If this flag is set to TRUE the duplication manager will query the database schema
@@ -88,7 +79,6 @@ public function getSchema() {
public function setCacheTables($yesNo) {
$this->cacheTables = $yesNo;
}
-
/**
* A filter array is an array with table names.
* By setting a table filter you can make the duplication manager only take into account
@@ -101,7 +91,6 @@ public function setCacheTables($yesNo) {
public function setFilters($filters) {
$this->filters = $filters;
}
-
/**
* Determines whether the bean has an own list based on
* schema inspection from realtime schema or cache.
@@ -114,7 +103,6 @@ public function setFilters($filters) {
protected function hasOwnList($type,$target) {
return (isset($this->columns[$target][$type.'_id']));
}
-
/**
* Determines whether the bea has a shared list based on
* schema inspection from realtime schema or cache.
@@ -130,7 +118,6 @@ protected function hasSharedList($type,$target) {
$linkType = implode('_',$linkType);
return (in_array($linkType,$this->tables));
}
-
/**
* Makes a copy of a bean. This method makes a deep copy
* of the bean.The copy will have the following features.
@@ -167,7 +154,6 @@ public function dup($bean,$trail=array(),$pid=false) {
}
return $rs;
}
-
/**
* Makes a copy of a bean. This method makes a deep copy
* of the bean.The copy will have the following features.
@@ -189,7 +175,6 @@ public function dup($bean,$trail=array(),$pid=false) {
* @return array $copiedBean the duplicated bean
*/
protected function duplicate($bean,$trail=array(),$pid=false) {
-
$type = $bean->getMeta('type');
$key = $type.$bean->getID();
if (isset($trail[$key])) return $bean;
@@ -221,12 +206,10 @@ protected function duplicate($bean,$trail=array(),$pid=false) {
}
}
$copy->setMeta('sys.shadow.'.$shared,null);
-
}
if ($pid) $copy->id = $bean->id;
return $copy;
}
-
/**
* Exports a collection of beans. Handy for XML/JSON exports with a
* Javascript framework like Dojo or ExtJS.
View
4 RedBean/Exception/SQL.php
@@ -12,13 +12,11 @@
* with this source code in the file license.txt.
*/
class RedBean_Exception_SQL extends RuntimeException {
-
/**
* Holds the current SQL Strate code.
* @var string
*/
private $sqlState;
-
/**
* Returns an ANSI-92 compliant SQL state.
*
@@ -27,7 +25,6 @@ class RedBean_Exception_SQL extends RuntimeException {
public function getSQLState() {
return $this->sqlState;
}
-
/**
* @todo parse state to verify valid ANSI92!
* Stores ANSI-92 compliant SQL state.
@@ -39,7 +36,6 @@ public function getSQLState() {
public function setSQLState( $sqlState ) {
$this->sqlState = $sqlState;
}
-
/**
* To String prints both code and SQL state.
*
View
1  RedBean/Logger/Default.php
@@ -12,7 +12,6 @@
* with this source code in the file license.txt.
*/
class RedBean_Logger_Default implements RedBean_Logger {
-
/**
* Default logger method logging to STDOUT.
* This is the default/reference implementation of a logger.
View
17 RedBean/Plugin/BeanCan.php
@@ -16,20 +16,17 @@
* with this source code in the file license.txt.
*/
class RedBean_Plugin_BeanCan implements RedBean_Plugin {
-
/**
* Holds a FUSE instance.
* @var RedBean_ModelHelper
*/
private $modelHelper;
-
/**
* Constructor.
*/
public function __construct() {
$this->modelHelper = new RedBean_ModelHelper;
}
-
/**
* Writes a response object for the client (JSON encoded). Internal method.
*
@@ -42,16 +39,14 @@ public function __construct() {
*/
private function resp($result=null, $id=null, $errorCode='-32603',$errorMessage='Internal Error') {
$response = array('jsonrpc'=>'2.0');
- if (!is_null($id)) { $response['id'] = $id; }
+ if (!is_null($id)) { $response['id'] = $id; }
if ($result) {
$response['result']=$result;
- }
- else {
+ } else {
$response['error'] = array('code'=>$errorCode,'message'=>$errorMessage);
}
return (json_encode($response));
}
-
/**
* Processes a JSON object request.
*
@@ -89,7 +84,6 @@ public function handleJSONRequest( $jsonString ) {
//May not contain anything other than ALPHA NUMERIC chars and _
if (preg_match('/\W/',$beanType)) return $this->resp(null, $id, -32600,'Invalid Bean Type String');
if (preg_match('/\W/',$action)) return $this->resp(null, $id, -32600,'Invalid Action String');
-
try {
switch($action) {
case 'store':
@@ -121,12 +115,10 @@ public function handleJSONRequest( $jsonString ) {
if (!method_exists($beanModel,$action)) return $this->resp(null, $id, -32601,"Method not found in Bean: $beanType ");
return $this->resp( call_user_func_array(array($beanModel,$action), $data), $id);
}
- }
- catch(Exception $exception) {
+ } catch(Exception $exception) {
return $this->resp(null, $id, -32099,$exception->getCode().'-'.$exception->getMessage());
}
}
-
/**
* Support for RESTFul GET-requests.
* Only supports very BASIC REST requests, for more functionality please use
@@ -153,5 +145,4 @@ public function handleRESTGetRequest( $pathToResource ) {
return $this->resp(null,0,-32099);
}
}
-}
-
+}
View
19 RedBean/Plugin/Cache.php
@@ -15,7 +15,6 @@
*/
class RedBean_Plugin_Cache extends RedBean_OODB implements RedBean_Plugin {
-
/**
* Bean cache, contains the cached beans identified by
* label keys containing the type id and the fetch method;
@@ -24,9 +23,6 @@ class RedBean_Plugin_Cache extends RedBean_OODB implements RedBean_Plugin {
* @var array
*/
protected $cache = array();
-
-
-
/**
* Number of hits (beans/calls being served from cache).
* Can be used to monitor cache performance.
@@ -34,7 +30,6 @@ class RedBean_Plugin_Cache extends RedBean_OODB implements RedBean_Plugin {
* @var integer
*/
protected $hits = 0;
-
/**
* Number of misses (beans not being served from cache), can be
* used to monitor cache performance.
@@ -42,7 +37,6 @@ class RedBean_Plugin_Cache extends RedBean_OODB implements RedBean_Plugin {
* @var integer
*/
protected $misses = 0;
-
/**
* Constructor.
* Cache decorates RedBeanPHP OODB class, so needs a writer.
@@ -52,9 +46,6 @@ class RedBean_Plugin_Cache extends RedBean_OODB implements RedBean_Plugin {
public function __construct(RedBean_QueryWriter $writer) {
parent::__construct($writer);
}
-
-
-
/**
* Loads a bean by type and id. If the bean cannot be found an
* empty bean will be returned instead. This is a cached version
@@ -82,7 +73,6 @@ public function load($type,$id) {
}
return $bean;
}
-
/**
* Stores a RedBean OODBBean and caches it.
*
@@ -97,7 +87,6 @@ public function store( $bean ) {
$this->cache[$type][$id] = $bean;
return $id;
}
-
/**
* Trashes a RedBean OODBBean and removes it from cache.
*
@@ -110,7 +99,6 @@ public function trash( $bean ) {
if (isset($this->cache[$type][$id])) unset($this->cache[$type][$id]);
return parent::trash($bean);
}
-
/**
* Flushes the cache for a given type.
*
@@ -122,7 +110,6 @@ public function flush($type) {
if (isset($this->cache[$type])) $this->cache[$type]=array();
return $this;
}
-
/**
* Flushes the cache completely.
*
@@ -132,8 +119,6 @@ public function flushAll() {
$this->cache = array();
return $this;
}
-
-
/**
* Returns the number of hits. If a call to load() or
* batch() can use the cache this counts as a hit.
@@ -144,7 +129,6 @@ public function flushAll() {
public function getHits() {
return $this->hits;
}
-
/**
* Returns the number of hits. If a call to load() or
* batch() can use the cache this counts as a hit.
@@ -155,19 +139,16 @@ public function getHits() {
public function getMisses() {
return $this->misses;
}
-
/**
* Resets hits counter to 0.
*/
public function resetHits() {
$this->hits = 0;
}
-
/**
* Resets misses counter to 0.
*/
public function resetMisses() {
$this->misses = 0;
}
-
}
View
31 RedBean/Plugin/Cooker.php
@@ -19,13 +19,11 @@
* with this source code in the file license.txt.
*/
class RedBean_Plugin_Cooker implements RedBean_Plugin {
-
/**
* Flag, determines whether it's possible to load beans with graph().
* @var boolean
*/
private static $loadBeans = false;
-
/**
* This flag indicates whether empty strings in beans will be
* interpreted as NULL or not. TRUE means Yes, will be converted to NULL,
@@ -33,7 +31,6 @@ class RedBean_Plugin_Cooker implements RedBean_Plugin {
* @var boolean
*/
private static $useNULLForEmptyString = false;
-
/**
* If you enable bean loading graph will load beans if there is an ID in the array.
* This is very powerful but can also cause security issues if a user knows how to
@@ -44,7 +41,6 @@ class RedBean_Plugin_Cooker implements RedBean_Plugin {
public static function enableBeanLoading($yesNo) {
self::$loadBeans = ($yesNo);
}
-
/**
* Sets the toolbox to be used by graph()
*
@@ -55,7 +51,6 @@ public function setToolbox(RedBean_Toolbox $toolbox) {
$this->toolbox = $toolbox;
$this->redbean = $this->toolbox->getRedbean();
}
-
/**
* Turns an array (post/request array) into a collection of beans.
* Handy for turning forms into bean structures that can be stored with a
@@ -103,29 +98,23 @@ public function graph( $array, $filterEmpty = false ) {
if (self::$loadBeans) {
$id = (int) $array['id'];
$bean = $this->redbean->load($type,$id);
- }
- else {
+ } else {
throw new RedBean_Exception_Security('Attempt to load a bean in Cooker. Use enableBeanLoading to override but please read security notices first.');
}
- }
- else {
+ } else {
$bean = $this->redbean->dispense($type);
}
foreach($array as $property=>$value) {
if (is_array($value)) {
$bean->$property = $this->graph($value,$filterEmpty);
- }
- else {
+ } else {
if($value == '' && self::$useNULLForEmptyString){
$bean->$property = null;
- }
- else
- $bean->$property = $value;
+ } else $bean->$property = $value;
}
}
return $bean;
- }
- elseif (is_array($array)) {
+ } elseif (is_array($array)) {
foreach($array as $key=>$value) {
$listBean = $this->graph($value,$filterEmpty);
if (!($listBean instanceof RedBean_OODBBean)) {
@@ -135,18 +124,15 @@ public function graph( $array, $filterEmpty = false ) {
if (!$filterEmpty) {
$beans[$key] = $listBean;
}
- }
- else {
+ } else {
$beans[$key] = $listBean;
}
}
return $beans;
- }
- else {
+ } else {
throw new RedBean_Exception_Security('Expected array but got :'.gettype($array));
}
}
-
/**
* Toggles the use-NULL flag.
*
@@ -155,5 +141,4 @@ public function graph( $array, $filterEmpty = false ) {
public function setUseNullFlag($yesNo) {
self::$useNULLForEmptyString = (boolean) $yesNo;
}
-
-}
+}
View
18 RedBean/Plugin/QueryLogger.php
@@ -11,15 +11,12 @@
* This source file is subject to the BSD/GPLv2 License that is bundled
* with this source code in the file license.txt.
*/
-
class RedBean_Plugin_QueryLogger implements RedBean_Observer, RedBean_Plugin {
-
/**
* @var array
* contains log messages
*/
protected $logs = array();
-
/**
* Creates a new instance of the Query Logger and attaches
* this logger to the adapter.
@@ -34,13 +31,11 @@ public static function getInstanceAndAttach( RedBean_Observable $adapter ) {
$adapter->addEventListener( 'sql_exec', $queryLog );
return $queryLog;
}
-
/**
* Singleton pattern
* Constructor - private
*/
private function __construct(){}
-
/**
* Implementation of the onEvent() method for Observer interface.
* If a query gets executed this method gets invoked because the
@@ -56,7 +51,6 @@ public function onEvent( $eventName, $adapter ) {
$this->logs[] = $adapter->getSQL();
}
}
-
/**
* Searches the logs for the given word and returns the entries found in
* the log container.
@@ -74,22 +68,16 @@ public function grep( $word ) {
}
return $found;
}
-
/**
* Returns all the logs.
*
* @return array $logs logs
*/
- public function getLogs() {
- return $this->logs;
- }
-
+ public function getLogs() { return $this->logs; }
/**
* Clears the logs.
*
* @return void
*/
- public function clear() {
- $this->logs = array();
- }
-}
+ public function clear() { $this->logs = array();}
+}
View
13 RedBean/Plugin/Sync.php
@@ -1,7 +1,6 @@
<?php
/**
* Sync
- *
* @file RedBean/Plugin/Sync.php
* @desc Plugin for Synchronizing databases.
*
@@ -16,7 +15,6 @@
* with this source code in the file license.txt.
*/
class RedBean_Plugin_Sync implements RedBean_Plugin {
-
/**
* Captures the SQL required to adjust source database to match
* schema of target database and feeds this sql code to the
@@ -26,10 +24,8 @@ class RedBean_Plugin_Sync implements RedBean_Plugin {
* @param RedBean_Toolbox $target toolbox of target database
*/
public function doSync(RedBean_Toolbox $source, RedBean_Toolbox $target) {
-
$sourceWriter = $source->getWriter();
$targetWriter = $target->getWriter();
-
$longText = str_repeat('lorem ipsum', 9000);
$testmap = array(
false, 1, 2.5, -10, 1000, 'abc', $longText, '2010-10-10', '2010-10-10 10:00:00', '10:00:00', 'POINT(1 2)'
@@ -44,13 +40,10 @@ public function doSync(RedBean_Toolbox $source, RedBean_Toolbox $target) {
if ($translation > $translations[$code] && $translation < 50)
$translations[$code] = $translation;
}
-
-
//Fix narrow translations SQLiteT stores date as double. (double != really double)
if (get_class($sourceWriter)==='RedBean_QueryWriter_SQLiteT') {
$translations[1] = $defaultCode; //use magic number in case writer not loaded.
}
-
$sourceTables = $sourceWriter->getTables();
$targetTables = $targetWriter->getTables();
$missingTables = array_diff($sourceTables, $targetTables);
@@ -78,7 +71,6 @@ public function doSync(RedBean_Toolbox $source, RedBean_Toolbox $target) {
}
}
}
-
foreach ($sourceTables as $sourceTable) {
$sourceColumns = $sourceWriter->getColumns($sourceTable);
foreach ($sourceColumns as $sourceColumn => $sourceType) {
@@ -98,8 +90,6 @@ public function doSync(RedBean_Toolbox $source, RedBean_Toolbox $target) {
}
}
}
-
-
/**
* Performs a database schema sync. For use with facade.
* Instead of toolboxes this method accepts simply string keys and is static.
@@ -115,5 +105,4 @@ public static function syncSchema($database1,$database2) {
$sync = new self;
$sync->doSync($db1, $db2);
}
-
-}
+}
View
6 RedBean/Plugin/TimeLine.php
@@ -14,16 +14,13 @@
* This source file is subject to the BSD/GPLv2 License that is bundled
* with this source code in the file license.txt.
*/
-
class RedBean_Plugin_TimeLine extends RedBean_Plugin_QueryLogger implements RedBean_Plugin {
-
/**
* Path to file to write SQL and comments to.
*
* @var string
*/
protected $file;
-
/**
* Constructor.
* Requires a path to an existing and writable file.
@@ -35,7 +32,6 @@ public function __construct($outputPath) {
throw new RedBean_Exception_Security('Cannot write to file: '.$outputPath);
$this->file = $outputPath;
}
-
/**
* Implementation of the onEvent() method for Observer interface.
* If a query gets executed this method gets invoked because the
@@ -65,6 +61,4 @@ public function onEvent( $eventName, $adapter ) {
}
}
}
-
-
}
Please sign in to comment.
Something went wrong with that request. Please try again.