mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 18:48:51 +02:00
migration symfony 5 4 (#300)
* symfony 5.4 (diff dev) * symfony 5.4 (working) * symfony 5.4 (update autoload) * symfony 5.4 (remove swiftmailer mailer implementation) * symfony 5.4 (php doc and split Global accessor class) ### Impacted packages: composer require php:">=7.2.5 <8.0.0" symfony/console:5.4.* symfony/dotenv:5.4.* symfony/framework-bundle:5.4.* symfony/twig-bundle:5.4.* symfony/yaml:5.4.* --update-with-dependencies composer require symfony/stopwatch:5.4.* symfony/web-profiler-bundle:5.4.* --dev --update-with-dependencies
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Bundle\FrameworkBundle\Command;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
@@ -22,6 +23,7 @@ use Symfony\Component\Filesystem\Exception\IOException;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
|
||||
/**
|
||||
* Command that places bundle web assets into a given directory.
|
||||
@@ -29,34 +31,26 @@ use Symfony\Component\HttpKernel\Bundle\BundleInterface;
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Gábor Egyed <gabor.egyed@gmail.com>
|
||||
*
|
||||
* @final since version 3.4
|
||||
* @final
|
||||
*/
|
||||
class AssetsInstallCommand extends ContainerAwareCommand
|
||||
class AssetsInstallCommand extends Command
|
||||
{
|
||||
const METHOD_COPY = 'copy';
|
||||
const METHOD_ABSOLUTE_SYMLINK = 'absolute symlink';
|
||||
const METHOD_RELATIVE_SYMLINK = 'relative symlink';
|
||||
public const METHOD_COPY = 'copy';
|
||||
public const METHOD_ABSOLUTE_SYMLINK = 'absolute symlink';
|
||||
public const METHOD_RELATIVE_SYMLINK = 'relative symlink';
|
||||
|
||||
protected static $defaultName = 'assets:install';
|
||||
protected static $defaultDescription = 'Install bundle\'s web assets under a public directory';
|
||||
|
||||
private $filesystem;
|
||||
private $projectDir;
|
||||
|
||||
/**
|
||||
* @param Filesystem $filesystem
|
||||
*/
|
||||
public function __construct($filesystem = null)
|
||||
public function __construct(Filesystem $filesystem, string $projectDir)
|
||||
{
|
||||
if (!$filesystem instanceof Filesystem) {
|
||||
@trigger_error(sprintf('%s() expects an instance of "%s" as first argument since Symfony 3.4. Not passing it is deprecated and will throw a TypeError in 4.0.', __METHOD__, Filesystem::class), \E_USER_DEPRECATED);
|
||||
|
||||
parent::__construct($filesystem);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->filesystem = $filesystem;
|
||||
$this->projectDir = $projectDir;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -68,9 +62,10 @@ class AssetsInstallCommand extends ContainerAwareCommand
|
||||
->setDefinition([
|
||||
new InputArgument('target', InputArgument::OPTIONAL, 'The target directory', null),
|
||||
])
|
||||
->addOption('symlink', null, InputOption::VALUE_NONE, 'Symlinks the assets instead of copying it')
|
||||
->addOption('symlink', null, InputOption::VALUE_NONE, 'Symlink the assets instead of copying them')
|
||||
->addOption('relative', null, InputOption::VALUE_NONE, 'Make relative symlinks')
|
||||
->setDescription('Installs bundles web assets under a public directory')
|
||||
->addOption('no-cleanup', null, InputOption::VALUE_NONE, 'Do not remove the assets of the bundles that no longer exist')
|
||||
->setDescription(self::$defaultDescription)
|
||||
->setHelp(<<<'EOT'
|
||||
The <info>%command.name%</info> command installs bundle assets into a given
|
||||
directory (e.g. the <comment>public</comment> directory).
|
||||
@@ -97,32 +92,20 @@ EOT
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
// BC to be removed in 4.0
|
||||
if (null === $this->filesystem) {
|
||||
$this->filesystem = $this->getContainer()->get('filesystem');
|
||||
$baseDir = $this->getContainer()->getParameter('kernel.project_dir');
|
||||
}
|
||||
|
||||
/** @var KernelInterface $kernel */
|
||||
$kernel = $this->getApplication()->getKernel();
|
||||
$targetArg = rtrim($input->getArgument('target'), '/');
|
||||
|
||||
$targetArg = rtrim($input->getArgument('target') ?? '', '/');
|
||||
if (!$targetArg) {
|
||||
$targetArg = $this->getPublicDirectory($this->getContainer());
|
||||
$targetArg = $this->getPublicDirectory($kernel->getContainer());
|
||||
}
|
||||
|
||||
if (!is_dir($targetArg)) {
|
||||
$targetArg = (isset($baseDir) ? $baseDir : $kernel->getContainer()->getParameter('kernel.project_dir')).'/'.$targetArg;
|
||||
$targetArg = $kernel->getProjectDir().'/'.$targetArg;
|
||||
|
||||
if (!is_dir($targetArg)) {
|
||||
// deprecated, logic to be removed in 4.0
|
||||
// this allows the commands to work out of the box with web/ and public/
|
||||
if (is_dir(\dirname($targetArg).'/web')) {
|
||||
$targetArg = \dirname($targetArg).'/web';
|
||||
} else {
|
||||
throw new InvalidArgumentException(sprintf('The target directory "%s" does not exist.', $targetArg));
|
||||
}
|
||||
throw new InvalidArgumentException(sprintf('The target directory "%s" does not exist.', $targetArg));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,7 +133,7 @@ EOT
|
||||
$validAssetDirs = [];
|
||||
/** @var BundleInterface $bundle */
|
||||
foreach ($kernel->getBundles() as $bundle) {
|
||||
if (!is_dir($originDir = $bundle->getPath().'/Resources/public')) {
|
||||
if (!is_dir($originDir = $bundle->getPath().'/Resources/public') && !is_dir($originDir = $bundle->getPath().'/public')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -190,7 +173,7 @@ EOT
|
||||
}
|
||||
}
|
||||
// remove the assets of the bundles that no longer exist
|
||||
if (is_dir($bundlesDir)) {
|
||||
if (!$input->getOption('no-cleanup') && is_dir($bundlesDir)) {
|
||||
$dirsToRemove = Finder::create()->depth(0)->directories()->exclude($validAssetDirs)->in($bundlesDir);
|
||||
$this->filesystem->remove($dirsToRemove);
|
||||
}
|
||||
@@ -215,13 +198,8 @@ EOT
|
||||
* Try to create relative symlink.
|
||||
*
|
||||
* Falling back to absolute symlink and finally hard copy.
|
||||
*
|
||||
* @param string $originDir
|
||||
* @param string $targetDir
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function relativeSymlinkWithFallback($originDir, $targetDir)
|
||||
private function relativeSymlinkWithFallback(string $originDir, string $targetDir): string
|
||||
{
|
||||
try {
|
||||
$this->symlink($originDir, $targetDir, true);
|
||||
@@ -237,13 +215,8 @@ EOT
|
||||
* Try to create absolute symlink.
|
||||
*
|
||||
* Falling back to hard copy.
|
||||
*
|
||||
* @param string $originDir
|
||||
* @param string $targetDir
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function absoluteSymlinkWithFallback($originDir, $targetDir)
|
||||
private function absoluteSymlinkWithFallback(string $originDir, string $targetDir): string
|
||||
{
|
||||
try {
|
||||
$this->symlink($originDir, $targetDir);
|
||||
@@ -259,13 +232,9 @@ EOT
|
||||
/**
|
||||
* Creates symbolic link.
|
||||
*
|
||||
* @param string $originDir
|
||||
* @param string $targetDir
|
||||
* @param bool $relative
|
||||
*
|
||||
* @throws IOException if link can not be created
|
||||
* @throws IOException if link cannot be created
|
||||
*/
|
||||
private function symlink($originDir, $targetDir, $relative = false)
|
||||
private function symlink(string $originDir, string $targetDir, bool $relative = false)
|
||||
{
|
||||
if ($relative) {
|
||||
$this->filesystem->mkdir(\dirname($targetDir));
|
||||
@@ -279,13 +248,8 @@ EOT
|
||||
|
||||
/**
|
||||
* Copies origin to target.
|
||||
*
|
||||
* @param string $originDir
|
||||
* @param string $targetDir
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function hardCopy($originDir, $targetDir)
|
||||
private function hardCopy(string $originDir, string $targetDir): string
|
||||
{
|
||||
$this->filesystem->mkdir($targetDir, 0777);
|
||||
// We use a custom iterator to ignore VCS files
|
||||
@@ -294,15 +258,15 @@ EOT
|
||||
return self::METHOD_COPY;
|
||||
}
|
||||
|
||||
private function getPublicDirectory(ContainerInterface $container)
|
||||
private function getPublicDirectory(ContainerInterface $container): string
|
||||
{
|
||||
$defaultPublicDir = 'public';
|
||||
|
||||
if (!$container->hasParameter('kernel.project_dir')) {
|
||||
if (null === $this->projectDir && !$container->hasParameter('kernel.project_dir')) {
|
||||
return $defaultPublicDir;
|
||||
}
|
||||
|
||||
$composerFilePath = $container->getParameter('kernel.project_dir').'/composer.json';
|
||||
$composerFilePath = ($this->projectDir ?? $container->getParameter('kernel.project_dir')).'/composer.json';
|
||||
|
||||
if (!file_exists($composerFilePath)) {
|
||||
return $defaultPublicDir;
|
||||
@@ -310,10 +274,6 @@ EOT
|
||||
|
||||
$composerConfig = json_decode(file_get_contents($composerFilePath), true);
|
||||
|
||||
if (isset($composerConfig['extra']['public-dir'])) {
|
||||
return $composerConfig['extra']['public-dir'];
|
||||
}
|
||||
|
||||
return $defaultPublicDir;
|
||||
return $composerConfig['extra']['public-dir'] ?? $defaultPublicDir;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user