BakeTask.php 2.0 KB

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