-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzend-db-model-generator.php
136 lines (108 loc) · 3.63 KB
/
zend-db-model-generator.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/php
<?php
if (!is_file(dirname(__FILE__).'/config/config.php')){
die("please copy config/config.php-default to config/config.php and modify.");
}
define('VERSION', '0.7');
define('AUTHOR', 'Kfir Ozer <[email protected]>');
require_once('config/config.php');
require_once('class/ArgvParser.php');
if (!ini_get('short_open_tag') && version_compare(PHP_VERSION, '5.4.0') < 0) {
die("please enable short_open_tag directive in php.ini\n");
}
if (!ini_get('register_argc_argv')) {
die("please enable register_argc_argv directive in php.ini\n");
}
$parser = new ArgvParser($argv,AUTHOR,VERSION);
$params=$parser->checkParams();
if (sizeof($params['--zfv']) == 1) {
$config['default_zend_framework_version']=$params['--zfv'][0];
}
switch ($config['default_zend_framework_version']) {
case 1:
require_once('class/MakeDbTablev1.php');
break;
case 2:
require_once('class/MakeDbTablev2.php');
break;
default:
die("error: default_zend_framework_version - bad parameter");
}
echo "about to create classes for zend framework".$config['default_zend_framework_version']."\n";
$db_type = $config['db.type'];
$class = 'Make_' . $db_type;
$include = @include_once (dirname(__FILE__).DIRECTORY_SEPARATOR.'class'.DIRECTORY_SEPARATOR.'Make.'. $db_type . '.php');
if (! $include || ! class_exists($class)) {
die ("Database type specified is not supported\n");
}
$namespace=$config['namespace.default'];
if (sizeof($params['--namespace']) == 1) {
$namespace=$params['--namespace'][0];
}
$dbname=$params['--database'][0];
$cls = new $class($config,$dbname,$namespace);
$tables=array();
if ($params['--all-tables'] || sizeof($params['--tables-regex'])>0) {
$tables=$cls->getTablesNamesFromDb();
}
$tables=$parser->compileListOfTables($tables, $params);
if (sizeof($tables) == 0) {
die("error: please provide at least one table to parse.\n");
}
$path='';
//die(dirname(__FILE__).DIRECTORY_SEPARATOR.$params['--database'][0]);
if (sizeof($params['--location']) == 1) {
// Check if a relative path
if (! realpath($params['--location'][0])) {
$path = realpath(dirname(__FILE__).DIRECTORY_SEPARATOR.$params['--location'][0]);
} else {
$path = realpath($params['--location'][0]);
}
$cls->setLocation($path);
$path .= DIRECTORY_SEPARATOR;
$cls->addTablePrefixes($params['--table-prefix']);
} else {
$cls->setLocation(dirname(__FILE__).DIRECTORY_SEPARATOR.$params['--database'][0]);
$path=dirname(__FILE__).DIRECTORY_SEPARATOR.$params['--database'][0].DIRECTORY_SEPARATOR;
}
$templatepath='';
if (sizeof($params['--templates']) == 1) {
// Check if a relative path
if (! realpath($params['--templates'][0])) {
$templatepath = realpath(dirname(__FILE__).DIRECTORY_SEPARATOR.$params['--templates'][0]);
} else {
$templatepath = realpath($params['--templates'][0]);
}
$cls->setTemplatePath($templatepath);
}
switch ($config['default_zend_framework_version']) {
case 1:
foreach (array('DbTable', 'mappers') as $name) {
$dir = $path . $name;
if (!is_dir($dir)) {
if (!@mkdir($dir,0755,true)) {
die("error: could not create directory $dir\n");
}
}
}
break;
case 2:
if (!is_dir($path)) {
if (!@mkdir($path,0755,true)) {
die("error: could not create directory $path\n");
}
}
break;
}
$cls->setTableList($tables);
$cls->addTablePrefixes($params['--table-prefix']);
foreach ($tables as $table) {
$cls->setTableName($table);
try {
$cls->parseTable();
$cls->doItAll();
} catch (Exception $e) {
echo "Warining: Failed to process $table: " . $e->getMessage(). " ... Skipping\n";
}
}
echo "done!\n";