for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace nebula\component\database\connector;
use PDO;
use PDOException;
use nebula\component\database\exception\ConnectionException;
/**
* 连接器
*/
abstract class Connector
{
protected static $connetionCount = 0;
* PDO实例
*
* @var PDO|null
protected $pdo = 0;
* 连接器类型
* @var string
protected static $type;
* 配置信息
protected $config;
* 应用配置
* @param array $config
* @return void
public function applyConfig(array $config) {
$this->config = $config;
$config
array
string
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..
}
* 获取PDO链接描述
* @return string
abstract public function getDsn():string;
* 获取类型
public static function type():string {
return static::$type;
* 链接数据库
public function connect()
// 链接数据库
if (is_null($this->pdo)) {
try {
$this->pdo = new PDO($this->getDsn(), $this->user, $this->password);
password
nebula\component\database\connector\Connector
user
static::$connetionCount ++;
} catch (PDOException $e) {
throw new ConnectionException($e->getMessage(), $e->getCode());
public function getPdo()
return $this->pdo;
* 判断是否连接
* @return boolean
public function isConnected():bool
return $this->pdo !== null;
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..