TaskRegistry.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 \Cake\Console\Shell
  29. */
  30. protected $_Shell;
  31. /**
  32. * Constructor
  33. *
  34. * @param \Cake\Console\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. * and Cake\Core\ObjectRegistry::unload()
  57. *
  58. * @param string $class The classname that is missing.
  59. * @param string $plugin The plugin the task is missing in.
  60. * @return void
  61. * @throws \Cake\Console\Exception\MissingTaskException
  62. */
  63. protected function _throwMissingClassError($class, $plugin)
  64. {
  65. throw new MissingTaskException([
  66. 'class' => $class,
  67. 'plugin' => $plugin
  68. ]);
  69. }
  70. /**
  71. * Create the task instance.
  72. *
  73. * Part of the template method for Cake\Core\ObjectRegistry::load()
  74. *
  75. * @param string $class The classname to create.
  76. * @param string $alias The alias of the task.
  77. * @param array $settings An array of settings to use for the task.
  78. * @return \Cake\Console\Shell The constructed task class.
  79. */
  80. protected function _create($class, $alias, $settings)
  81. {
  82. return new $class($this->_Shell->io());
  83. }
  84. }