diff options
| author | Damien Regad <dregad@mantisbt.org> | 2022-01-08 12:13:00 +0100 |
|---|---|---|
| committer | Damien Regad <dregad@mantisbt.org> | 2022-01-08 12:13:00 +0100 |
| commit | ef1beb93161fc87f308e0566695ee8d45756224d (patch) | |
| tree | 729d6a6ed6e421a9738425053d2ebd104a7c8954 /adodb-loadbalancer.inc.php | |
| parent | 2a82884df7f254a7308a02d92a8c70c95c32d1ce (diff) | |
| download | adodb-ef1beb93161fc87f308e0566695ee8d45756224d.tar.gz adodb-ef1beb93161fc87f308e0566695ee8d45756224d.tar.bz2 adodb-ef1beb93161fc87f308e0566695ee8d45756224d.zip | |
Coding guidelines
Diffstat (limited to 'adodb-loadbalancer.inc.php')
| -rw-r--r-- | adodb-loadbalancer.inc.php | 76 |
1 files changed, 39 insertions, 37 deletions
diff --git a/adodb-loadbalancer.inc.php b/adodb-loadbalancer.inc.php index 797bfd4d..88f5d0fd 100644 --- a/adodb-loadbalancer.inc.php +++ b/adodb-loadbalancer.inc.php @@ -233,7 +233,7 @@ class ADOdbLoadBalancer * @return bool|ADOConnection * @throws Exception */ - public function getConnectionById( $connection_id) + public function getConnectionById($connection_id) { if (isset($this->connections[$connection_id])) { $connection_obj = $this->connections[$connection_id]; @@ -261,12 +261,14 @@ class ADOdbLoadBalancer throw $e; // No connections left, reThrow exception so application can catch it. } - //Check to see if a connection test callback was defined, and if so execute it. - // This is useful for testing replication lag and such to ensure the connection is suitable to be used. - $test_connection_callback = $connection_obj->getConnectionTestCallback(); - if ( is_callable( $test_connection_callback ) AND $test_connection_callback( $connection_obj, $adodb_obj ) !== TRUE ) { - return FALSE; - } + // Check to see if a connection test callback was defined, and if so execute it. + // This is useful for testing replication lag and such to ensure the connection is suitable to be used. + $test_connection_callback = $connection_obj->getConnectionTestCallback(); + if (is_callable($test_connection_callback) + && $test_connection_callback($connection_obj, $adodb_obj) !== TRUE + ) { + return false; + } if (is_array($this->user_defined_session_init_sql)) { foreach ($this->user_defined_session_init_sql as $session_init_sql) { @@ -306,11 +308,11 @@ class ADOdbLoadBalancer if ($connection_id !== false) { try { $adodb_obj = $this->getConnectionById($connection_id); - if ( is_object( $adodb_obj ) ) { - break; //Found valid connection, continue with it. - } else { - throw new Exception('ADODB Connection Object does not exist. Perhaps LoadBalancer Database Connection Test Failed?'); - } + if (is_object($adodb_obj)) { + break; //Found valid connection, continue with it. + } else { + throw new Exception('ADODB Connection Object does not exist. Perhaps LoadBalancer Database Connection Test Failed?'); + } } catch (Exception $e) { // Connection error, see if there are other connections to try still. $this->removeConnection($connection_id); @@ -325,9 +327,9 @@ class ADOdbLoadBalancer } } - if ( !isset($connection_id) ) { - throw new Exception('No connection available to use at this time! Type: '. $type ); - } + if (!isset($connection_id)) { + throw new Exception('No connection available to use at this time! Type: ' . $type); + } $this->last_connection_id[$type] = $connection_id; @@ -446,7 +448,7 @@ class ADOdbLoadBalancer && $connection_obj->getADOdbObject()->_connectionID !== false ) ) { - $adodb_obj = $this->getConnectionById( $key); + $adodb_obj = $this->getConnectionById($key); if (is_object($adodb_obj)) { $result_arr[] = $adodb_obj->Execute($sql, $inputarr); } @@ -609,7 +611,7 @@ class ADOdbLoadBalancer case 'binddate': case 'bindtimestamp': case 'setfetchmode': - case 'setcustommetatype': + case 'setcustommetatype': $type = false; // No connection necessary. break; @@ -701,10 +703,10 @@ class ADOdbLoadBalancerConnection */ protected $adodb_obj = false; - /** - * @var callable Closure - */ - protected $connection_test_callback = NULL; + /** + * @var callable Closure + */ + protected $connection_test_callback = NULL; /** * @var string Type of connection, either 'write' capable or 'readonly' @@ -781,23 +783,23 @@ class ADOdbLoadBalancerConnection return true; } - /** - * Anonymous function that is called and must return TRUE for the connection to be usable. - * The first argument is the type of connection to test. - * Useful to check things like replication lag. - * @param $callback - * @return void - */ - function setConnectionTestCallback( $callback ) { - $this->connection_test_callback = $callback; - } + /** + * Anonymous function that is called and must return TRUE for the connection to be usable.* + * The first argument is the type of connection to test. + * Useful to check things like replication lag. + * @param callable $callback + * @return void + */ + function setConnectionTestCallback($callback) { + $this->connection_test_callback = $callback; + } - /** - * @return callable|null - */ - function getConnectionTestCallback() { - return $this->connection_test_callback; - } + /** + * @return callable|null + */ + function getConnectionTestCallback() { + return $this->connection_test_callback; + } /** * Returns the ADODB object for this connection. |
