Skip to content

Commit

Permalink
sqlite: separate name and fileName in config
Browse files Browse the repository at this point in the history
  • Loading branch information
h-wang committed Feb 8, 2017
1 parent aeeb283 commit e97ab41
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/Config.php
Expand Up @@ -15,6 +15,7 @@ class Config
protected $address;
protected $port = 3306;
protected $properties = [];
protected $fileName;

public function getName()
{
Expand Down Expand Up @@ -111,6 +112,17 @@ public function setDriver($driver)
return $this;
}

public function getFileName()
{
return $this->fileName;
}

public function setFileName($fileName)
{
$this->fileName = $fileName;

return $this;
}

public function setProperty($key, $value)
{
Expand Down
6 changes: 4 additions & 2 deletions src/Connector.php
Expand Up @@ -28,7 +28,9 @@ public function getConfig($dsn)
}
$urlPath = parse_url($dsn, PHP_URL_PATH);
if (parse_url($dsn, PHP_URL_SCHEME) == 'sqlite') {
$config->setName($urlPath);
$i = pathinfo($urlPath);
$config->setName($i['filename']);
$config->setFileName($urlPath);
} else {
$config->setName(substr($urlPath, 1));
}
Expand Down Expand Up @@ -87,7 +89,7 @@ public function getPdoDsn(Config $config, $mode = 'db')
}
break;
case 'sqlite':
$pdoDsn .= $config->getName();
$pdoDsn .= $config->getFileName();
break;
default:
throw new RuntimeException("Unsupported driver: " . $config->getDriver());
Expand Down

0 comments on commit e97ab41

Please sign in to comment.