PluginAssetsCopyCommand.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. * Execute the command
  37. *
  38. * Copying plugin assets to app's webroot. For vendor namespaced plugin,
  39. * parent folder for vendor name are created if required.
  40. *
  41. * @param \Cake\Console\Arguments $args The command arguments.
  42. * @param \Cake\Console\ConsoleIo $io The console io
  43. * @return int|null The exit code or null for success
  44. */
  45. public function execute(Arguments $args, ConsoleIo $io): ?int
  46. {
  47. $this->io = $io;
  48. $this->args = $args;
  49. $name = $args->getArgument('name');
  50. $overwrite = (bool)$args->getOption('overwrite');
  51. $this->_process($this->_list($name), true, $overwrite);
  52. return static::CODE_SUCCESS;
  53. }
  54. /**
  55. * Get the option parser.
  56. *
  57. * @param \Cake\Console\ConsoleOptionParser $parser The option parser to update
  58. * @return \Cake\Console\ConsoleOptionParser
  59. */
  60. public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser
  61. {
  62. $parser->setDescription([
  63. 'Copy plugin assets to app\'s webroot.',
  64. ])->addArgument('name', [
  65. 'help' => 'A specific plugin you want to copy assets for.',
  66. 'required' => false,
  67. ])->addOption('overwrite', [
  68. 'help' => 'Overwrite existing symlink / folder / files.',
  69. 'default' => false,
  70. 'boolean' => true,
  71. ]);
  72. return $parser;
  73. }
  74. }