PluginAssetsCopyCommand.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  5. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  6. *
  7. * Licensed under The MIT License
  8. * For full copyright and license information, please see the LICENSE.txt
  9. * Redistributions of files must retain the above copyright notice.
  10. *
  11. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  12. * @link https://cakephp.org CakePHP(tm) Project
  13. * @since 3.0.0
  14. * @license https://opensource.org/licenses/mit-license.php MIT License
  15. */
  16. namespace Cake\Command;
  17. use Cake\Console\Arguments;
  18. use Cake\Console\ConsoleIo;
  19. use Cake\Console\ConsoleOptionParser;
  20. /**
  21. * Command for copying plugin assets to app's webroot.
  22. *
  23. * @psalm-suppress PropertyNotSetInConstructor
  24. */
  25. class PluginAssetsCopyCommand extends Command
  26. {
  27. use PluginAssetsTrait;
  28. /**
  29. * @inheritDoc
  30. */
  31. public static function defaultName(): string
  32. {
  33. return 'plugin assets copy';
  34. }
  35. /**
  36. * @inheritDoc
  37. */
  38. public static function getDescription(): string
  39. {
  40. return "Copy plugin assets to app's webroot.";
  41. }
  42. /**
  43. * Execute the command
  44. *
  45. * Copying plugin assets to app's webroot. For vendor namespaced plugin,
  46. * parent folder for vendor name are created if required.
  47. *
  48. * @param \Cake\Console\Arguments $args The command arguments.
  49. * @param \Cake\Console\ConsoleIo $io The console io
  50. * @return int|null The exit code or null for success
  51. */
  52. public function execute(Arguments $args, ConsoleIo $io): ?int
  53. {
  54. $this->io = $io;
  55. $this->args = $args;
  56. $name = $args->getArgument('name');
  57. $overwrite = (bool)$args->getOption('overwrite');
  58. $this->_process($this->_list($name), true, $overwrite);
  59. return static::CODE_SUCCESS;
  60. }
  61. /**
  62. * Get the option parser.
  63. *
  64. * @param \Cake\Console\ConsoleOptionParser $parser The option parser to update
  65. * @return \Cake\Console\ConsoleOptionParser
  66. */
  67. public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser
  68. {
  69. $parser->setDescription(
  70. static::getDescription()
  71. )->addArgument('name', [
  72. 'help' => 'A specific plugin you want to copy assets for.',
  73. 'required' => false,
  74. ])->addOption('overwrite', [
  75. 'help' => 'Overwrite existing symlink / folder / files.',
  76. 'default' => false,
  77. 'boolean' => true,
  78. ]);
  79. return $parser;
  80. }
  81. }