From 7c1f735f9b4c4aa77e6d8f8fd9547b923c46f830 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 6 Oct 2015 01:39:01 +0200 Subject: [PATCH] used PHP 5.4 syntax --- .travis.yml | 4 +- dibi/dibi.php | 2 +- examples/connecting-to-databases.php | 40 +-- examples/database-reflection.php | 4 +- examples/dumping-sql-and-result-set.php | 4 +- examples/fetching-examples.php | 4 +- examples/importing-dump-from-file.php | 4 +- examples/query-language-and-conditions.php | 10 +- examples/query-language-basic-examples.php | 22 +- examples/result-set-data-types.php | 4 +- examples/tracy-and-exceptions.php | 8 +- examples/tracy.php | 8 +- examples/using-datetime.php | 8 +- examples/using-extension-methods.php | 4 +- examples/using-fluent-syntax.php | 8 +- examples/using-limit-and-offset.php | 4 +- examples/using-logger.php | 8 +- examples/using-profiler.php | 8 +- examples/using-substitutions.php | 4 +- examples/using-transactions.php | 8 +- readme.md | 20 +- src/Dibi/Bridges/Nette/DibiExtension21.php | 8 +- src/Dibi/Bridges/Nette/DibiExtension22.php | 4 +- src/Dibi/Bridges/Nette/Panel.php | 14 +- src/Dibi/Bridges/Tracy/Panel.php | 12 +- src/Dibi/Connection.php | 25 +- src/Dibi/DataSource.php | 10 +- src/Dibi/Drivers/FirebirdDriver.php | 50 +-- src/Dibi/Drivers/MsSql2005Driver.php | 8 +- src/Dibi/Drivers/MsSql2005Reflector.php | 20 +- src/Dibi/Drivers/MsSqlDriver.php | 10 +- src/Dibi/Drivers/MsSqlReflector.php | 28 +- src/Dibi/Drivers/MySqlDriver.php | 12 +- src/Dibi/Drivers/MySqlReflector.php | 16 +- src/Dibi/Drivers/MySqliDriver.php | 16 +- src/Dibi/Drivers/OdbcDriver.php | 28 +- src/Dibi/Drivers/OracleDriver.php | 12 +- src/Dibi/Drivers/PdoDriver.php | 18 +- src/Dibi/Drivers/PostgreDriver.php | 38 +- src/Dibi/Drivers/Sqlite3Driver.php | 12 +- src/Dibi/Drivers/SqliteReflector.php | 18 +- src/Dibi/Event.php | 6 +- src/Dibi/Fluent.php | 72 ++-- src/Dibi/Helpers.php | 4 +- src/Dibi/Loggers/FirePhpLogger.php | 14 +- src/Dibi/Object.php | 4 +- src/Dibi/Reflection/Column.php | 8 +- src/Dibi/Reflection/Database.php | 4 +- src/Dibi/Reflection/ForeignKey.php | 2 +- src/Dibi/Reflection/Result.php | 4 +- src/Dibi/Reflection/Table.php | 6 +- src/Dibi/Result.php | 16 +- src/Dibi/Translator.php | 10 +- src/Dibi/dibi.php | 74 ++-- src/Dibi/exceptions.php | 6 +- tests/dibi/Connection.affectedRows.phpt | 4 +- tests/dibi/Connection.connect.phpt | 2 +- tests/dibi/Connection.fetch.phpt | 394 ++++++++++----------- tests/dibi/Connection.transactions.phpt | 8 +- tests/dibi/DataSource.phpt | 36 +- tests/dibi/Fluent.fetch.phpt | 36 +- tests/dibi/Fluent.insert.phpt | 4 +- tests/dibi/Fluent.select.phpt | 14 +- tests/dibi/Fluent.update.phpt | 6 +- tests/dibi/Result.meta.phpt | 4 +- tests/dibi/Result.types.phpt | 4 +- tests/dibi/Row.phpt | 4 +- tests/dibi/Translator.phpt | 158 ++++----- tests/dibi/meta.phpt | 2 +- 69 files changed, 718 insertions(+), 733 deletions(-) diff --git a/.travis.yml b/.travis.yml index 07edc0b5..4259ab83 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,7 @@ matrix: script: - vendor/bin/tester tests -s -p php -c tests/php-unix.ini - - php code-checker/src/code-checker.php + - php temp/code-checker/src/code-checker.php --short-arrays after_failure: # Print *.actual content @@ -21,7 +21,7 @@ after_failure: before_script: # Install Nette Tester & Code Checker - travis_retry composer install --no-interaction - - travis_retry composer create-project nette/code-checker code-checker ~2.5 --no-interaction + - travis_retry composer create-project nette/code-checker temp/code-checker ~2.5 --no-interaction # Create databases.ini - cp ./tests/databases.sample.ini ./tests/databases.ini diff --git a/dibi/dibi.php b/dibi/dibi.php index 33213417..e5df9ef3 100644 --- a/dibi/dibi.php +++ b/dibi/dibi.php @@ -1,3 +1,3 @@ Connecting to Sqlite: '; try { - dibi::connect(array( + dibi::connect([ 'driver' => 'sqlite3', 'database' => 'data/sample.s3db', - )); + ]); echo 'OK'; } catch (DibiException $e) { echo get_class($e), ': ', $e->getMessage(), "\n"; @@ -24,10 +24,10 @@ echo "

\n"; // connects to SQlite using DibiConnection object echo '

Connecting to Sqlite: '; try { - $connection = new DibiConnection(array( + $connection = new DibiConnection([ 'driver' => 'sqlite3', 'database' => 'data/sample.s3db', - )); + ]); echo 'OK'; } catch (DibiException $e) { echo get_class($e), ': ', $e->getMessage(), "\n"; @@ -49,17 +49,17 @@ echo "

\n"; // connects to MySQLi using array echo '

Connecting to MySQLi: '; try { - dibi::connect(array( + dibi::connect([ 'driver' => 'mysqli', 'host' => 'localhost', 'username' => 'root', 'password' => 'xxx', 'database' => 'dibi', - 'options' => array( + 'options' => [ MYSQLI_OPT_CONNECT_TIMEOUT => 30, - ), + ], 'flags' => MYSQLI_CLIENT_COMPRESS, - )); + ]); echo 'OK'; } catch (DibiException $e) { echo get_class($e), ': ', $e->getMessage(), "\n"; @@ -70,12 +70,12 @@ echo "

\n"; // connects to ODBC echo '

Connecting to ODBC: '; try { - dibi::connect(array( + dibi::connect([ 'driver' => 'odbc', 'username' => 'root', 'password' => '***', 'dsn' => 'Driver={Microsoft Access Driver (*.mdb)};Dbq='.__DIR__.'/data/sample.mdb', - )); + ]); echo 'OK'; } catch (DibiException $e) { echo get_class($e), ': ', $e->getMessage(), "\n"; @@ -86,11 +86,11 @@ echo "

\n"; // connects to PostgreSql echo '

Connecting to PostgreSql: '; try { - dibi::connect(array( + dibi::connect([ 'driver' => 'postgre', 'string' => 'host=localhost port=5432 dbname=mary', 'persistent' => TRUE, - )); + ]); echo 'OK'; } catch (DibiException $e) { echo get_class($e), ': ', $e->getMessage(), "\n"; @@ -101,10 +101,10 @@ echo "

\n"; // connects to PDO echo '

Connecting to Sqlite via PDO: '; try { - dibi::connect(array( + dibi::connect([ 'driver' => 'pdo', 'dsn' => 'sqlite::memory:', - )); + ]); echo 'OK'; } catch (DibiException $e) { echo get_class($e), ': ', $e->getMessage(), "\n"; @@ -115,12 +115,12 @@ echo "

\n"; // connects to MS SQL echo '

Connecting to MS SQL: '; try { - dibi::connect(array( + dibi::connect([ 'driver' => 'mssql', 'host' => 'localhost', 'username' => 'root', 'password' => 'xxx', - )); + ]); echo 'OK'; } catch (DibiException $e) { echo get_class($e), ': ', $e->getMessage(), "\n"; @@ -131,13 +131,13 @@ echo "

\n"; // connects to MS SQL 2005 echo '

Connecting to MS SQL 2005: '; try { - dibi::connect(array( + dibi::connect([ 'driver' => 'mssql2005', 'host' => '(local)', 'username' => 'Administrator', 'password' => 'xxx', 'database' => 'main', - )); + ]); echo 'OK'; } catch (DibiException $e) { echo get_class($e), ': ', $e->getMessage(), "\n"; @@ -148,12 +148,12 @@ echo "

\n"; // connects to Oracle echo '

