From 5644c678d18d0d12c4e6e2b104d321e01c750dbe Mon Sep 17 00:00:00 2001 From: andrepereiradasilva Date: Sun, 11 Aug 2019 21:53:09 +0100 Subject: [PATCH 1/3] isConnectionEncryptionSupported method --- Tests/Mock/Driver.php | 1 + Tests/Stubs/nosqldriver.php | 12 ++++++++++++ src/DatabaseInterface.php | 9 +++++++++ src/Mysql/MysqlDriver.php | 16 ++++++++++++++++ src/Mysqli/MysqliDriver.php | 16 ++++++++++++++++ src/Pgsql/PgsqlDriver.php | 36 +++++++++++++++++++++++------------- src/Sqlite/SqliteDriver.php | 13 +++++++++++++ src/Sqlsrv/SqlsrvDriver.php | 13 +++++++++++++ 8 files changed, 103 insertions(+), 13 deletions(-) diff --git a/Tests/Mock/Driver.php b/Tests/Mock/Driver.php index b5aec54c1..2c146103b 100644 --- a/Tests/Mock/Driver.php +++ b/Tests/Mock/Driver.php @@ -49,6 +49,7 @@ public static function create(TestCase $test, $nullDate = '0000-00-00 00:00:00', 'getCollation', 'getConnectionCollation', 'getConnectionEncryption', + 'isConnectionEncryptionSupported', 'getConnectors', 'getDateFormat', 'getInstance', diff --git a/Tests/Stubs/nosqldriver.php b/Tests/Stubs/nosqldriver.php index e8384c87c..5ced55b02 100644 --- a/Tests/Stubs/nosqldriver.php +++ b/Tests/Stubs/nosqldriver.php @@ -227,6 +227,18 @@ public function getConnectionEncryption(): string return ''; } + /** + * Method to test if the database TLS connections encryption are supported. + * + * @return boolean Whether the databse supports TLS connections encryption. + * + * @since __DEPLOY_VERSION__ + */ + public function isConnectionEncryptionSupported(): bool + { + return false; + } + /** * Get the number of returned rows for the previous executed SQL statement. * diff --git a/src/DatabaseInterface.php b/src/DatabaseInterface.php index da850ce56..6ff90b6f6 100644 --- a/src/DatabaseInterface.php +++ b/src/DatabaseInterface.php @@ -149,6 +149,15 @@ public function getConnectionCollation(); */ public function getConnectionEncryption(): string; + /** + * Method to test if the database TLS connections encryption are supported. + * + * @return boolean Whether the databse supports TLS connections encryption. + * + * @since __DEPLOY_VERSION__ + */ + public function isConnectionEncryptionSupported(): bool; + /** * Get the total number of SQL statements executed by the database driver. * diff --git a/src/Mysql/MysqlDriver.php b/src/Mysql/MysqlDriver.php index b8223f72a..84ef4be64 100644 --- a/src/Mysql/MysqlDriver.php +++ b/src/Mysql/MysqlDriver.php @@ -361,6 +361,22 @@ public function getConnectionEncryption(): string return ''; } + /** + * Method to test if the database TLS connections encryption are supported. + * + * @return boolean Whether the databse supports TLS connections encryption. + * + * @since __DEPLOY_VERSION__ + */ + public function isConnectionEncryptionSupported(): bool + { + $this->connect(); + + $variables = $this->setQuery('SHOW SESSION VARIABLES WHERE `Variable_name` IN (\'have_ssl\')')->loadObjectList('Variable_name'); + + return !empty($variables['have_ssl']->Value) && $variables['have_ssl']->Value === 'YES'; + } + /** * Return the query string to create new Database. * diff --git a/src/Mysqli/MysqliDriver.php b/src/Mysqli/MysqliDriver.php index 1267d12df..7d2cca7dd 100644 --- a/src/Mysqli/MysqliDriver.php +++ b/src/Mysqli/MysqliDriver.php @@ -484,6 +484,22 @@ public function getConnectionEncryption(): string return ''; } + /** + * Method to test if the database TLS connections encryption are supported. + * + * @return boolean Whether the databse supports TLS connections encryption. + * + * @since __DEPLOY_VERSION__ + */ + public function isConnectionEncryptionSupported(): bool + { + $this->connect(); + + $variables = $this->setQuery('SHOW SESSION VARIABLES WHERE `Variable_name` IN (\'have_ssl\')')->loadObjectList('Variable_name'); + + return !empty($variables['have_ssl']->Value) && $variables['have_ssl']->Value === 'YES'; + } + /** * Return the query string to create new Database. * diff --git a/src/Pgsql/PgsqlDriver.php b/src/Pgsql/PgsqlDriver.php index ca25dcf98..f1ed46e3a 100644 --- a/src/Pgsql/PgsqlDriver.php +++ b/src/Pgsql/PgsqlDriver.php @@ -158,6 +158,20 @@ public function getConnectionEncryption(): string return ''; } + /** + * Method to test if the database TLS connections encryption are supported. + * + * @return boolean Whether the databse supports TLS connections encryption. + * + * @since __DEPLOY_VERSION__ + */ + public function isConnectionEncryptionSupported(): bool + { + $variables = $this->setQuery('SHOW "ssl"')->loadAssoc(); + + return !empty($variables['ssl']) && $variables['ssl'] === 'on'; + } + /** * Shows the table CREATE statement that creates the given tables. * @@ -233,18 +247,6 @@ public function getTableColumns($table, $typeOnly = true) { foreach ($fields as $field) { - // Change Postgresql's NULL::* type with PHP's null one - if (preg_match('/^NULL::*/', $field->Default)) - { - $field->Default = null; - } - - // Normalise default values like datetime - if (preg_match('/^\'(.*)\'::.*/', $field->Default, $matches)) - { - $field->Default = $matches[1]; - } - // Do some dirty translation to MySQL output. // @todo: Come up with and implement a standard across databases. $result[$field->column_name] = (object) [ @@ -262,6 +264,15 @@ public function getTableColumns($table, $typeOnly = true) } } + // Change Postgresql's NULL::* type with PHP's null one + foreach ($fields as $field) + { + if (preg_match('/^NULL::*/', $field->Default)) + { + $field->Default = null; + } + } + return $result; } @@ -591,7 +602,6 @@ public function sqlValue($columns, $field_name, $field_value) break; - case 'timestamp without time zone': case 'date': case 'timestamp without time zone': if (empty($field_value)) diff --git a/src/Sqlite/SqliteDriver.php b/src/Sqlite/SqliteDriver.php index f2d89681d..81262c04c 100644 --- a/src/Sqlite/SqliteDriver.php +++ b/src/Sqlite/SqliteDriver.php @@ -182,6 +182,19 @@ public function getConnectionEncryption(): string return ''; } + /** + * Method to test if the database TLS connections encryption are supported. + * + * @return boolean Whether the databse supports TLS connections encryption. + * + * @since __DEPLOY_VERSION__ + */ + public function isConnectionEncryptionSupported(): bool + { + // TODO: Not fake this + return false; + } + /** * Shows the table CREATE statement that creates the given tables. * diff --git a/src/Sqlsrv/SqlsrvDriver.php b/src/Sqlsrv/SqlsrvDriver.php index ea5f2b92c..9476f2f04 100644 --- a/src/Sqlsrv/SqlsrvDriver.php +++ b/src/Sqlsrv/SqlsrvDriver.php @@ -368,6 +368,19 @@ public function getConnectionEncryption(): string return ''; } + /** + * Method to test if the database TLS connections encryption are supported. + * + * @return boolean Whether the databse supports TLS connections encryption. + * + * @since __DEPLOY_VERSION__ + */ + public function isConnectionEncryptionSupported(): bool + { + // TODO: Not fake this + return false; + } + /** * Retrieves field information about the given tables. * From ee0ae3f176b7d41c0a97344481ffc148ce443841 Mon Sep 17 00:00:00 2001 From: andrepereiradasilva Date: Sun, 11 Aug 2019 22:08:31 +0100 Subject: [PATCH 2/3] sincronyze --- src/Pgsql/PgsqlDriver.php | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/Pgsql/PgsqlDriver.php b/src/Pgsql/PgsqlDriver.php index f1ed46e3a..4ba1294fa 100644 --- a/src/Pgsql/PgsqlDriver.php +++ b/src/Pgsql/PgsqlDriver.php @@ -247,6 +247,18 @@ public function getTableColumns($table, $typeOnly = true) { foreach ($fields as $field) { + // Change Postgresql's NULL::* type with PHP's null one + if (preg_match('/^NULL::*/', $field->Default)) + { + $field->Default = null; + } + + // Normalise default values like datetime + if (preg_match('/^\'(.*)\'::.*/', $field->Default, $matches)) + { + $field->Default = $matches[1]; + } + // Do some dirty translation to MySQL output. // @todo: Come up with and implement a standard across databases. $result[$field->column_name] = (object) [ @@ -264,15 +276,6 @@ public function getTableColumns($table, $typeOnly = true) } } - // Change Postgresql's NULL::* type with PHP's null one - foreach ($fields as $field) - { - if (preg_match('/^NULL::*/', $field->Default)) - { - $field->Default = null; - } - } - return $result; } @@ -602,6 +605,7 @@ public function sqlValue($columns, $field_name, $field_value) break; + case 'timestamp without time zone': case 'date': case 'timestamp without time zone': if (empty($field_value)) @@ -1094,4 +1098,4 @@ public function decodeBinary($data) return $data; } -} +} \ No newline at end of file From ff47f088459d4f347ff6cb1b4c9bbaaa434e9d11 Mon Sep 17 00:00:00 2001 From: andrepereiradasilva Date: Sun, 11 Aug 2019 22:34:05 +0100 Subject: [PATCH 3/3] cs: newline missing at the end of file --- src/Pgsql/PgsqlDriver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Pgsql/PgsqlDriver.php b/src/Pgsql/PgsqlDriver.php index 4ba1294fa..8bb5f82e7 100644 --- a/src/Pgsql/PgsqlDriver.php +++ b/src/Pgsql/PgsqlDriver.php @@ -1098,4 +1098,4 @@ public function decodeBinary($data) return $data; } -} \ No newline at end of file +}