mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 19:38:26 +00:00
2b008eb66a
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@3735 3807eeeb-6ff5-0310-8944-8be069107fe0
144 lines
No EOL
3.5 KiB
PHP
144 lines
No EOL
3.5 KiB
PHP
<?php
|
|
/* SVN FILE: $Id$ */
|
|
/**
|
|
* The DbconfigTask creates the database configuration 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
|
|
*/
|
|
class DbconfigTask extends BakeTask {
|
|
|
|
var $database;
|
|
var $user;
|
|
var $password = '';
|
|
var $configName = 'default';
|
|
var $databaseDriver = 'mysql';
|
|
var $persistent = 'false';
|
|
var $host = 'localhost';
|
|
var $port = '';
|
|
var $prefix = '';
|
|
|
|
function execute($params) {
|
|
|
|
$paramCount = count($params);
|
|
|
|
if ($paramCount >= 2) {
|
|
$this->database = array_shift($params);
|
|
$this->user = array_shift($params);
|
|
|
|
if ($paramCount > 2) {
|
|
$this->handleParams($params);
|
|
}
|
|
|
|
$this->createFile(CONFIGS.'database.php', $this->getFileContent());
|
|
|
|
} else {
|
|
$this->help();
|
|
}
|
|
}
|
|
|
|
function help() {
|
|
echo "The dbconfig task creates the database configuration file for you.\n";
|
|
echo "Usage: bake2 dbconfig [app-alias] database user [password] [-c=configName] [-d=databaseDriver] \n";
|
|
echo " [-persistent] [-h=hostname[:port]] [-p=prefix]\n";
|
|
}
|
|
|
|
function beginsWith($str, $sub) {
|
|
return (substr($str, 0, strlen($sub)) === $sub);
|
|
}
|
|
|
|
function createFile($path, $content) {
|
|
|
|
if ($f = fopen($path, 'w')) {
|
|
fwrite($f, $content);
|
|
fclose($f);
|
|
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
function getFileContent() {
|
|
$out = "<?php\n";
|
|
$out .= "class DATABASE_CONFIG {\n\n";
|
|
$out .= "\tvar \${$this->configName} = array(\n";
|
|
$out .= "\t\t'driver' => '{$this->databaseDriver}',\n";
|
|
$out .= "\t\t'host' => '{$this->host}',\n";
|
|
|
|
if ($this->port != '') {
|
|
$out .= "\t\t'port' => {$this->port}, \n";
|
|
}
|
|
|
|
$out .= "\t\t'login' => '{$this->user}',\n";
|
|
$out .= "\t\t'password' => '{$this->password}',\n";
|
|
$out .= "\t\t'database' => '{$this->database}', \n";
|
|
$out .= "\t\t'persistent' => {$this->persistent}, \n";
|
|
$out .= "\t\t'prefix' => '{$this->prefix}' \n";
|
|
$out .= "\t);\n";
|
|
$out .= "}\n";
|
|
$out .= "?>";
|
|
|
|
return $out;
|
|
}
|
|
|
|
function handleParams($params) {
|
|
if (!$this->beginsWith($params[0], '-')) {
|
|
$this->password = array_shift($params);
|
|
}
|
|
|
|
while (count($params) > 0) {
|
|
$param = array_shift($params);
|
|
$firstThreeChars = substr($param, 0, 3);
|
|
$paramValue = substr($param, 3);
|
|
|
|
switch ($firstThreeChars) {
|
|
case '-c=':
|
|
$this->configName = $paramValue;
|
|
break;
|
|
case '-d=':
|
|
$this->databaseDriver = $paramValue;
|
|
break;
|
|
case '-pe':
|
|
$this->persistent = 'true';
|
|
break;
|
|
case '-h=':
|
|
if (strpos($paramValue, ':') === false) {
|
|
$this->host = $paramValue;
|
|
} else {
|
|
$hostData = explode(':', $paramValue);
|
|
$this->host = $hostData[0];
|
|
$this->port = $hostData[1];
|
|
}
|
|
|
|
break;
|
|
case '-p=':
|
|
$this->prefix = $paramValue;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
?>
|