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 Project Task handles creating the base application
  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.scripts.bake
 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 new project apps and plugins
 31:  *
 32:  * @package       cake
 33:  * @subpackage    cake.cake.console.libs.tasks
 34:  */
 35: class ProjectTask extends Shell {
 36: /**
 37:  * Checks that given project path does not already exist, and
 38:  * finds the app directory in it. Then it calls bake() with that information.
 39:  *
 40:  * @param string $project Project path
 41:  * @access public
 42:  */
 43:     function execute($project = null) {
 44:         if ($project === null) {
 45:             if (isset($this->args[0])) {
 46:                 $project = $this->args[0];
 47:                 $this->Dispatch->shiftArgs();
 48:             }
 49:         }
 50: 
 51:         if ($project) {
 52:             $this->Dispatch->parseParams(array('-app', $project));
 53:             $project = $this->params['working'];
 54:         }
 55: 
 56:         if (empty($this->params['skel'])) {
 57:             $this->params['skel'] = '';
 58:             if (is_dir(CAKE_CORE_INCLUDE_PATH.DS.'cake'.DS.'console'.DS.'libs'.DS.'templates'.DS.'skel') === true) {
 59:                 $this->params['skel'] = CAKE_CORE_INCLUDE_PATH.DS.'cake'.DS.'console'.DS.'libs'.DS.'templates'.DS.'skel';
 60:             }
 61:         }
 62: 
 63:         while (!$project) {
 64:             $project = $this->in("What is the full path for this app including the app directory name?\nExample: ".$this->params['working'] . DS . "myapp", null, $this->params['working'] . DS . 'myapp');
 65:         }
 66: 
 67:         if ($project) {
 68:             $response = false;
 69:             while ($response == false && is_dir($project) === true && file_exists($project . 'config' . 'core.php')) {
 70:                 $response = $this->in('A project already exists in this location: '.$project.' Overwrite?', array('y','n'), 'n');
 71:                 if (strtolower($response) === 'n') {
 72:                     $response = $project = false;
 73:                 }
 74:             }
 75:         }
 76: 
 77:         if ($this->bake($project)) {
 78:             $path = Folder::slashTerm($project);
 79:             if ($this->createHome($path)) {
 80:                 $this->out(__('Welcome page created', true));
 81:             } else {
 82:                 $this->out(__('The Welcome page was NOT created', true));
 83:             }
 84: 
 85:             if ($this->securitySalt($path) === true ) {
 86:                 $this->out(__('Random hash key created for \'Security.salt\'', true));
 87:             } else {
 88:                 $this->err(sprintf(__('Unable to generate random hash for \'Security.salt\', you should change it in %s', true), CONFIGS . 'core.php'));
 89:             }
 90: 
 91:             $corePath = $this->corePath($path);
 92:             if ($corePath === true ) {
 93:                 $this->out(sprintf(__('CAKE_CORE_INCLUDE_PATH set to %s in webroot/index.php', true), CAKE_CORE_INCLUDE_PATH));
 94:                 $this->out(sprintf(__('CAKE_CORE_INCLUDE_PATH set to %s in webroot/test.php', true), CAKE_CORE_INCLUDE_PATH));
 95:                 $this->out(__('Remember to check these value after moving to production server', true));
 96:             } elseif ($corePath === false) {
 97:                 $this->err(sprintf(__('Unable to set CAKE_CORE_INCLUDE_PATH, you should change it in %s', true), $path . 'webroot' .DS .'index.php'));
 98:             }
 99:             $Folder = new Folder($path);
100:             if (!$Folder->chmod($path . 'tmp', 0777)) {
101:                 $this->err(sprintf(__('Could not set permissions on %s', true), $path . DS .'tmp'));
102:                 $this->out(sprintf(__('chmod -R 0777 %s', true), $path . DS .'tmp'));
103:             }
104: 
105:             $this->params['working'] = $path;
106:             $this->params['app'] = basename($path);
107:             return true;
108:         }
109:     }
110: /**
111:  * Looks for a skeleton template of a Cake application,
112:  * and if not found asks the user for a path. When there is a path
113:  * this method will make a deep copy of the skeleton to the project directory.
114:  * A default home page will be added, and the tmp file storage will be chmod'ed to 0777.
115:  *
116:  * @param string $path Project path
117:  * @param string $skel Path to copy from
118:  * @param string $skip array of directories to skip when copying
119:  * @access private
120:  */
121:     function bake($path, $skel = null, $skip = array('empty')) {
122:         if (!$skel) {
123:             $skel = $this->params['skel'];
124:         }
125: 
126:         while (!$skel) {
127:             $skel = $this->in(sprintf(__("What is the path to the directory layout you wish to copy?\nExample: %s"), APP, null, ROOT . DS . 'myapp' . DS));
128:             if ($skel == '') {
129:                 $this->out(__('The directory path you supplied was empty. Please try again.', true));
130:             } else {
131:                 while (is_dir($skel) === false) {
132:                     $skel = $this->in(__('Directory path does not exist please choose another:', true));
133:                 }
134:             }
135:         }
136: 
137:         $app = basename($path);
138: 
139:         $this->out('Bake Project');
140:         $this->out("Skel Directory: $skel");
141:         $this->out("Will be copied to: {$path}");
142:         $this->hr();
143: 
144:         $looksGood = $this->in('Look okay?', array('y', 'n', 'q'), 'y');
145: 
146:         if (strtolower($looksGood) == 'y' || strtolower($looksGood) == 'yes') {
147:             $verbose = $this->in(__('Do you want verbose output?', true), array('y', 'n'), 'n');
148: 
149:             $Folder = new Folder($skel);
150:             if ($Folder->copy(array('to' => $path, 'skip' => $skip))) {
151:                 $this->hr();
152:                 $this->out(sprintf(__("Created: %s in %s", true), $app, $path));
153:                 $this->hr();
154:             } else {
155:                 $this->err(" '" . $app . "' could not be created properly");
156:                 return false;
157:             }
158: 
159:             if (strtolower($verbose) == 'y' || strtolower($verbose) == 'yes') {
160:                 foreach ($Folder->messages() as $message) {
161:                     $this->out($message);
162:                 }
163:             }
164: 
165:             return true;
166:         } elseif (strtolower($looksGood) == 'q' || strtolower($looksGood) == 'quit') {
167:             $this->out('Bake Aborted.');
168:         } else {
169:             $this->execute(false);
170:             return false;
171:         }
172:     }
173: /**
174:  * Writes a file with a default home page to the project.
175:  *
176:  * @param string $dir Path to project
177:  * @return boolean Success
178:  * @access public
179:  */
180:     function createHome($dir) {
181:         $app = basename($dir);
182:         $path = $dir . 'views' . DS . 'pages' . DS;
183:         include(CAKE_CORE_INCLUDE_PATH.DS.'cake'.DS.'console'.DS.'libs'.DS.'templates'.DS.'views'.DS.'home.ctp');
184:         return $this->createFile($path.'home.ctp', $output);
185:     }
186: /**
187:  * Generates and writes 'Security.salt'
188:  *
189:  * @param string $path Project path
190:  * @return boolean Success
191:  * @access public
192:  */
193:     function securitySalt($path) {
194:         $File =& new File($path . 'config' . DS . 'core.php');
195:         $contents = $File->read();
196:         if (preg_match('/([\\t\\x20]*Configure::write\\(\\\'Security.salt\\\',[\\t\\x20\'A-z0-9]*\\);)/', $contents, $match)) {
197:             if (!class_exists('Security')) {
198:                 uses('Security');
199:             }
200:             $string = Security::generateAuthKey();
201:             $result = str_replace($match[0], "\t" . 'Configure::write(\'Security.salt\', \''.$string.'\');', $contents);
202:             if ($File->write($result)) {
203:                 return true;
204:             }
205:             return false;
206:         }
207:         return false;
208:     }
209: /**
210:  * Generates and writes CAKE_CORE_INCLUDE_PATH
211:  *
212:  * @param string $path Project path
213:  * @return boolean Success
214:  * @access public
215:  */
216:     function corePath($path) {
217:         if (dirname($path) !== CAKE_CORE_INCLUDE_PATH) {
218:             $File =& new File($path . 'webroot' . DS . 'index.php');
219:             $contents = $File->read();
220:             if (preg_match('/([\\t\\x20]*define\\(\\\'CAKE_CORE_INCLUDE_PATH\\\',[\\t\\x20\'A-z0-9]*\\);)/', $contents, $match)) {
221:                 $result = str_replace($match[0], "\t\tdefine('CAKE_CORE_INCLUDE_PATH', '" . CAKE_CORE_INCLUDE_PATH . "');", $contents);
222:                 if (!$File->write($result)) {
223:                     return false;
224:                 }
225:             } else {
226:                 return false;
227:             }
228: 
229:             $File =& new File($path . 'webroot' . DS . 'test.php');
230:             $contents = $File->read();
231:             if (preg_match('/([\\t\\x20]*define\\(\\\'CAKE_CORE_INCLUDE_PATH\\\',[\\t\\x20\'A-z0-9]*\\);)/', $contents, $match)) {
232:                 $result = str_replace($match[0], "\t\tdefine('CAKE_CORE_INCLUDE_PATH', '" . CAKE_CORE_INCLUDE_PATH . "');", $contents);
233:                 if (!$File->write($result)) {
234:                     return false;
235:                 }
236:             } else {
237:                 return false;
238:             }
239:             return true;
240:         }
241:     }
242: /**
243:  * Enables Configure::read('Routing.admin') in /app/config/core.php
244:  *
245:  * @param string $name Name to use as admin routing
246:  * @return boolean Success
247:  * @access public
248:  */
249:     function cakeAdmin($name) {
250:         $File =& new File(CONFIGS . 'core.php');
251:         $contents = $File->read();
252:         if (preg_match('%([/\\t\\x20]*Configure::write\(\'Routing.admin\',[\\t\\x20\'a-z]*\\);)%', $contents, $match)) {
253:             $result = str_replace($match[0], "\t" . 'Configure::write(\'Routing.admin\', \''.$name.'\');', $contents);
254:             if ($File->write($result)) {
255:                 Configure::write('Routing.admin', $name);
256:                 return true;
257:             } else {
258:                 return false;
259:             }
260:         } else {
261:             return false;
262:         }
263:     }
264: /**
265:  * Help
266:  *
267:  * @return void
268:  * @access public
269:  */
270:     function help() {
271:         $this->hr();
272:         $this->out("Usage: cake bake project <arg1>");
273:         $this->hr();
274:         $this->out('Commands:');
275:         $this->out("\n\tproject <name>\n\t\tbakes app directory structure.\n\t\tif <name> begins with '/' path is absolute.");
276:         $this->out("");
277:         $this->_stop();
278:     }
279: 
280: }
281: ?>
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