BakeTask.php 2.0 KB

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