- md5
- 9e82e30b840ddeee8761606ec23022a2
- sha1
- 99ee579a5fb644301ea5501985e0d798e69d86f4
- sha256
- b8a7268bdd0f36e3461c766a3d788865f7b5f9c0e6385bb9eb0105a7cab19e00
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
<?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Console;
use Joomla\CMS\Helper\PublicFolderGeneratorHelper;
use Joomla\Console\Command\AbstractCommand;
use Joomla\Filter\InputFilter;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Console command for creating a public folder
*
* @since 5.0.0
*/
class SiteCreatePublicFolderCommand extends AbstractCommand
{
/**
* The default command name
*
* @var string
* @since 5.0.0
*/
protected static $defaultName = 'site:create-public-folder';
/**
* SymfonyStyle Object
* @var object
* @since 5.0.0
*/
private $ioStyle;
/**
* Stores the Input Object
* @var object
* @since 5.0.0
*/
private $cliInput;
/**
* The public folder path (absolute)
*
* @var string
*
* @since 5.0.0
*/
private $publicFolder;
/**
* Internal function to execute the command.
*
* @param InputInterface $input The input to inject into the command.
* @param OutputInterface $output The output to inject into the command.
*
* @return integer The command exit code
*
* @since 5.0.0
*/
protected function doExecute(InputInterface $input, OutputInterface $output): int
{
$this->configureIO($input, $output);
$this->ioStyle->title('Create a public folder');
$this->publicFolder = $this->getStringFromOption('public-folder', 'Please enter the absolute path to the public folder', true);
// Remove the last (Windows || NIX) slash
$this->publicFolder = rtrim((new InputFilter())->clean($this->publicFolder, 'PATH'), '/');
$this->publicFolder = rtrim($this->publicFolder, '\\');
try {
(new PublicFolderGeneratorHelper())->createPublicFolder($this->publicFolder);
} catch (\Exception $e) {
return Command::FAILURE;
}
$this->ioStyle->success("Public folder created! \nAdjust your server configuration to serve from the public folder.");
return Command::SUCCESS;
}
/**
* Method to get a value from option
*
* @param string $option set the option name
* @param string $question set the question if user enters no value to option
* @param bool $required is it required
*
* @return string
*
* @since 5.0.0
*/
public function getStringFromOption($option, $question, $required = true): string
{
$answer = (string) $this->cliInput->getOption($option);
while (!$answer && $required) {
$answer = (string) $this->ioStyle->ask($question);
}
if (!$required) {
$answer = (string) $this->ioStyle->ask($question);
}
return $answer;
}
/**
* Configure the IO.
*
* @param InputInterface $input The input to inject into the command.
* @param OutputInterface $output The output to inject into the command.
*
* @return void
*
* @since 5.0.0
*/
private function configureIO(InputInterface $input, OutputInterface $output)
{
$this->cliInput = $input;
$this->ioStyle = new SymfonyStyle($input, $output);
}
/**
* Configure the command.
*
* @return void
*
* @since 5.0.0
*/
protected function configure(): void
{
$help = "<info>%command.name%</info> will create a public folder
\nUsage: <info>php %command.full_name%</info>";
$this->addOption('public-folder', null, InputOption::VALUE_REQUIRED, 'public folder absolute path');
$this->setDescription('Create a public folder');
$this->setHelp($help);
}
}
The same content is in 17 releases, Joomla 5.0.0-beta2 to 5.1.0-alpha4. See them all, or every version of this file.