BakeTask.php 1.9 KB

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