-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParser.php
More file actions
45 lines (43 loc) · 1.23 KB
/
Parser.php
File metadata and controls
45 lines (43 loc) · 1.23 KB
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
40
41
42
43
44
45
<?php
/**
* Database setting file parser
*
* @package Tsukiyo
* @author Satoshi Nishimura <nishim314@gmail.com>
* @copyright Copyright (c) 2012 Satoshi Nishimura
*/
/**
* Database setting file parser
*
* @package Tsukiyo
* @author Satoshi Nishimura <nishim314@gmail.com>
* @copyright Copyright (c) 2012 Satoshi Nishimura
*/
class Tsukiyo_Parser
{
const FKEY_SECTION = '__forignKeys__';
public static function generate($db, $file){
$tables = $db->getMetaTables();
$data = '';
foreach ($tables as $table){
$metaPkeys = $db->getMetaPrimaryKeys($table);
$pkeys = '';
foreach ($metaPkeys as $pkey => $seq){
$pkeys .= "$pkey:$seq,";
}
$pkeys = rtrim($pkeys, ',');
$data .= "[$table:$pkeys]\n";
$metaCols = $db->getMetaColumns($table);
foreach ($metaCols as $col => $typ){
$data .= "$col\t = $typ\n";
}
$data .= "\n";
}
$data .= "[" . self::FKEY_SECTION . "]\n";
$fkeys = $db->getMetaForignKeys();
foreach ($fkeys as $from => $to){
$data .= "$from\t= $to\n";
}
file_put_contents($file, $data);
}
}