This repository has been archived by the owner on Sep 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from 1ma/backend-decoupling
Backend decoupling
- Loading branch information
Showing
8 changed files
with
159 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
/composer.lock | ||
/composer.phar | ||
/tags | ||
/vendor | ||
config/config.php | ||
|
||
# phpstorm files | ||
.idea/ | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php | ||
|
||
class Xhgui_Saver_Pdo implements Xhgui_Saver_Interface | ||
{ | ||
const TABLE_DDL = <<<SQL | ||
CREATE TABLE IF NOT EXISTS "%s" ( | ||
id TEXT PRIMARY KEY, | ||
profile TEXT NOT NULL, | ||
url TEXT NULL, | ||
SERVER TEXT NULL, | ||
GET TEXT NULL, | ||
ENV TEXT NULL, | ||
simple_url TEXT NULL, | ||
request_ts INTEGER NOT NULL, | ||
request_ts_micro NUMERIC(15, 4) NOT NULL, | ||
request_date DATE NOT NULL, | ||
main_wt INTEGER NOT NULL, | ||
main_ct INTEGER NOT NULL, | ||
main_cpu INTEGER NOT NULL, | ||
main_mu INTEGER NOT NULL, | ||
main_pmu INTEGER NOT NULL | ||
); | ||
SQL; | ||
|
||
const INSERT_DML = <<<SQL | ||
INSERT INTO "%s" ( | ||
id, | ||
profile, | ||
url, | ||
SERVER, | ||
GET, | ||
ENV, | ||
simple_url, | ||
request_ts, | ||
request_ts_micro, | ||
request_date, | ||
main_wt, | ||
main_ct, | ||
main_cpu, | ||
main_mu, | ||
main_pmu | ||
) VALUES ( | ||
:id, | ||
:profile, | ||
:url, | ||
:SERVER, | ||
:GET, | ||
:ENV, | ||
:simple_url, | ||
:request_ts, | ||
:request_ts_micro, | ||
:request_date, | ||
:main_wt, | ||
:main_ct, | ||
:main_cpu, | ||
:main_mu, | ||
:main_pmu | ||
); | ||
SQL; | ||
|
||
/** | ||
* @var PDOStatement | ||
*/ | ||
private $stmt; | ||
|
||
/** | ||
* @param PDO $pdo | ||
* @param string $table | ||
*/ | ||
public function __construct(PDO $pdo, $table) | ||
{ | ||
$pdo->exec(sprintf(self::TABLE_DDL, $table)); | ||
|
||
$this->stmt = $pdo->prepare(sprintf(self::INSERT_DML, $table)); | ||
} | ||
|
||
public function save(array $data) | ||
{ | ||
$main = $data['profile']['main()']; | ||
|
||
$this->stmt->execute(array( | ||
'id' => Xhgui_Util::generateId(), | ||
'profile' => json_encode($data['profile']), | ||
'url' => $data['meta']['url'], | ||
'SERVER' => json_encode($data['meta']['SERVER']), | ||
'GET' => json_encode($data['meta']['get']), | ||
'ENV' => json_encode($data['meta']['env']), | ||
'simple_url' => $data['meta']['simple_url'], | ||
'request_ts' => $data['meta']['request_ts']['sec'], | ||
'request_ts_micro' => "{$data['meta']['request_ts_micro']['sec']}.{$data['meta']['request_ts_micro']['usec']}", | ||
'request_date' => $data['meta']['request_date'], | ||
'main_wt' => $main['wt'], | ||
'main_ct' => $main['ct'], | ||
'main_cpu' => $main['cpu'], | ||
'main_mu' => $main['mu'], | ||
'main_pmu' => $main['pmu'], | ||
)); | ||
|
||
$this->stmt->closeCursor(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters