Skip to content
Extraits de code Groupes Projets

Comparer les révisions

Les modifications sont affichées comme si la révision source était fusionnée avec la révision cible. En savoir plus sur la comparaison des révisions.

Source

Sélectionner le projet cible
No results found

Cible

Sélectionner le projet cible
  • spip-league/composer-installer
1 résultat
Afficher les modifications
Validations sur la source (2)
Affichage de
avec 124 ajouts et 127 suppressions
......@@ -11,4 +11,4 @@ return RectorConfig::configure()
->withRootFiles()
->withPhpSets(php74: true)
->withRules([LogicalToBooleanRector::class])
->withSkip([ NullToStrictStringFuncCallArgRector::class]);
->withSkip([NullToStrictStringFuncCallArgRector::class]);
......@@ -11,31 +11,30 @@ use Symfony\Component\Filesystem\Filesystem as SymfonyFilesystem;
*/
class AssetsClearCache
{
/** @var string[] */
private static array $dirs = [
SpipPaths::DIR_ASSETS_CSS,
SpipPaths::DIR_ASSETS_JS,
];
/**
* @var string[]
*/
private static array $dirs = [SpipPaths::DIR_ASSETS_CSS, SpipPaths::DIR_ASSETS_JS];
/**
* To delete the cache files dedicated for public compiled assets
*
* @param $event
*
* @return void
*/
public static function clearCache(Event $event)
{
$event->getIO()->write('Clearing the assets cache ...');
$vendorDir = $event->getComposer()->getConfig()->get('vendor-dir') . '/';
$event->getIO()
->write('Clearing the assets cache ...');
$vendorDir = $event->getComposer()
->getConfig()
->get('vendor-dir') . '/';
$fs = new Filesystem($event->getComposer()->getLoop()->getProcessExecutor());
$sffs = new SymfonyFilesystem;
$sffs = new SymfonyFilesystem();
foreach (self::$dirs as $dir) {
$fs->emptyDirectory($vendorDir . '../' . SpipPaths::interpolate($dir));
$sffs->chmod($vendorDir . '../' . SpipPaths::interpolate($dir), SpipPaths::CHMOD, SpipPaths::UMASK);
}
$event->getIO()->write('Done.');
$event->getIO()
->write('Done.');
}
}
......@@ -10,12 +10,14 @@ use Symfony\Component\Filesystem\Filesystem;
*/
class BaseDirectories
{
/** @var string[] */
private static array $readOnlyDirs = [
SpipPaths::ETC,
];
/**
* @var string[]
*/
private static array $readOnlyDirs = [SpipPaths::ETC];
/** @var string[] */
/**
* @var string[]
*/
private static array $writeableDirs = [
SpipPaths::VAR,
SpipPaths::TMP,
......@@ -26,46 +28,57 @@ class BaseDirectories
/**
* To create base directories
*
* @param $event
*
* @return void
*/
public static function createBaseDirectories(Event $event, bool $check = false)
{
if ($check) {
$event->getIO()->write('Checking base directories ...');
$event->getIO()
->write('Checking base directories ...');
} else {
$event->getIO()->write('Creating base directories ...');
$event->getIO()
->write('Creating base directories ...');
}
$vendorDir = $event->getComposer()->getConfig()->get('vendor-dir') . '/';
$vendorDir = $event->getComposer()
->getConfig()
->get('vendor-dir') . '/';
$fs = new Filesystem();
foreach (self::$readOnlyDirs as $dir) {
$toCreate = $vendorDir . '../' . SpipPaths::interpolate($dir);
if (!$fs->exists($toCreate)) {
$event->getIO()->write('Creating ' . SpipPaths::interpolate($dir) . ' ...');
$event->getIO()
->write('Creating ' . SpipPaths::interpolate($dir) . ' ...');
$fs->mkdir($toCreate);
} else {
$event->getIO()->write(SpipPaths::interpolate($dir) . ' OK');
$event->getIO()
->write(SpipPaths::interpolate($dir) . ' OK');
}
$event->getIO()->write(\sprintf('Applying chmod %04o on ', SpipPaths::CHMOD & ~0022) . SpipPaths::interpolate($dir) . ' ...');
$event->getIO()
->write(
\sprintf('Applying chmod %04o on ', SpipPaths::CHMOD & ~0022) . SpipPaths::interpolate(
$dir,
) . ' ...',
);
$fs->chmod($toCreate, SpipPaths::CHMOD, SpipPaths::UMASK | 0022);
}
foreach (self::$writeableDirs as $dir) {
$toCreate = $vendorDir . '../' . SpipPaths::interpolate($dir);
if (!$fs->exists($toCreate)) {
$event->getIO()->write('Creating ' . SpipPaths::interpolate($dir) . ' ...');
$event->getIO()
->write('Creating ' . SpipPaths::interpolate($dir) . ' ...');
$fs->mkdir($toCreate);
} else {
$event->getIO()->write(SpipPaths::interpolate($dir) . ' OK');
$event->getIO()
->write(SpipPaths::interpolate($dir) . ' OK');
}
$event->getIO()->write(\sprintf('Applying chmod %04o on ', SpipPaths::CHMOD) . SpipPaths::interpolate($dir) . ' ...');
$event->getIO()
->write(\sprintf('Applying chmod %04o on ', SpipPaths::CHMOD) . SpipPaths::interpolate($dir) . ' ...');
$fs->chmod($toCreate, SpipPaths::CHMOD, SpipPaths::UMASK);
}
$event->getIO()->write('Done.');
$event->getIO()
->write('Done.');
}
}
......@@ -9,7 +9,8 @@ abstract class AbstractSpipCommand extends BaseCommand
protected function getRootDir(): string
{
$composer = $this->requireComposer();
$vendorDir = $composer->getConfig()->get('vendor-dir');
$vendorDir = $composer->getConfig()
->get('vendor-dir');
return \realpath($vendorDir . '/..') ?: '';
}
......
......@@ -13,12 +13,15 @@ use Symfony\Component\Console\Output\OutputInterface;
/**
* @since 0.7.0
*
* @author JamesRezo <jamees@rezo.net>
*/
abstract class AbstractSwitchCommand extends AbstractSpipCommand
{
abstract protected function doSwitch(Analyzer $analyzer, Switcher $switcher, OutputInterface $output, callable $reset): int;
abstract protected function doSwitch(
Analyzer $analyzer,
Switcher $switcher,
OutputInterface $output,
callable $reset,
): int;
protected function execute(InputInterface $input, OutputInterface $output): int
{
......@@ -51,12 +54,15 @@ abstract class AbstractSwitchCommand extends AbstractSpipCommand
if (
$exitCode === AbstractSpipCommand::SUCCESS
) {
$exitCode = $this->getApplication()->doRun(new ArrayInput(['command' => 'update']), $output);
$exitCode = $this->getApplication()
->doRun(new ArrayInput(['command' => 'update']), $output);
if (
$exitCode === AbstractSpipCommand::SUCCESS
&& $this->getApplication()->has('normalize')
&& $this->getApplication()
->has('normalize')
) {
$exitCode = $this->getApplication()->doRun(new ArrayInput(['command' => 'normalize']), $output);
$exitCode = $this->getApplication()
->doRun(new ArrayInput(['command' => 'normalize']), $output);
}
}
......@@ -73,7 +79,7 @@ abstract class AbstractSwitchCommand extends AbstractSpipCommand
} else {
\file_put_contents(
$distributionFile,
\json_encode($distribution, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES)
\json_encode($distribution, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES),
);
}
}
......
......@@ -66,14 +66,13 @@ class LocalCommand extends AbstractSpipCommand
// create new input without "local" command prefix
$input = new StringInput(Preg::replace('{\bl(?:o(?:c(?:a(?:l)?)?)?)?\b}', '', $input->__toString(), 1));
$this->getApplication()->resetComposer();
$this->getApplication()
->resetComposer();
return $this->getApplication()->run($input, $output);
return $this->getApplication()
->run($input, $output);
}
/**
* @inheritDoc
*/
public function isProxyCommand(): bool
{
return true;
......
......@@ -27,13 +27,14 @@ class ModeDevCommand extends AbstractSpipCommand
{
$composerFile = Factory::getComposerFile();
$composer = $this->tryComposer();
if (\is_null($composer)) {
if ($composer === null) {
return AbstractSpipCommand::FAILURE;
}
$output->writeln('Looking into ' . $composerFile);
if (SpipPaths::LOCAL_COMPOSER == $composerFile) {
$tmp = $composer->getConfig()->get('preferred-install');
if ($composerFile == SpipPaths::LOCAL_COMPOSER) {
$tmp = $composer->getConfig()
->get('preferred-install');
if (is_string($tmp)) {
$tmp = [$tmp];
}
......@@ -42,7 +43,9 @@ class ModeDevCommand extends AbstractSpipCommand
}
if (empty(\array_intersect(['spip/*' => 'source'], $tmp))) {
$output->writeln('<warning>Missing preferred-install in ' . $composerFile . '</warning>');
if (!$this->getIO()->askConfirmation('<info>Adding default preferred-install ?</info> [<comment>Y,n</comment>]?')) {
if (!$this->getIO()->askConfirmation(
'<info>Adding default preferred-install ?</info> [<comment>Y,n</comment>]?',
)) {
$output->writeln('Aborting.');
return AbstractSpipCommand::FAILURE;
}
......@@ -52,7 +55,7 @@ class ModeDevCommand extends AbstractSpipCommand
$json->addConfigSetting('preferred-install', ['spip/*' => 'source']);
$this->resetComposer();
$composer = $this->tryComposer();
if (\is_null($composer)) {
if ($composer === null) {
return AbstractSpipCommand::FAILURE;
}
}
......
......@@ -11,13 +11,11 @@ use Symfony\Component\Console\Output\OutputInterface;
/**
* @since 0.7.0
*
* @author JamesRezo <jamees@rezo.net>
*/
#[AsCommand(
name: 'spip:extensions:switch-back',
description: 'Switch back to a SPIP4-Like installation of extensions',
aliases: ['switch:back', 'back']
aliases: ['switch:back', 'back'],
)]
class SwitchBackCommand extends AbstractSwitchCommand
{
......
......@@ -10,13 +10,11 @@ use Symfony\Component\Console\Output\OutputInterface;
/**
* @since 0.7.0
*
* @author JamesRezo <jamees@rezo.net>
*/
#[AsCommand(
name: 'spip:extensions:switch-forward',
description: 'Switch to a SPIP5-Like installation of extensions',
aliases: ['switch:forward', 'forward']
aliases: ['switch:forward', 'forward'],
)]
class SwitchForwardCommand extends AbstractSwitchCommand
{
......
......@@ -13,16 +13,8 @@ use SpipLeague\Composer\Command\SwitchForwardCommand;
*/
class CommandProvider implements CommandProviderCapability
{
/**
* {@inheritDoc}
*/
public function getCommands()
{
return [
new LocalCommand(),
new ModeDevCommand(),
new SwitchForwardCommand(),
new SwitchBackCommand(),
];
return [new LocalCommand(), new ModeDevCommand(), new SwitchForwardCommand(), new SwitchBackCommand()];
}
}
......@@ -27,10 +27,9 @@ class PreferredInstall
}
$toCheck = array_keys(array_filter(
$this->composer->getConfig()->get('preferred-install'),
function ($install) {
return $install === 'source';
},
$this->composer->getConfig()
->get('preferred-install'),
fn($install) => $install === 'source',
));
// packages to change by mode-dev
......@@ -41,7 +40,8 @@ class PreferredInstall
$template = $extra['spip']['template'] ?? ''; // -> SpipPaths::TEMPLATE/
$privateTemplate = $extra['spip']['private_template'] ?? ''; // -> SpipPaths::PRIVATE_TEMPLATE/
$backOffice = $extra['spip']['back_office'] ?? ''; // -> SpipPaths::BACK_OFFICE/
$vendorDir = $this->composer->getConfig()->get('vendor-dir'); // -> vendor/
$vendorDir = $this->composer->getConfig()
->get('vendor-dir'); // -> vendor/
$rootDir = realpath($vendorDir . '/..');
// -> plugins/ ?
......
......@@ -9,8 +9,6 @@ use SpipLeague\Composer\SpipPaths;
* Déduite du contenu du fichier `./plugins-dist.json`
*
* @since 0.7.0
*
* @author JamesRezo <james@rezo.net>
*/
class Collection implements CollectionInterface
{
......@@ -24,9 +22,10 @@ class Collection implements CollectionInterface
public function __construct(array $distribution, ?string $file = \null)
{
$originalCount = \count($distribution);
$distribution = \array_filter($distribution, function ($specification) {
return $specification instanceof SpecificationInterface && !empty($specification->getPrefix());
});
$distribution = \array_filter(
$distribution,
fn($specification) => $specification instanceof SpecificationInterface && !empty($specification->getPrefix()),
);
$count = \count($distribution);
if ($originalCount != 0 && ($count < 1 || $originalCount != $count)) {
throw new InvalidSpecificationException('A collection must contain at least one valid specification.', 2);
......@@ -40,24 +39,19 @@ class Collection implements CollectionInterface
$this->file = $file;
}
/**
* @throws \RuntimeException on any composer errror
* @throws \LogicException if plugins-dist.json is missing
*/
public static function fromJsonFile(RemoteUrlsInterface $changer, ?string $file = null): self
{
if (\is_null($file)) {
if ($file === null) {
$file = SpipPaths::LOCAL_PLUGINS_DIST;
}
if (!(\file_exists($file) || \file_put_contents($file, '{}'))) {
throw new \LogicException('<error>File "' . $file . '" is missing and can\' be created. Can\'t upgrade/downgrade.</error>');
throw new \LogicException(
'<error>File "' . $file . '" is missing and can\' be created. Can\'t upgrade/downgrade.</error>',
);
}
$pluginsDist = \json_decode(
\file_get_contents($file) ?: '',
\true
);
$pluginsDist = \json_decode(\file_get_contents($file) ?: '', \true);
if (!\is_array($pluginsDist)) {
throw new \LogicException('<error>File "' . $file . '" malformed. Can\'t upgrade/downgrade.</error>');
}
......
......@@ -9,8 +9,6 @@ namespace SpipLeague\Composer\Extensions;
* @extends \Iterator<string,SpecificationInterface>
*
* @since 0.7.0
*
* @author JamesRezo <james@rezo.net>
*/
interface CollectionInterface extends \Countable, \Iterator, \JsonSerializable, \ArrayAccess
{
......
......@@ -6,17 +6,19 @@ namespace SpipLeague\Composer\Extensions;
* Implémentation concrète de \Countable, \Iterator, \JsonSerializable, \ArrayAccess.
*
* @since 0.7.0
*
* @author JamesRezo <james@rezo.net>
*/
trait CollectionTrait
{
protected int $position = 0;
/** @var string[] */
/**
* @var string[]
*/
protected array $keys = [];
/** @var array<string,SpecificationInterface> */
/**
* @var array<string,SpecificationInterface>
*/
protected array $collection = [];
public function count(): int
......@@ -76,7 +78,7 @@ trait CollectionTrait
public function offsetGet(mixed $offset): mixed
{
return isset($this->collection[$offset]) ? $this->collection[$offset] : null;
return $this->collection[$offset] ?? null;
}
public function offsetSet(mixed $offset, mixed $value): void
......@@ -85,7 +87,7 @@ trait CollectionTrait
throw new InvalidSpecificationException('A collection must only contain valid specifications.', 3);
}
if (is_null($offset) || !\is_string($offset)) {
if ($offset === null || !\is_string($offset)) {
$offset = $value->getPrefix();
}
......
......@@ -4,9 +4,5 @@ namespace SpipLeague\Composer\Extensions;
/**
* @since 0.7.0
*
* @author JamesRezo <jamees@rezo.net>
*/
class InvalidSpecificationException extends \DomainException
{
}
class InvalidSpecificationException extends \DomainException {}
......@@ -13,18 +13,22 @@ use SpipLeague\Composer\SpipPaths;
* Déduites du contenu du fichier `./plugins-dist.json`
*
* @since 0.7.0
*
* @author JamesRezo <james@rezo.net>
*/
class Specification implements SpecificationInterface
{
private string $prefix;
private string $path;
private string $source;
private string $branch;
private string $tag;
/** @var array<int,array{name:string,version:string,source?:array{url?:string}}>|null */
/**
* @var array<int,array{name:string,version:string,source?:array{url?:string}}>|null
*/
private static ?array $packages = \null;
protected ?RemoteUrlsInterface $changer = null;
......@@ -83,12 +87,10 @@ class Specification implements SpecificationInterface
*
* Limitation: l'extension DOIT être composerisée et être
* distribuée dans un dépôt composer accessible.
*
* @throws InvalidSpecificationException if a composer.lock error occurs or vendorName is missing.
*/
public static function createFromComposer(Composer $composer, string $vendorName): self
{
if (\is_null(self::$packages)) {
if (self::$packages === null) {
$lockFile = Factory::getLockFile(Factory::getComposerFile());
/** @var array{packages?:array<int,array{name:string,version:string,source?:array{url?:string}}>} $lockFileContent */
$lockFileContent = \json_decode(\file_get_contents($lockFile) ?: 'null', \true);
......@@ -101,12 +103,13 @@ class Specification implements SpecificationInterface
}
$tag = $branch = \null;
$links = $composer->getPackage()->getRequires();
$links = $composer->getPackage()
->getRequires();
$require = $links[$vendorName] ?? null;
if ($require) {
$prefix = (string) \preg_replace(',^[^/]+/,', '', $vendorName);
$search = \array_filter(self::$packages, fn ($package) => $vendorName === $package['name']);
$search = \array_filter(self::$packages, fn($package) => $vendorName === $package['name']);
$sourceUrl = '';
if (\count($search) > 0) {
$package = \array_shift($search);
......@@ -178,7 +181,7 @@ class Specification implements SpecificationInterface
*/
public function computeVendorName(): string
{
if (\is_null($this->changer)) {
if ($this->changer === null) {
return '';
}
......
......@@ -6,8 +6,6 @@ namespace SpipLeague\Composer\Extensions;
* Spécifiations d'installation d'un "plugins-dist" en SPIP4.4.
*
* @since 0.7.0
*
* @author JamesRezo <james@rezo.net>
*/
interface SpecificationInterface extends \JsonSerializable
{
......
......@@ -8,8 +8,6 @@ use SpipLeague\Composer\Git\RemoteUrlsInterface;
/**
* @since 0.7.0
*
* @author JamesRezo <james@rezo.net>
*/
class Factory
{
......
......@@ -2,7 +2,6 @@
namespace SpipLeague\Composer\Git;
use Composer\IO\IOInterface;
use Composer\Util\ProcessExecutor;
/**
......@@ -11,12 +10,10 @@ use Composer\Util\ProcessExecutor;
*/
class RemoteUrls implements RemoteUrlsInterface
{
/** @var string[] */
private array $matching = [
'github.com',
'gitlab.com',
'git.spip.net',
];
/**
* @var string[]
*/
private array $matching = ['github.com', 'gitlab.com', 'git.spip.net'];
private ?ProcessExecutor $processor;
......
......@@ -10,7 +10,9 @@ use Composer\Util\Filesystem;
*/
class PluginsClearCache
{
/** @var string[] */
/**
* @var string[]
*/
private static array $files = [
'%spip.dirs.tmp%/plugin_xml_cache.gz',
'%spip.dirs.cache%/charger_pipelines.php',
......@@ -25,21 +27,21 @@ class PluginsClearCache
/**
* To delete the cache files dedicated of the activated plugins
*
* @param $event
*
* @return void
*/
public static function clearCache(Event $event)
{
$event->getIO()->write('Clearing the plugins cache ...');
$vendorDir = $event->getComposer()->getConfig()->get('vendor-dir') . '/';
$event->getIO()
->write('Clearing the plugins cache ...');
$vendorDir = $event->getComposer()
->getConfig()
->get('vendor-dir') . '/';
$fs = new Filesystem($event->getComposer()->getLoop()->getProcessExecutor());
foreach (self::$files as $file) {
$fs->remove($vendorDir . '../' . SpipPaths::interpolate($file));
}
$event->getIO()->write('Done.');
$event->getIO()
->write('Done.');
}
}