2006-08-16 16:20:55 +00:00
|
|
|
#!/usr/bin/php -q
|
|
|
|
<?php
|
|
|
|
/* SVN FILE: $Id$ */
|
|
|
|
/**
|
|
|
|
* Short description for file.
|
|
|
|
*
|
|
|
|
* Long description for file
|
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
|
|
|
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
|
|
|
* Copyright (c) 2005, Cake Software Foundation, Inc.
|
|
|
|
* 1785 E. Sahara Avenue, Suite 490-204
|
|
|
|
* Las Vegas, Nevada 89104
|
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
|
|
|
* @filesource
|
|
|
|
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
|
|
|
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.scripts.bake
|
|
|
|
* @since CakePHP v 1.2
|
|
|
|
* @version $Revision$
|
|
|
|
* @modifiedby $LastChangedBy$
|
|
|
|
* @lastmodified $Date$
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
|
|
|
*/
|
|
|
|
defineConstants();
|
|
|
|
$cakeDir = CORE_PATH.DS.'cake'.DS;
|
2006-09-10 13:50:23 +00:00
|
|
|
$argCount = count($argv);
|
2006-08-16 16:20:55 +00:00
|
|
|
|
2006-09-10 13:50:23 +00:00
|
|
|
if ($argCount == 1 || $argv[1] == 'help') {
|
|
|
|
showHelp();
|
|
|
|
} else {
|
|
|
|
$taskName = $argv[1];
|
|
|
|
$appPath = false;
|
|
|
|
$params = null;
|
|
|
|
$showHelp = false;
|
|
|
|
|
|
|
|
if ($argCount > 2) {
|
|
|
|
if ($argv[2] == 'help') {
|
|
|
|
$showHelp = true;
|
|
|
|
} else {
|
|
|
|
$appPath = getAppPath($argv[2]);
|
|
|
|
}
|
|
|
|
}
|
2006-08-16 16:20:55 +00:00
|
|
|
|
|
|
|
if ($appPath != false) {
|
|
|
|
defineAppConstants($appPath);
|
|
|
|
$params = prepareParams($argv, 3);
|
|
|
|
} else {
|
|
|
|
defineAppConstantsWithDefaultValues();
|
|
|
|
$params = prepareParams($argv, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
includeCoreFiles($cakeDir);
|
2006-09-10 13:50:23 +00:00
|
|
|
|
|
|
|
if ($showHelp) {
|
|
|
|
showHelpForTask($taskName);
|
|
|
|
} else {
|
|
|
|
executeTask($taskName, $params);
|
|
|
|
}
|
2006-08-16 16:20:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function defineAppConstants($appPath) {
|
|
|
|
$delimiter = strrpos($appPath, DS);
|
|
|
|
$root = substr($appPath, 0, $delimiter);
|
|
|
|
$appdir = substr($appPath, $delimiter + 1);
|
|
|
|
|
|
|
|
define('ROOT', $root);
|
|
|
|
define('APP_DIR', $appdir);
|
2006-08-18 07:33:33 +00:00
|
|
|
define('APP_PATH', ROOT.DS.APP_DIR.DS);
|
2006-10-24 14:45:55 +00:00
|
|
|
// TODO: how to handle situation with a non-standard webroot setup?
|
|
|
|
define('WWW_ROOT', APP_PATH.DS.'webroot'.DS);
|
2006-08-16 16:20:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function defineAppConstantsWithDefaultValues() {
|
|
|
|
define('ROOT', CORE_PATH);
|
|
|
|
define('APP_DIR', 'app');
|
2006-08-18 07:33:33 +00:00
|
|
|
define('APP_PATH', ROOT.DS.APP_DIR.DS);
|
2006-10-24 14:45:55 +00:00
|
|
|
define('WWW_ROOT', APP_PATH.DS.'webroot'.DS);
|
2006-08-16 16:20:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function defineConstants() {
|
|
|
|
define('DS', DIRECTORY_SEPARATOR);
|
2006-08-18 07:33:33 +00:00
|
|
|
define('CAKE_CORE_INCLUDE_PATH', dirname(dirname(dirname(__FILE__))));
|
|
|
|
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH.DS);
|
2006-08-16 16:20:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function executeTask($taskName, $params) {
|
2006-09-10 13:50:23 +00:00
|
|
|
$class = getTaskClass($taskName);
|
2006-10-24 12:10:33 +00:00
|
|
|
|
|
|
|
if ($class !== null) {
|
2006-10-22 12:34:50 +00:00
|
|
|
$class->execute($params);
|
|
|
|
} else {
|
|
|
|
echo "Task not found: " . $taskName . "\n";
|
|
|
|
}
|
2006-08-16 16:20:55 +00:00
|
|
|
}
|
|
|
|
|
2006-09-10 13:50:23 +00:00
|
|
|
function getAppPath($appPathShortcut) {
|
|
|
|
$iniFile = CORE_PATH.DS.'apps.ini';
|
2006-08-16 16:20:55 +00:00
|
|
|
|
|
|
|
if (file_exists($iniFile)) {
|
|
|
|
$appArray = readConfigFile($iniFile);
|
|
|
|
|
|
|
|
if (array_key_exists($appPathShortcut, $appArray)) {
|
|
|
|
return $appArray[$appPathShortcut];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2006-09-10 13:50:23 +00:00
|
|
|
|
|
|
|
function getTaskClass($taskName) {
|
|
|
|
$scriptDir = dirname(__FILE__);
|
|
|
|
$taskPath = 'tasks'.DS.$taskName.'_task.php';
|
2006-10-22 12:34:50 +00:00
|
|
|
$fileExists = true;
|
2006-09-10 13:50:23 +00:00
|
|
|
require($scriptDir.DS.'tasks'.DS.'bake_task.php');
|
|
|
|
|
|
|
|
if (file_exists(VENDORS.$taskPath)) {
|
|
|
|
require(VENDORS.$taskPath);
|
2006-10-22 12:34:50 +00:00
|
|
|
} elseif (file_exists($scriptDir.DS.$taskPath)) {
|
2006-09-10 13:50:23 +00:00
|
|
|
require($scriptDir.DS.$taskPath);
|
2006-10-22 12:34:50 +00:00
|
|
|
} else {
|
|
|
|
$fileExists = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($fileExists) {
|
|
|
|
$className = $taskName.'Task';
|
|
|
|
return new $className;
|
2006-09-10 13:50:23 +00:00
|
|
|
}
|
|
|
|
|
2006-10-22 12:34:50 +00:00
|
|
|
return null;
|
2006-09-10 13:50:23 +00:00
|
|
|
}
|
2006-08-16 16:20:55 +00:00
|
|
|
|
|
|
|
function includeCoreFiles($cakePath) {
|
|
|
|
require($cakePath.'basics.php');
|
|
|
|
require($cakePath.'config'.DS.'paths.php');
|
|
|
|
}
|
|
|
|
|
|
|
|
function prepareParams($originalParams, $elementsToRemove) {
|
|
|
|
$params = $originalParams;
|
|
|
|
|
|
|
|
for ($i = 0; $i < $elementsToRemove; $i++) {
|
|
|
|
array_shift($params);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $params;
|
|
|
|
}
|
|
|
|
|
|
|
|
function readConfigFile($fileName) {
|
|
|
|
$fileLineArray = file($fileName);
|
|
|
|
|
|
|
|
foreach($fileLineArray as $fileLine) {
|
|
|
|
$dataLine = trim($fileLine);
|
|
|
|
|
|
|
|
$delimiter = strpos($dataLine, '=');
|
|
|
|
|
|
|
|
if ($delimiter > 0) {
|
|
|
|
$key = strtolower(trim(substr($dataLine, 0, $delimiter)));
|
|
|
|
$value = trim(substr($dataLine, $delimiter + 1));
|
|
|
|
$iniSetting[$key] = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $iniSetting;
|
|
|
|
}
|
|
|
|
|
|
|
|
function showHelp() {
|
|
|
|
echo "Usage: php bake2.php task [param1, ...]\n";
|
|
|
|
}
|
2006-09-10 13:50:23 +00:00
|
|
|
|
|
|
|
function showHelpForTask($taskName) {
|
|
|
|
$class = getTaskClass($taskName);
|
|
|
|
$class->help();
|
|
|
|
}
|
2006-08-16 16:20:55 +00:00
|
|
|
?>
|