TaskRegistry.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  11. * @link http://cakephp.org CakePHP(tm) Project
  12. * @since 2.0.0
  13. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Console;
  16. use Cake\Console\Exception\MissingTaskException;
  17. use Cake\Core\App;
  18. use Cake\Core\ObjectRegistry;
  19. /**
  20. * Registry for Tasks. Provides features
  21. * for lazily loading tasks.
  22. */
  23. class TaskRegistry extends ObjectRegistry
  24. {
  25. /**
  26. * Shell to use to set params to tasks.
  27. *
  28. * @var Shell
  29. */
  30. protected $_Shell;
  31. /**
  32. * Constructor
  33. *
  34. * @param Shell $Shell Shell instance
  35. */
  36. public function __construct(Shell $Shell)
  37. {
  38. $this->_Shell = $Shell;
  39. }
  40. /**
  41. * Resolve a task classname.
  42. *
  43. * Part of the template method for Cake\Core\ObjectRegistry::load()
  44. *
  45. * @param string $class Partial classname to resolve.
  46. * @return string|false Either the correct classname or false.
  47. */
  48. protected function _resolveClassName($class)
  49. {
  50. return App::className($class, 'Shell/Task', 'Task');
  51. }
  52. /**
  53. * Throws an exception when a task is missing.
  54. *
  55. * Part of the template method for Cake\Core\ObjectRegistry::load()
  56. *
  57. * @param string $class The classname that is missing.
  58. * @param string $plugin The plugin the task is missing in.
  59. * @return void
  60. * @throws \Cake\Console\Exception\MissingTaskException
  61. */
  62. protected function _throwMissingClassError($class, $plugin)
  63. {
  64. throw new MissingTaskException([
  65. 'class' => $class,
  66. 'plugin' => $plugin
  67. ]);
  68. }
  69. /**
  70. * Create the task instance.
  71. *
  72. * Part of the template method for Cake\Core\ObjectRegistry::load()
  73. *
  74. * @param string $class The classname to create.
  75. * @param string $alias The alias of the task.
  76. * @param array $settings An array of settings to use for the task.
  77. * @return \Cake\Console\Shell The constructed task class.
  78. */
  79. protected function _create($class, $alias, $settings)
  80. {
  81. return new $class($this->_Shell->io());
  82. }
  83. }