Skip to content

Commit e1e2368

Browse files
committed
🎨 更新composer 依赖申明
1 parent d8a2638 commit e1e2368

File tree

3 files changed

+119
-114
lines changed

3 files changed

+119
-114
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
],
1616
"minimum-stability": "dev",
1717
"require": {
18-
"php": ">=5.2",
18+
"php": ">=5.4",
1919
"ext-mysqli": "*",
2020
"ext-pdo": "*"
2121
},

src/Sync.php

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

33
namespace Zyimm\dbStructSync;
44

5+
use Exception;
6+
use PDO;
57
use Zyimm\dbStructSync\builder\Mysql;
6-
use \Zyimm\dbStructSync\connector\Mysql as Connector;
8+
use Zyimm\dbStructSync\connector\Mysql as Connector;
79

810
class Sync
911
{
@@ -17,7 +19,7 @@ class Sync
1719
];
1820

1921
/**
20-
* @var \PDO
22+
* @var PDO
2123
*/
2224
public $localConnector;
2325

@@ -29,7 +31,7 @@ class Sync
2931
/**
3032
* Sync constructor.
3133
* @param array $config
32-
* @throws \Exception
34+
* @throws Exception
3335
*/
3436
public function __construct(array $config)
3537
{
@@ -82,6 +84,8 @@ public function executeSync()
8284

8385
/**
8486
* toHtml
87+
*
88+
* @return mixed
8589
*/
8690
public function toHtml()
8791
{

src/connector/Mysql.php

Lines changed: 111 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,111 @@
1-
<?php
2-
3-
namespace Zyimm\dbStructSync\connector;
4-
5-
use Exception;
6-
use PDO;
7-
8-
/**
9-
* Class Mysql
10-
*
11-
* @package Zyimm\dbStructSync\connector
12-
*/
13-
class Mysql
14-
{
15-
/**
16-
* @var PDO
17-
*/
18-
private $localConnection;
19-
20-
/**
21-
* @var PDO
22-
*/
23-
private $devConnection;
24-
25-
public $localDb = [];
26-
27-
public $devDb = [];
28-
29-
/**
30-
* connectionMap
31-
*
32-
* @return string[]
33-
*/
34-
public static function connectionMap()
35-
{
36-
return [
37-
'local' => 'localConnection',
38-
'dev' => 'devConnection'
39-
];
40-
}
41-
42-
/**
43-
* Mysql constructor.
44-
*
45-
* @param array $config
46-
* @throws Exception
47-
*/
48-
public function __construct(array $config = [])
49-
{
50-
$config = empty($config) ? $this->getConfig() : $config;
51-
foreach (static::connectionMap() as $key => $connect) {
52-
$this->{$key.'Db'} = $config[$key];
53-
$dsn = $this->getDsn($config[$key]['host'], $config[$key]['dbname']);
54-
$user = $config[$key]['username'];
55-
$password = $config[$key]['passwd'];
56-
$this->{$connect} = new PDO($dsn, $user, $password,
57-
[PDO::MYSQL_ATTR_INIT_COMMAND => "set names utf8"]);
58-
}
59-
}
60-
61-
/**
62-
* getConfig
63-
*
64-
* @return false|string
65-
* @throws Exception
66-
*/
67-
public function getConfig()
68-
{
69-
$file = dirname(__DIR__).'/config.php';
70-
if (is_file($file)) {
71-
$config = file_get_contents($file);
72-
}
73-
if (empty($config)) {
74-
throw new Exception('db config exception');
75-
}
76-
return $config;
77-
}
78-
79-
/**
80-
* getDsn
81-
*
82-
* @param string $host
83-
* @param string $db_name
84-
* @return string
85-
*/
86-
public function getDsn($host = '', $db_name = '')
87-
{
88-
return "mysql:host={$host};dbname={$db_name}";
89-
}
90-
91-
/**
92-
* getDevConnection
93-
*
94-
* @return PDO
95-
*/
96-
public function getLocalConnection()
97-
{
98-
return $this->localConnection;
99-
}
100-
101-
/**
102-
* getDevConnection
103-
*
104-
* @return PDO
105-
*/
106-
public function getDevConnection()
107-
{
108-
return $this->devConnection;
109-
}
110-
}
1+
<?php
2+
3+
namespace Zyimm\dbStructSync\connector;
4+
5+
use Exception;
6+
use PDO;
7+
8+
/**
9+
* Class Mysql
10+
*
11+
* @package Zyimm\dbStructSync\connector
12+
*/
13+
class Mysql
14+
{
15+
/**
16+
* @var PDO
17+
*/
18+
private $localConnection;
19+
20+
/**
21+
* @var PDO
22+
*/
23+
private $devConnection;
24+
25+
public $localDb = [];
26+
27+
public $devDb = [];
28+
29+
/**
30+
* connectionMap
31+
*
32+
* @return string[]
33+
*/
34+
public static function connectionMap()
35+
{
36+
return [
37+
'local' => 'localConnection',
38+
'dev' => 'devConnection'
39+
];
40+
}
41+
42+
/**
43+
* Mysql constructor.
44+
*
45+
* @param array $config
46+
* @throws Exception
47+
*/
48+
public function __construct(array $config = [])
49+
{
50+
$config = empty($config) ? $this->getConfig() : $config;
51+
foreach (static::connectionMap() as $key => $connect) {
52+
$this->{$key.'Db'} = $config[$key];
53+
$dsn = $this->getDsn($config[$key]['host'], $config[$key]['dbname']);
54+
$user = $config[$key]['username'];
55+
$password = $config[$key]['passwd'];
56+
$this->{$connect} = new PDO($dsn, $user, $password,
57+
[PDO::MYSQL_ATTR_INIT_COMMAND => "set names utf8"]);
58+
}
59+
}
60+
61+
/**
62+
* getConfig
63+
*
64+
* @return string
65+
* @throws Exception
66+
*/
67+
public function getConfig()
68+
{
69+
$file = dirname(__DIR__).'/config.php';
70+
if (is_file($file)) {
71+
$config = file_get_contents($file);
72+
}
73+
if (empty($config)) {
74+
throw new Exception('db config exception');
75+
}
76+
return $config;
77+
}
78+
79+
/**
80+
* getDsn
81+
*
82+
* @param string $host
83+
* @param string $db_name
84+
*
85+
* @return string
86+
*/
87+
public function getDsn($host = '', $db_name = '')
88+
{
89+
return "mysql:host=$host;dbname=$db_name";
90+
}
91+
92+
/**
93+
* getDevConnection
94+
*
95+
* @return PDO
96+
*/
97+
public function getLocalConnection()
98+
{
99+
return $this->localConnection;
100+
}
101+
102+
/**
103+
* getDevConnection
104+
*
105+
* @return PDO
106+
*/
107+
public function getDevConnection()
108+
{
109+
return $this->devConnection;
110+
}
111+
}

0 commit comments

Comments
 (0)