- md5
- f062278e28e1c4946b9fbd45611654c3
- sha1
- 3d77940cf1f76bf9dafeb9c79fb1a2b4d764cf43
- sha256
- ba507b572b718a1f07971de476d62f9294616555cf42c2f9b7e452b607ef6a8c
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
<?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, '\\');
// Check if the symlink function is available
if (!\function_exists('symlink')) {
$this->ioStyle->error('symlink() function is not enabled on the server. Please enable it to proceed.');
return Command::FAILURE;
}
try {
(new PublicFolderGeneratorHelper())->createPublicFolder($this->publicFolder);
} catch (\Exception) {
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 93 releases, Joomla 5.3.0-beta2 to 6.2.1-rc1. See them all, or every version of this file.