Skip to content
Permalink
Browse files

ID#323: introduced type declaration for database connection classes.

  • Loading branch information...
Christian Achatz
Christian Achatz committed May 15, 2018
1 parent f774d24 commit 8730d3c694f7312c59a3a5d0bdc12c5b6e4f9814
@@ -201,27 +201,35 @@ abstract class AbstractDatabaseHandler extends APFObject implements DatabaseConn
*
* @param string $host The database host to connect to.
*
* @return $this This instance for further usage.
*
* @author Christian Achatz
* @version
* Version 0.1, 07.05.2012<br />
*/
public function setHost($host) {
public function setHost(string $host) {
$this->dbHost = $host;
return $this;
}
/**
* Defines the database port to connect to.
* <p/>
* Can be used for manual or DI configuration.
*
* @param int $port The database port to connect to.
* @param string $port The database port to connect to.
*
* @return $this This instance for further usage.
*
* @author Christian Achatz
* @version
* Version 0.1, 07.05.2012<br />
*/
public function setPort($port) {
public function setPort(string $port) {
$this->dbPort = $port;
return $this;
}
/**
@@ -231,12 +239,16 @@ public function setPort($port) {
*
* @param string $name Th name of the database to connect to.
*
* @return $this This instance for further usage.
*
* @author Christian Achatz
* @version
* Version 0.1, 07.05.2012<br />
*/
public function setDatabaseName($name) {
public function setDatabaseName(string $name) {
$this->dbName = $name;
return $this;
}
/**
@@ -246,12 +258,16 @@ public function setDatabaseName($name) {
*
* @param string $user The database user.
*
* @return $this This instance for further usage.
*
* @author Christian Achatz
* @version
* Version 0.1, 07.05.2012<br />
*/
public function setUser($user) {
public function setUser(string $user) {
$this->dbUser = $user;
return $this;
}
/**
@@ -261,12 +277,16 @@ public function setUser($user) {
*
* @param string $pass The database password.
*
* @return $this This instance for further usage.
*
* @author Christian Achatz
* @version
* Version 0.1, 07.05.2012<br />
*/
public function setPass($pass) {
public function setPass(string $pass) {
$this->dbPass = $pass;
return $this;
}
/**
@@ -276,12 +296,16 @@ public function setPass($pass) {
*
* @param string $socket The socket descriptor.
*
* @return $this This instance for further usage.
*
* @author Christian Achatz
* @version
* Version 0.1, 07.05.2012<br />
*/
public function setSocket($socket) {
public function setSocket(string $socket) {
$this->dbSocket = $socket;
return $this;
}
/**
@@ -291,12 +315,16 @@ public function setSocket($socket) {
*
* @param string $charset The desired character set.
*
* @return $this This instance for further usage.
*
* @author Christian Achatz
* @version
* Version 0.1, 07.05.2012<br />
*/
public function setCharset($charset) {
public function setCharset(string $charset) {
$this->dbCharset = $charset;
return $this;
}
/**
@@ -306,27 +334,35 @@ public function setCharset($charset) {
*
* @param string $collation The desired collation.
*
* @return $this This instance for further usage.
*
* @author Christian Achatz
* @version
* Version 0.1, 07.05.2012<br />
*/
public function setCollation($collation) {
public function setCollation(string $collation) {
$this->dbCollation = $collation;
return $this;
}
/**
* Enables (true) or disables (false) the internal debugging feature (=statement logging).
* <p/>
* Can be used for manual or DI configuration.
*
* @param boolean $debug <em>True</em> in case the logging feature should be switched on, <em>false</em> otherwise.
* @param string $debug <em>true|1</em> in case the logging feature should be switched on, <em>false|0</em> otherwise.
*
* @return $this This instance for further usage.
*
* @author Christian Achatz
* @version
* Version 0.1, 07.05.2012<br />
*/
public function setDebug($debug) {
public function setDebug(string $debug) {
$this->dbDebug = ($debug == 'true' || $debug == '1') ? true : false;
return $this;
}
/**
@@ -336,12 +372,16 @@ public function setDebug($debug) {
*
* @param string $logTarget The name of debug log file.
*
* @return $this This instance for further usage.
*
* @author Christian Achatz
* @version
* Version 0.1, 07.05.2012<br />
*/
public function setLogTarget($logTarget) {
public function setLogTarget(string $logTarget) {
$this->dbLogTarget = $logTarget;
return $this;
}
/**
@@ -367,7 +407,7 @@ public function setup() {
* @version
* Version 0.1, 10.02.2008<br />
*/
public function init($initParam) {
public function init(array $initParam) {
if ($this->isInitialized == false) {
@@ -484,7 +524,7 @@ protected function initCharsetAndCollation() {
* @version
* Version 0.1, 03.02.2011<br />
*/
protected function getPreparedStatement($namespace, $name, array $params = []) {
protected function getPreparedStatement(string $namespace, string $name, array $params = []) {
try {
$config = $this->getConfiguration($namespace, $name);
} catch (ConfigurationException $e) {
@@ -57,7 +57,7 @@ public function setup();
* @version
* Version 0.1, 10.02.2008<br />
*/
public function executeStatement($namespace, $statementName, array $params = [], $logStatement = false);
public function executeStatement(string $namespace, string $statementName, array $params = [], bool $logStatement = false);
/**
* Executes a statement applied as a string to the method and returns the
@@ -73,7 +73,7 @@ public function executeStatement($namespace, $statementName, array $params = [],
* @version
* Version 0.1, 10.02.2008<br />
*/
public function executeTextStatement($statement, $logStatement = false);
public function executeTextStatement(string $statement, bool $logStatement = false);
/**
* Fetches a record from the database using the given result resource.
@@ -101,7 +101,7 @@ public function fetchData($resultCursor, $type = self::ASSOC_FETCH_MODE);
* @version
* Version 0.1, 23.02.2008<br />
*/
public function escapeValue($value);
public function escapeValue(string $value);
/**
* Returns the amount of rows, that are affected by a previous update or delete call.
@@ -68,7 +68,7 @@ public function __construct() {
* @version
* Version 0.1, 10.03.2010<br />
*/
public function executeStatement($namespace, $statementFile, array $params = [], $logStatement = false) {
public function executeStatement(string $namespace, string $statementFile, array $params = [], bool $logStatement = false) {
// load statement file content
$statement = $this->getPreparedStatement($namespace, $statementFile, $params);
@@ -393,7 +393,7 @@ public function getBindNumRows() {
* @version
* Version 0.1, 24.02.2010<br />
*/
public function escapeValue($value) {
public function escapeValue(string $value) {
return $this->dbConn->real_escape_string($value);
}
@@ -491,7 +491,7 @@ public function getNumRows($result) {
* @version
* Version 0.1, 09.03.2010<br />
*/
public function executeTextStatement($statement, $logStatement = false) {
public function executeTextStatement(string $statement, bool $logStatement = false) {
// log statements in debug mode or when requested explicitly
if ($this->dbDebug == true || $logStatement == true) {
@@ -54,7 +54,7 @@ public function __construct() {
}
}
public function init($initParam) {
public function init(array $initParam) {
// set database type for pdo connection
if (isset($initParam['PDO'])) {
@@ -149,7 +149,7 @@ public function prepareStatement($statement) {
* @version
* Version 0.1, 11.04.2012<br />
*/
public function executeStatement($namespace, $statementFile, array $params = [], $logStatement = false) {
public function executeStatement(string $namespace, string $statementFile, array $params = [], bool $logStatement = false) {
// load statement file content
$statement = $this->getPreparedStatement($namespace, $statementFile, $params);
@@ -190,7 +190,7 @@ public function executeStatement($namespace, $statementFile, array $params = [],
* @version
* Version 0.1, 11.04.2012<br />
*/
public function executeTextStatement($statement, $logStatement = false) {
public function executeTextStatement(string $statement, bool $logStatement = false) {
// log statements in debug mode or when requested explicitly
if ($this->dbDebug == true || $logStatement == true) {
$this->dbLog->logEntry($this->dbLogTarget, '[PDOHandler::executeTextStatement()] Current statement: ' . $statement, LogEntry::SEVERITY_DEBUG);
@@ -256,7 +256,7 @@ public function fetchData($pdoStatement, $type = self::ASSOC_FETCH_MODE) {
* @version
* Version 0.1, 11.04.2012<br />
*/
public function escapeValue($value) {
public function escapeValue(string $value) {
$quoted = $this->dbConn->quote($value);
return substr($quoted, 1, strlen($quoted) - 2);
@@ -69,7 +69,7 @@ public function __construct() {
* @version
* Version 0.1, 10.02.2008<br />
*/
public function executeTextStatement($statement, $logStatement = false) {
public function executeTextStatement(string $statement, bool $logStatement = false) {
if ($logStatement == true) {
$this->dbLog->logEntry($this->dbLogTarget, '[SQLiteHandler::executeTextStatement()] Current statement: ' . $statement, LogEntry::SEVERITY_DEBUG);
@@ -106,7 +106,7 @@ public function executeTextStatement($statement, $logStatement = false) {
* Version 0.1, 24.02.2008<br />
* Version 0.2, 21.06.2008 (Replaced APPS__ENVIRONMENT with a value from the Registry)<br />
*/
public function executeStatement($namespace, $statementName, array $params = [], $logStatement = false) {
public function executeStatement(string $namespace, string $statementName, array $params = [], bool $logStatement = false) {
$statement = $this->getPreparedStatement($namespace, $statementName, $params);
@@ -162,7 +162,7 @@ public function fetchData($resultCursor, $type = self::ASSOC_FETCH_MODE) {
* @version
* Version 0.1, 23.02.2008<br />
*/
public function escapeValue($value) {
public function escapeValue(string $value) {
return sqlite_escape_string($value);
}
Oops, something went wrong.

0 comments on commit 8730d3c

Please sign in to comment.
You can’t perform that action at this time.