1: <?php
2: /**
3: * Base class for Bake Tasks.
4: *
5: * PHP 5
6: *
7: * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
8: * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
9: *
10: * Licensed under The MIT License
11: * For full copyright and license information, please see the LICENSE.txt
12: * Redistributions of files must retain the above copyright notice.
13: *
14: * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
15: * @link http://cakephp.org CakePHP(tm) Project
16: * @since CakePHP(tm) v 1.3
17: * @license http://www.opensource.org/licenses/mit-license.php MIT License
18: */
19:
20: App::uses('AppShell', 'Console/Command');
21:
22: /**
23: * Base class for Bake Tasks.
24: *
25: * @package Cake.Console.Command.Task
26: */
27: class BakeTask extends AppShell {
28:
29: /**
30: * Name of plugin
31: *
32: * @var string
33: */
34: public $plugin = null;
35:
36: /**
37: * The db connection being used for baking
38: *
39: * @var string
40: */
41: public $connection = null;
42:
43: /**
44: * Flag for interactive mode
45: *
46: * @var boolean
47: */
48: public $interactive = false;
49:
50: /**
51: * Disable caching and enable debug for baking.
52: * This forces the most current database schema to be used.
53: *
54: * @return void
55: */
56: public function startup() {
57: Configure::write('debug', 2);
58: Configure::write('Cache.disable', 1);
59: parent::startup();
60: }
61:
62: /**
63: * Gets the path for output. Checks the plugin property
64: * and returns the correct path.
65: *
66: * @return string Path to output.
67: */
68: public function getPath() {
69: $path = $this->path;
70: if (isset($this->plugin)) {
71: $path = $this->_pluginPath($this->plugin) . $this->name . DS;
72: }
73: return $path;
74: }
75:
76: /**
77: * Base execute method parses some parameters and sets some properties on the bake tasks.
78: * call when overriding execute()
79: *
80: * @return void
81: */
82: public function execute() {
83: foreach ($this->args as $i => $arg) {
84: if (strpos($arg, '.')) {
85: list($this->params['plugin'], $this->args[$i]) = pluginSplit($arg);
86: break;
87: }
88: }
89: if (isset($this->params['plugin'])) {
90: $this->plugin = $this->params['plugin'];
91: }
92: }
93:
94: }
95: