⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bakecommand.java

📁 CakePHP的Eclipse插件
💻 JAVA
字号:
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;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -