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
Affichage de
avec 115 ajouts et 103 suppressions
......@@ -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.');
}
}
......@@ -18,27 +18,30 @@ class Security
public static function copySafetyScreen(Event $event): void
{
$search = array_filter(
$event->getComposer()->getPackage()->getRequires(),
function (Link $link) {
return $link->getTarget() === 'spip/security';
},
$event->getComposer()
->getPackage()
->getRequires(),
fn(Link $link) => $link->getTarget() === 'spip/security',
);
if (empty($search)) {
$event->getIO()->warning('spip/security is not installed.');
$event->getIO()
->warning('spip/security is not installed.');
return;
}
$event->getIO()->write('Updating the safety screen ...');
$vendorDir = $event->getComposer()->getConfig()->get('vendor-dir');
$event->getIO()
->write('Updating the safety screen ...');
$vendorDir = $event->getComposer()
->getConfig()
->get('vendor-dir');
try {
\copy(
$vendorDir . '/spip/security/ecran_securite.php',
$vendorDir . '/../config/ecran_securite.php',
);
$event->getIO()->write('Done.');
\copy($vendorDir . '/spip/security/ecran_securite.php', $vendorDir . '/../config/ecran_securite.php');
$event->getIO()
->write('Done.');
} catch (\Throwable $th) {
$event->getIO()->error($th->getMessage());
$event->getIO()
->error($th->getMessage());
}
}
}
......@@ -7,22 +7,20 @@ use Composer\Package\PackageInterface;
class SpipInstaller extends LibraryInstaller
{
/**
* {@inheritDoc}
*/
public function getInstallPath(PackageInterface $package)
{
if ('spip-ecrire' === $package->getType()) {
if ($package->getType() === 'spip-ecrire') {
return './' . SpipPaths::BACK_OFFICE;
}
if ('spip-prive' === $package->getType()) {
if ($package->getType() === 'spip-prive') {
return './' . SpipPaths::PRIVATE_TEMPLATE;
}
if ('spip-plugin' === $package->getType()) {
if ($package->getType() === 'spip-plugin') {
/** @var array{spip?:array{extensions?:string[],template?:string,private_template?:string,back_office?:string}} */
$extra = $this->composer->getPackage()->getExtra();
$extra = $this->composer->getPackage()
->getExtra();
$template = $extra['spip']['template'] ?? '';
$extensions = $extra['spip']['extensions'] ?? [];
$name = $package->getName();
......@@ -38,10 +36,7 @@ class SpipInstaller extends LibraryInstaller
return './' . SpipPaths::PLUGINS . '/' . $name;
}
if (in_array($package->getType(), [
'spip-lang',
'spip-theme',
])) {
if (in_array($package->getType(), ['spip-lang', 'spip-theme'])) {
throw new \InvalidArgumentException(
'Unable to install this package as its type is not supported for now.' .
' Wait for a future SPIP version for using it.',
......@@ -51,9 +46,6 @@ class SpipInstaller extends LibraryInstaller
return parent::getInstallPath($package);
}
/**
* {@inheritDoc}
*/
public function supports(string $packageType)
{
return in_array($packageType, [
......
......@@ -17,16 +17,13 @@ class SpipInstallerPlugin implements PluginInterface, EventSubscriberInterface,
public function activate(Composer $composer, IOInterface $io)
{
$installer = new SpipInstaller($io, $composer);
$composer->getInstallationManager()->addInstaller($installer);
$composer->getInstallationManager()
->addInstaller($installer);
}
public function deactivate(Composer $composer, IOInterface $io)
{
}
public function deactivate(Composer $composer, IOInterface $io) {}
public function uninstall(Composer $composer, IOInterface $io)
{
}
public function uninstall(Composer $composer, IOInterface $io) {}
public static function getSubscribedEvents()
{
......@@ -82,7 +79,7 @@ class SpipInstallerPlugin implements PluginInterface, EventSubscriberInterface,
public function getCapabilities()
{
return [
'Composer\Plugin\Capability\CommandProvider' => 'SpipLeague\Composer\CommandProvider',
\Composer\Plugin\Capability\CommandProvider::class => \SpipLeague\Composer\CommandProvider::class,
];
}
}
......@@ -5,24 +5,37 @@ namespace SpipLeague\Composer;
class SpipPaths
{
public const CHMOD = 0777;
public const UMASK = 0000;
public const PLUGINS = 'plugins';
public const EXTENSIONS = 'plugins-dist';
public const TEMPLATE = 'squelettes-dist';
public const PRIVATE_TEMPLATE = 'prive';
public const BACK_OFFICE = 'ecrire';
public const TMP = 'tmp';
public const ETC = 'config';
public const VAR = 'local';
public const DOC = 'IMG';
public const LOCAL_COMPOSER = 'composer.local.json';
public const LOCAL_PLUGINS_DIST = 'plugins-dist.json';
public const DIR_CACHE = '%spip.dirs.tmp%/cache';
public const DIR_LOG = '%spip.dirs.tmp%/log';
public const DIR_ASSETS_CSS = '%spip.dirs.var%/cache-css';
public const DIR_ASSETS_JS = '%spip.dirs.var%/cache-js';
public const WHEELS_CACHE = '%spip.dirs.cache%/wheels';
......
......@@ -17,18 +17,18 @@ use SpipLeague\Composer\Switch\Operation\RemoveSpecification;
/**
* @since 0.7.0
*
* @author JamesRezo <james@rezo.net>
*/
class Analyzer
{
private Filesystem $filesystem;
private CollectionInterface $distribution;
private Composer $composer;
public function __construct(
CollectionInterface $distribution,
Composer $composer
Composer $composer,
) {
$this->distribution = $distribution;
$this->composer = $composer;
......@@ -42,7 +42,8 @@ class Analyzer
{
$extensions = [];
/** @var array{spip?:array{extensions?:mixed}} $extra */
$extra = $this->composer->getPackage()->getExtra();
$extra = $this->composer->getPackage()
->getExtra();
if (isset($extra['spip']['extensions']) && \is_array($extra['spip']['extensions'])) {
$extensions = $extra['spip']['extensions'];
}
......@@ -75,7 +76,8 @@ class Analyzer
public function back(): \Generator
{
$extensions = $this->getExtensions();
$requires = $this->composer->getPackage()->getRequires();
$requires = $this->composer->getPackage()
->getRequires();
$vendorNames = \array_keys($requires);
$vendorDirs = [];
......
......@@ -8,6 +8,7 @@ use SpipLeague\Composer\Extensions\CollectionInterface;
class AddToRequire implements OperationInterface
{
private string $vendorName;
private string $constraint;
public function __construct(string $vendorName, string $constraint)
......@@ -33,8 +34,6 @@ class AddToRequire implements OperationInterface
}
/**
* {@inheritDoc}
*
* @codeCoverageIgnore
*/
public function mark(CollectionInterface $distribution, Composer $composer): ?self
......@@ -44,7 +43,9 @@ class AddToRequire implements OperationInterface
public function do(CollectionInterface $distribution, Composer $composer): string
{
$composer->getConfig()->getConfigSource()->addLink('require', $this->vendorName, $this->constraint);
$composer->getConfig()
->getConfigSource()
->addLink('require', $this->vendorName, $this->constraint);
return 'require ' . $this->vendorName . ':' . $this->constraint . ' added.';
}
......
......@@ -34,7 +34,8 @@ class AddToSpipExtraExtensions implements OperationInterface
{
$extensions = [];
/** @var array{spip?:array{extensions?:mixed}} $extra */
$extra = $composer->getPackage()->getExtra();
$extra = $composer->getPackage()
->getExtra();
if (isset($extra['spip']['extensions']) && \is_array($extra['spip']['extensions'])) {
$extensions = $extra['spip']['extensions'];
}
......@@ -46,7 +47,8 @@ class AddToSpipExtraExtensions implements OperationInterface
{
$extensions = [];
/** @var array{spip?:array{extensions?:mixed}} $extra */
$extra = $composer->getPackage()->getExtra();
$extra = $composer->getPackage()
->getExtra();
if (isset($extra['spip']['extensions']) && \is_array($extra['spip']['extensions'])) {
$extensions = $extra['spip']['extensions'];
}
......@@ -55,7 +57,9 @@ class AddToSpipExtraExtensions implements OperationInterface
}
$extensions[] = $this->vendorName;
$composer->getConfig()->getConfigSource()->addProperty('extra.spip.extensions', $extensions);
$composer->getConfig()
->getConfigSource()
->addProperty('extra.spip.extensions', $extensions);
return 'extensions ' . $this->vendorName . ' added';
}
......
......@@ -7,8 +7,6 @@ use SpipLeague\Composer\Extensions\CollectionInterface;
/**
* @since 0.7.0
*
* @author JamesRezo <jamees@rezo.net>
*/
interface OperationInterface
{
......
......@@ -8,13 +8,13 @@ use SpipLeague\Composer\Extensions\CollectionInterface;
/**
* @since 0.7.0
*
* @author JamesRezo <james@rezo.net>
*/
class RemoveDirectory implements OperationInterface
{
private Filesystem $filesystem;
private string $directory;
private bool $ifEmpty;
public function __construct(Filesystem $filesystem, string $directory, bool $ifEmpty = false)
......
......@@ -7,8 +7,6 @@ use SpipLeague\Composer\Extensions\CollectionInterface;
/**
* @since 0.7.0
*
* @author JamesRezo <james@rezo.net>
*/
class RemoveFromRequire implements OperationInterface
{
......@@ -42,7 +40,9 @@ class RemoveFromRequire implements OperationInterface
public function do(CollectionInterface $distribution, Composer $composer): string
{
$composer->getConfig()->getConfigSource()->removeLink('require', $this->vendorName);
$composer->getConfig()
->getConfigSource()
->removeLink('require', $this->vendorName);
return 'require ' . $this->vendorName . ' removed';
}
......
......@@ -7,8 +7,6 @@ use SpipLeague\Composer\Extensions\CollectionInterface;
/**
* @since 0.7.0
*
* @author JamesRezo <james@rezo.net>
*/
class RemoveFromSpipExtraExtensions implements OperationInterface
{
......@@ -39,7 +37,8 @@ class RemoveFromSpipExtraExtensions implements OperationInterface
{
$extensions = [];
/** @var array{spip?:array{extensions?:mixed}} $extra */
$extra = $composer->getPackage()->getExtra();
$extra = $composer->getPackage()
->getExtra();
if (isset($extra['spip']['extensions']) && \is_array($extra['spip']['extensions'])) {
$extensions = $extra['spip']['extensions'];
}
......@@ -51,7 +50,8 @@ class RemoveFromSpipExtraExtensions implements OperationInterface
{
$extensions = [];
/** @var array{spip?:array{extensions?:mixed}} $extra */
$extra = $composer->getPackage()->getExtra();
$extra = $composer->getPackage()
->getExtra();
if (isset($extra['spip']['extensions']) && \is_array($extra['spip']['extensions'])) {
$extensions = $extra['spip']['extensions'];
}
......@@ -59,7 +59,9 @@ class RemoveFromSpipExtraExtensions implements OperationInterface
return 'nothing to do';
}
$composer->getConfig()->getConfigSource()->addProperty('extra.spip.extensions', \array_diff($extensions, [$this->vendorName]));
$composer->getConfig()
->getConfigSource()
->addProperty('extra.spip.extensions', \array_diff($extensions, [$this->vendorName]));
return 'extensions ' . $this->vendorName . ' removed';
}
......
......@@ -22,7 +22,6 @@ class RemoveSpecification implements OperationInterface
return 'RemoveSpecification ' . $this->prefix;
}
/**
* @codeCoverageIgnore
*/
......
......@@ -8,15 +8,16 @@ use SpipLeague\Composer\Switch\Operation\OperationInterface;
/**
* @since 0.7.0
*
* @author JamesRezo <james@rezo.net>
*/
class Switcher
{
private CollectionInterface $distribution;
private Composer $composer;
/** @var array<string,OperationInterface[]> */
/**
* @var array<string,OperationInterface[]>
*/
private array $operations = [
'distribution' => [],
'extensions' => [],
......@@ -33,7 +34,7 @@ class Switcher
public function to(OperationInterface $operation): void
{
$operation = $operation->mark($this->distribution, $this->composer);
if (!\is_null($operation)) {
if ($operation !== null) {
$this->operations[$operation->getType()][] = $operation;
}
}
......
......@@ -10,16 +10,22 @@ class WheelsClearCache
{
public static function clearCache(Event $event): void
{
$event->getIO()->write('Clearing the Textwheel cache ...');
$vendorDir = $event->getComposer()->getConfig()->get('vendor-dir') . '/';
$event->getIO()
->write('Clearing the Textwheel cache ...');
$vendorDir = $event->getComposer()
->getConfig()
->get('vendor-dir') . '/';
$fs = new Filesystem($event->getComposer()->getLoop()->getProcessExecutor());
$sffs = new SymfonyFilesystem;
$fs->emptyDirectory(
$vendorDir . '../' . SpipPaths::interpolate(SpipPaths::WHEELS_CACHE)
$sffs = new SymfonyFilesystem();
$fs->emptyDirectory($vendorDir . '../' . SpipPaths::interpolate(SpipPaths::WHEELS_CACHE));
$sffs->chmod(
$vendorDir . '../' . SpipPaths::interpolate(SpipPaths::WHEELS_CACHE),
SpipPaths::CHMOD,
SpipPaths::UMASK,
);
$sffs->chmod($vendorDir . '../' .SpipPaths::interpolate(SpipPaths::WHEELS_CACHE), SpipPaths::CHMOD, SpipPaths::UMASK);
$event->getIO()->write('Done.');
$event->getIO()
->write('Done.');
}
}