Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/php-security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
php-version:
- "7.3"
- "7.4"
- "8.0"
operating-system:
- "ubuntu-latest"

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
php-version:
- "7.3"
- "7.4"
- "8.0"
operating-system:
- "ubuntu-latest"

Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
vendor/
composer.lock
.phpunit.result.cache
instances/example/config/test.sqlite3
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
}
],
"require": {
"php": "^7.3|^7.4",
"php": "^7.3|^7.4|^8.0",
"adodb/adodb-php": "^5.21",
"geoip/geoip": "^1.17",
"neutron/sphinxsearch-api": "^2.0",
Expand All @@ -40,8 +40,9 @@
"weotch/phpthumb": "^1.0.5"
},
"require-dev": {
"ext-pdo_sqlite": "*",
"adlawson/vfs": "^0.12.1",
"mikey179/vfsstream": "^1.6",
"mikey179/vfsstream": "^1.6.10",
"phpcompatibility/php-compatibility": "^9.3",
"phpunit/phpunit": "^9.5",
"sifophp/sifo-common-instance": "@dev",
Expand All @@ -51,6 +52,9 @@
},
"scripts": {
"cs-check": "phpcs src --colors",
"cs-check:php73": "phpcs -p ./src --standard=vendor/phpcompatibility/php-compatibility/PHPCompatibility --runtime-set testVersion 7.3",
"cs-check:php74": "phpcs -p ./src --standard=vendor/phpcompatibility/php-compatibility/PHPCompatibility --runtime-set testVersion 7.4",
"cs-check:php8": "phpcs -p ./src --standard=vendor/phpcompatibility/php-compatibility/PHPCompatibility --runtime-set testVersion 8.0",
"cs-fix": "phpcbf src --colors"
},
"config": {
Expand Down
8 changes: 2 additions & 6 deletions instances/example/config/domains.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,8 @@
'static_host' => 'http://static.sifo.local',
'media_host' => 'http://static.sifo.local', // Alternative static content (media). Comment to disable.
'database' => array(
'db_driver' => 'mysql', // To use transactions you must use mysqli driver.
'db_host' => '127.0.0.1',
'db_user' => 'root',
'db_password' => 'root',
'db_name' => 'yourdatabase',
'db_init_commands' => array( 'SET NAMES utf8' ) // Commands launched before the queries.
'db_driver' => 'sqlite', // To use transactions you must use mysqli driver.
'db_dsn' => sprintf('sqlite:/%s/test.sqlite3', __DIR__),
),
'php_ini_sets' => array( // Empty array if you don't want any php.ini overriden.
'log_errors' => 'On',
Expand Down
1 change: 0 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
convertWarningsToExceptions="true"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
enforceTimeLimit="true"
beStrictAboutTestsThatDoNotTestAnything="false"
processIsolation="false"
stopOnFailure="false"
Expand Down
103 changes: 73 additions & 30 deletions src/Sifo/Debug/Mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@
namespace Sifo;
use PDO,PDOStatement;

include_once ROOT_PATH . '/vendor/sifophp/sifo/src/Sifo/Mysql.php';

/**
* DbDebugStatement class that is extended for debugging purposes.
*/
class DebugMysqlStatement extends MysqlStatement
abstract class PDOBadAbstractionDebugMysqlStatement extends MysqlStatement
{
/**
* Binded parameters ( not binded values ).
Expand Down Expand Up @@ -83,8 +81,11 @@ public function execute($parameters = null)
$query_string = $this->_replacePreparedParameters( $query_string, $parameters );

preg_match('/\/\* (.*?) \*\/\n(.*)/s', $query_string, $matches);
$context = $matches[1];
$query_string = $matches[2];
$context = 'unknow';
if (false === empty($matches)) {
$context = $matches[1];
$query_string = $matches[2];
}

DebugMysql::setDebug( $query_string, $query_time, $context, $this, $this->db_params );

Expand Down Expand Up @@ -152,32 +153,64 @@ public function fetch( $fetch_style = PDO::FETCH_ASSOC, $cursor_orientation = PD

return parent::fetch( $fetch_style, $cursor_orientation, $cursor_offset );
}
}

/**
* Returns an array containing all of the result set rows.
*
* @param integer $fetch_style Controls the contents of the returned array as documented in PDOStatement::fetch().
* @param mixed $fetch_argument This argument have a different meaning depending on the value of the fetch_style parameter.
* @param array $ctor_args Arguments of custom class constructor when the fetch_style parameter is PDO::FETCH_CLASS.
* @return array
*/
public function fetchAll( $fetch_style = PDO::FETCH_ASSOC, $fetch_argument = null, $ctor_args = array() )
{
if ($this->result !== null)
if (version_compare(PHP_VERSION, '8.0.0') >= 0) {
class DebugMysqlStatement extends PDOBadAbstractionDebugMysqlStatement
{
/**
* Returns an array containing all of the result set rows.
*
* @param integer $fetch_style Controls the contents of the returned array as documented in PDOStatement::fetch().
* @param mixed $fetch_argument This argument have a different meaning depending on the value of the fetch_style parameter.
* @param array $ctor_args Arguments of custom class constructor when the fetch_style parameter is PDO::FETCH_CLASS.
* @return array
*/
public function fetchAll(int $fetch_style = PDO::FETCH_ASSOC, $fetch_argument = null, mixed ...$ctor_args): array
{
$results = $this->result;
$this->result = null;
if ($this->result !== null) {
$results = $this->result;
$this->result = null;

return $results;
}

if ($fetch_argument === null) {
return $this->result = parent::fetchAll($fetch_style);
}

return $results;
return $this->result = parent::fetchAll($fetch_style, $fetch_argument, $ctor_args);
}
}
}

if ( $fetch_argument === null )
{
return $this->result = parent::fetchAll( $fetch_style );
}
if (version_compare(PHP_VERSION, '8.0.0') < 0) {
class DebugMysqlStatement extends PDOBadAbstractionDebugMysqlStatement
{
/**
* Returns an array containing all of the result set rows.
*
* @param integer $fetch_style Controls the contents of the returned array as documented in PDOStatement::fetch().
* @param mixed $fetch_argument This argument have a different meaning depending on the value of the fetch_style parameter.
* @param array $ctor_args Arguments of custom class constructor when the fetch_style parameter is PDO::FETCH_CLASS.
* @return array
*/
public function fetchAll($fetch_style = PDO::FETCH_ASSOC, $fetch_argument = null, $ctor_args = []): array
{
if ($this->result !== null) {
$results = $this->result;
$this->result = null;

return $this->result = parent::fetchAll( $fetch_style, $fetch_argument, $ctor_args );
}
return $results;
}

if ($fetch_argument === null) {
return $this->result = parent::fetchAll($fetch_style);
}

return $this->result = parent::fetchAll($fetch_style, $fetch_argument, $ctor_args);
}
}
}

/**
Expand Down Expand Up @@ -302,20 +335,30 @@ public static function setDebug( $statement, $query_time, $context, $resultset,
}

$sql = '/* ' . $context . ' */' . PHP_EOL . $statement;
$debug_query = array(
if (isset($db_params['db_dsn'])) {
$database = [
'dsn' => $db_params['db_dsn']
];

} else {
$database = [
'host' => $db_params['db_host'],
'database' => $db_params['db_name'],
'user' => $db_params['db_user'],
];
}

$debug_query = array_merge([
"tag" => $context,
"sql" => $sql,
"type" => ( ( 0 === stripos( $statement, 'SELECT' ) ) ? 'read' : 'write' ),
"host" => $db_params['db_host'],
"database" => $db_params['db_name'],
"user" => $db_params['db_user'],
// phpcs:ignore
"trace" => DebugMysql::generateTrace( debug_backtrace( false ) ),
// Show a table with the method name and number (functions: Affected_Rows, Last_InsertID
"resultset" => $resultset_array,
"time" => $query_time,
"error" => ( isset( $error[2] ) !== false ) ? $error[2] : false
);
], $database);

$debug_query['rows_num'] = $rows_num;

Expand Down
Loading