Skip to content

Commit 3304f90

Browse files
committed
Merge branch 'master' into v5
2 parents 1c2a392 + cc6f98b commit 3304f90

24 files changed

+289
-227
lines changed

.github/workflows/ezsql-linux.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ on:
1212
jobs:
1313
linux:
1414
name: Linux (PHP ${{ matrix.php-versions }} CI)
15-
runs-on: ubuntu-latest
15+
runs-on: ubuntu-18.04
1616
strategy:
1717
fail-fast: false
1818
matrix:
19-
operating-system: [ubuntu-latest]
20-
php-versions: ['7.4', '8.0']
19+
operating-system: [ubuntu-18.04]
20+
php-versions: ['7.4', '8.0', '8.1']
2121

2222
steps:
2323
- name: Checkout

.github/workflows/ezsql-macos.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ jobs:
3434
brew install mysql@5.7
3535
- name: Brew Start MySQL
3636
run: |
37-
brew services start mysql@5.7
3837
brew link mysql@5.7 --force
39-
mysqld --initialize-insecure
38+
sudo rm -rf /usr/local/var/mysql
39+
sudo rm /usr/local/etc/my.cnf
40+
mysqld --initialize-insecure --explicit_defaults_for_timestamp
4041
mysql.server start
4142
- name: Setup MySQL Database
4243
run: |

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ $db = Database::initialize('****', [$dsn_path_user, $password, $database, $other
6767
use ezsql\Config;
6868
use ezsql\Database\ez_****;
6969

70-
$setting = new Config('****', [$dsn_path_user, $password, $database, $other_settings]);
70+
$settings = new Config('****', [$dsn_path_user, $password, $database, $other_settings]);
7171

7272
$db = new ez_****($settings);
7373
```

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"issues": "https://github.com/ezSQL/ezSQL/issues"
4040
},
4141
"require": {
42-
"php": "^7.1 || ^8",
42+
"php": ">7.1",
4343
"psr/container": "^1.0"
4444
},
4545
"provide": {
@@ -55,7 +55,7 @@
5555
}
5656
},
5757
"require-dev": {
58-
"phpunit/phpunit": "^6 || ^7 || ^8"
58+
"phpunit/phpunit": "^6 | ^7 | ^8"
5959
},
6060
"autoload-dev": {
6161
"psr-4": {

lib/Config.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
class Config extends ConfigAbstract implements ConfigInterface
1212
{
13-
public function __construct(string $driver = '', array $arguments = null)
13+
public function __construct(string $driver = '', ?array $arguments = null)
1414
{
1515
$sql = \strtolower($driver);
1616
if (!\array_key_exists($sql, \VENDOR) || empty($arguments)) {
@@ -31,7 +31,7 @@ public function __construct(string $driver = '', array $arguments = null)
3131
}
3232
}
3333

34-
public static function initialize(string $driver = '', array $arguments = null)
34+
public static function initialize(string $driver = '', ?array $arguments = null)
3535
{
3636
return new self($driver, $arguments);
3737
}

lib/ConfigInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,5 @@ interface ConfigInterface
9999
* for: **sqlite3** - (`filePath`, `database`)
100100
* - `filePath` // The path to open an SQLite database
101101
*/
102-
public static function initialize(string $driver = '', array $arguments = null);
102+
public static function initialize(string $driver = '', ?array $arguments = null);
103103
}

lib/Constants.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
\define('_BETWEEN', 'BETWEEN');
4040
\define('_notBETWEEN', 'NOT BETWEEN');
4141

42-
\define('_isNULL', 'IS NULL');
43-
\define('_notNULL', 'IS NOT NULL');
42+
\define('_isNULL', 'IS');
43+
\define('_notNULL', 'IS NOT');
4444
\define('_BOOLEAN_OPERATORS', [
4545
'<', '>', '=', '!=', '>=', '<=', '<>',
4646
'IN', 'LIKE', 'NOT LIKE', 'BETWEEN', 'NOT BETWEEN', 'IS', 'IS NOT'

lib/Database.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
namespace ezsql;
66

7+
use ezsql\Db;
78
use ezsql\DInjector;
8-
use function ezsql\functions\setInstance;
99

1010
class Database
1111
{
@@ -15,7 +15,10 @@ class Database
1515
* @var float
1616
*/
1717
private static $_ts = null;
18-
private static $factory = null;
18+
19+
/**
20+
* @var ezQueryInterface[]
21+
*/
1922
private static $instances = [];
2023

2124
// @codeCoverageIgnoreStart
@@ -67,10 +70,10 @@ public function __wakeup()
6770
* @param string $tag Store the instance for later use
6871
* @return Database\ez_pdo|Database\ez_pgsql|Database\ez_sqlsrv|Database\ez_sqlite3|Database\ez_mysqli
6972
*/
70-
public static function initialize(?string $vendor = null, ?array $setting = null, ?string $tag = null)
73+
public static function initialize(?string $vendor = null, ?array $setting = null, ?string $tag = null): ezQueryInterface
7174
{
7275
if (isset(self::$instances[$vendor]) && empty($setting) && empty($tag))
73-
return setInstance(self::$instances[$vendor]) ? self::$instances[$vendor] : false;
76+
return self::$instances[$vendor];
7477

7578
if (empty($vendor) || empty($setting)) {
7679
throw new \Exception(\MISSING_CONFIGURATION);
@@ -79,7 +82,7 @@ public static function initialize(?string $vendor = null, ?array $setting = null
7982
$key = $vendor;
8083
$value = \VENDOR[$key];
8184

82-
if (empty($GLOBALS['ez' . $key]) || !empty($tag)) {
85+
if (!Db::has('ez' . $key) || !empty($tag)) {
8386
$di = new DInjector();
8487
$di->set($key, $value);
8588
$di->set('ezsql\ConfigInterface', 'ezsql\Config');
@@ -90,8 +93,9 @@ public static function initialize(?string $vendor = null, ?array $setting = null
9093
}
9194
}
9295

93-
setInstance($GLOBALS['ez' . $key]);
94-
return $GLOBALS['ez' . $key];
96+
$db = Db::get('ez' . $key);
97+
Db::set('global', $db);
98+
return $db;
9599
}
96100
}
97101

lib/Database/ez_mysqli.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
namespace ezsql\Database;
66

77
use Exception;
8+
use ezsql\Db;
89
use ezsql\ezsqlModel;
910
use ezsql\ConfigInterface;
1011
use ezsql\DatabaseInterface;
11-
use function ezsql\functions\setInstance;
1212

1313
class ez_mysqli extends ezsqlModel implements DatabaseInterface
1414
{
@@ -35,7 +35,7 @@ class ez_mysqli extends ezsqlModel implements DatabaseInterface
3535
private $database;
3636
protected $shortcutUsed = false;
3737

38-
public function __construct(ConfigInterface $settings = null)
38+
public function __construct(?ConfigInterface $settings = null)
3939
{
4040
if (empty($settings)) {
4141
throw new Exception(\MISSING_CONFIGURATION);
@@ -44,9 +44,9 @@ public function __construct(ConfigInterface $settings = null)
4444
parent::__construct();
4545
$this->database = $settings;
4646

47-
if (empty($GLOBALS['ez' . \MYSQLI]))
48-
$GLOBALS['ez' . \MYSQLI] = $this;
49-
setInstance($this);
47+
if (!Db::has('ez' . \MYSQLI))
48+
Db::set('ez' . \MYSQLI, $this);
49+
Db::set('global', $this);
5050
} // __construct
5151

5252
public function settings()
@@ -278,7 +278,7 @@ private function fetch_prepared_result(&$stmt, $query)
278278
* @param array $param
279279
* @return bool|\mysqli_result
280280
*/
281-
public function query_prepared(string $query, array $param = null)
281+
public function query_prepared(string $query, ?array $param = null)
282282
{
283283
$stmt = $this->dbh->prepare($query);
284284
if (!$stmt instanceof \mysqli_stmt) {
@@ -291,7 +291,7 @@ public function query_prepared(string $query, array $param = null)
291291
$params = [];
292292
$types = \array_reduce(
293293
$param,
294-
function ($string, &$arg) use (&$params) {
294+
function ($string, $arg) use (&$params) {
295295
$params[] = &$arg;
296296
if (\is_float($arg))
297297
$string .= 'd';

lib/Database/ez_pdo.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
namespace ezsql\Database;
66

77
use Exception;
8+
use ezsql\Db;
89
use ezsql\ezsqlModel;
910
use ezsql\ConfigInterface;
1011
use ezsql\DatabaseInterface;
11-
use function ezsql\functions\setInstance;
1212

1313
class ez_pdo extends ezsqlModel implements DatabaseInterface
1414
{
@@ -35,7 +35,7 @@ class ez_pdo extends ezsqlModel implements DatabaseInterface
3535
*/
3636
private $database;
3737

38-
public function __construct(ConfigInterface $settings = null)
38+
public function __construct(?ConfigInterface $settings = null)
3939
{
4040
if (empty($settings)) {
4141
throw new Exception(\MISSING_CONFIGURATION);
@@ -47,9 +47,9 @@ public function __construct(ConfigInterface $settings = null)
4747
// Turn on track errors
4848
ini_set('track_errors', '1');
4949

50-
if (empty($GLOBALS['ez' . \Pdo]))
51-
$GLOBALS['ez' . \Pdo] = $this;
52-
setInstance($this);
50+
if (!Db::has('ez' . \Pdo))
51+
Db::set('ez' . \Pdo, $this);
52+
Db::set('global', $this);
5353
} // __construct
5454

5555
public function settings()
@@ -235,7 +235,7 @@ public function catch_error()
235235
* @param boolean $isSelect - return \PDOStatement, if SELECT SQL statement, otherwise int
236236
* @return bool|int|\PDOStatement
237237
*/
238-
public function query_prepared(string $query, array $param = null, $isSelect = false)
238+
public function query_prepared(string $query, ?array $param = null, $isSelect = false)
239239
{
240240
$stmt = $this->dbh->prepare($query);
241241
$result = false;
@@ -349,7 +349,7 @@ private function processResult(string $query, $result = null, bool $isSelect = f
349349
* @param array $param
350350
* @return bool|void
351351
*/
352-
private function processQuery(string $query, array $param = null)
352+
private function processQuery(string $query, ?array $param = null)
353353
{
354354
// Query was an insert, delete, update, replace
355355
if (\preg_match("/^(insert|delete|update|replace|drop|create)\s+/i", $query)) {

0 commit comments

Comments
 (0)