?? bakecommand.java
字號(hào):
package org.xicabin.radcake.core.bake;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.StringTokenizer;
import org.xicabin.radcake.core.util.PHPCommandBuilder;
import org.xicabin.radcake.core.util.PHPRunner;
public class BakeCommand {
private static final String DS = PHPCommandBuilder.DS;
private String cakeRoot;
private PHPRunner php;
public BakeCommand(String cakeRoot, String php)
throws FileNotFoundException {
this(cakeRoot, new PHPRunner(php));
}
public BakeCommand(String cakeRoot, PHPRunner runner) {
this.cakeRoot = cakeRoot;
this.php = runner;
if (!this.cakeRoot.endsWith(DS)) {
this.cakeRoot += DS;
}
}
public String[] getTables() throws IOException {
PHPCommandBuilder builder = new PHPCommandBuilder();
appendInclude(builder);
builder
.appendLine("$db =& ConnectionManager::getDataSource('default');");
builder
.appendLine("$usePrefix = empty($db->config['prefix']) ? '' : $db->config['prefix'];");
builder.appendLine("if ($usePrefix) {");
builder.appendLine("$tables = array();");
builder.appendLine("foreach ($db->listSources() as $table) {");
builder
.appendLine("if (!strncmp($table, $usePrefix, strlen($usePrefix))) {");
builder.appendLine("$tables[] = substr($table, strlen($usePrefix));");
builder.appendLine("}");
builder.appendLine("}");
builder.appendLine("} else {");
builder.appendLine("$tables = $db->listSources();");
builder.appendLine("}");
builder
.appendLine("foreach ($tables as $table) { echo $table.' '; }");
return parseArray(php.exec(builder.toString()));
}
private void appendInclude(PHPCommandBuilder builder) {
builder.appendLine("define ('DS', DIRECTORY_SEPARATOR);");
builder.appendLine("define ('CAKE_CORE_INCLUDE_PATH', '" + cakeRoot
+ "\\');");
builder.appendLine("define ('ROOT', '" + cakeRoot + "\\');");
builder.appendLine("define ('APP_DIR', 'app');");
builder.appendLine("define ('APP_PATH', ROOT . DS . APP_DIR . DS);");
builder
.appendLine("define ('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);");
builder.appendLine("require_once ('" + cakeRoot + "cake" + DS
+ "basics.php');");
builder.appendLine("require_once ('" + cakeRoot + "cake" + DS
+ "config" + DS + "paths.php');");
builder.appendLine("require_once ('" + cakeRoot + "cake" + DS
+ "dispatcher.php');");
builder
.appendLine("uses('object', 'session', 'security', 'configure', 'inflector', 'model'.DS.'connection_manager');");
}
private String[] parseArray(String str) {
StringTokenizer token = new StringTokenizer(str);
String[] output = new String[token.countTokens()];
for (int I = 0; I < output.length; ++I) {
output[I] = token.nextToken();
}
return output;
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -