CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (GitHub)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • Slack
    • Paid Support
CakePHP

C CakePHP 1.2 API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 1.2
      • 4.2
      • 4.1
      • 4.0
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Classes

  • AclBase
  • AclBehavior
  • AclComponent
  • AclNode
  • AclShell
  • Aco
  • AcoAction
  • AjaxHelper
  • ApcEngine
  • ApiShell
  • App
  • AppController
  • AppHelper
  • AppModel
  • Aro
  • AuthComponent
  • BakeShell
  • BehaviorCollection
  • Cache
  • CacheEngine
  • CacheHelper
  • CakeErrorController
  • CakeLog
  • CakeSchema
  • CakeSession
  • CakeSocket
  • ClassRegistry
  • Component
  • Configure
  • ConnectionManager
  • ConsoleShell
  • ContainableBehavior
  • Controller
  • ControllerTask
  • CookieComponent
  • DataSource
  • DbAcl
  • DbAclSchema
  • DbConfigTask
  • DboAdodb
  • DboDb2
  • DboFirebird
  • DboMssql
  • DboMysql
  • DboMysqlBase
  • DboMysqli
  • DboOdbc
  • DboOracle
  • DboPostgres
  • DboSource
  • DboSqlite
  • DboSybase
  • Debugger
  • EmailComponent
  • ErrorHandler
  • ExtractTask
  • File
  • FileEngine
  • Flay
  • Folder
  • FormHelper
  • Helper
  • HtmlHelper
  • HttpSocket
  • I18n
  • I18nModel
  • i18nSchema
  • I18nShell
  • Inflector
  • IniAcl
  • JavascriptHelper
  • JsHelper
  • JsHelperObject
  • L10n
  • MagicDb
  • MagicFileResource
  • MediaView
  • MemcacheEngine
  • Model
  • ModelBehavior
  • ModelTask
  • Multibyte
  • NumberHelper
  • Object
  • Overloadable
  • Overloadable2
  • PagesController
  • PaginatorHelper
  • Permission
  • PluginTask
  • ProjectTask
  • RequestHandlerComponent
  • Router
  • RssHelper
  • Sanitize
  • Scaffold
  • ScaffoldView
  • SchemaShell
  • Security
  • SecurityComponent
  • SessionComponent
  • SessionHelper
  • SessionsSchema
  • Set
  • Shell
  • String
  • TestSuiteShell
  • TestTask
  • TextHelper
  • ThemeView
  • TimeHelper
  • TranslateBehavior
  • TreeBehavior
  • Validation
  • View
  • ViewTask
  • XcacheEngine
  • Xml
  • XmlElement
  • XmlHelper
  • XmlManager
  • XmlNode
  • XmlTextNode

Functions

  • __enclose
  • make_clean_css
  • mb_encode_mimeheader
  • mb_stripos
  • mb_stristr
  • mb_strlen
  • mb_strpos
  • mb_strrchr
  • mb_strrichr
  • mb_strripos
  • mb_strrpos
  • mb_strstr
  • mb_strtolower
  • mb_strtoupper
  • mb_substr
  • mb_substr_count
  • write_css_cache
  1: <?php
  2: /* SVN FILE: $Id$ */
  3: /**
  4:  * The DbConfig Task handles creating and updating the database.php
  5:  *
  6:  * Long description for file
  7:  *
  8:  * PHP versions 4 and 5
  9:  *
 10:  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 11:  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 12:  *
 13:  * Licensed under The MIT License
 14:  * Redistributions of files must retain the above copyright notice.
 15:  *
 16:  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 17:  * @link          http://cakephp.org CakePHP(tm) Project
 18:  * @package       cake
 19:  * @subpackage    cake.cake.console.libs.tasks
 20:  * @since         CakePHP(tm) v 1.2
 21:  * @version       $Revision$
 22:  * @modifiedby    $LastChangedBy$
 23:  * @lastmodified  $Date$
 24:  * @license       http://www.opensource.org/licenses/mit-license.php The MIT License
 25:  */
 26: if (!class_exists('File')) {
 27:     uses('file');
 28: }
 29: /**
 30:  * Task class for creating and updating the database configuration file.
 31:  *
 32:  * @package       cake
 33:  * @subpackage    cake.cake.console.libs.tasks
 34:  */
 35: class DbConfigTask extends Shell {
 36: /**
 37:  * path to CONFIG directory
 38:  *
 39:  * @var string
 40:  * @access public
 41:  */
 42:     var $path = null;
 43: /**
 44:  * Default configuration settings to use
 45:  *
 46:  * @var array
 47:  * @access private
 48:  */
 49:     var $__defaultConfig = array(
 50:         'name' => 'default', 'driver'=> 'mysql', 'persistent'=> 'false', 'host'=> 'localhost',
 51:         'login'=> 'root', 'password'=> 'password', 'database'=> 'project_name',
 52:         'schema'=> null, 'prefix'=> null, 'encoding' => null, 'port' => null
 53:     );
 54: /**
 55:  * initialization callback
 56:  *
 57:  * @var string
 58:  * @access public
 59:  */
 60:     function initialize() {
 61:         $this->path = $this->params['working'] . DS . 'config' . DS;
 62:     }
 63: /**
 64:  * Execution method always used for tasks
 65:  *
 66:  * @access public
 67:  */
 68:     function execute() {
 69:         if (empty($this->args)) {
 70:             $this->__interactive();
 71:             $this->_stop();
 72:         }
 73:     }
 74: /**
 75:  * Interactive interface
 76:  *
 77:  * @access private
 78:  */
 79:     function __interactive() {
 80:         $this->hr();
 81:         $this->out('Database Configuration:');
 82:         $this->hr();
 83:         $done = false;
 84:         $dbConfigs = array();
 85: 
 86:         while ($done == false) {
 87:             $name = '';
 88: 
 89:             while ($name == '') {
 90:                 $name = $this->in("Name:", null, 'default');
 91:                 if (preg_match('/[^a-z0-9_]/i', $name)) {
 92:                     $name = '';
 93:                     $this->out('The name may only contain unaccented latin characters, numbers or underscores');
 94:                 }
 95:                 else if (preg_match('/^[^a-z_]/i', $name)) {
 96:                     $name = '';
 97:                     $this->out('The name must start with an unaccented latin character or an underscore');
 98:                 }
 99:             }
100:             $driver = '';
101: 
102:             while ($driver == '') {
103:                 $driver = $this->in('Driver:', array('db2', 'firebird', 'mssql', 'mysql', 'mysqli', 'odbc', 'oracle', 'postgres', 'sqlite', 'sybase'), 'mysql');
104:             }
105:             $persistent = '';
106: 
107:             while ($persistent == '') {
108:                 $persistent = $this->in('Persistent Connection?', array('y', 'n'), 'n');
109:             }
110: 
111:             if (strtolower($persistent) == 'n') {
112:                 $persistent = 'false';
113:             } else {
114:                 $persistent = 'true';
115:             }
116:             $host = '';
117: 
118:             while ($host == '') {
119:                 $host = $this->in('Database Host:', null, 'localhost');
120:             }
121:             $port = '';
122: 
123:             while ($port == '') {
124:                 $port = $this->in('Port?', null, 'n');
125:             }
126: 
127:             if (strtolower($port) == 'n') {
128:                 $port = null;
129:             }
130:             $login = '';
131: 
132:             while ($login == '') {
133:                 $login = $this->in('User:', null, 'root');
134:             }
135:             $password = '';
136:             $blankPassword = false;
137: 
138:             while ($password == '' && $blankPassword == false) {
139:                 $password = $this->in('Password:');
140: 
141:                 if ($password == '') {
142:                     $blank = $this->in('The password you supplied was empty. Use an empty password?', array('y', 'n'), 'n');
143:                     if ($blank == 'y')
144:                     {
145:                         $blankPassword = true;
146:                     }
147:                 }
148:             }
149:             $database = '';
150: 
151:             while ($database == '') {
152:                 $database = $this->in('Database Name:', null, 'cake');
153:             }
154:             $prefix = '';
155: 
156:             while ($prefix == '') {
157:                 $prefix = $this->in('Table Prefix?', null, 'n');
158:             }
159: 
160:             if (strtolower($prefix) == 'n') {
161:                 $prefix = null;
162:             }
163:             $encoding = '';
164: 
165:             while ($encoding == '') {
166:                 $encoding = $this->in('Table encoding?', null, 'n');
167:             }
168: 
169:             if (strtolower($encoding) == 'n') {
170:                 $encoding = null;
171:             }
172:             $schema = '';
173: 
174:             if ($driver == 'postgres') {
175:                 while ($schema == '') {
176:                     $schema = $this->in('Table schema?', null, 'n');
177:                 }
178:             }
179: 
180:             if (strtolower($schema) == 'n') {
181:                 $schema = null;
182:             }
183: 
184:             $config = compact('name', 'driver', 'persistent', 'host', 'login', 'password', 'database', 'prefix', 'encoding', 'port', 'schema');
185: 
186:             while ($this->__verify($config) == false) {
187:                 $this->__interactive();
188:             }
189:             $dbConfigs[] = $config;
190:             $doneYet = $this->in('Do you wish to add another database configuration?', null, 'n');
191: 
192:             if (strtolower($doneYet == 'n')) {
193:                 $done = true;
194:             }
195:         }
196: 
197:         $this->bake($dbConfigs);
198:         config('database');
199:         return true;
200:     }
201: /**
202:  * Output verification message and bake if it looks good
203:  *
204:  * @return boolean True if user says it looks good, false otherwise
205:  * @access private
206:  */
207:     function __verify($config) {
208:         $config = array_merge($this->__defaultConfig, $config);
209:         extract($config);
210:         $this->out('');
211:         $this->hr();
212:         $this->out('The following database configuration will be created:');
213:         $this->hr();
214:         $this->out("Name:         $name");
215:         $this->out("Driver:       $driver");
216:         $this->out("Persistent:   $persistent");
217:         $this->out("Host:         $host");
218: 
219:         if ($port) {
220:             $this->out("Port:         $port");
221:         }
222: 
223:         $this->out("User:         $login");
224:         $this->out("Pass:         " . str_repeat('*', strlen($password)));
225:         $this->out("Database:     $database");
226: 
227:         if ($prefix) {
228:             $this->out("Table prefix: $prefix");
229:         }
230: 
231:         if ($schema) {
232:             $this->out("Schema:       $schema");
233:         }
234: 
235:         if ($encoding) {
236:             $this->out("Encoding:     $encoding");
237:         }
238: 
239:         $this->hr();
240:         $looksGood = $this->in('Look okay?', array('y', 'n'), 'y');
241: 
242:         if (strtolower($looksGood) == 'y' || strtolower($looksGood) == 'yes') {
243:             return $config;
244:         }
245:         return false;
246:     }
247: /**
248:  * Assembles and writes database.php
249:  *
250:  * @param array $configs Configuration settings to use
251:  * @return boolean Success
252:  * @access public
253:  */
254:     function bake($configs) {
255:         if (!is_dir($this->path)) {
256:             $this->err($this->path . ' not found');
257:             return false;
258:         }
259: 
260:         $filename = $this->path . 'database.php';
261:         $oldConfigs = array();
262: 
263:         if (file_exists($filename)) {
264:             $db = new DATABASE_CONFIG;
265:             $temp = get_class_vars(get_class($db));
266: 
267:             foreach ($temp as $configName => $info) {
268:                 $info = array_merge($this->__defaultConfig, $info);
269: 
270:                 if (!isset($info['schema'])) {
271:                     $info['schema'] = null;
272:                 }
273:                 if (!isset($info['encoding'])) {
274:                     $info['encoding'] = null;
275:                 }
276:                 if (!isset($info['port'])) {
277:                     $info['port'] = null;
278:                 }
279: 
280:                 if ($info['persistent'] === false) {
281:                     $info['persistent'] = 'false';
282:                 } else {
283:                     $info['persistent'] = ($info['persistent'] == true) ? 'true' : 'false';
284:                 }
285: 
286:                 $oldConfigs[] = array(
287:                     'name' => $configName,
288:                     'driver' => $info['driver'],
289:                     'persistent' => $info['persistent'],
290:                     'host' => $info['host'],
291:                     'port' => $info['port'],
292:                     'login' => $info['login'],
293:                     'password' => $info['password'],
294:                     'database' => $info['database'],
295:                     'prefix' => $info['prefix'],
296:                     'schema' => $info['schema'],
297:                     'encoding' => $info['encoding']
298:                 );
299:             }
300:         }
301: 
302:         foreach ($oldConfigs as $key => $oldConfig) {
303:             foreach ($configs as $key1 => $config) {
304:                 if ($oldConfig['name'] == $config['name']) {
305:                     unset($oldConfigs[$key]);
306:                 }
307:             }
308:         }
309: 
310:         $configs = array_merge($oldConfigs, $configs);
311:         $out = "<?php\n";
312:         $out .= "class DATABASE_CONFIG {\n\n";
313: 
314:         foreach ($configs as $config) {
315:             $config = array_merge($this->__defaultConfig, $config);
316:             extract($config);
317: 
318:             $out .= "\tvar \${$name} = array(\n";
319:             $out .= "\t\t'driver' => '{$driver}',\n";
320:             $out .= "\t\t'persistent' => {$persistent},\n";
321:             $out .= "\t\t'host' => '{$host}',\n";
322: 
323:             if ($port) {
324:                 $out .= "\t\t'port' => {$port},\n";
325:             }
326: 
327:             $out .= "\t\t'login' => '{$login}',\n";
328:             $out .= "\t\t'password' => '{$password}',\n";
329:             $out .= "\t\t'database' => '{$database}',\n";
330: 
331:             if ($schema) {
332:                 $out .= "\t\t'schema' => '{$schema}',\n";
333:             }
334: 
335:             if ($prefix) {
336:                 $out .= "\t\t'prefix' => '{$prefix}',\n";
337:             }
338: 
339:             if ($encoding) {
340:                 $out .= "\t\t'encoding' => '{$encoding}'\n";
341:             }
342: 
343:             $out .= "\t);\n";
344:         }
345: 
346:         $out .= "}\n";
347:         $out .= "?>";
348:         $filename = $this->path.'database.php';
349:         return $this->createFile($filename, $out);
350:     }
351: }
352: ?>
OpenHub
Rackspace
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (GitHub)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • Slack
  • Paid Support

Generated using CakePHP API Docs