BakeTask.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. App::uses('AppShell', 'Console/Command');
  20. /**
  21. * Base class for Bake Tasks.
  22. *
  23. * @package Cake.Console.Command.Task
  24. */
  25. class BakeTask extends AppShell {
  26. /**
  27. * Name of plugin
  28. *
  29. * @var string
  30. */
  31. public $plugin = null;
  32. /**
  33. * The db connection being used for baking
  34. *
  35. * @var string
  36. */
  37. public $connection = null;
  38. /**
  39. * Flag for interactive mode
  40. *
  41. * @var boolean
  42. */
  43. public $interactive = false;
  44. /**
  45. * Disable caching and enable debug for baking.
  46. * This forces the most current database schema to be used.
  47. *
  48. * @return void
  49. */
  50. public function startup() {
  51. Configure::write('debug', 2);
  52. Configure::write('Cache.disable', 1);
  53. parent::startup();
  54. }
  55. /**
  56. * Gets the path for output. Checks the plugin property
  57. * and returns the correct path.
  58. *
  59. * @return string Path to output.
  60. */
  61. public function getPath() {
  62. $path = $this->path;
  63. if (isset($this->plugin)) {
  64. $path = $this->_pluginPath($this->plugin) . $this->name . DS;
  65. }
  66. return $path;
  67. }
  68. /**
  69. * Base execute method parses some parameters and sets some properties on the bake tasks.
  70. * call when overriding execute()
  71. *
  72. * @return void
  73. */
  74. public function execute() {
  75. foreach ($this->args as $i => $arg) {
  76. if (strpos($arg, '.')) {
  77. list($this->params['plugin'], $this->args[$i]) = pluginSplit($arg);
  78. break;
  79. }
  80. }
  81. if (isset($this->params['plugin'])) {
  82. $this->plugin = $this->params['plugin'];
  83. }
  84. }
  85. }