Connecting to Oracle: '; try { - dibi::connect(array( + dibi::connect([ 'driver' => 'oracle', 'username' => 'root', 'password' => 'xxx', 'database' => 'db', - )); + ]); echo 'OK'; } catch (DibiException $e) { echo get_class($e), ': ', $e->getMessage(), "\n"; diff --git a/examples/database-reflection.php b/examples/database-reflection.php index 119ac3c0..ba6a7bf0 100644 --- a/examples/database-reflection.php +++ b/examples/database-reflection.php @@ -7,10 +7,10 @@ require __DIR__ . '/../src/loader.php'; -dibi::connect(array( +dibi::connect([ 'driver' => 'sqlite3', 'database' => 'data/sample.s3db', -)); +]); // retrieve database reflection diff --git a/examples/dumping-sql-and-result-set.php b/examples/dumping-sql-and-result-set.php index bbf86b23..67e12a21 100644 --- a/examples/dumping-sql-and-result-set.php +++ b/examples/dumping-sql-and-result-set.php @@ -7,10 +7,10 @@ require __DIR__ . '/../src/loader.php'; -dibi::connect(array( +dibi::connect([ 'driver' => 'sqlite3', 'database' => 'data/sample.s3db', -)); +]); $res = dibi::query(' diff --git a/examples/fetching-examples.php b/examples/fetching-examples.php index 329ae356..4bfa7adb 100644 --- a/examples/fetching-examples.php +++ b/examples/fetching-examples.php @@ -11,10 +11,10 @@ if (@!include __DIR__ . '/../vendor/autoload.php') { Tracy\Debugger::enable(); -dibi::connect(array( +dibi::connect([ 'driver' => 'sqlite3', 'database' => 'data/sample.s3db', -)); +]); /* diff --git a/examples/importing-dump-from-file.php b/examples/importing-dump-from-file.php index ea5e5512..bc4437df 100644 --- a/examples/importing-dump-from-file.php +++ b/examples/importing-dump-from-file.php @@ -7,10 +7,10 @@ require __DIR__ . '/../src/loader.php'; -dibi::connect(array( +dibi::connect([ 'driver' => 'sqlite3', 'database' => 'data/sample.s3db', -)); +]); $count = dibi::loadFile('compress.zlib://data/sample.dump.sql.gz'); diff --git a/examples/query-language-and-conditions.php b/examples/query-language-and-conditions.php index 703286e1..16ddd8cc 100644 --- a/examples/query-language-and-conditions.php +++ b/examples/query-language-and-conditions.php @@ -7,10 +7,10 @@ require __DIR__ . '/../src/loader.php'; -dibi::connect(array( +dibi::connect([ 'driver' => 'sqlite3', 'database' => 'data/sample.s3db', -)); +]); // some variables @@ -55,7 +55,7 @@ dibi::test(' // IF() -dibi::test('UPDATE products SET', array( - 'price' => array('IF(price_fixed, price, ?)', 123), -)); +dibi::test('UPDATE products SET', [ + 'price' => ['IF(price_fixed, price, ?)', 123], +]); // -> SELECT * FROM customers WHERE LIMIT 10 diff --git a/examples/query-language-basic-examples.php b/examples/query-language-basic-examples.php index e62f1623..26cb83f5 100644 --- a/examples/query-language-basic-examples.php +++ b/examples/query-language-basic-examples.php @@ -9,10 +9,10 @@ require __DIR__ . '/../src/loader.php'; date_default_timezone_set('Europe/Prague'); -dibi::connect(array( +dibi::connect([ 'driver' => 'sqlite3', 'database' => 'data/sample.s3db', -)); +]); // SELECT @@ -30,37 +30,37 @@ dibi::test(' // dibi detects INSERT or REPLACE command dibi::test(' - REPLACE INTO products', array( + REPLACE INTO products', [ 'title' => 'Super product', 'price' => 318, 'active' => TRUE, -)); +]); // -> REPLACE INTO products ([title], [price], [active]) VALUES ('Super product', 318, 1) // multiple INSERT command -$array = array( +$array = [ 'title' => 'Super Product', 'price' => 12, 'brand' => NULL, 'created' => new DateTime, -); +]; dibi::test('INSERT INTO products', $array, $array, $array); // -> INSERT INTO products ([title], [price], [brand], [created]) VALUES ('Super Product', ...) , (...) , (...) // dibi detects UPDATE command dibi::test(' - UPDATE colors SET', array( + UPDATE colors SET', [ 'color' => 'blue', 'order' => 12, - ), ' + ], ' WHERE id=?', 123); // -> UPDATE colors SET [color]='blue', [order]=12 WHERE id=123 // modifier applied to array -$array = array(1, 2, 3); +$array = [1, 2, 3]; dibi::test(' SELECT * FROM people @@ -70,10 +70,10 @@ dibi::test(' // modifier %by for ORDER BY -$order = array( +$order = [ 'field1' => 'asc', 'field2' => 'desc', -); +]; dibi::test(' SELECT * FROM people diff --git a/examples/result-set-data-types.php b/examples/result-set-data-types.php index db6ab3f7..ff35c022 100644 --- a/examples/result-set-data-types.php +++ b/examples/result-set-data-types.php @@ -13,10 +13,10 @@ Tracy\Debugger::enable(); date_default_timezone_set('Europe/Prague'); -dibi::connect(array( +dibi::connect([ 'driver' => 'sqlite3', 'database' => 'data/sample.s3db', -)); +]); // using manual hints diff --git a/examples/tracy-and-exceptions.php b/examples/tracy-and-exceptions.php index 31a5a25a..3522e7e8 100644 --- a/examples/tracy-and-exceptions.php +++ b/examples/tracy-and-exceptions.php @@ -15,13 +15,13 @@ if (@!include __DIR__ . '/../vendor/autoload.php') { Tracy\Debugger::enable(); -$connection = dibi::connect(array( +$connection = dibi::connect([ 'driver' => 'sqlite3', 'database' => 'data/sample.s3db', - 'profiler' => array( + 'profiler' => [ 'run' => TRUE, - ), -)); + ], +]); // add panel to debug bar diff --git a/examples/tracy.php b/examples/tracy.php index 859fe202..b2751fa9 100644 --- a/examples/tracy.php +++ b/examples/tracy.php @@ -17,13 +17,13 @@ if (@!include __DIR__ . '/../vendor/autoload.php') { Tracy\Debugger::enable(); -$connection = dibi::connect(array( +$connection = dibi::connect([ 'driver' => 'sqlite3', 'database' => 'data/sample.s3db', - 'profiler' => array( + 'profiler' => [ 'run' => TRUE, - ), -)); + ], +]); // add panel to debug bar diff --git a/examples/using-datetime.php b/examples/using-datetime.php index 96665639..8cba64ef 100644 --- a/examples/using-datetime.php +++ b/examples/using-datetime.php @@ -10,20 +10,20 @@ date_default_timezone_set('Europe/Prague'); // CHANGE TO REAL PARAMETERS! -dibi::connect(array( +dibi::connect([ 'driver' => 'sqlite3', 'database' => 'data/sample.s3db', 'formatDate' => "'Y-m-d'", 'formatDateTime' => "'Y-m-d H-i-s'", -)); +]); // generate and dump SQL dibi::test(' - INSERT INTO [mytable]', array( + INSERT INTO [mytable]', [ 'id' => 123, 'date' => new DateTime('12.3.2007'), 'stamp' => new DateTime('23.1.2007 10:23'), - ) + ] ); // -> INSERT INTO [mytable] ([id], [date], [stamp]) VALUES (123, '2007-03-12', '2007-01-23 10-23-00') diff --git a/examples/using-extension-methods.php b/examples/using-extension-methods.php index 394584e1..9a84230d 100644 --- a/examples/using-extension-methods.php +++ b/examples/using-extension-methods.php @@ -11,10 +11,10 @@ if (@!include __DIR__ . '/../vendor/autoload.php') { Tracy\Debugger::enable(); -dibi::connect(array( +dibi::connect([ 'driver' => 'sqlite3', 'database' => 'data/sample.s3db', -)); +]); // using the "prototype" to add custom method to class DibiResult diff --git a/examples/using-fluent-syntax.php b/examples/using-fluent-syntax.php index edc2d272..b78d44eb 100644 --- a/examples/using-fluent-syntax.php +++ b/examples/using-fluent-syntax.php @@ -9,18 +9,18 @@ require __DIR__ . '/../src/loader.php'; date_default_timezone_set('Europe/Prague'); -dibi::connect(array( +dibi::connect([ 'driver' => 'sqlite3', 'database' => 'data/sample.s3db', -)); +]); $id = 10; -$record = array( +$record = [ 'title' => 'Super product', 'price' => 318, 'active' => TRUE, -); +]; // SELECT ... dibi::select('product_id')->as('id') diff --git a/examples/using-limit-and-offset.php b/examples/using-limit-and-offset.php index af3fc1c0..cb658ce3 100644 --- a/examples/using-limit-and-offset.php +++ b/examples/using-limit-and-offset.php @@ -7,10 +7,10 @@ require __DIR__ . '/../src/loader.php'; -dibi::connect(array( +dibi::connect([ 'driver' => 'sqlite3', 'database' => 'data/sample.s3db', -)); +]); // no limit diff --git a/examples/using-logger.php b/examples/using-logger.php index b7ef0d4d..b590137e 100644 --- a/examples/using-logger.php +++ b/examples/using-logger.php @@ -9,15 +9,15 @@ require __DIR__ . '/../src/loader.php'; date_default_timezone_set('Europe/Prague'); -dibi::connect(array( +dibi::connect([ 'driver' => 'sqlite3', 'database' => 'data/sample.s3db', // enable query logging to this file - 'profiler' => array( + 'profiler' => [ 'run' => TRUE, 'file' => 'data/log.sql', - ), -)); + ], +]); try { diff --git a/examples/using-profiler.php b/examples/using-profiler.php index c4db5e74..11f1095a 100644 --- a/examples/using-profiler.php +++ b/examples/using-profiler.php @@ -9,13 +9,13 @@ require __DIR__ . '/../src/loader.php'; -dibi::connect(array( +dibi::connect([ 'driver' => 'sqlite3', 'database' => 'data/sample.s3db', - 'profiler' => array( + 'profiler' => [ 'run' => TRUE, - ), -)); + ], +]); // execute some queries... diff --git a/examples/using-substitutions.php b/examples/using-substitutions.php index 9fd7dfbe..0c48963e 100644 --- a/examples/using-substitutions.php +++ b/examples/using-substitutions.php @@ -7,10 +7,10 @@ require __DIR__ . '/../src/loader.php'; -dibi::connect(array( +dibi::connect([ 'driver' => 'sqlite3', 'database' => 'data/sample.s3db', -)); +]); // create new substitution :blog: ==> wp_ diff --git a/examples/using-transactions.php b/examples/using-transactions.php index d3200ea5..b77fae50 100644 --- a/examples/using-transactions.php +++ b/examples/using-transactions.php @@ -7,10 +7,10 @@ require __DIR__ . '/../src/loader.php'; -dibi::connect(array( +dibi::connect([ 'driver' => 'sqlite3', 'database' => 'data/sample.s3db', -)); +]); echo "

Before

\n"; @@ -19,9 +19,9 @@ dibi::query('SELECT * FROM [products]')->dump(); dibi::begin(); -dibi::query('INSERT INTO [products]', array( +dibi::query('INSERT INTO [products]', [ 'title' => 'Test product', -)); +]); echo "

After INSERT

\n"; dibi::query('SELECT * FROM [products]')->dump(); diff --git a/readme.md b/readme.md index 74acea8a..e1e1fb42 100644 --- a/readme.md +++ b/readme.md @@ -30,12 +30,12 @@ Connect to database: ```php // connect to database (static way) -dibi::connect(array( +dibi::connect([ 'driver' => 'mysql', 'host' => 'localhost', 'username' => 'root', 'password' => '***', -)); +]); // or object way; in all other examples use $connection-> instead of dibi:: $connection = new DibiConnection($options); @@ -46,19 +46,19 @@ SELECT, INSERT, UPDATE ```php dibi::query('SELECT * FROM users WHERE id = ?', $id); -$arr = array( +$arr = [ 'name' => 'John', 'is_admin' => TRUE, -); +]; dibi::query('INSERT INTO users', $arr); // INSERT INTO users (`name`, `is_admin`) VALUES ('John', 1) dibi::query('UPDATE users SET', $arr, 'WHERE `id`=?', $x); // UPDATE users SET `name`='John', `is_admin`=1 WHERE `id` = 123 -dibi::query('UPDATE users SET', array( +dibi::query('UPDATE users SET', [ 'title' => array('SHA1(?)', 'tajneheslo'), -)); +]); // UPDATE users SET 'title' = SHA1('tajneheslo') ``` @@ -81,10 +81,10 @@ foreach ($result as $n => $row) { Modifiers for arrays: ```php -dibi::query('SELECT * FROM users WHERE %and', array( +dibi::query('SELECT * FROM users WHERE %and', [ array('number > ?', 10), array('number < ?', 100), -)); +]); // SELECT * FROM users WHERE (number > 10) AND (number < 100) ``` @@ -116,9 +116,9 @@ dibi::query("SELECT * FROM table WHERE name LIKE %like~", $query); DateTime: ```php -dibi::query('UPDATE users SET', array( +dibi::query('UPDATE users SET', [ 'time' => new DateTime, -)); +]); // UPDATE users SET ('2008-01-01 01:08:10') ``` diff --git a/src/Dibi/Bridges/Nette/DibiExtension21.php b/src/Dibi/Bridges/Nette/DibiExtension21.php index 979b4d91..aa105b59 100644 --- a/src/Dibi/Bridges/Nette/DibiExtension21.php +++ b/src/Dibi/Bridges/Nette/DibiExtension21.php @@ -34,16 +34,16 @@ class DibiNette21Extension extends Nette\DI\CompilerExtension } $connection = $container->addDefinition($this->prefix('connection')) - ->setClass('DibiConnection', array($config)) + ->setClass('DibiConnection', [$config]) ->setAutowired(isset($config['autowired']) ? $config['autowired'] : TRUE); if ($useProfiler) { $panel = $container->addDefinition($this->prefix('panel')) ->setClass('DibiNettePanel') - ->addSetup('Nette\Diagnostics\Debugger::getBar()->addPanel(?)', array('@self')) - ->addSetup('Nette\Diagnostics\Debugger::getBlueScreen()->addPanel(?)', array('DibiNettePanel::renderException')); + ->addSetup('Nette\Diagnostics\Debugger::getBar()->addPanel(?)', ['@self']) + ->addSetup('Nette\Diagnostics\Debugger::getBlueScreen()->addPanel(?)', ['DibiNettePanel::renderException']); - $connection->addSetup('$service->onEvent[] = ?', array(array($panel, 'logEvent'))); + $connection->addSetup('$service->onEvent[] = ?', [[$panel, 'logEvent']]); } } diff --git a/src/Dibi/Bridges/Nette/DibiExtension22.php b/src/Dibi/Bridges/Nette/DibiExtension22.php index 70afe531..70d04b86 100644 --- a/src/Dibi/Bridges/Nette/DibiExtension22.php +++ b/src/Dibi/Bridges/Nette/DibiExtension22.php @@ -39,13 +39,13 @@ class DibiExtension22 extends Nette\DI\CompilerExtension } $connection = $container->addDefinition($this->prefix('connection')) - ->setClass('DibiConnection', array($config)) + ->setClass('DibiConnection', [$config]) ->setAutowired(isset($config['autowired']) ? $config['autowired'] : TRUE); if ($useProfiler) { $panel = $container->addDefinition($this->prefix('panel')) ->setClass('Dibi\Bridges\Tracy\Panel'); - $connection->addSetup(array($panel, 'register'), array($connection)); + $connection->addSetup([$panel, 'register'], [$connection]); } } diff --git a/src/Dibi/Bridges/Nette/Panel.php b/src/Dibi/Bridges/Nette/Panel.php index a40039b2..14c19329 100644 --- a/src/Dibi/Bridges/Nette/Panel.php +++ b/src/Dibi/Bridges/Nette/Panel.php @@ -25,7 +25,7 @@ class DibiNettePanel extends DibiObject implements Nette\Diagnostics\IBarPanel public $filter; /** @var array */ - private $events = array(); + private $events = []; public function __construct($explain = TRUE, $filter = NULL) @@ -38,8 +38,8 @@ class DibiNettePanel extends DibiObject implements Nette\Diagnostics\IBarPanel public function register(DibiConnection $connection) { Debugger::getBar()->addPanel($this); - Debugger::getBlueScreen()->addPanel(array(__CLASS__, 'renderException')); - $connection->onEvent[] = array($this, 'logEvent'); + Debugger::getBlueScreen()->addPanel([__CLASS__, 'renderException']); + $connection->onEvent[] = [$this, 'logEvent']; } @@ -63,10 +63,10 @@ class DibiNettePanel extends DibiObject implements Nette\Diagnostics\IBarPanel public static function renderException($e) { if ($e instanceof DibiException && $e->getSql()) { - return array( + return [ 'tab' => 'SQL', 'panel' => dibi::dump($e->getSql(), TRUE), - ); + ]; } } @@ -101,7 +101,7 @@ class DibiNettePanel extends DibiObject implements Nette\Diagnostics\IBarPanel $explain = NULL; // EXPLAIN is called here to work SELECT FOUND_ROWS() if ($this->explain && $event->type === DibiEvent::SELECT) { try { - $backup = array($event->connection->onEvent, dibi::$numOfQueries, dibi::$totalTime); + $backup = [$event->connection->onEvent, dibi::$numOfQueries, dibi::$totalTime]; $event->connection->onEvent = NULL; $cmd = is_string($this->explain) ? $this->explain : ($event->connection->getConfig('driver') === 'oracle' ? 'EXPLAIN PLAN FOR' : 'EXPLAIN'); $explain = dibi::dump($event->connection->nativeQuery("$cmd $event->sql"), TRUE); @@ -126,7 +126,7 @@ class DibiNettePanel extends DibiObject implements Nette\Diagnostics\IBarPanel if (!class_exists($helpers)) { $helpers = class_exists('NDebugHelpers') ? 'NDebugHelpers' : 'DebugHelpers'; } - $s .= call_user_func(array($helpers, 'editorLink'), $event->source[0], $event->source[1])->class('nette-DibiProfiler-source'); + $s .= call_user_func([$helpers, 'editorLink'], $event->source[0], $event->source[1])->class('nette-DibiProfiler-source'); } $s .= "{$event->count}{$h($event->connection->getConfig('driver') . '/' . $event->connection->getConfig('name'))}"; diff --git a/src/Dibi/Bridges/Tracy/Panel.php b/src/Dibi/Bridges/Tracy/Panel.php index efaccbda..fde26208 100644 --- a/src/Dibi/Bridges/Tracy/Panel.php +++ b/src/Dibi/Bridges/Tracy/Panel.php @@ -27,7 +27,7 @@ class Panel extends \DibiObject implements Tracy\IBarPanel public $filter; /** @var array */ - private $events = array(); + private $events = []; public function __construct($explain = TRUE, $filter = NULL) @@ -40,8 +40,8 @@ class Panel extends \DibiObject implements Tracy\IBarPanel public function register(\DibiConnection $connection) { Tracy\Debugger::getBar()->addPanel($this); - Tracy\Debugger::getBlueScreen()->addPanel(array(__CLASS__, 'renderException')); - $connection->onEvent[] = array($this, 'logEvent'); + Tracy\Debugger::getBlueScreen()->addPanel([__CLASS__, 'renderException']); + $connection->onEvent[] = [$this, 'logEvent']; } @@ -65,10 +65,10 @@ class Panel extends \DibiObject implements Tracy\IBarPanel public static function renderException($e) { if ($e instanceof \DibiException && $e->getSql()) { - return array( + return [ 'tab' => 'SQL', 'panel' => dibi::dump($e->getSql(), TRUE), - ); + ]; } } @@ -104,7 +104,7 @@ class Panel extends \DibiObject implements Tracy\IBarPanel $explain = NULL; // EXPLAIN is called here to work SELECT FOUND_ROWS() if ($this->explain && $event->type === \DibiEvent::SELECT) { try { - $backup = array($event->connection->onEvent, dibi::$numOfQueries, dibi::$totalTime); + $backup = [$event->connection->onEvent, dibi::$numOfQueries, dibi::$totalTime]; $event->connection->onEvent = NULL; $cmd = is_string($this->explain) ? $this->explain : ($event->connection->getConfig('driver') === 'oracle' ? 'EXPLAIN PLAN FOR' : 'EXPLAIN'); $explain = dibi::dump($event->connection->nativeQuery("$cmd $event->sql"), TRUE); diff --git a/src/Dibi/Connection.php b/src/Dibi/Connection.php index 8e870b0e..b9924880 100644 --- a/src/Dibi/Connection.php +++ b/src/Dibi/Connection.php @@ -55,7 +55,7 @@ class DibiConnection extends DibiObject parse_str($config, $config); } elseif ($config instanceof Traversable) { - $tmp = array(); + $tmp = []; foreach ($config as $key => $val) { $tmp[$key] = $val instanceof Traversable ? iterator_to_array($val) : $val; } @@ -75,7 +75,7 @@ class DibiConnection extends DibiObject $config['driver'] = dibi::$defaultDriver; } - $class = $tmp = preg_replace(array('#\W#', '#sql#'), array('_', 'Sql'), ucfirst(strtolower($config['driver']))); + $class = $tmp = preg_replace(['#\W#', '#sql#'], ['_', 'Sql'], ucfirst(strtolower($config['driver']))); $class = "Dibi{$class}Driver"; if (!class_exists($class)) { throw new DibiException("Unable to create instance of dibi driver '$class'."); @@ -89,17 +89,17 @@ class DibiConnection extends DibiObject // profiler $profilerCfg = & $config['profiler']; if (is_scalar($profilerCfg)) { - $profilerCfg = array('run' => (bool) $profilerCfg); + $profilerCfg = ['run' => (bool) $profilerCfg]; } if (!empty($profilerCfg['run'])) { $filter = isset($profilerCfg['filter']) ? $profilerCfg['filter'] : DibiEvent::QUERY; if (isset($profilerCfg['file'])) { - $this->onEvent[] = array(new DibiFileLogger($profilerCfg['file'], $filter), 'logEvent'); + $this->onEvent[] = [new DibiFileLogger($profilerCfg['file'], $filter), 'logEvent']; } if (DibiFirePhpLogger::isAvailable()) { - $this->onEvent[] = array(new DibiFirePhpLogger($filter), 'logEvent'); + $this->onEvent[] = [new DibiFirePhpLogger($filter), 'logEvent']; } if (!interface_exists('Tracy\IBarPanel') && interface_exists('Nette\Diagnostics\IBarPanel') && class_exists('DibiNettePanel')) { @@ -108,7 +108,7 @@ class DibiConnection extends DibiObject } } - $this->substitutes = new DibiHashMap(create_function('$expr', 'return ":$expr:";')); + $this->substitutes = new DibiHashMap(function ($expr) { return ":$expr:"; }); if (!empty($config['substitutes'])) { foreach ($config['substitutes'] as $key => $value) { $this->substitutes->$key = $value; @@ -542,16 +542,9 @@ class DibiConnection extends DibiObject */ public function substitute($value) { - return strpos($value, ':') === FALSE ? $value : preg_replace_callback('#:([^:\s]*):#', array($this, 'subCb'), $value); - } - - - /** - * Substitution callback. - */ - private function subCb($m) - { - return $this->substitutes->{$m[1]}; + return strpos($value, ':') === FALSE + ? $value + : preg_replace_callback('#:([^:\s]*):#', function ($m) { $this->substitutes->{$m[1]}; }, $value); } diff --git a/src/Dibi/DataSource.php b/src/Dibi/DataSource.php index c0dfa7f5..c5e3c1d1 100644 --- a/src/Dibi/DataSource.php +++ b/src/Dibi/DataSource.php @@ -29,13 +29,13 @@ class DibiDataSource extends DibiObject implements IDataSource private $totalCount; /** @var array */ - private $cols = array(); + private $cols = []; /** @var array */ - private $sorting = array(); + private $sorting = []; /** @var array */ - private $conds = array(); + private $conds = []; /** @var int */ private $offset; @@ -259,8 +259,8 @@ class DibiDataSource extends DibiObject implements IDataSource return $this->connection->translate(' SELECT %n', (empty($this->cols) ? '*' : $this->cols), ' FROM %SQL', $this->sql, ' -%ex', $this->conds ? array('WHERE %and', $this->conds) : NULL, ' -%ex', $this->sorting ? array('ORDER BY %by', $this->sorting) : NULL, ' +%ex', $this->conds ? ['WHERE %and', $this->conds] : NULL, ' +%ex', $this->sorting ? ['ORDER BY %by', $this->sorting] : NULL, ' %ofs %lmt', $this->offset, $this->limit ); } catch (Exception $e) { diff --git a/src/Dibi/Drivers/FirebirdDriver.php b/src/Dibi/Drivers/FirebirdDriver.php index 147476de..633d968b 100644 --- a/src/Dibi/Drivers/FirebirdDriver.php +++ b/src/Dibi/Drivers/FirebirdDriver.php @@ -65,13 +65,13 @@ class DibiFirebirdDriver extends DibiObject implements IDibiDriver, IDibiResultD } else { // default values - $config += array( + $config += [ 'username' => ini_get('ibase.default_password'), 'password' => ini_get('ibase.default_user'), 'database' => ini_get('ibase.default_db'), 'charset' => ini_get('ibase.default_charset'), 'buffers' => 0, - ); + ]; DibiDriverException::tryError(); if (empty($config['persistent'])) { @@ -432,15 +432,15 @@ class DibiFirebirdDriver extends DibiObject implements IDibiDriver, IDibiResultD public function getResultColumns() { $count = ibase_num_fields($this->resultSet); - $columns = array(); + $columns = []; for ($i = 0; $i < $count; $i++) { $row = (array) ibase_field_info($this->resultSet, $i); - $columns[] = array( + $columns[] = [ 'name' => $row['name'], 'fullname' => $row['name'], 'table' => $row['relation'], 'nativetype' => $row['type'], - ); + ]; } return $columns; } @@ -461,12 +461,12 @@ class DibiFirebirdDriver extends DibiObject implements IDibiDriver, IDibiResultD FROM RDB\$RELATIONS WHERE RDB\$SYSTEM_FLAG = 0;" ); - $tables = array(); + $tables = []; while ($row = $res->fetch(FALSE)) { - $tables[] = array( + $tables[] = [ 'name' => $row[0], 'view' => $row[1] === 'TRUE', - ); + ]; } return $tables; } @@ -510,10 +510,10 @@ class DibiFirebirdDriver extends DibiObject implements IDibiDriver, IDibiResultD ORDER BY r.RDB\$FIELD_POSITION;" ); - $columns = array(); + $columns = []; while ($row = $res->fetch(TRUE)) { $key = $row['FIELD_NAME']; - $columns[$key] = array( + $columns[$key] = [ 'name' => $key, 'table' => $table, 'nativetype' => trim($row['FIELD_TYPE']), @@ -521,7 +521,7 @@ class DibiFirebirdDriver extends DibiObject implements IDibiDriver, IDibiResultD 'nullable' => $row['NULLABLE'] === 'TRUE', 'default' => $row['DEFAULT_VALUE'], 'autoincrement' => FALSE, - ); + ]; } return $columns; } @@ -548,7 +548,7 @@ class DibiFirebirdDriver extends DibiObject implements IDibiDriver, IDibiResultD WHERE UPPER(i.RDB\$RELATION_NAME) = '$table' ORDER BY s.RDB\$FIELD_POSITION" ); - $indexes = array(); + $indexes = []; while ($row = $res->fetch(TRUE)) { $key = $row['INDEX_NAME']; $indexes[$key]['name'] = $key; @@ -578,14 +578,14 @@ class DibiFirebirdDriver extends DibiObject implements IDibiDriver, IDibiResultD AND r.RDB\$CONSTRAINT_TYPE = 'FOREIGN KEY' ORDER BY s.RDB\$FIELD_POSITION" ); - $keys = array(); + $keys = []; while ($row = $res->fetch(TRUE)) { $key = $row['INDEX_NAME']; - $keys[$key] = array( + $keys[$key] = [ 'name' => $key, 'column' => $row['FIELD_NAME'], 'table' => $table, - ); + ]; } return $keys; } @@ -605,7 +605,7 @@ class DibiFirebirdDriver extends DibiObject implements IDibiDriver, IDibiResultD AND RDB\$UNIQUE_FLAG IS NULL AND RDB\$FOREIGN_KEY IS NULL;" ); - $indices = array(); + $indices = []; while ($row = $res->fetch(FALSE)) { $indices[] = $row[0]; } @@ -629,7 +629,7 @@ class DibiFirebirdDriver extends DibiObject implements IDibiDriver, IDibiResultD OR RDB\$FOREIGN_KEY IS NOT NULL );" ); - $constraints = array(); + $constraints = []; while ($row = $res->fetch(FALSE)) { $constraints[] = $row[0]; } @@ -672,15 +672,15 @@ class DibiFirebirdDriver extends DibiObject implements IDibiDriver, IDibiResultD WHERE RDB\$SYSTEM_FLAG = 0" . ($table === NULL ? ';' : " AND RDB\$RELATION_NAME = UPPER('$table');") ); - $triggers = array(); + $triggers = []; while ($row = $res->fetch(TRUE)) { - $triggers[$row['TRIGGER_NAME']] = array( + $triggers[$row['TRIGGER_NAME']] = [ 'name' => $row['TRIGGER_NAME'], 'table' => $row['TABLE_NAME'], 'type' => trim($row['TRIGGER_TYPE']), 'event' => trim($row['TRIGGER_EVENT']), 'enabled' => trim($row['TRIGGER_ENABLED']) === 'TRUE', - ); + ]; } return $triggers; } @@ -700,7 +700,7 @@ class DibiFirebirdDriver extends DibiObject implements IDibiDriver, IDibiResultD $q .= $table === NULL ? ';' : " AND RDB\$RELATION_NAME = UPPER('$table')"; $res = $this->query($q); - $triggers = array(); + $triggers = []; while ($row = $res->fetch(FALSE)) { $triggers[] = $row[0]; } @@ -747,7 +747,7 @@ class DibiFirebirdDriver extends DibiObject implements IDibiDriver, IDibiResultD LEFT JOIN RDB\$FIELDS f ON f.RDB\$FIELD_NAME = p.RDB\$FIELD_SOURCE ORDER BY p.RDB\$PARAMETER_TYPE, p.RDB\$PARAMETER_NUMBER;" ); - $procedures = array(); + $procedures = []; while ($row = $res->fetch(TRUE)) { $key = $row['PROCEDURE_NAME']; $io = trim($row['PARAMETER_TYPE']); @@ -771,7 +771,7 @@ class DibiFirebirdDriver extends DibiObject implements IDibiDriver, IDibiResultD SELECT TRIM(RDB\$PROCEDURE_NAME) FROM RDB\$PROCEDURES;" ); - $procedures = array(); + $procedures = []; while ($row = $res->fetch(FALSE)) { $procedures[] = $row[0]; } @@ -790,7 +790,7 @@ class DibiFirebirdDriver extends DibiObject implements IDibiDriver, IDibiResultD FROM RDB\$GENERATORS WHERE RDB\$SYSTEM_FLAG = 0;" ); - $generators = array(); + $generators = []; while ($row = $res->fetch(FALSE)) { $generators[] = $row[0]; } @@ -809,7 +809,7 @@ class DibiFirebirdDriver extends DibiObject implements IDibiDriver, IDibiResultD FROM RDB\$FUNCTIONS WHERE RDB\$SYSTEM_FLAG = 0;" ); - $functions = array(); + $functions = []; while ($row = $res->fetch(FALSE)) { $functions[] = $row[0]; } diff --git a/src/Dibi/Drivers/MsSql2005Driver.php b/src/Dibi/Drivers/MsSql2005Driver.php index d02f6590..564acff1 100644 --- a/src/Dibi/Drivers/MsSql2005Driver.php +++ b/src/Dibi/Drivers/MsSql2005Driver.php @@ -264,7 +264,7 @@ class DibiMsSql2005Driver extends DibiObject implements IDibiDriver, IDibiResult */ public function escapeLike($value, $pos) { - $value = strtr($value, array("'" => "''", '%' => '[%]', '_' => '[_]', '[' => '[[]')); + $value = strtr($value, ["'" => "''", '%' => '[%]', '_' => '[_]', '[' => '[[]']); return ($pos <= 0 ? "'%" : "'") . $value . ($pos >= 0 ? "%'" : "'"); } @@ -366,13 +366,13 @@ class DibiMsSql2005Driver extends DibiObject implements IDibiDriver, IDibiResult */ public function getResultColumns() { - $columns = array(); + $columns = []; foreach ((array) sqlsrv_field_metadata($this->resultSet) as $fieldMetadata) { - $columns[] = array( + $columns[] = [ 'name' => $fieldMetadata['Name'], 'fullname' => $fieldMetadata['Name'], 'nativetype' => $fieldMetadata['Type'], - ); + ]; } return $columns; } diff --git a/src/Dibi/Drivers/MsSql2005Reflector.php b/src/Dibi/Drivers/MsSql2005Reflector.php index df38e4d5..1179a8ec 100644 --- a/src/Dibi/Drivers/MsSql2005Reflector.php +++ b/src/Dibi/Drivers/MsSql2005Reflector.php @@ -31,12 +31,12 @@ class DibiMsSql2005Reflector extends DibiObject implements IDibiReflector public function getTables() { $res = $this->driver->query('SELECT TABLE_NAME, TABLE_TYPE FROM INFORMATION_SCHEMA.TABLES'); - $tables = array(); + $tables = []; while ($row = $res->fetch(FALSE)) { - $tables[] = array( + $tables[] = [ 'name' => $row[0], 'view' => isset($row[1]) && $row[1] === 'VIEW', - ); + ]; } return $tables; } @@ -56,7 +56,7 @@ class DibiMsSql2005Reflector extends DibiObject implements IDibiReflector WHERE t.name = {$this->driver->escapeText($table)} "); - $autoIncrements = array(); + $autoIncrements = []; while ($row = $res->fetch(TRUE)) { $autoIncrements[$row['COLUMN_NAME']] = (bool) $row['AUTO_INCREMENT']; } @@ -76,9 +76,9 @@ class DibiMsSql2005Reflector extends DibiObject implements IDibiReflector ) As Z WHERE C.TABLE_NAME = {$this->driver->escapeText($table)} "); - $columns = array(); + $columns = []; while ($row = $res->fetch(TRUE)) { - $columns[] = array( + $columns[] = [ 'name' => $row['COLUMN_NAME'], 'table' => $table, 'nativetype' => strtoupper($row['DATA_TYPE']), @@ -88,7 +88,7 @@ class DibiMsSql2005Reflector extends DibiObject implements IDibiReflector 'default' => $row['COLUMN_DEFAULT'], 'autoincrement' => $autoIncrements[$row['COLUMN_NAME']], 'vendor' => $row, - ); + ]; } return $columns; } @@ -102,18 +102,18 @@ class DibiMsSql2005Reflector extends DibiObject implements IDibiReflector public function getIndexes($table) { $keyUsagesRes = $this->driver->query("SELECT * FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE TABLE_NAME = {$this->driver->escapeText($table)}"); - $keyUsages = array(); + $keyUsages = []; while ($row = $keyUsagesRes->fetch(TRUE)) { $keyUsages[$row['CONSTRAINT_NAME']][(int) $row['ORDINAL_POSITION'] - 1] = $row['COLUMN_NAME']; } $res = $this->driver->query("SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE TABLE_NAME = {$this->driver->escapeText($table)}"); - $indexes = array(); + $indexes = []; while ($row = $res->fetch(TRUE)) { $indexes[$row['CONSTRAINT_NAME']]['name'] = $row['CONSTRAINT_NAME']; $indexes[$row['CONSTRAINT_NAME']]['unique'] = $row['CONSTRAINT_TYPE'] === 'UNIQUE'; $indexes[$row['CONSTRAINT_NAME']]['primary'] = $row['CONSTRAINT_TYPE'] === 'PRIMARY KEY'; - $indexes[$row['CONSTRAINT_NAME']]['columns'] = isset($keyUsages[$row['CONSTRAINT_NAME']]) ? $keyUsages[$row['CONSTRAINT_NAME']] : array(); + $indexes[$row['CONSTRAINT_NAME']]['columns'] = isset($keyUsages[$row['CONSTRAINT_NAME']]) ? $keyUsages[$row['CONSTRAINT_NAME']] : []; } return array_values($indexes); } diff --git a/src/Dibi/Drivers/MsSqlDriver.php b/src/Dibi/Drivers/MsSqlDriver.php index 449f460a..43b0a92c 100644 --- a/src/Dibi/Drivers/MsSqlDriver.php +++ b/src/Dibi/Drivers/MsSqlDriver.php @@ -214,7 +214,7 @@ class DibiMsSqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv public function escapeIdentifier($value) { // @see https://msdn.microsoft.com/en-us/library/ms176027.aspx - return '[' . str_replace(array('[', ']'), array('[[', ']]'), $value) . ']'; + return '[' . str_replace(['[', ']'], ['[[', ']]'], $value) . ']'; } @@ -250,7 +250,7 @@ class DibiMsSqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv */ public function escapeLike($value, $pos) { - $value = strtr($value, array("'" => "''", '%' => '[%]', '_' => '[_]', '[' => '[[]')); + $value = strtr($value, ["'" => "''", '%' => '[%]', '_' => '[_]', '[' => '[[]']); return ($pos <= 0 ? "'%" : "'") . $value . ($pos >= 0 ? "%'" : "'"); } @@ -353,15 +353,15 @@ class DibiMsSqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv public function getResultColumns() { $count = mssql_num_fields($this->resultSet); - $columns = array(); + $columns = []; for ($i = 0; $i < $count; $i++) { $row = (array) mssql_fetch_field($this->resultSet, $i); - $columns[] = array( + $columns[] = [ 'name' => $row['name'], 'fullname' => $row['column_source'] ? $row['column_source'] . '.' . $row['name'] : $row['name'], 'table' => $row['column_source'], 'nativetype' => $row['type'], - ); + ]; } return $columns; } diff --git a/src/Dibi/Drivers/MsSqlReflector.php b/src/Dibi/Drivers/MsSqlReflector.php index 815148b7..1bf91a47 100644 --- a/src/Dibi/Drivers/MsSqlReflector.php +++ b/src/Dibi/Drivers/MsSqlReflector.php @@ -34,12 +34,12 @@ class DibiMsSqlReflector extends DibiObject implements IDibiReflector SELECT TABLE_NAME, TABLE_TYPE FROM INFORMATION_SCHEMA.TABLES '); - $tables = array(); + $tables = []; while ($row = $res->fetch(FALSE)) { - $tables[] = array( + $tables[] = [ 'name' => $row[0], 'view' => isset($row[1]) && $row[1] === 'VIEW', - ); + ]; } return $tables; } @@ -90,19 +90,19 @@ class DibiMsSqlReflector extends DibiObject implements IDibiReflector WHERE TABLE_NAME = {$this->driver->escapeText($table)} ORDER BY TABLE_NAME, ORDINAL_POSITION "); - $columns = array(); + $columns = []; while ($row = $res->fetch(TRUE)) { $size = FALSE; $type = strtoupper($row['DATA_TYPE']); - $size_cols = array( + $size_cols = [ 'DATETIME' => 'DATETIME_PRECISION', 'DECIMAL' => 'NUMERIC_PRECISION', 'CHAR' => 'CHARACTER_MAXIMUM_LENGTH', 'NCHAR' => 'CHARACTER_OCTET_LENGTH', 'NVARCHAR' => 'CHARACTER_OCTET_LENGTH', 'VARCHAR' => 'CHARACTER_OCTET_LENGTH', - ); + ]; if (isset($size_cols[$type])) { if ($size_cols[$type]) { @@ -110,7 +110,7 @@ class DibiMsSqlReflector extends DibiObject implements IDibiReflector } } - $columns[] = array( + $columns[] = [ 'name' => $row['COLUMN_NAME'], 'table' => $table, 'nativetype' => $type, @@ -120,7 +120,7 @@ class DibiMsSqlReflector extends DibiObject implements IDibiReflector 'default' => $row['COLUMN_DEFAULT'], 'autoincrement' => FALSE, 'vendor' => $row, - ); + ]; } return $columns; @@ -150,16 +150,16 @@ class DibiMsSqlReflector extends DibiObject implements IDibiReflector t.name, ind.name, ind.index_id, ic.index_column_id "); - $indexes = array(); + $indexes = []; while ($row = $res->fetch(TRUE)) { $index_name = $row['index_name']; if (!isset($indexes[$index_name])) { - $indexes[$index_name] = array(); + $indexes[$index_name] = []; $indexes[$index_name]['name'] = $index_name; $indexes[$index_name]['unique'] = (bool) $row['is_unique']; $indexes[$index_name]['primary'] = (bool) $row['is_primary_key']; - $indexes[$index_name]['columns'] = array(); + $indexes[$index_name]['columns'] = []; } $indexes[$index_name]['columns'][] = $row['column_name']; } @@ -190,15 +190,15 @@ class DibiMsSqlReflector extends DibiObject implements IDibiReflector WHERE OBJECT_NAME(f.parent_object_id) = {$this->driver->escapeText($table)} "); - $keys = array(); + $keys = []; while ($row = $res->fetch(TRUE)) { $key_name = $row['foreign_key']; if (!isset($keys[$key_name])) { $keys[$key_name]['name'] = $row['foreign_key']; // foreign key name - $keys[$key_name]['local'] = array($row['column_name']); // local columns + $keys[$key_name]['local'] = [$row['column_name']]; // local columns $keys[$key_name]['table'] = $row['reference_table_name']; // referenced table - $keys[$key_name]['foreign'] = array($row['reference_column_name']); // referenced columns + $keys[$key_name]['foreign'] = [$row['reference_column_name']]; // referenced columns $keys[$key_name]['onDelete'] = FALSE; $keys[$key_name]['onUpdate'] = FALSE; } else { diff --git a/src/Dibi/Drivers/MySqlDriver.php b/src/Dibi/Drivers/MySqlDriver.php index 9f54c93e..e8f0c5a0 100644 --- a/src/Dibi/Drivers/MySqlDriver.php +++ b/src/Dibi/Drivers/MySqlDriver.php @@ -69,12 +69,12 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv } else { // default values DibiConnection::alias($config, 'flags', 'options'); - $config += array( + $config += [ 'charset' => 'utf8', 'timezone' => date('P'), 'username' => ini_get('mysql.default_user'), 'password' => ini_get('mysql.default_password'), - ); + ]; if (!isset($config['host'])) { $host = ini_get('mysql.default_host'); if ($host) { @@ -168,7 +168,7 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv */ public function getInfo() { - $res = array(); + $res = []; preg_match_all('#(.+?): +(\d+) *#', mysql_info($this->connection), $matches, PREG_SET_ORDER); if (preg_last_error()) { throw new DibiPcreException; @@ -443,16 +443,16 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv public function getResultColumns() { $count = mysql_num_fields($this->resultSet); - $columns = array(); + $columns = []; for ($i = 0; $i < $count; $i++) { $row = (array) mysql_fetch_field($this->resultSet, $i); - $columns[] = array( + $columns[] = [ 'name' => $row['name'], 'table' => $row['table'], 'fullname' => $row['table'] ? $row['table'] . '.' . $row['name'] : $row['name'], 'nativetype' => strtoupper($row['type']), 'vendor' => $row, - ); + ]; } return $columns; } diff --git a/src/Dibi/Drivers/MySqlReflector.php b/src/Dibi/Drivers/MySqlReflector.php index cf9c2d87..db504a7c 100644 --- a/src/Dibi/Drivers/MySqlReflector.php +++ b/src/Dibi/Drivers/MySqlReflector.php @@ -36,12 +36,12 @@ class DibiMySqlReflector extends DibiObject implements IDibiReflector WHERE TABLE_SCHEMA = DATABASE() ");*/ $res = $this->driver->query('SHOW FULL TABLES'); - $tables = array(); + $tables = []; while ($row = $res->fetch(FALSE)) { - $tables[] = array( + $tables[] = [ 'name' => $row[0], 'view' => isset($row[1]) && $row[1] === 'VIEW', - ); + ]; } return $tables; } @@ -61,10 +61,10 @@ class DibiMySqlReflector extends DibiObject implements IDibiReflector WHERE TABLE_NAME = $table AND TABLE_SCHEMA = DATABASE() ");*/ $res = $this->driver->query("SHOW FULL COLUMNS FROM {$this->driver->escapeIdentifier($table)}"); - $columns = array(); + $columns = []; while ($row = $res->fetch(TRUE)) { $type = explode('(', $row['Type']); - $columns[] = array( + $columns[] = [ 'name' => $row['Field'], 'table' => $table, 'nativetype' => strtoupper($type[0]), @@ -74,7 +74,7 @@ class DibiMySqlReflector extends DibiObject implements IDibiReflector 'default' => $row['Default'], 'autoincrement' => $row['Extra'] === 'auto_increment', 'vendor' => $row, - ); + ]; } return $columns; } @@ -95,7 +95,7 @@ class DibiMySqlReflector extends DibiObject implements IDibiReflector AND REFERENCED_COLUMN_NAME IS NULL ");*/ $res = $this->driver->query("SHOW INDEX FROM {$this->driver->escapeIdentifier($table)}"); - $indexes = array(); + $indexes = []; while ($row = $res->fetch(TRUE)) { $indexes[$row['Key_name']]['name'] = $row['Key_name']; $indexes[$row['Key_name']]['unique'] = !$row['Non_unique']; @@ -132,7 +132,7 @@ class DibiMySqlReflector extends DibiObject implements IDibiReflector GROUP BY rc.CONSTRAINT_NAME "); - $foreignKeys = array(); + $foreignKeys = []; while ($row = $res->fetch(TRUE)) { $keyName = $row['CONSTRAINT_NAME']; diff --git a/src/Dibi/Drivers/MySqliDriver.php b/src/Dibi/Drivers/MySqliDriver.php index 426110db..1ab331e3 100644 --- a/src/Dibi/Drivers/MySqliDriver.php +++ b/src/Dibi/Drivers/MySqliDriver.php @@ -70,14 +70,14 @@ class DibiMySqliDriver extends DibiObject implements IDibiDriver, IDibiResultDri } else { // default values - $config += array( + $config += [ 'charset' => 'utf8', 'timezone' => date('P'), 'username' => ini_get('mysqli.default_user'), 'password' => ini_get('mysqli.default_pw'), 'socket' => (string) ini_get('mysqli.default_socket'), 'port' => NULL, - ); + ]; if (!isset($config['host'])) { $host = ini_get('mysqli.default_host'); if ($host) { @@ -163,7 +163,7 @@ class DibiMySqliDriver extends DibiObject implements IDibiDriver, IDibiResultDri */ public function getInfo() { - $res = array(); + $res = []; preg_match_all('#(.+?): +(\d+) *#', mysqli_info($this->connection), $matches, PREG_SET_ORDER); if (preg_last_error()) { throw new DibiPcreException; @@ -432,8 +432,8 @@ class DibiMySqliDriver extends DibiObject implements IDibiDriver, IDibiResultDri static $types; if ($types === NULL) { $consts = get_defined_constants(TRUE); - $types = array(); - foreach (isset($consts['mysqli']) ? $consts['mysqli'] : array() as $key => $value) { + $types = []; + foreach (isset($consts['mysqli']) ? $consts['mysqli'] : [] as $key => $value) { if (strncmp($key, 'MYSQLI_TYPE_', 12) === 0) { $types[$value] = substr($key, 12); } @@ -442,16 +442,16 @@ class DibiMySqliDriver extends DibiObject implements IDibiDriver, IDibiResultDri } $count = mysqli_num_fields($this->resultSet); - $columns = array(); + $columns = []; for ($i = 0; $i < $count; $i++) { $row = (array) mysqli_fetch_field_direct($this->resultSet, $i); - $columns[] = array( + $columns[] = [ 'name' => $row['name'], 'table' => $row['orgtable'], 'fullname' => $row['table'] ? $row['table'] . '.' . $row['name'] : $row['name'], 'nativetype' => isset($types[$row['type']]) ? $types[$row['type']] : $row['type'], 'vendor' => $row, - ); + ]; } return $columns; } diff --git a/src/Dibi/Drivers/OdbcDriver.php b/src/Dibi/Drivers/OdbcDriver.php index 45c74614..8bd6757d 100644 --- a/src/Dibi/Drivers/OdbcDriver.php +++ b/src/Dibi/Drivers/OdbcDriver.php @@ -59,11 +59,11 @@ class DibiOdbcDriver extends DibiObject implements IDibiDriver, IDibiResultDrive $this->connection = $config['resource']; } else { // default values - $config += array( + $config += [ 'username' => ini_get('odbc.default_user'), 'password' => ini_get('odbc.default_pw'), 'dsn' => ini_get('odbc.default_db'), - ); + ]; if (empty($config['persistent'])) { $this->connection = @odbc_connect($config['dsn'], $config['username'], $config['password']); // intentionally @ @@ -238,7 +238,7 @@ class DibiOdbcDriver extends DibiObject implements IDibiDriver, IDibiResultDrive public function escapeIdentifier($value) { - return '[' . str_replace(array('[', ']'), array('[[', ']]'), $value) . ']'; + return '[' . str_replace(['[', ']'], ['[[', ']]'], $value) . ']'; } @@ -274,7 +274,7 @@ class DibiOdbcDriver extends DibiObject implements IDibiDriver, IDibiResultDrive */ public function escapeLike($value, $pos) { - $value = strtr($value, array("'" => "''", '%' => '[%]', '_' => '[_]', '[' => '[[]')); + $value = strtr($value, ["'" => "''", '%' => '[%]', '_' => '[_]', '[' => '[[]']); return ($pos <= 0 ? "'%" : "'") . $value . ($pos >= 0 ? "%'" : "'"); } @@ -353,7 +353,7 @@ class DibiOdbcDriver extends DibiObject implements IDibiDriver, IDibiResultDrive return FALSE; } $count = odbc_num_fields($set); - $cols = array(); + $cols = []; for ($i = 1; $i <= $count; $i++) { $cols[] = odbc_result($set, $i); } @@ -392,14 +392,14 @@ class DibiOdbcDriver extends DibiObject implements IDibiDriver, IDibiResultDrive public function getResultColumns() { $count = odbc_num_fields($this->resultSet); - $columns = array(); + $columns = []; for ($i = 1; $i <= $count; $i++) { - $columns[] = array( + $columns[] = [ 'name' => odbc_field_name($this->resultSet, $i), 'table' => NULL, 'fullname' => odbc_field_name($this->resultSet, $i), 'nativetype' => odbc_field_type($this->resultSet, $i), - ); + ]; } return $columns; } @@ -426,13 +426,13 @@ class DibiOdbcDriver extends DibiObject implements IDibiDriver, IDibiResultDrive public function getTables() { $res = odbc_tables($this->connection); - $tables = array(); + $tables = []; while ($row = odbc_fetch_array($res)) { if ($row['TABLE_TYPE'] === 'TABLE' || $row['TABLE_TYPE'] === 'VIEW') { - $tables[] = array( + $tables[] = [ 'name' => $row['TABLE_NAME'], 'view' => $row['TABLE_TYPE'] === 'VIEW', - ); + ]; } } odbc_free_result($res); @@ -448,17 +448,17 @@ class DibiOdbcDriver extends DibiObject implements IDibiDriver, IDibiResultDrive public function getColumns($table) { $res = odbc_columns($this->connection); - $columns = array(); + $columns = []; while ($row = odbc_fetch_array($res)) { if ($row['TABLE_NAME'] === $table) { - $columns[] = array( + $columns[] = [ 'name' => $row['COLUMN_NAME'], 'table' => $table, 'nativetype' => $row['TYPE_NAME'], 'size' => $row['COLUMN_SIZE'], 'nullable' => (bool) $row['NULLABLE'], 'default' => $row['COLUMN_DEF'], - ); + ]; } } odbc_free_result($res); diff --git a/src/Dibi/Drivers/OracleDriver.php b/src/Dibi/Drivers/OracleDriver.php index f6ef549b..b3eeb534 100644 --- a/src/Dibi/Drivers/OracleDriver.php +++ b/src/Dibi/Drivers/OracleDriver.php @@ -378,15 +378,15 @@ class DibiOracleDriver extends DibiObject implements IDibiDriver, IDibiResultDri public function getResultColumns() { $count = oci_num_fields($this->resultSet); - $columns = array(); + $columns = []; for ($i = 1; $i <= $count; $i++) { $type = oci_field_type($this->resultSet, $i); - $columns[] = array( + $columns[] = [ 'name' => oci_field_name($this->resultSet, $i), 'table' => NULL, 'fullname' => oci_field_name($this->resultSet, $i), 'nativetype' => $type === 'NUMBER' && oci_field_scale($this->resultSet, $i) === 0 ? 'INTEGER' : $type, - ); + ]; } return $columns; } @@ -413,13 +413,13 @@ class DibiOracleDriver extends DibiObject implements IDibiDriver, IDibiResultDri public function getTables() { $res = $this->query('SELECT * FROM cat'); - $tables = array(); + $tables = []; while ($row = $res->fetch(FALSE)) { if ($row[1] === 'TABLE' || $row[1] === 'VIEW') { - $tables[] = array( + $tables[] = [ 'name' => $row[0], 'view' => $row[1] === 'VIEW', - ); + ]; } } return $tables; diff --git a/src/Dibi/Drivers/PdoDriver.php b/src/Dibi/Drivers/PdoDriver.php index 19c65953..c5342507 100644 --- a/src/Dibi/Drivers/PdoDriver.php +++ b/src/Dibi/Drivers/PdoDriver.php @@ -101,7 +101,7 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver { // must detect if SQL returns result set or num of affected rows $cmd = strtoupper(substr(ltrim($sql), 0, 6)); - static $list = array('UPDATE' => 1, 'DELETE' => 1, 'INSERT' => 1, 'REPLAC' => 1); + static $list = ['UPDATE' => 1, 'DELETE' => 1, 'INSERT' => 1, 'REPLAC' => 1]; $this->affectedRows = FALSE; if (isset($list[$cmd])) { @@ -275,7 +275,7 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver case 'odbc': case 'mssql': - return '[' . str_replace(array('[', ']'), array('[[', ']]'), $value) . ']'; + return '[' . str_replace(['[', ']'], ['[[', ']]'], $value) . ']'; case 'dblib': case 'sqlsrv': @@ -336,7 +336,7 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver case 'pgsql': $bs = substr($this->connection->quote('\\', PDO::PARAM_STR), 1, -1); // standard_conforming_strings = on/off $value = substr($this->connection->quote($value, PDO::PARAM_STR), 1, -1); - $value = strtr($value, array('%' => $bs . '%', '_' => $bs . '_', '\\' => '\\\\')); + $value = strtr($value, ['%' => $bs . '%', '_' => $bs . '_', '\\' => '\\\\']); return ($pos <= 0 ? "'%" : "'") . $value . ($pos >= 0 ? "%'" : "'"); case 'sqlite': @@ -347,7 +347,7 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver case 'mssql': case 'dblib': case 'sqlsrv': - $value = strtr($value, array("'" => "''", '%' => '[%]', '_' => '[_]', '[' => '[[]')); + $value = strtr($value, ["'" => "''", '%' => '[%]', '_' => '[_]', '[' => '[[]']); return ($pos <= 0 ? "'%" : "'") . $value . ($pos >= 0 ? "%'" : "'"); default: @@ -491,24 +491,24 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver public function getResultColumns() { $count = $this->resultSet->columnCount(); - $columns = array(); + $columns = []; for ($i = 0; $i < $count; $i++) { $row = @$this->resultSet->getColumnMeta($i); // intentionally @ if ($row === FALSE) { throw new DibiNotSupportedException('Driver does not support meta data.'); } - $row = $row + array( + $row = $row + [ 'table' => NULL, 'native_type' => 'VAR_STRING', - ); + ]; - $columns[] = array( + $columns[] = [ 'name' => $row['name'], 'table' => $row['table'], 'nativetype' => $row['native_type'], 'fullname' => $row['table'] ? $row['table'] . '.' . $row['name'] : $row['name'], 'vendor' => $row, - ); + ]; } return $columns; } diff --git a/src/Dibi/Drivers/PostgreDriver.php b/src/Dibi/Drivers/PostgreDriver.php index 0b0c2595..a2f404b0 100644 --- a/src/Dibi/Drivers/PostgreDriver.php +++ b/src/Dibi/Drivers/PostgreDriver.php @@ -57,16 +57,16 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver, IDibiResultDr $this->connection = $config['resource']; } else { - $config += array( + $config += [ 'charset' => 'utf8', - ); + ]; if (isset($config['string'])) { $string = $config['string']; } else { $string = ''; DibiConnection::alias($config, 'user', 'username'); DibiConnection::alias($config, 'dbname', 'database'); - foreach (array('host', 'hostaddr', 'port', 'dbname', 'user', 'password', 'connect_timeout', 'options', 'sslmode', 'service') as $key) { + foreach (['host', 'hostaddr', 'port', 'dbname', 'user', 'password', 'connect_timeout', 'options', 'sslmode', 'service'] as $key) { if (isset($config[$key])) { $string .= $key . '=' . $config[$key] . ' '; } @@ -219,7 +219,7 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver, IDibiResultDr */ public function inTransaction() { - return !in_array(pg_transaction_status($this->connection), array(PGSQL_TRANSACTION_UNKNOWN, PGSQL_TRANSACTION_IDLE), TRUE); + return !in_array(pg_transaction_status($this->connection), [PGSQL_TRANSACTION_UNKNOWN, PGSQL_TRANSACTION_IDLE], TRUE); } @@ -323,7 +323,7 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver, IDibiResultDr { $bs = pg_escape_string($this->connection, '\\'); // standard_conforming_strings = on/off $value = pg_escape_string($this->connection, $value); - $value = strtr($value, array('%' => $bs . '%', '_' => $bs . '_', '\\' => '\\\\')); + $value = strtr($value, ['%' => $bs . '%', '_' => $bs . '_', '\\' => '\\\\']); return ($pos <= 0 ? "'%" : "'") . $value . ($pos >= 0 ? "%'" : "'"); } @@ -425,13 +425,13 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver, IDibiResultDr public function getResultColumns() { $count = pg_num_fields($this->resultSet); - $columns = array(); + $columns = []; for ($i = 0; $i < $count; $i++) { - $row = array( + $row = [ 'name' => pg_field_name($this->resultSet, $i), 'table' => pg_field_table($this->resultSet, $i), 'nativetype' => pg_field_type($this->resultSet, $i), - ); + ]; $row['fullname'] = $row['table'] ? $row['table'] . '.' . $row['name'] : $row['name']; $columns[] = $row; } @@ -489,7 +489,7 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver, IDibiResultDr $res = $this->query($query); $tables = pg_fetch_all($res->resultSet); - return $tables ? $tables : array(); + return $tables ? $tables : []; } @@ -542,10 +542,10 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver, IDibiResultDr "); } - $columns = array(); + $columns = []; while ($row = $res->fetch(TRUE)) { $size = (int) max($row['character_maximum_length'], $row['numeric_precision']); - $columns[] = array( + $columns[] = [ 'name' => $row['column_name'], 'table' => $table, 'nativetype' => strtoupper($row['udt_name']), @@ -554,7 +554,7 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver, IDibiResultDr 'default' => $row['column_default'], 'autoincrement' => (int) $row['ordinal_position'] === $primary && substr($row['column_default'], 0, 7) === 'nextval', 'vendor' => $row, - ); + ]; } return $columns; } @@ -582,7 +582,7 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver, IDibiResultDr ORDER BY ordinal_position "); - $columns = array(); + $columns = []; while ($row = $res->fetch(TRUE)) { $columns[$row['ordinal_position']] = $row['column_name']; } @@ -595,7 +595,7 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver, IDibiResultDr WHERE pg_class.oid = $_table::regclass "); - $indexes = array(); + $indexes = []; while ($row = $res->fetch(TRUE)) { $indexes[$row['relname']]['name'] = $row['relname']; $indexes[$row['relname']]['unique'] = $row['indisunique'] === 't'; @@ -656,17 +656,17 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver, IDibiResultDr c.conrelid = $_table::regclass "); - $fKeys = $references = array(); + $fKeys = $references = []; while ($row = $res->fetch(TRUE)) { if (!isset($fKeys[$row['name']])) { - $fKeys[$row['name']] = array( + $fKeys[$row['name']] = [ 'name' => $row['name'], 'table' => $row['table'], - 'local' => array(), - 'foreign' => array(), + 'local' => [], + 'foreign' => [], 'onUpdate' => $row['onUpdate'], 'onDelete' => $row['onDelete'], - ); + ]; $l = explode(',', trim($row['conkey'], '{}')); $f = explode(',', trim($row['confkey'], '{}')); diff --git a/src/Dibi/Drivers/Sqlite3Driver.php b/src/Dibi/Drivers/Sqlite3Driver.php index 1a629889..ca91be6c 100644 --- a/src/Dibi/Drivers/Sqlite3Driver.php +++ b/src/Dibi/Drivers/Sqlite3Driver.php @@ -332,12 +332,12 @@ class DibiSqlite3Driver extends DibiObject implements IDibiDriver, IDibiResultDr $row = $this->resultSet->fetchArray($assoc ? SQLITE3_ASSOC : SQLITE3_NUM); $charset = $this->charset === NULL ? NULL : $this->charset . '//TRANSLIT'; if ($row && ($assoc || $charset)) { - $tmp = array(); + $tmp = []; foreach ($row as $k => $v) { if ($charset !== NULL && is_string($v)) { $v = iconv($this->dbcharset, $charset, $v); } - $tmp[str_replace(array('[', ']'), '', $k)] = $v; + $tmp[str_replace(['[', ']'], '', $k)] = $v; } return $tmp; } @@ -375,15 +375,15 @@ class DibiSqlite3Driver extends DibiObject implements IDibiDriver, IDibiResultDr public function getResultColumns() { $count = $this->resultSet->numColumns(); - $columns = array(); - static $types = array(SQLITE3_INTEGER => 'int', SQLITE3_FLOAT => 'float', SQLITE3_TEXT => 'text', SQLITE3_BLOB => 'blob', SQLITE3_NULL => 'null'); + $columns = []; + static $types = [SQLITE3_INTEGER => 'int', SQLITE3_FLOAT => 'float', SQLITE3_TEXT => 'text', SQLITE3_BLOB => 'blob', SQLITE3_NULL => 'null']; for ($i = 0; $i < $count; $i++) { - $columns[] = array( + $columns[] = [ 'name' => $this->resultSet->columnName($i), 'table' => NULL, 'fullname' => $this->resultSet->columnName($i), 'nativetype' => $types[$this->resultSet->columnType($i)], - ); + ]; } return $columns; } diff --git a/src/Dibi/Drivers/SqliteReflector.php b/src/Dibi/Drivers/SqliteReflector.php index b6461b21..f0789e46 100644 --- a/src/Dibi/Drivers/SqliteReflector.php +++ b/src/Dibi/Drivers/SqliteReflector.php @@ -36,7 +36,7 @@ class DibiSqliteReflector extends DibiObject implements IDibiReflector SELECT name, type = 'view' as view FROM sqlite_temp_master WHERE type IN ('table', 'view') ORDER BY name "); - $tables = array(); + $tables = []; while ($row = $res->fetch(TRUE)) { $tables[] = $row; } @@ -58,11 +58,11 @@ class DibiSqliteReflector extends DibiObject implements IDibiReflector ")->fetch(TRUE); $res = $this->driver->query("PRAGMA table_info({$this->driver->escapeIdentifier($table)})"); - $columns = array(); + $columns = []; while ($row = $res->fetch(TRUE)) { $column = $row['name']; $type = explode('(', $row['type']); - $columns[] = array( + $columns[] = [ 'name' => $column, 'table' => $table, 'fullname' => "$table.$column", @@ -72,7 +72,7 @@ class DibiSqliteReflector extends DibiObject implements IDibiReflector 'default' => $row['dflt_value'], 'autoincrement' => $row['pk'] && $type[0] === 'INTEGER', 'vendor' => $row, - ); + ]; } return $columns; } @@ -86,7 +86,7 @@ class DibiSqliteReflector extends DibiObject implements IDibiReflector public function getIndexes($table) { $res = $this->driver->query("PRAGMA index_list({$this->driver->escapeIdentifier($table)})"); - $indexes = array(); + $indexes = []; while ($row = $res->fetch(TRUE)) { $indexes[$row['name']]['name'] = $row['name']; $indexes[$row['name']]['unique'] = (bool) $row['unique']; @@ -114,12 +114,12 @@ class DibiSqliteReflector extends DibiObject implements IDibiReflector if (!$indexes) { // @see http://www.sqlite.org/lang_createtable.html#rowid foreach ($columns as $column) { if ($column['vendor']['pk']) { - $indexes[] = array( + $indexes[] = [ 'name' => 'ROWID', 'unique' => TRUE, 'primary' => TRUE, - 'columns' => array($column['name']), - ); + 'columns' => [$column['name']], + ]; break; } } @@ -137,7 +137,7 @@ class DibiSqliteReflector extends DibiObject implements IDibiReflector public function getForeignKeys($table) { $res = $this->driver->query("PRAGMA foreign_key_list({$this->driver->escapeIdentifier($table)})"); - $keys = array(); + $keys = []; while ($row = $res->fetch(TRUE)) { $keys[$row['id']]['name'] = $row['id']; // foreign key name $keys[$row['id']]['local'][$row['seq']] = $row['from']; // local columns diff --git a/src/Dibi/Event.php b/src/Dibi/Event.php index 55f3a8dd..a1b172b8 100644 --- a/src/Dibi/Event.php +++ b/src/Dibi/Event.php @@ -56,10 +56,10 @@ class DibiEvent $this->time = -microtime(TRUE); if ($type === self::QUERY && preg_match('#\(?\s*(SELECT|UPDATE|INSERT|DELETE)#iA', $this->sql, $matches)) { - static $types = array( + static $types = [ 'SELECT' => self::SELECT, 'UPDATE' => self::UPDATE, 'INSERT' => self::INSERT, 'DELETE' => self::DELETE, - ); + ]; $this->type = $types[strtoupper($matches[1])]; } @@ -67,7 +67,7 @@ class DibiEvent $dibiDir = dirname($rc->getFileName()) . DIRECTORY_SEPARATOR; foreach (debug_backtrace(FALSE) as $row) { if (isset($row['file']) && is_file($row['file']) && strpos($row['file'], $dibiDir) !== 0) { - $this->source = array($row['file'], (int) $row['line']); + $this->source = [$row['file'], (int) $row['line']]; break; } } diff --git a/src/Dibi/Fluent.php b/src/Dibi/Fluent.php index 063f9ace..255e73f2 100644 --- a/src/Dibi/Fluent.php +++ b/src/Dibi/Fluent.php @@ -28,16 +28,16 @@ class DibiFluent extends DibiObject implements IDataSource const REMOVE = FALSE; /** @var array */ - public static $masks = array( - 'SELECT' => array('SELECT', 'DISTINCT', 'FROM', 'WHERE', 'GROUP BY', - 'HAVING', 'ORDER BY', 'LIMIT', 'OFFSET'), - 'UPDATE' => array('UPDATE', 'SET', 'WHERE', 'ORDER BY', 'LIMIT'), - 'INSERT' => array('INSERT', 'INTO', 'VALUES', 'SELECT'), - 'DELETE' => array('DELETE', 'FROM', 'USING', 'WHERE', 'ORDER BY', 'LIMIT'), - ); + public static $masks = [ + 'SELECT' => ['SELECT', 'DISTINCT', 'FROM', 'WHERE', 'GROUP BY', + 'HAVING', 'ORDER BY', 'LIMIT', 'OFFSET'], + 'UPDATE' => ['UPDATE', 'SET', 'WHERE', 'ORDER BY', 'LIMIT'], + 'INSERT' => ['INSERT', 'INTO', 'VALUES', 'SELECT'], + 'DELETE' => ['DELETE', 'FROM', 'USING', 'WHERE', 'ORDER BY', 'LIMIT'], + ]; /** @var array default modifiers for arrays */ - public static $modifiers = array( + public static $modifiers = [ 'SELECT' => '%n', 'FROM' => '%n', 'IN' => '%in', @@ -47,10 +47,10 @@ class DibiFluent extends DibiObject implements IDataSource 'HAVING' => '%and', 'ORDER BY' => '%by', 'GROUP BY' => '%by', - ); + ]; /** @var array clauses separators */ - public static $separators = array( + public static $separators = [ 'SELECT' => ',', 'FROM' => ',', 'WHERE' => 'AND', @@ -62,30 +62,30 @@ class DibiFluent extends DibiObject implements IDataSource 'SET' => ',', 'VALUES' => ',', 'INTO' => FALSE, - ); + ]; /** @var array clauses */ - public static $clauseSwitches = array( + public static $clauseSwitches = [ 'JOIN' => 'FROM', 'INNER JOIN' => 'FROM', 'LEFT JOIN' => 'FROM', 'RIGHT JOIN' => 'FROM', - ); + ]; /** @var DibiConnection */ private $connection; /** @var array */ - private $setups = array(); + private $setups = []; /** @var string */ private $command; /** @var array */ - private $clauses = array(); + private $clauses = []; /** @var array */ - private $flags = array(); + private $flags = []; /** @var array */ private $cursor; @@ -102,7 +102,7 @@ class DibiFluent extends DibiObject implements IDataSource $this->connection = $connection; if (self::$normalizer === NULL) { - self::$normalizer = new DibiHashMap(array(__CLASS__, '_formatClause')); + self::$normalizer = new DibiHashMap([__CLASS__, '_formatClause']); } } @@ -123,7 +123,7 @@ class DibiFluent extends DibiObject implements IDataSource $this->clauses = array_fill_keys(self::$masks[$clause], NULL); } $this->cursor = & $this->clauses[$clause]; - $this->cursor = array(); + $this->cursor = []; $this->command = $clause; } @@ -137,7 +137,7 @@ class DibiFluent extends DibiObject implements IDataSource $this->cursor = & $this->clauses[$clause]; // TODO: really delete? - if ($args === array(self::REMOVE)) { + if ($args === [self::REMOVE]) { $this->cursor = NULL; return $this; } @@ -145,7 +145,7 @@ class DibiFluent extends DibiObject implements IDataSource if (isset(self::$separators[$clause])) { $sep = self::$separators[$clause]; if ($sep === FALSE) { // means: replace - $this->cursor = array(); + $this->cursor = []; } elseif (!empty($this->cursor)) { $this->cursor[] = $sep; @@ -154,7 +154,7 @@ class DibiFluent extends DibiObject implements IDataSource } else { // append to currect flow - if ($args === array(self::REMOVE)) { + if ($args === [self::REMOVE]) { return $this; } @@ -162,7 +162,7 @@ class DibiFluent extends DibiObject implements IDataSource } if ($this->cursor === NULL) { - $this->cursor = array(); + $this->cursor = []; } // special types or argument @@ -173,14 +173,14 @@ class DibiFluent extends DibiObject implements IDataSource return $this; } elseif (is_string($arg) && preg_match('#^[a-z:_][a-z0-9_.:]*\z#i', $arg)) { // identifier - $args = array('%n', $arg); + $args = ['%n', $arg]; } elseif (is_array($arg) || ($arg instanceof Traversable && !$arg instanceof self)) { // any array if (isset(self::$modifiers[$clause])) { - $args = array(self::$modifiers[$clause], $arg); + $args = [self::$modifiers[$clause], $arg]; } elseif (is_string(key($arg))) { // associative array - $args = array('%a', $arg); + $args = ['%a', $arg]; } } // case $arg === FALSE is handled above } @@ -205,7 +205,7 @@ class DibiFluent extends DibiObject implements IDataSource { $this->cursor = & $this->clauses[self::$normalizer->$clause]; if ($this->cursor === NULL) { - $this->cursor = array(); + $this->cursor = []; } return $this; @@ -316,7 +316,7 @@ class DibiFluent extends DibiObject implements IDataSource public function fetch() { if ($this->command === 'SELECT') { - return $this->query($this->_export(NULL, array('%lmt', 1)))->fetch(); + return $this->query($this->_export(NULL, ['%lmt', 1]))->fetch(); } else { return $this->query($this->_export())->fetch(); } @@ -330,7 +330,7 @@ class DibiFluent extends DibiObject implements IDataSource public function fetchSingle() { if ($this->command === 'SELECT') { - return $this->query($this->_export(NULL, array('%lmt', 1)))->fetchSingle(); + return $this->query($this->_export(NULL, ['%lmt', 1]))->fetchSingle(); } else { return $this->query($this->_export())->fetchSingle(); } @@ -345,7 +345,7 @@ class DibiFluent extends DibiObject implements IDataSource */ public function fetchAll($offset = NULL, $limit = NULL) { - return $this->query($this->_export(NULL, array('%ofs %lmt', $offset, $limit)))->fetchAll(); + return $this->query($this->_export(NULL, ['%ofs %lmt', $offset, $limit]))->fetchAll(); } @@ -380,7 +380,7 @@ class DibiFluent extends DibiObject implements IDataSource */ public function getIterator($offset = NULL, $limit = NULL) { - return $this->query($this->_export(NULL, array('%ofs %lmt', $offset, $limit)))->getIterator(); + return $this->query($this->_export(NULL, ['%ofs %lmt', $offset, $limit]))->getIterator(); } @@ -400,9 +400,9 @@ class DibiFluent extends DibiObject implements IDataSource */ public function count() { - return (int) $this->query(array( + return (int) $this->query([ 'SELECT COUNT(*) FROM (%ex', $this->_export(), ') AS [data]', - ))->fetchSingle(); + ])->fetchSingle(); } @@ -413,7 +413,7 @@ class DibiFluent extends DibiObject implements IDataSource { $res = $this->connection->query($args); foreach ($this->setups as $setup) { - call_user_func_array(array($res, array_shift($setup)), $setup); + call_user_func_array([$res, array_shift($setup)], $setup); } return $res; } @@ -450,7 +450,7 @@ class DibiFluent extends DibiObject implements IDataSource * @param string clause name * @return array */ - protected function _export($clause = NULL, $args = array()) + protected function _export($clause = NULL, $args = []) { if ($clause === NULL) { $data = $this->clauses; @@ -458,9 +458,9 @@ class DibiFluent extends DibiObject implements IDataSource } else { $clause = self::$normalizer->$clause; if (array_key_exists($clause, $this->clauses)) { - $data = array($clause => $this->clauses[$clause]); + $data = [$clause => $this->clauses[$clause]]; } else { - return array(); + return []; } } diff --git a/src/Dibi/Helpers.php b/src/Dibi/Helpers.php index 1b22d799..929e7f28 100644 --- a/src/Dibi/Helpers.php +++ b/src/Dibi/Helpers.php @@ -15,14 +15,14 @@ class DibiHelpers /** @internal */ public static function escape($driver, $value, $type) { - static $types = array( + static $types = [ dibi::TEXT => 'text', dibi::BINARY => 'binary', dibi::BOOL => 'bool', dibi::DATE => 'date', dibi::DATETIME => 'datetime', dibi::IDENTIFIER => 'identifier', - ); + ]; if (isset($types[$type])) { return $driver->{'escape' . $types[$type]}($value); } else { diff --git a/src/Dibi/Loggers/FirePhpLogger.php b/src/Dibi/Loggers/FirePhpLogger.php index d21a9237..cf7e3eb6 100644 --- a/src/Dibi/Loggers/FirePhpLogger.php +++ b/src/Dibi/Loggers/FirePhpLogger.php @@ -32,7 +32,7 @@ class DibiFirePhpLogger extends DibiObject public $numOfQueries = 0; /** @var array */ - private static $fireTable = array(array('Time', 'SQL Statement', 'Rows', 'Connection')); + private static $fireTable = [['Time', 'SQL Statement', 'Rows', 'Connection']]; /** @@ -67,20 +67,20 @@ class DibiFirePhpLogger extends DibiObject } $this->totalTime += $event->time; $this->numOfQueries++; - self::$fireTable[] = array( + self::$fireTable[] = [ sprintf('%0.3f', $event->time * 1000), strlen($event->sql) > self::$maxLength ? substr($event->sql, 0, self::$maxLength) . '...' : $event->sql, $event->result instanceof Exception ? 'ERROR' : (string) $event->count, $event->connection->getConfig('driver') . '/' . $event->connection->getConfig('name'), - ); + ]; - $payload = json_encode(array( - array( + $payload = json_encode([ + [ 'Type' => 'TABLE', 'Label' => 'dibi profiler (' . $this->numOfQueries . ' SQL queries took ' . sprintf('%0.3f', $this->totalTime * 1000) . ' ms)', - ), + ], self::$fireTable, - )); + ]); foreach (str_split($payload, self::$streamChunkSize) as $num => $s) { $num++; header("X-Wf-dibi-1-1-d$num: |$s|\\"); // protocol-, structure-, plugin-, message-index diff --git a/src/Dibi/Object.php b/src/Dibi/Object.php index 12c6895a..eaa15e06 100644 --- a/src/Dibi/Object.php +++ b/src/Dibi/Object.php @@ -48,7 +48,7 @@ */ abstract class DibiObject { - /** @var array (method => array(type => callback)) */ + /** @var array [method => [type => callback]] */ private static $extMethods; @@ -95,7 +95,7 @@ abstract class DibiObject if (is_array($list) || $list instanceof Traversable) { foreach ($list as $handler) { /**/if (is_object($handler)) { - call_user_func_array(array($handler, '__invoke'), $args); + call_user_func_array([$handler, '__invoke'], $args); } else /**/{ call_user_func_array($handler, $args); diff --git a/src/Dibi/Reflection/Column.php b/src/Dibi/Reflection/Column.php index d0041fe7..430b72ed 100644 --- a/src/Dibi/Reflection/Column.php +++ b/src/Dibi/Reflection/Column.php @@ -76,7 +76,7 @@ class DibiColumnInfo extends DibiObject if (empty($this->info['table']) || !$this->reflector) { throw new DibiException("Table is unknown or not available."); } - return new DibiTableInfo($this->reflector, array('name' => $this->info['table'])); + return new DibiTableInfo($this->reflector, ['name' => $this->info['table']]); } @@ -170,7 +170,7 @@ class DibiColumnInfo extends DibiObject */ public static function detectType($type) { - static $patterns = array( + static $patterns = [ '^_' => dibi::TEXT, // PostgreSQL arrays 'BYTEA|BLOB|BIN' => dibi::BINARY, 'TEXT|CHAR|POINT|INTERVAL' => dibi::TEXT, @@ -180,7 +180,7 @@ class DibiColumnInfo extends DibiObject 'TIME' => dibi::DATETIME, // DATETIME, TIMESTAMP 'DATE' => dibi::DATE, 'BOOL' => dibi::BOOL, - ); + ]; foreach ($patterns as $s => $val) { if (preg_match("#$s#i", $type)) { @@ -197,7 +197,7 @@ class DibiColumnInfo extends DibiObject public static function getTypeCache() { if (self::$types === NULL) { - self::$types = new DibiHashMap(array(__CLASS__, 'detectType')); + self::$types = new DibiHashMap([__CLASS__, 'detectType']); } return self::$types; } diff --git a/src/Dibi/Reflection/Database.php b/src/Dibi/Reflection/Database.php index c7598dd3..8cff21bc 100644 --- a/src/Dibi/Reflection/Database.php +++ b/src/Dibi/Reflection/Database.php @@ -59,7 +59,7 @@ class DibiDatabaseInfo extends DibiObject public function getTableNames() { $this->init(); - $res = array(); + $res = []; foreach ($this->tables as $table) { $res[] = $table->getName(); } @@ -101,7 +101,7 @@ class DibiDatabaseInfo extends DibiObject protected function init() { if ($this->tables === NULL) { - $this->tables = array(); + $this->tables = []; foreach ($this->reflector->getTables() as $info) { $this->tables[strtolower($info['name'])] = new DibiTableInfo($this->reflector, $info); } diff --git a/src/Dibi/Reflection/ForeignKey.php b/src/Dibi/Reflection/ForeignKey.php index 645815a5..d9cb6d3b 100644 --- a/src/Dibi/Reflection/ForeignKey.php +++ b/src/Dibi/Reflection/ForeignKey.php @@ -20,7 +20,7 @@ class DibiForeignKeyInfo extends DibiObject /** @var string */ private $name; - /** @var array of array(local, foreign, onDelete, onUpdate) */ + /** @var array of [local, foreign, onDelete, onUpdate] */ private $references; diff --git a/src/Dibi/Reflection/Result.php b/src/Dibi/Reflection/Result.php index e03302d4..80661893 100644 --- a/src/Dibi/Reflection/Result.php +++ b/src/Dibi/Reflection/Result.php @@ -49,7 +49,7 @@ class DibiResultInfo extends DibiObject public function getColumnNames($fullNames = FALSE) { $this->initColumns(); - $res = array(); + $res = []; foreach ($this->columns as $column) { $res[] = $fullNames ? $column->getFullName() : $column->getName(); } @@ -91,7 +91,7 @@ class DibiResultInfo extends DibiObject protected function initColumns() { if ($this->columns === NULL) { - $this->columns = array(); + $this->columns = []; $reflector = $this->driver instanceof IDibiReflector ? $this->driver : NULL; foreach ($this->driver->getResultColumns() as $info) { $this->columns[] = $this->names[$info['name']] = new DibiColumnInfo($reflector, $info); diff --git a/src/Dibi/Reflection/Table.php b/src/Dibi/Reflection/Table.php index 38afc1b2..301880ed 100644 --- a/src/Dibi/Reflection/Table.php +++ b/src/Dibi/Reflection/Table.php @@ -85,7 +85,7 @@ class DibiTableInfo extends DibiObject public function getColumnNames() { $this->initColumns(); - $res = array(); + $res = []; foreach ($this->columns as $column) { $res[] = $column->getName(); } @@ -157,7 +157,7 @@ class DibiTableInfo extends DibiObject protected function initColumns() { if ($this->columns === NULL) { - $this->columns = array(); + $this->columns = []; foreach ($this->reflector->getColumns($this->name) as $info) { $this->columns[strtolower($info['name'])] = new DibiColumnInfo($this->reflector, $info); } @@ -172,7 +172,7 @@ class DibiTableInfo extends DibiObject { if ($this->indexes === NULL) { $this->initColumns(); - $this->indexes = array(); + $this->indexes = []; foreach ($this->reflector->getIndexes($this->name) as $info) { foreach ($info['columns'] as $key => $name) { $info['columns'][$key] = $this->columns[strtolower($name)]; diff --git a/src/Dibi/Result.php b/src/Dibi/Result.php index f7f24e49..8755a1a7 100644 --- a/src/Dibi/Result.php +++ b/src/Dibi/Result.php @@ -32,7 +32,7 @@ class DibiResult extends DibiObject implements IDataSource private $driver; /** @var array Translate table */ - private $types = array(); + private $types = []; /** @var DibiResultInfo */ private $meta; @@ -47,7 +47,7 @@ class DibiResult extends DibiObject implements IDataSource private $rowFactory; /** @var array format */ - private $formats = array(); + private $formats = []; /** @@ -229,10 +229,10 @@ class DibiResult extends DibiObject implements IDataSource $this->seek((int) $offset); $row = $this->fetch(); if (!$row) { - return array(); // empty result set + return []; // empty result set } - $data = array(); + $data = []; do { if ($limit === 0) { break; @@ -265,7 +265,7 @@ class DibiResult extends DibiObject implements IDataSource $this->seek(0); $row = $this->fetch(); if (!$row) { - return array(); // empty result set + return []; // empty result set } $data = NULL; @@ -333,7 +333,7 @@ class DibiResult extends DibiObject implements IDataSource $this->seek(0); $row = $this->fetch(); if (!$row) { - return array(); // empty result set + return []; // empty result set } $data = NULL; @@ -410,10 +410,10 @@ class DibiResult extends DibiObject implements IDataSource $this->seek(0); $row = $this->fetch(); if (!$row) { - return array(); // empty result set + return []; // empty result set } - $data = array(); + $data = []; if ($value === NULL) { if ($key !== NULL) { diff --git a/src/Dibi/Translator.php b/src/Dibi/Translator.php index 64f68cec..6f5bef6d 100644 --- a/src/Dibi/Translator.php +++ b/src/Dibi/Translator.php @@ -50,7 +50,7 @@ final class DibiTranslator extends DibiObject public function __construct(DibiConnection $connection) { $this->connection = $connection; - $this->identifiers = new DibiHashMap(array($this, 'delimite')); + $this->identifiers = new DibiHashMap([$this, 'delimite']); } @@ -87,7 +87,7 @@ final class DibiTranslator extends DibiObject $comment = FALSE; // iterate - $sql = array(); + $sql = []; while ($cursor < count($this->args)) { $arg = $this->args[$cursor]; $cursor++; @@ -116,7 +116,7 @@ final class DibiTranslator extends DibiObject )/xs', */ // note: this can change $this->args & $this->cursor & ... . preg_replace_callback('/(?=[`[\'":%?])(?:`(.+?)`|\[(.+?)\]|(\')((?:\'\'|[^\'])*)\'|(")((?:""|[^"])*)"|(\'|")|:(\S*?:)([a-zA-Z0-9._]?)|%([a-zA-Z~][a-zA-Z0-9~]{0,5})|(\?))/s', - array($this, 'cb'), + [$this, 'cb'], substr($arg, $toSkip) ); if (preg_last_error()) { @@ -199,7 +199,7 @@ final class DibiTranslator extends DibiObject } if (is_array($value)) { - $vx = $kx = array(); + $vx = $kx = []; switch ($modifier) { case 'and': case 'or': // key=val AND key IS NULL AND ... @@ -401,7 +401,7 @@ final class DibiTranslator extends DibiObject $value = substr($value, 0, $toSkip) . preg_replace_callback( '/(?=[`[\'":])(?:`(.+?)`|\[(.+?)\]|(\')((?:\'\'|[^\'])*)\'|(")((?:""|[^"])*)"|(\'|")|:(\S*?:)([a-zA-Z0-9._]?))/s', - array($this, 'cb'), + [$this, 'cb'], substr($value, $toSkip) ); if (preg_last_error()) { diff --git a/src/Dibi/dibi.php b/src/Dibi/dibi.php index 036e281e..51f08263 100644 --- a/src/Dibi/dibi.php +++ b/src/Dibi/dibi.php @@ -46,13 +46,13 @@ class dibi DESC = 'DESC'; /** @var DibiConnection[] Connection registry storage for DibiConnection objects */ - private static $registry = array(); + private static $registry = []; /** @var DibiConnection Current connection */ private static $connection; /** @var array @see addHandler */ - private static $handlers = array(); + private static $handlers = []; /** @var string Last SQL command @see dibi::query() */ public static $sql; @@ -89,7 +89,7 @@ class dibi * @return DibiConnection * @throws DibiException */ - public static function connect($config = array(), $name = 0) + public static function connect($config = [], $name = 0) { return self::$connection = self::$registry[$name] = new DibiConnection($config, $name); } @@ -376,7 +376,7 @@ class dibi //if ($name = 'select', 'update', ...') { // return self::command()->$name($args); //} - return call_user_func_array(array(self::getConnection(), $name), $args); + return call_user_func_array([self::getConnection(), $name], $args); } @@ -399,7 +399,7 @@ class dibi public static function select($args) { $args = func_get_args(); - return call_user_func_array(array(self::getConnection(), 'select'), $args); + return call_user_func_array([self::getConnection(), 'select'], $args); } @@ -485,13 +485,39 @@ class dibi $highlighter = "#(/\\*.+?\\*/)|(\\*\\*.+?\\*\\*)|(?<=[\\s,(])($keywords1)(?=[\\s,)])|(?<=[\\s,(=])($keywords2)(?=[\\s,)=])#is"; if (PHP_SAPI === 'cli') { if (substr(getenv('TERM'), 0, 5) === 'xterm') { - $sql = preg_replace_callback($highlighter, array('dibi', 'cliHighlightCallback'), $sql); + $sql = preg_replace_callback($highlighter, function ($m) { + if (!empty($m[1])) { // comment + return "\033[1;30m" . $m[1] . "\033[0m"; + + } elseif (!empty($m[2])) { // error + return "\033[1;31m" . $m[2] . "\033[0m"; + + } elseif (!empty($m[3])) { // most important keywords + return "\033[1;34m" . $m[3] . "\033[0m"; + + } elseif (!empty($m[4])) { // other keywords + return "\033[1;32m" . $m[4] . "\033[0m"; + } + }, $sql); } echo trim($sql) . "\n\n"; } else { $sql = htmlSpecialChars($sql); - $sql = preg_replace_callback($highlighter, array('dibi', 'highlightCallback'), $sql); + $sql = preg_replace_callback($highlighter, function ($m) { + if (!empty($m[1])) { // comment + return '' . $m[1] . ''; + + } elseif (!empty($m[2])) { // error + return '' . $m[2] . ''; + + } elseif (!empty($m[3])) { // most important keywords + return '' . $m[3] . ''; + + } elseif (!empty($m[4])) { // other keywords + return '' . $m[4] . ''; + } + }, $sql); echo '
', trim($sql), "
\n\n"; } } @@ -503,38 +529,4 @@ class dibi } } - - private static function highlightCallback($matches) - { - if (!empty($matches[1])) { // comment - return '' . $matches[1] . ''; - - } elseif (!empty($matches[2])) { // error - return '' . $matches[2] . ''; - - } elseif (!empty($matches[3])) { // most important keywords - return '' . $matches[3] . ''; - - } elseif (!empty($matches[4])) { // other keywords - return '' . $matches[4] . ''; - } - } - - - private static function cliHighlightCallback($matches) - { - if (!empty($matches[1])) { // comment - return "\033[1;30m" . $matches[1] . "\033[0m"; - - } elseif (!empty($matches[2])) { // error - return "\033[1;31m" . $matches[2] . "\033[0m"; - - } elseif (!empty($matches[3])) { // most important keywords - return "\033[1;34m" . $matches[3] . "\033[0m"; - - } elseif (!empty($matches[4])) { // other keywords - return "\033[1;32m" . $matches[4] . "\033[0m"; - } - } - } diff --git a/src/Dibi/exceptions.php b/src/Dibi/exceptions.php index f7e1dc82..5963c9cf 100644 --- a/src/Dibi/exceptions.php +++ b/src/Dibi/exceptions.php @@ -71,7 +71,7 @@ class DibiDriverException extends DibiException */ public static function tryError() { - set_error_handler(array(__CLASS__, '_errorHandler'), E_ALL); + set_error_handler([__CLASS__, '_errorHandler'], E_ALL); self::$errorMsg = NULL; } @@ -118,13 +118,13 @@ class DibiPcreException extends Exception { public function __construct($message = '%msg.') { - static $messages = array( + static $messages = [ PREG_INTERNAL_ERROR => 'Internal error', PREG_BACKTRACK_LIMIT_ERROR => 'Backtrack limit was exhausted', PREG_RECURSION_LIMIT_ERROR => 'Recursion limit was exhausted', PREG_BAD_UTF8_ERROR => 'Malformed UTF-8 data', 5 => 'Offset didn\'t correspond to the begin of a valid UTF-8 code point', // PREG_BAD_UTF8_OFFSET_ERROR - ); + ]; $code = preg_last_error(); parent::__construct(str_replace('%msg', isset($messages[$code]) ? $messages[$code] : 'Unknown error', $message), $code); } diff --git a/tests/dibi/Connection.affectedRows.phpt b/tests/dibi/Connection.affectedRows.phpt index 4aba92e3..3f03d7bb 100644 --- a/tests/dibi/Connection.affectedRows.phpt +++ b/tests/dibi/Connection.affectedRows.phpt @@ -12,9 +12,9 @@ $conn = new DibiConnection($config); $conn->loadFile(__DIR__ . "/data/$config[system].sql"); -$conn->query('INSERT INTO products', array( +$conn->query('INSERT INTO products', [ 'title' => 'Test product', -)); +]); Assert::same(1, $conn->getAffectedRows()); diff --git a/tests/dibi/Connection.connect.phpt b/tests/dibi/Connection.connect.phpt index e5b94c28..c73fb400 100644 --- a/tests/dibi/Connection.connect.phpt +++ b/tests/dibi/Connection.connect.phpt @@ -19,7 +19,7 @@ test(function () use ($config) { test(function () use ($config) { // lazy - $conn = new DibiConnection($config + array('lazy' => TRUE)); + $conn = new DibiConnection($config + ['lazy' => TRUE]); Assert::false($conn->isConnected()); $conn->query('SELECT 1'); diff --git a/tests/dibi/Connection.fetch.phpt b/tests/dibi/Connection.fetch.phpt index c8723e40..3fe1f8be 100644 --- a/tests/dibi/Connection.fetch.phpt +++ b/tests/dibi/Connection.fetch.phpt @@ -29,43 +29,43 @@ Assert::same('Chair', $res->fetchSingle()); // fetch complete result set $res = $conn->query('SELECT * FROM [products] ORDER BY product_id'); -Assert::equal(array( - new DibiRow(array('product_id' => num(1), 'title' => 'Chair')), - new DibiRow(array('product_id' => num(2), 'title' => 'Table')), - new DibiRow(array('product_id' => num(3), 'title' => 'Computer')), -), $res->fetchAll()); +Assert::equal([ + new DibiRow(['product_id' => num(1), 'title' => 'Chair']), + new DibiRow(['product_id' => num(2), 'title' => 'Table']), + new DibiRow(['product_id' => num(3), 'title' => 'Computer']), +], $res->fetchAll()); // fetch complete result set like pairs key => value $res = $conn->query('SELECT * FROM [products] ORDER BY product_id'); Assert::same( - array(1 => 'Chair', 'Table', 'Computer'), + [1 => 'Chair', 'Table', 'Computer'], $res->fetchPairs('product_id', 'title') ); $res = $conn->query('SELECT * FROM [products] ORDER BY product_id'); Assert::same( - array(1 => 'Chair', 'Table', 'Computer'), + [1 => 'Chair', 'Table', 'Computer'], $res->fetchPairs() ); // fetch row by row $res = $conn->query('SELECT * FROM [products] ORDER BY product_id'); -Assert::equal(array( - new DibiRow(array('product_id' => num(1), 'title' => 'Chair')), - new DibiRow(array('product_id' => num(2), 'title' => 'Table')), - new DibiRow(array('product_id' => num(3), 'title' => 'Computer')), -), iterator_to_array($res)); +Assert::equal([ + new DibiRow(['product_id' => num(1), 'title' => 'Chair']), + new DibiRow(['product_id' => num(2), 'title' => 'Table']), + new DibiRow(['product_id' => num(3), 'title' => 'Computer']), +], iterator_to_array($res)); // fetch complete result set like association array $res = $conn->query('SELECT * FROM [products] ORDER BY product_id'); -Assert::equal(array( - 'Chair' => new DibiRow(array('product_id' => num(1), 'title' => 'Chair')), - 'Table' => new DibiRow(array('product_id' => num(2), 'title' => 'Table')), - 'Computer' => new DibiRow(array('product_id' => num(3), 'title' => 'Computer')), -), $res->fetchAssoc('title')); +Assert::equal([ + 'Chair' => new DibiRow(['product_id' => num(1), 'title' => 'Chair']), + 'Table' => new DibiRow(['product_id' => num(2), 'title' => 'Table']), + 'Computer' => new DibiRow(['product_id' => num(3), 'title' => 'Computer']), +], $res->fetchAssoc('title')); @@ -88,242 +88,242 @@ function query($conn) { } -Assert::equal(array( - 'Arnold Rimmer' => array( - 'Chair' => new DibiRow(array('title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0))), - 'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0))), - ), - 'Dave Lister' => array( - 'Table' => new DibiRow(array('title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0))), - ), - 'Kristine Kochanski' => array( - 'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0))), - ), -), query($conn)->fetchAssoc('name,title')); +Assert::equal([ + 'Arnold Rimmer' => [ + 'Chair' => new DibiRow(['title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0)]), + 'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0)]), + ], + 'Dave Lister' => [ + 'Table' => new DibiRow(['title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0)]), + ], + 'Kristine Kochanski' => [ + 'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0)]), + ], +], query($conn)->fetchAssoc('name,title')); -Assert::equal(array( - 'Arnold Rimmer' => array( - array( - 'Chair' => new DibiRow(array('title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0))), - ), - array( - 'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0))), - ), - ), - 'Dave Lister' => array( - array( - 'Table' => new DibiRow(array('title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0))), - ), - ), - 'Kristine Kochanski' => array( - array( - 'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0))), - ), - ), -), query($conn)->fetchAssoc('name,#,title')); +Assert::equal([ + 'Arnold Rimmer' => [ + [ + 'Chair' => new DibiRow(['title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0)]), + ], + [ + 'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0)]), + ], + ], + 'Dave Lister' => [ + [ + 'Table' => new DibiRow(['title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0)]), + ], + ], + 'Kristine Kochanski' => [ + [ + 'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0)]), + ], + ], +], query($conn)->fetchAssoc('name,#,title')); -Assert::equal(array( - 'Arnold Rimmer' => array( - 'title' => array( - 'Chair' => new DibiRow(array('title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0))), - 'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0))), - ), +Assert::equal([ + 'Arnold Rimmer' => [ + 'title' => [ + 'Chair' => new DibiRow(['title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0)]), + 'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0)]), + ], 'name' => 'Arnold Rimmer', 'amount' => num(7.0), - ), - 'Dave Lister' => array( - 'title' => array( - 'Table' => new DibiRow(array('title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0))), - ), + ], + 'Dave Lister' => [ + 'title' => [ + 'Table' => new DibiRow(['title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0)]), + ], 'name' => 'Dave Lister', 'amount' => num(3.0), - ), - 'Kristine Kochanski' => array( - 'title' => array( - 'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0))), - ), + ], + 'Kristine Kochanski' => [ + 'title' => [ + 'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0)]), + ], 'name' => 'Kristine Kochanski', 'amount' => num(5.0), - ), -), query($conn)->fetchAssoc('name,=,title')); + ], +], query($conn)->fetchAssoc('name,=,title')); -Assert::equal(array( - 'Arnold Rimmer' => new DibiRow(array( - 'title' => array( - 'Chair' => new DibiRow(array('title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0))), - 'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0))), - ), +Assert::equal([ + 'Arnold Rimmer' => new DibiRow([ + 'title' => [ + 'Chair' => new DibiRow(['title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0)]), + 'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0)]), + ], 'name' => 'Arnold Rimmer', 'amount' => num(7.0), - )), - 'Dave Lister' => new DibiRow(array( - 'title' => array( - 'Table' => new DibiRow(array('title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0))), - ), + ]), + 'Dave Lister' => new DibiRow([ + 'title' => [ + 'Table' => new DibiRow(['title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0)]), + ], 'name' => 'Dave Lister', 'amount' => num(3.0), - )), - 'Kristine Kochanski' => new DibiRow(array( - 'title' => array( - 'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0))), - ), + ]), + 'Kristine Kochanski' => new DibiRow([ + 'title' => [ + 'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0)]), + ], 'name' => 'Kristine Kochanski', 'amount' => num(5.0), - )), -), query($conn)->fetchAssoc('name,@,title')); + ]), +], query($conn)->fetchAssoc('name,@,title')); -Assert::equal(array( - new DibiRow(array('title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0))), - new DibiRow(array( - 'title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0))), - new DibiRow(array( - 'title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0))), - new DibiRow(array( - 'title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0))), -), query($conn)->fetchAssoc('@,=')); +Assert::equal([ + new DibiRow(['title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0)]), + new DibiRow([ + 'title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0)]), + new DibiRow([ + 'title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0)]), + new DibiRow([ + 'title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0)]), +], query($conn)->fetchAssoc('@,=')); -Assert::equal(array( - 'Arnold Rimmer' => array( - 'title' => array( - 'Chair' => new DibiRow(array('title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0))), - 'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0))), - ), +Assert::equal([ + 'Arnold Rimmer' => [ + 'title' => [ + 'Chair' => new DibiRow(['title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0)]), + 'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0)]), + ], 'name' => 'Arnold Rimmer', 'amount' => num(7.0), - ), - 'Dave Lister' => array( - 'title' => array( - 'Table' => new DibiRow(array('title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0))), - ), + ], + 'Dave Lister' => [ + 'title' => [ + 'Table' => new DibiRow(['title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0)]), + ], 'name' => 'Dave Lister', 'amount' => num(3.0), - ), - 'Kristine Kochanski' => array( - 'title' => array( - 'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0))), - ), + ], + 'Kristine Kochanski' => [ + 'title' => [ + 'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0)]), + ], 'name' => 'Kristine Kochanski', 'amount' => num(5.0), - ), -), query($conn)->fetchAssoc('name,=,title,@')); + ], +], query($conn)->fetchAssoc('name,=,title,@')); // old syntax -Assert::equal(array( - 'Arnold Rimmer' => array( - 'Chair' => new DibiRow(array('title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0))), - 'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0))), - ), - 'Dave Lister' => array( - 'Table' => new DibiRow(array('title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0))), - ), - 'Kristine Kochanski' => array( - 'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0))), - ), -), query($conn)->fetchAssoc('name|title')); +Assert::equal([ + 'Arnold Rimmer' => [ + 'Chair' => new DibiRow(['title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0)]), + 'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0)]), + ], + 'Dave Lister' => [ + 'Table' => new DibiRow(['title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0)]), + ], + 'Kristine Kochanski' => [ + 'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0)]), + ], +], query($conn)->fetchAssoc('name|title')); -Assert::equal(array( - 'Arnold Rimmer' => array( - array( - 'Chair' => new DibiRow(array('title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0))), - ), - array( - 'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0))), - ), - ), - 'Dave Lister' => array( - array( - 'Table' => new DibiRow(array('title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0))), - ), - ), - 'Kristine Kochanski' => array( - array( - 'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0))), - ), - ), -), query($conn)->fetchAssoc('name[]title')); +Assert::equal([ + 'Arnold Rimmer' => [ + [ + 'Chair' => new DibiRow(['title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0)]), + ], + [ + 'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0)]), + ], + ], + 'Dave Lister' => [ + [ + 'Table' => new DibiRow(['title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0)]), + ], + ], + 'Kristine Kochanski' => [ + [ + 'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0)]), + ], + ], +], query($conn)->fetchAssoc('name[]title')); -Assert::equal(array( - 'Arnold Rimmer' => new DibiRow(array( - 'title' => array( - 'Chair' => new DibiRow(array('title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0))), - 'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0))), - ), +Assert::equal([ + 'Arnold Rimmer' => new DibiRow([ + 'title' => [ + 'Chair' => new DibiRow(['title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0)]), + 'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0)]), + ], 'name' => 'Arnold Rimmer', 'amount' => num(7.0), - )), - 'Dave Lister' => new DibiRow(array( - 'title' => array( - 'Table' => new DibiRow(array('title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0))), - ), + ]), + 'Dave Lister' => new DibiRow([ + 'title' => [ + 'Table' => new DibiRow(['title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0)]), + ], 'name' => 'Dave Lister', 'amount' => num(3.0), - )), - 'Kristine Kochanski' => new DibiRow(array( - 'title' => array( - 'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0))), - ), + ]), + 'Kristine Kochanski' => new DibiRow([ + 'title' => [ + 'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0)]), + ], 'name' => 'Kristine Kochanski', 'amount' => num(5.0), - )), -), query($conn)->fetchAssoc('name->title')); + ]), +], query($conn)->fetchAssoc('name->title')); -Assert::equal(array( - 'Arnold Rimmer' => new DibiRow(array( - 'title' => array('Chair' => 'Arnold Rimmer', 'Computer' => 'Arnold Rimmer'), +Assert::equal([ + 'Arnold Rimmer' => new DibiRow([ + 'title' => ['Chair' => 'Arnold Rimmer', 'Computer' => 'Arnold Rimmer'], 'name' => 'Arnold Rimmer', 'amount' => num(7.0), - )), - 'Dave Lister' => new DibiRow(array( - 'title' => array('Table' => 'Dave Lister'), + ]), + 'Dave Lister' => new DibiRow([ + 'title' => ['Table' => 'Dave Lister'], 'name' => 'Dave Lister', 'amount' => num(3.0), - )), - 'Kristine Kochanski' => new DibiRow(array( - 'title' => array('Computer' => 'Kristine Kochanski'), + ]), + 'Kristine Kochanski' => new DibiRow([ + 'title' => ['Computer' => 'Kristine Kochanski'], 'name' => 'Kristine Kochanski', 'amount' => num(5.0), - )), -), query($conn)->fetchAssoc('name->title=name')); + ]), +], query($conn)->fetchAssoc('name->title=name')); -Assert::equal(array( - new DibiRow(array('title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0))), - new DibiRow(array('title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0))), - new DibiRow(array('title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0))), - new DibiRow(array('title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0))), -), query($conn)->fetchAssoc('[]')); +Assert::equal([ + new DibiRow(['title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0)]), + new DibiRow(['title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0)]), + new DibiRow(['title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0)]), + new DibiRow(['title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0)]), +], query($conn)->fetchAssoc('[]')); -Assert::equal(array( - 'Arnold Rimmer' => new DibiRow(array( - 'title' => array( - 'Chair' => new DibiRow(array('title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0))), - 'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0))), - ), +Assert::equal([ + 'Arnold Rimmer' => new DibiRow([ + 'title' => [ + 'Chair' => new DibiRow(['title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0)]), + 'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0)]), + ], 'name' => 'Arnold Rimmer', 'amount' => num(7.0), - )), - 'Dave Lister' => new DibiRow(array( - 'title' => array( - 'Table' => new DibiRow(array('title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0))), - ), + ]), + 'Dave Lister' => new DibiRow([ + 'title' => [ + 'Table' => new DibiRow(['title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0)]), + ], 'name' => 'Dave Lister', 'amount' => num(3.0), - )), - 'Kristine Kochanski' => new DibiRow(array( - 'title' => array( - 'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0))), - ), + ]), + 'Kristine Kochanski' => new DibiRow([ + 'title' => [ + 'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0)]), + ], 'name' => 'Kristine Kochanski', 'amount' => num(5.0), - )), -), query($conn)->fetchAssoc('name->title->')); + ]), +], query($conn)->fetchAssoc('name->title->')); diff --git a/tests/dibi/Connection.transactions.phpt b/tests/dibi/Connection.transactions.phpt index 088c7ae2..5b243629 100644 --- a/tests/dibi/Connection.transactions.phpt +++ b/tests/dibi/Connection.transactions.phpt @@ -30,9 +30,9 @@ Assert::exception(function () use ($conn) { $conn->begin(); Assert::same(3, (int) $conn->query('SELECT COUNT(*) FROM [products]')->fetchSingle()); -$conn->query('INSERT INTO [products]', array( +$conn->query('INSERT INTO [products]', [ 'title' => 'Test product', -)); +]); Assert::same(4, (int) $conn->query('SELECT COUNT(*) FROM [products]')->fetchSingle()); $conn->rollback(); Assert::same(3, (int) $conn->query('SELECT COUNT(*) FROM [products]')->fetchSingle()); @@ -41,8 +41,8 @@ Assert::same(3, (int) $conn->query('SELECT COUNT(*) FROM [products]')->fetchSing $conn->begin(); -$conn->query('INSERT INTO [products]', array( +$conn->query('INSERT INTO [products]', [ 'title' => 'Test product', -)); +]); $conn->commit(); Assert::same(4, (int) $conn->query('SELECT COUNT(*) FROM [products]')->fetchSingle()); diff --git a/tests/dibi/DataSource.phpt b/tests/dibi/DataSource.phpt index 5385c9c3..11b49722 100644 --- a/tests/dibi/DataSource.phpt +++ b/tests/dibi/DataSource.phpt @@ -54,9 +54,9 @@ FROM (SELECT * FROM products) t ); -$ds->select(array('product_id')); -$ds->orderBy(array('product_id' => dibi::ASC)); -$ds->where(array('product_id = 1')); +$ds->select(['product_id']); +$ds->orderBy(['product_id' => dibi::ASC]); +$ds->where(['product_id = 1']); Assert::match( reformat(" SELECT [product_id] @@ -79,11 +79,11 @@ FROM (SELECT * FROM products) t Assert::same(1, $ds->toDataSource()->count()); -Assert::equal(array( - new DibiRow(array( +Assert::equal([ + new DibiRow([ 'product_id' => 1, - )), -), iterator_to_array($ds)); + ]), +], iterator_to_array($ds)); Assert::match( reformat(" @@ -117,32 +117,32 @@ FROM (SELECT [title] FROM [products]) t'), (string) $ds ); -Assert::equal(new DibiRow(array( +Assert::equal(new DibiRow([ 'product_id' => 1, 'title' => 'Chair', -)), $conn->dataSource('SELECT * FROM products ORDER BY product_id')->fetch()); +]), $conn->dataSource('SELECT * FROM products ORDER BY product_id')->fetch()); Assert::same(1, $conn->dataSource('SELECT * FROM products ORDER BY product_id')->fetchSingle()); Assert::same( - array(1 => 'Chair', 'Table', 'Computer'), + [1 => 'Chair', 'Table', 'Computer'], $conn->dataSource('SELECT * FROM products ORDER BY product_id')->fetchPairs() ); -Assert::equal(array( - 1 => new DibiRow(array( +Assert::equal([ + 1 => new DibiRow([ 'product_id' => 1, 'title' => 'Chair', - )), - new DibiRow(array( + ]), + new DibiRow([ 'product_id' => 2, 'title' => 'Table', - )), - new DibiRow(array( + ]), + new DibiRow([ 'product_id' => 3, 'title' => 'Computer', - )), -), $conn->dataSource('SELECT * FROM products ORDER BY product_id')->fetchAssoc('product_id')); + ]), +], $conn->dataSource('SELECT * FROM products ORDER BY product_id')->fetchAssoc('product_id')); $ds = new DibiDataSource('products', $conn); diff --git a/tests/dibi/Fluent.fetch.phpt b/tests/dibi/Fluent.fetch.phpt index 088b019a..41fd5bcc 100644 --- a/tests/dibi/Fluent.fetch.phpt +++ b/tests/dibi/Fluent.fetch.phpt @@ -29,31 +29,31 @@ Assert::equal('Chair', $res->fetchSingle()); // fetch complete result set $res = $conn->select('*')->from('products')->orderBy('product_id'); -Assert::equal(array( - new DibiRow(array('product_id' => num(1), 'title' => 'Chair')), - new DibiRow(array('product_id' => num(2), 'title' => 'Table')), - new DibiRow(array('product_id' => num(3), 'title' => 'Computer')), -), $res->fetchAll()); +Assert::equal([ + new DibiRow(['product_id' => num(1), 'title' => 'Chair']), + new DibiRow(['product_id' => num(2), 'title' => 'Table']), + new DibiRow(['product_id' => num(3), 'title' => 'Computer']), +], $res->fetchAll()); // more complex association array if ($config['system'] !== 'odbc') { - $res = $conn->select(array('products.title' => 'title', 'customers.name' => 'name'))->select('orders.amount')->as('amount') + $res = $conn->select(['products.title' => 'title', 'customers.name' => 'name'])->select('orders.amount')->as('amount') ->from('products') ->innerJoin('orders')->using('(product_id)') ->innerJoin('customers')->using('([customer_id])') ->orderBy('order_id'); - Assert::equal(array( - 'Arnold Rimmer' => array( - 'Chair' => new DibiRow(array('title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0))), - 'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0))), - ), - 'Dave Lister' => array( - 'Table' => new DibiRow(array('title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0))), - ), - 'Kristine Kochanski' => array( - 'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0))), - ), - ), $res->fetchAssoc('name,title')); + Assert::equal([ + 'Arnold Rimmer' => [ + 'Chair' => new DibiRow(['title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0)]), + 'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0)]), + ], + 'Dave Lister' => [ + 'Table' => new DibiRow(['title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0)]), + ], + 'Kristine Kochanski' => [ + 'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0)]), + ], + ], $res->fetchAssoc('name,title')); } diff --git a/tests/dibi/Fluent.insert.phpt b/tests/dibi/Fluent.insert.phpt index 24b988fa..e654c397 100644 --- a/tests/dibi/Fluent.insert.phpt +++ b/tests/dibi/Fluent.insert.phpt @@ -8,11 +8,11 @@ require __DIR__ . '/bootstrap.php'; $conn = new DibiConnection($config); -$arr = array( +$arr = [ 'title' => 'Super Product', 'price' => 12, 'brand' => NULL, -); +]; $fluent = $conn->insert('table', $arr) ->setFlag('IGNORE')->setFlag('DELAYED'); diff --git a/tests/dibi/Fluent.select.phpt b/tests/dibi/Fluent.select.phpt index 617d02ab..815a7136 100644 --- a/tests/dibi/Fluent.select.phpt +++ b/tests/dibi/Fluent.select.phpt @@ -14,7 +14,7 @@ $min = 5; $fluent = $conn->select('*') ->select('a') ->select('b')->as('bAlias') - ->select(array('c', 'd', 'e')) + ->select(['c', 'd', 'e']) ->select('%n', 'd'); Assert::same( @@ -58,10 +58,10 @@ Assert::same( $fluent->where('col > %i', $max) ->or('col < %i', $min) ->where('active = 1') - ->where('col')->in(array(1, 2, 3)) + ->where('col')->in([1, 2, 3]) ->orderBy('val')->asc() ->orderBy('[val2] DESC') - ->orderBy(array('val3' => -1)); + ->orderBy(['val3' => -1]); Assert::same( reformat('SELECT * , [a] , [b] AS [bAlias] , [c], [d], [e] , [d] FROM [anotherTable] AS [anotherAlias] INNER JOIN [table3] ON table.col = table3.col WHERE col > 10 OR col < 5 AND active = 1 AND [col] IN (1, 2, 3) ORDER BY [val] ASC , [val2] DESC , [val3] DESC'), @@ -104,11 +104,11 @@ Assert::same( $fluent = $conn->select('*') - ->select(array('x' => 'xAlias')) + ->select(['x' => 'xAlias']) ->from('products') ->innerJoin('orders')->using('(product_id)') ->innerJoin('customers')->using('([customer_id])') - ->innerJoin('items')->using('(%n)', array('customer_id', 'order_id')); + ->innerJoin('items')->using('(%n)', ['customer_id', 'order_id']); Assert::same( reformat('SELECT * , [x] AS [xAlias] FROM [products] INNER JOIN [orders] USING (product_id) INNER JOIN [customers] USING ([customer_id]) INNER JOIN [items] USING ([customer_id], [order_id])'), @@ -129,9 +129,9 @@ Assert::same( $fluent = $conn->select('*') - ->from(array('me' => 't')) + ->from(['me' => 't']) ->where('col > %i', $max) - ->where(array('x' => 'a', 'b', 'c')); + ->where(['x' => 'a', 'b', 'c']); Assert::same( reformat('SELECT * FROM [me] AS [t] WHERE col > 10 AND ([x] = \'a\') AND (b) AND (c)'), diff --git a/tests/dibi/Fluent.update.phpt b/tests/dibi/Fluent.update.phpt index 587bdcf3..9a27503a 100644 --- a/tests/dibi/Fluent.update.phpt +++ b/tests/dibi/Fluent.update.phpt @@ -8,11 +8,11 @@ require __DIR__ . '/bootstrap.php'; $conn = new DibiConnection($config); -$arr = array( +$arr = [ 'title' => 'Super Product', 'price' => 12, 'brand' => NULL, -); +]; $fluent = $conn->update('table', $arr) ->setFlag('IGNORE')->setFlag('DELAYED'); @@ -22,7 +22,7 @@ Assert::same( (string) $fluent ); -$fluent->set(array('another' => 123)); +$fluent->set(['another' => 123]); Assert::same( reformat('UPDATE IGNORE DELAYED [table] SET [title]=\'Super Product\', [price]=12, [brand]=NULL , [another]=123'), diff --git a/tests/dibi/Result.meta.phpt b/tests/dibi/Result.meta.phpt index 46d95e49..06cd250e 100644 --- a/tests/dibi/Result.meta.phpt +++ b/tests/dibi/Result.meta.phpt @@ -24,14 +24,14 @@ $info = $conn->query(' Assert::same( - array('product_id', 'order_id', 'name', 'xxx'), + ['product_id', 'order_id', 'name', 'xxx'], $info->getColumnNames() ); if ($config['driver'] !== 'sqlite3' && $config['driver'] !== 'pdo') { Assert::same( - array('products.product_id', 'orders.order_id', 'customers.name', 'xxx'), + ['products.product_id', 'orders.order_id', 'customers.name', 'xxx'], $info->getColumnNames(TRUE) ); } diff --git a/tests/dibi/Result.types.phpt b/tests/dibi/Result.types.phpt index fa8e20da..2d8f9130 100644 --- a/tests/dibi/Result.types.phpt +++ b/tests/dibi/Result.types.phpt @@ -12,7 +12,7 @@ $res = $conn->query('SELECT * FROM [customers]'); // auto-converts this column to integer $res->setType('customer_id', Dibi::DATETIME, 'H:i j.n.Y'); -Assert::equal(new DibiRow(array( +Assert::equal(new DibiRow([ 'customer_id' => new DibiDateTime('1970-01-01 01:00:01'), 'name' => 'Dave Lister', -)), $res->fetch()); +]), $res->fetch()); diff --git a/tests/dibi/Row.phpt b/tests/dibi/Row.phpt index 365e4450..dc91ce3e 100644 --- a/tests/dibi/Row.phpt +++ b/tests/dibi/Row.phpt @@ -35,8 +35,8 @@ Assert::false(isset($row['missing'])); // to array -Assert::same(array('product_id' => 1, 'title' => 'Chair'), iterator_to_array($row)); -Assert::same(array('product_id' => 1, 'title' => 'Chair'), $row->toArray()); +Assert::same(['product_id' => 1, 'title' => 'Chair'], iterator_to_array($row)); +Assert::same(['product_id' => 1, 'title' => 'Chair'], $row->toArray()); // counting Assert::same(2, count($row)); diff --git a/tests/dibi/Translator.phpt b/tests/dibi/Translator.phpt index f59eb068..5d16f625 100644 --- a/tests/dibi/Translator.phpt +++ b/tests/dibi/Translator.phpt @@ -8,24 +8,24 @@ use Tester\Assert; require __DIR__ . '/bootstrap.php'; -$conn = new DibiConnection($config + array('formatDateTime' => "'Y-m-d H:i:s'", 'formatDate' => "'Y-m-d'")); +$conn = new DibiConnection($config + ['formatDateTime' => "'Y-m-d H:i:s'", 'formatDate' => "'Y-m-d'"]); // dibi detects INSERT or REPLACE command & booleans Assert::same( reformat("REPLACE INTO [products] ([title], [price]) VALUES ('Drticka', 318)"), - $conn->translate('REPLACE INTO [products]', array( + $conn->translate('REPLACE INTO [products]', [ 'title' => 'Drticka', 'price' => 318, -))); +])); // multiple INSERT command -$array = array( +$array = [ 'title' => 'Super Product', 'price' => 12, 'brand' => NULL, -); +]; Assert::same( reformat('INSERT INTO [products] ([title], [price], [brand]) VALUES (\'Super Product\', 12, NULL) , (\'Super Product\', 12, NULL) , (\'Super Product\', 12, NULL)'), $conn->translate('INSERT INTO [products]', $array, $array, $array) @@ -33,11 +33,11 @@ Assert::same( // multiple INSERT command II -$array = array( - array('pole' => 'hodnota1', 'bit' => 1), - array('pole' => 'hodnota2', 'bit' => 1), - array('pole' => 'hodnota3', 'bit' => 1), -); +$array = [ + ['pole' => 'hodnota1', 'bit' => 1], + ['pole' => 'hodnota2', 'bit' => 1], + ['pole' => 'hodnota3', 'bit' => 1], +]; Assert::same( reformat('INSERT INTO [products] ([pole], [bit]) VALUES (\'hodnota1\', 1) , (\'hodnota2\', 1) , (\'hodnota3\', 1)'), $conn->translate('INSERT INTO [products] %ex', $array) @@ -47,14 +47,14 @@ Assert::same( // dibi detects UPDATE command Assert::same( reformat("UPDATE [colors] SET [color]='blue', [order]=12 WHERE [id]=123"), - $conn->translate('UPDATE [colors] SET', array( + $conn->translate('UPDATE [colors] SET', [ 'color' => 'blue', 'order' => 12, -), 'WHERE [id]=%i', 123)); +], 'WHERE [id]=%i', 123)); // IN array -$array = array(1, 2, 3); +$array = [1, 2, 3]; Assert::same( reformat('SELECT * FROM [people] WHERE [id] IN ( 1, 2, 3 )'), $conn->translate('SELECT * FROM [people] WHERE [id] IN (', $array, ')') @@ -75,7 +75,7 @@ Assert::same( // invalid input $e = Assert::exception(function () use ($conn) { - $conn->translate('SELECT %s', (object) array(123), ', %m', 123); + $conn->translate('SELECT %s', (object) [123], ', %m', 123); }, 'DibiException', 'SQL translate error'); Assert::same('SELECT **Unexpected type object** , **Unknown or invalid modifier %m**', $e->getSql()); @@ -86,16 +86,16 @@ Assert::same( Assert::same( reformat('TEST ([cond] > 2) OR ([cond2] = \'3\') OR (cond3 < RAND())'), - $conn->translate('TEST %or', array('[cond] > 2', '[cond2] = "3"', 'cond3 < RAND()')) + $conn->translate('TEST %or', ['[cond] > 2', '[cond2] = "3"', 'cond3 < RAND()']) ); Assert::same( reformat('TEST ([cond] > 2) AND ([cond2] = \'3\') AND (cond3 < RAND())'), - $conn->translate('TEST %and', array('[cond] > 2', '[cond2] = "3"', 'cond3 < RAND()')) + $conn->translate('TEST %and', ['[cond] > 2', '[cond2] = "3"', 'cond3 < RAND()']) ); // -$where = array(); +$where = []; $where[] = '[age] > 20'; $where[] = '[email] IS NOT NULL'; Assert::same( @@ -104,17 +104,17 @@ Assert::same( ); -$where = array(); +$where = []; $where['age'] = NULL; $where['email'] = 'ahoj'; -$where['id%l'] = array(10, 20, 30); +$where['id%l'] = [10, 20, 30]; Assert::same( reformat('SELECT * FROM [table] WHERE ([age] IS NULL) AND ([email] = \'ahoj\') AND ([id] IN (10, 20, 30))'), $conn->translate('SELECT * FROM [table] WHERE %and', $where) ); -$where = array(); +$where = []; Assert::same( reformat('SELECT * FROM [table] WHERE 1=1'), $conn->translate('SELECT * FROM [table] WHERE %and', $where) @@ -122,14 +122,14 @@ Assert::same( // ORDER BY array -$order = array( +$order = [ 'field1' => 'asc', 'field2' => 'desc', 'field3' => 1, 'field4' => -1, 'field5' => TRUE, 'field6' => FALSE, -); +]; Assert::same( reformat('SELECT * FROM [people] ORDER BY [field1] ASC, [field2] DESC, [field3] ASC, [field4] DESC, [field5] ASC, [field6] DESC'), $conn->translate('SELECT * FROM [people] ORDER BY %by', $order) @@ -138,10 +138,10 @@ Assert::same( // with limit = 2 Assert::same( - reformat(array( + reformat([ 'odbc' => 'SELECT TOP 2 * FROM (SELECT * FROM [products] ) t', 'SELECT * FROM [products] LIMIT 2', - )), + ]), $conn->translate('SELECT * FROM [products] %lmt', 2) ); @@ -158,11 +158,11 @@ if ($config['system'] === 'odbc') { // with offset = 50 Assert::same( - reformat(array( + reformat([ 'mysql' => 'SELECT * FROM `products` LIMIT 18446744073709551615 OFFSET 50', 'pgsql' => 'SELECT * FROM "products" OFFSET 50', 'SELECT * FROM [products] LIMIT -1 OFFSET 50', - )), + ]), $conn->translate('SELECT * FROM [products] %ofs', 50) ); } @@ -171,11 +171,11 @@ if ($config['system'] === 'odbc') { Assert::same( - reformat(array( + reformat([ 'odbc' => 'INSERT INTO test ([a2], [a4], [b1], [b2], [b3], [b4], [b5], [b6], [b7], [b8], [b9]) VALUES (#09/26/1212 00:00:00#, #12/31/1969 22:13:20#, #09/26/1212#, #09/26/1212 00:00:00#, #12/31/1969#, #12/31/1969 22:13:20#, #09/26/1212 00:00:00#, #09/26/1212#, #09/26/1212 00:00:00#, NULL, NULL)', "INSERT INTO test ([a2], [a4], [b1], [b2], [b3], [b4], [b5], [b6], [b7], [b8], [b9]) VALUES ('1212-09-26 00:00:00', '1969-12-31 22:13:20', '1212-09-26', '1212-09-26 00:00:00', '1969-12-31', '1969-12-31 22:13:20', '1212-09-26 00:00:00', '1212-09-26', '1212-09-26 00:00:00', NULL, NULL)", - )), - $conn->translate('INSERT INTO test', array( + ]), + $conn->translate('INSERT INTO test', [ 'a2' => new DibiDateTime('1212-09-26'), 'a4' => new DibiDateTime(-10000), 'b1%d' => '1212-09-26', @@ -187,17 +187,17 @@ Assert::same( 'b7%t' => new DateTime('1212-09-26'), 'b8%d' => NULL, 'b9%t' => NULL, -))); +])); // like -$args = array( +$args = [ 'SELECT * FROM products WHERE (title LIKE %like~ AND title LIKE %~like) OR title LIKE %~like~', 'C', 'r', "a\n%_\\'\"", -); +]; if ($config['system'] === 'pgsql') { $conn->query('SET escape_string_warning = off'); // do not log warnings @@ -215,11 +215,11 @@ if ($config['system'] === 'pgsql') { ); } elseif ($config['driver'] !== 'sqlite') { // sqlite2 Assert::same( - reformat(array( + reformat([ 'sqlite' => "SELECT * FROM products WHERE (title LIKE 'C%' ESCAPE '\\' AND title LIKE '%r' ESCAPE '\\') OR title LIKE '%a\n\\%\\_\\\\''\"%' ESCAPE '\\'", 'odbc' => "SELECT * FROM products WHERE (title LIKE 'C%' AND title LIKE '%r') OR title LIKE '%a\n[%][_]\\''\"%'", "SELECT * FROM products WHERE (title LIKE 'C%' AND title LIKE '%r') OR title LIKE '%a\\n\\%\\_\\\\\\\\\'\"%'", - )), + ]), $conn->translate($args[0], $args[1], $args[2], $args[3]) ); } @@ -231,7 +231,7 @@ $e = Assert::exception(function () use ($conn) { Assert::same('SELECT **Alone quote**', $e->getSql()); Assert::match( - reformat(array( + reformat([ 'mysql' => "SELECT DISTINCT HIGH_PRIORITY SQL_BUFFER_RESULT CONCAT(last_name, ', ', first_name) AS full_name GROUP BY `user` @@ -248,7 +248,7 @@ INTO OUTFILE '/tmp/result''.txt' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\\n' ", - )), + ]), $conn->translate('%sql', 'SELECT DISTINCT HIGH_PRIORITY SQL_BUFFER_RESULT CONCAT(last_name, ", ", first_name) AS full_name GROUP BY [user] @@ -263,25 +263,25 @@ LINES TERMINATED BY '\\n' -$array1 = array(1, 2, 3); -$array2 = array('one', 'two', 'three'); -$array3 = array( +$array1 = [1, 2, 3]; +$array2 = ['one', 'two', 'three']; +$array3 = [ 'col1' => 'one', 'col2' => 'two', 'col3' => 'three', -); -$array4 = array( +]; +$array4 = [ 'a' => 12, 'b' => NULL, 'c' => new DibiDateTime('12.3.2007'), 'd' => 'any string', -); +]; -$array5 = array('RAND()', '[col1] > [col2]'); +$array5 = ['RAND()', '[col1] > [col2]']; Assert::match( - reformat(array( + reformat([ 'mysql' => "SELECT * FROM `db`.`table` WHERE (`test`.`a` LIKE '1995-03-01' @@ -362,20 +362,20 @@ WHERE ([test].[a] LIKE '1995-03-01' OR [str_null]=NULL OR [str_not_null]='hello' LIMIT 10", - )), + ]), $conn->translate('SELECT * FROM [db.table] WHERE ([test.a] LIKE %d', '1995-03-01', ' OR [b1] IN (', $array1, ') OR [b2] IN (%s', $array1, ') - OR [b3] IN (%s', array(), ') + OR [b3] IN (%s', [], ') OR [b4] IN (', $array2, ') OR [b5] IN (%n', $array3, ') OR [b6] IN %l', $array3, ' - OR [b7] IN %in', array(), ' + OR [b7] IN %in', [], ' OR [b8] IN (%sql', $array5, ') - OR [b9] IN (', array(), ") + OR [b9] IN (', [], ") AND [c] = 'embedded '' string' OR [d]=%i", 10.3, ' OR [e]=%i', NULL, ' @@ -389,40 +389,40 @@ LIMIT 10') Assert::same( reformat('TEST [cond] > 2 [cond2] = \'3\' cond3 < RAND() 123'), - $conn->translate('TEST %ex', array('[cond] > 2', '[cond2] = "3"', 'cond3 < RAND()'), 123) + $conn->translate('TEST %ex', ['[cond] > 2', '[cond2] = "3"', 'cond3 < RAND()'], 123) ); Assert::same( reformat('TEST ([cond] > 2) OR ([cond2] > 3) OR ([cond3] = 10 + 1)'), - $conn->translate('TEST %or', array('`cond` > 2', array('[cond2] > %i', '3'), 'cond3%sql' => array('10 + 1'))) + $conn->translate('TEST %or', ['`cond` > 2', ['[cond2] > %i', '3'], 'cond3%sql' => ['10 + 1']]) ); Assert::same( reformat('TEST ([cond] = 2) OR ([cond3] = RAND())'), - $conn->translate('TEST %or', array('cond' => 2, 'cond3%sql' => 'RAND()')) + $conn->translate('TEST %or', ['cond' => 2, 'cond3%sql' => 'RAND()']) ); Assert::same( reformat('TEST ([cond1] 3) OR ([cond2] RAND()) OR ([cond3] LIKE \'string\')'), - $conn->translate('TEST %or', array('cond1%ex' => 3, 'cond2%ex' => 'RAND()', 'cond3%ex' => array('LIKE %s', 'string'))) + $conn->translate('TEST %or', ['cond1%ex' => 3, 'cond2%ex' => 'RAND()', 'cond3%ex' => ['LIKE %s', 'string']]) ); Assert::same( - reformat(array( + reformat([ 'odbc' => 'SELECT TOP 10 * FROM (SELECT * FROM [test] WHERE [id] LIKE \'%d%t\' ) t', 'SELECT * FROM [test] WHERE [id] LIKE \'%d%t\' LIMIT 10', - )), + ]), $conn->translate("SELECT * FROM [test] WHERE %n LIKE '%d%t' %lmt", 'id', 10) ); -$where = array( +$where = [ 'tablename.column' => 1, -); +]; Assert::same( reformat('SELECT * FROM [tablename] WHERE ([tablename].[column] = 1)'), $conn->translate('SELECT * FROM [tablename] WHERE %and', $where) @@ -447,39 +447,39 @@ Assert::same( Assert::same( reformat('INSERT INTO [products] ([product_id], [title]) VALUES (1, SHA1(\'Test product\')) , (1, SHA1(\'Test product\'))'), - $conn->translate('INSERT INTO [products]', array( + $conn->translate('INSERT INTO [products]', [ 'product_id' => 1, - 'title' => array('SHA1(%s)', 'Test product'), -), array( + 'title' => ['SHA1(%s)', 'Test product'], +], [ 'product_id' => 1, - 'title' => array('SHA1(%s)', 'Test product'), -)) + 'title' => ['SHA1(%s)', 'Test product'], +]) ); Assert::same( reformat('UPDATE [products] [product_id]=1, [title]=SHA1(\'Test product\')'), - $conn->translate('UPDATE [products]', array( + $conn->translate('UPDATE [products]', [ 'product_id' => 1, - 'title' => array('SHA1(%s)', 'Test product'), -)) + 'title' => ['SHA1(%s)', 'Test product'], +]) ); $e = Assert::exception(function () use ($conn) { - $array6 = array( - 'id' => array(1, 2, 3, 4), - 'text' => array('ahoj', 'jak', 'se', array('SUM(%i)', '5')), - 'num%i' => array('1', ''), - ); + $array6 = [ + 'id' => [1, 2, 3, 4], + 'text' => ['ahoj', 'jak', 'se', ['SUM(%i)', '5']], + 'num%i' => ['1', ''], + ]; $conn->translate('INSERT INTO test %m', $array6); }, 'DibiException', 'SQL translate error'); Assert::same('INSERT INTO test **Multi-insert array "num%i" is different.**', $e->getSql()); -$array6 = array( - 'id' => array(1, 2, 3, 4), - 'text' => array('ahoj', 'jak', 'se', array('SUM(%i)', '5')), - 'num%i' => array('1', '', 10.3, 1), -); +$array6 = [ + 'id' => [1, 2, 3, 4], + 'text' => ['ahoj', 'jak', 'se', ['SUM(%i)', '5']], + 'num%i' => ['1', '', 10.3, 1], +]; Assert::same( reformat('INSERT INTO test ([id], [text], [num]) VALUES (1, \'ahoj\', 1), (2, \'jak\', 0), (3, \'se\', 10), (4, SUM(5), 1)'), @@ -487,10 +487,10 @@ Assert::same( ); -$by = array( - array('funkce(nazev_pole) ASC'), +$by = [ + ['funkce(nazev_pole) ASC'], 'jine_pole' => 'DESC', -); +]; Assert::same( reformat('SELECT * FROM table ORDER BY funkce(nazev_pole) ASC, [jine_pole] DESC'), @@ -513,12 +513,12 @@ setLocale(LC_ALL, 'czech'); Assert::same( reformat("UPDATE [colors] SET [color]='blue', [price]=-12.4, [spec]=-9E-005, [spec2]=1000, [spec3]=10000, [spec4]=10000 WHERE [price]=123.5"), - $conn->translate('UPDATE [colors] SET', array( + $conn->translate('UPDATE [colors] SET', [ 'color' => 'blue', 'price' => -12.4, 'spec%f' => '-9E-005', 'spec2%f' => 1000.00, 'spec3%i' => 10000, 'spec4' => 10000, -), 'WHERE [price]=%f', 123.5) +], 'WHERE [price]=%f', 123.5) ); diff --git a/tests/dibi/meta.phpt b/tests/dibi/meta.phpt index 88454961..70bef32b 100644 --- a/tests/dibi/meta.phpt +++ b/tests/dibi/meta.phpt @@ -22,7 +22,7 @@ Assert::same(3, count($meta->getTables())); $names = $meta->getTableNames(); sort($names); -Assert::equal(array('customers', 'orders', 'products'), $names); +Assert::equal(['customers', 'orders', 'products'], $names); Assert::false($meta->hasTable('xxxx'));