-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDb1Loader.php
39 lines (33 loc) · 1.05 KB
/
Db1Loader.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
/**
* Tests for database loaders.
*
* @package SugiPHP.Config
* @author Plamen Popov <[email protected]>
* @license http://opensource.org/licenses/mit-license.php (MIT License)
*/
namespace SugiPHP\Config\Tests;
use SugiPHP\Config\LoaderInterface;
use SQLite3;
class Db1Loader implements LoaderInterface
{
private $db;
public function __construct()
{
$this->db = new SQLite3(":memory:");
$this->db->exec("CREATE TABLE config (key VARCHAR NOT NULL PRIMARY KEY, host VARCHAR(255), debug INTEGER)");
$this->db->exec("INSERT INTO config VALUES ('development', 'localhost', 1)");
$this->db->exec("INSERT INTO config VALUES ('production', 'example.com', null)");
}
public function load($resource)
{
$key = $this->db->escapeString($resource);
$result = $this->db->query("SELECT * FROM config WHERE key = '$key'");
$array = $result->fetchArray(SQLITE3_ASSOC);
if ($array === false) {
return null;
}
unset($array["key"]);
return $array;
}
}