Skip to content

Commit

Permalink
Move the plugin config in the config section of package
Browse files Browse the repository at this point in the history
  • Loading branch information
francoispluchino committed Feb 16, 2017
1 parent 531ffa0 commit 9b630ce
Show file tree
Hide file tree
Showing 21 changed files with 606 additions and 327 deletions.
12 changes: 6 additions & 6 deletions Composer/ScriptHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ScriptHandler
{
/**
* Remove ignored files of the installed package defined in the root
* package extra section.
* package config section.
*
* @param PackageEvent $event
*/
Expand All @@ -38,19 +38,19 @@ public static function deleteIgnoredFiles(PackageEvent $event)
return;
}

$section = static::getIgnoreExtraSection();
$section = static::getIgnoreConfigSection();
$manager = IgnoreFactory::create($event->getComposer(), $package, null, $section);
$manager->cleanup();
}

/**
* Get the root extra section of igore file patterns for each package.
* Get the root config section of igore file patterns for each package.
*
* @return string The extra section name
* @return string The config section name
*/
protected static function getIgnoreExtraSection()
protected static function getIgnoreConfigSection()
{
return 'asset-ignore-files';
return 'ignore-files';
}

/**
Expand Down
13 changes: 6 additions & 7 deletions FxpAssetPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Fxp\Composer\AssetPlugin\Repository\AssetRepositoryManager;
use Fxp\Composer\AssetPlugin\Repository\VcsPackageFilter;
use Fxp\Composer\AssetPlugin\Util\AssetPlugin;
use Fxp\Composer\AssetPlugin\Util\Config;

/**
* Composer plugin.
Expand Down Expand Up @@ -77,15 +78,11 @@ public function activate(Composer $composer, IOInterface $io)
$this->io = $io;
$this->packageFilter = new VcsPackageFilter($composer->getPackage(), $composer->getInstallationManager(), $installedRepository);
$this->assetRepositoryManager = new AssetRepositoryManager($io, $composer->getRepositoryManager(), $this->packageFilter);
$extra = $composer->getPackage()->getExtra();
$rm = $composer->getRepositoryManager();

AssetPlugin::addRegistryRepositories($this->assetRepositoryManager, $this->packageFilter, $extra);
AssetPlugin::setVcsTypeRepositories($rm);
AssetPlugin::addRegistryRepositories($this->assetRepositoryManager, $this->packageFilter, $composer->getPackage());
AssetPlugin::setVcsTypeRepositories($composer->getRepositoryManager());

if (isset($extra['asset-repositories']) && is_array($extra['asset-repositories'])) {
$this->assetRepositoryManager->addRepositories($extra['asset-repositories']);
}
$this->assetRepositoryManager->addRepositories(Config::getArray($composer->getPackage(), 'repositories'));

AssetPlugin::addInstallers($composer, $io);
}
Expand All @@ -97,6 +94,8 @@ public function activate(Composer $composer, IOInterface $io)
*/
public function onPluginCommand(CommandEvent $event)
{
Config::validate($this->io, $this->composer->getPackage(), $event->getCommandName());

if (!in_array($event->getCommandName(), array('install', 'update'))) {
$this->packageFilter->setEnabled(false);
}
Expand Down
8 changes: 5 additions & 3 deletions Installer/AssetInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Composer\Util\Filesystem;
use Fxp\Composer\AssetPlugin\Type\AssetTypeInterface;
use Fxp\Composer\AssetPlugin\Util\AssetPlugin;
use Fxp\Composer\AssetPlugin\Util\Config;

/**
* Installer for asset packages.
Expand All @@ -39,9 +40,10 @@ public function __construct(IOInterface $io, Composer $composer, AssetTypeInterf
{
parent::__construct($io, $composer, $assetType->getComposerType(), $filesystem);

$extra = $composer->getPackage()->getExtra();
if (!empty($extra['asset-installer-paths'][$this->type])) {
$this->vendorDir = rtrim($extra['asset-installer-paths'][$this->type], '/');
$paths = Config::getArray($composer->getPackage(), 'installer-paths');

if (!empty($paths[$this->type])) {
$this->vendorDir = rtrim($paths[$this->type], '/');
} else {
$this->vendorDir = rtrim($this->vendorDir.'/'.$assetType->getComposerVendorName(), '/');
}
Expand Down
17 changes: 8 additions & 9 deletions Installer/IgnoreFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Composer\Composer;
use Composer\Package\PackageInterface;
use Fxp\Composer\AssetPlugin\Util\Config;

/**
* Factory of ignore manager patterns.
Expand All @@ -27,22 +28,20 @@ class IgnoreFactory
* @param Composer $composer The composer instance
* @param PackageInterface $package The package instance
* @param string|null $installDir The custom installation directory
* @param string|null $section The extra section of ignore patterns
* @param string|null $section The config section of ignore patterns
*
* @return IgnoreManager
*/
public static function create(Composer $composer, PackageInterface $package, $installDir = null, $section = 'asset-ignore-files')
public static function create(Composer $composer, PackageInterface $package, $installDir = null, $section = 'ignore-files')
{
$installDir = static::getInstallDir($composer, $package, $installDir);
$manager = new IgnoreManager($installDir);
$extra = $composer->getPackage()->getExtra();
$config = Config::getArray($composer->getPackage(), $section);

if (isset($extra[$section])) {
foreach ($extra[$section] as $packageName => $patterns) {
if ($packageName === $package->getName()) {
static::addPatterns($manager, $patterns);
break;
}
foreach ($config as $packageName => $patterns) {
if ($packageName === $package->getName()) {
static::addPatterns($manager, $patterns);
break;
}
}

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ This allows you to manage asset dependencies in a PHP based project very easily.
- Conversion of [multiple versions of the same dependency](Resources/doc/schema.md#multiple-version-of-depdendency-in-the-same-project) to different dependencies of composer
- Add manually the [multiple versions of a same dependency in the project](Resources/doc/index.md#usage-with-multiple-version-of-a-same-dependency)
- Add a [custom config of VCS Repository](Resources/doc/index.md#usage-with-vcs-repository)
- Override the [config of VCS Repository](Resources/doc/index.md#overriding-the-config-of-a-vcs-repository) defined by the asset registry directly in extra section of root composer
- Override the [config of VCS Repository](Resources/doc/index.md#overriding-the-config-of-a-vcs-repository) defined by the asset registry directly in config section of root composer
- VCS drivers for:
- [Git](Resources/doc/index.md#usage-with-vcs-repository)
- [GitHub](Resources/doc/index.md#usage-with-vcs-repository) (compatible with repository redirects)
Expand Down
13 changes: 5 additions & 8 deletions Repository/BowerPrivateRegistryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

namespace Fxp\Composer\AssetPlugin\Repository;

use Composer\Package\RootPackageInterface;
use Fxp\Composer\AssetPlugin\Util\AssetPlugin;
use Fxp\Composer\AssetPlugin\Util\Config;

/**
* Factory of bower private repository registries.
Expand All @@ -23,18 +25,13 @@ class BowerPrivateRegistryFactory implements RegistryFactoryInterface
/**
* {@inheritdoc}
*/
public static function create(AssetRepositoryManager $arm, VcsPackageFilter $filter, array $extra)
public static function create(AssetRepositoryManager $arm, VcsPackageFilter $filter, RootPackageInterface $package)
{
if (!array_key_exists('asset-private-bower-registries', $extra)
|| !is_array($extra['asset-private-bower-registries'])) {
return;
}

$rm = $arm->getRepositoryManager();
$registries = $extra['asset-private-bower-registries'];
$registries = Config::getArray($package, 'private-bower-registries');

foreach ($registries as $registryName => $registryUrl) {
$config = AssetPlugin::createRepositoryConfig($arm, $filter, $extra, $registryName);
$config = AssetPlugin::createRepositoryConfig($arm, $filter, $package, $registryName);
$config['private-registry-url'] = $registryUrl;

$rm->setRepositoryClass($registryName, 'Fxp\Composer\AssetPlugin\Repository\BowerPrivateRepository');
Expand Down
5 changes: 3 additions & 2 deletions Repository/DefaultRegistryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Fxp\Composer\AssetPlugin\Repository;

use Composer\Package\RootPackageInterface;
use Fxp\Composer\AssetPlugin\Assets;
use Fxp\Composer\AssetPlugin\Util\AssetPlugin;

Expand All @@ -24,12 +25,12 @@ class DefaultRegistryFactory implements RegistryFactoryInterface
/**
* {@inheritdoc}
*/
public static function create(AssetRepositoryManager $arm, VcsPackageFilter $filter, array $extra)
public static function create(AssetRepositoryManager $arm, VcsPackageFilter $filter, RootPackageInterface $package)
{
$rm = $arm->getRepositoryManager();

foreach (Assets::getDefaultRegistries() as $assetType => $registryClass) {
$config = AssetPlugin::createRepositoryConfig($arm, $filter, $extra, $assetType);
$config = AssetPlugin::createRepositoryConfig($arm, $filter, $package, $assetType);

$rm->setRepositoryClass($assetType, $registryClass);
$rm->addRepository($rm->createRepository($assetType, $config));
Expand Down
10 changes: 4 additions & 6 deletions Repository/FilterUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Composer\Package\RootPackageInterface;
use Composer\Semver\Constraint\ConstraintInterface;
use Fxp\Composer\AssetPlugin\Package\Version\VersionParser;
use Fxp\Composer\AssetPlugin\Util\Config;

/**
* Helper for Filter Package of Repository.
Expand Down Expand Up @@ -110,18 +111,15 @@ public static function getMinimumStabilityFlag(RootPackageInterface $package, Li
}

/**
* Check the extra option.
* Check the config option.
*
* @param RootPackageInterface $package The root package
* @param string $name The extra option name
*
* @return bool
*/
public static function checkExtraOption(RootPackageInterface $package, $name)
public static function checkConfigOption(RootPackageInterface $package, $name)
{
$extra = $package->getExtra();

return !array_key_exists($name, $extra)
|| true === $extra[$name];
return true === Config::get($package, $name, true);
}
}
10 changes: 6 additions & 4 deletions Repository/RegistryFactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Fxp\Composer\AssetPlugin\Repository;

use Composer\Package\RootPackageInterface;

/**
* Interface of repository registry factory.
*
Expand All @@ -21,9 +23,9 @@ interface RegistryFactoryInterface
/**
* Create the repository registries.
*
* @param AssetRepositoryManager $arm The asset repository manager
* @param VcsPackageFilter $filter The vcs package filter
* @param array $extra The composer extra
* @param AssetRepositoryManager $arm The asset repository manager
* @param VcsPackageFilter $filter The vcs package filter
* @param RootPackageInterface $package The root package
*/
public static function create(AssetRepositoryManager $arm, VcsPackageFilter $filter, array $extra);
public static function create(AssetRepositoryManager $arm, VcsPackageFilter $filter, RootPackageInterface $package);
}
19 changes: 7 additions & 12 deletions Repository/VcsPackageFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Composer\Semver\Constraint\MultiConstraint;
use Fxp\Composer\AssetPlugin\Package\Version\VersionParser;
use Fxp\Composer\AssetPlugin\Type\AssetTypeInterface;
use Fxp\Composer\AssetPlugin\Util\Config;

/**
* Filters the asset packages imported into VCS repository to optimize
Expand Down Expand Up @@ -172,17 +173,11 @@ protected function satisfy(Link $require, $normalizedVersion)
*/
protected function skipByPattern()
{
$extra = $this->package->getExtra();
$skip = Config::get($this->package, 'pattern-skip-version', false);

if (!array_key_exists('asset-pattern-skip-version', $extra)) {
$extra['asset-pattern-skip-version'] = false;
}

if (is_string($extra['asset-pattern-skip-version'])) {
return trim($extra['asset-pattern-skip-version'], '/');
}

return false;
return is_string($skip)
? trim($skip, '/')
: false;
}

/**
Expand Down Expand Up @@ -262,7 +257,7 @@ protected function initialize()
);

if (null !== $this->installedRepository
&& FilterUtil::checkExtraOption($this->package, 'asset-optimize-with-installed-packages')) {
&& FilterUtil::checkConfigOption($this->package, 'optimize-with-installed-packages')) {
$this->initInstalledPackages();
}
}
Expand Down Expand Up @@ -297,7 +292,7 @@ private function includeRootConstraint(PackageInterface $package, Link $link)
if (isset($this->requires[$package->getName()])) {
/* @var Link $rLink */
$rLink = $this->requires[$package->getName()];
$useConjunctive = FilterUtil::checkExtraOption($this->package, 'asset-optimize-with-conjunctive');
$useConjunctive = FilterUtil::checkConfigOption($this->package, 'optimize-with-conjunctive');
$constraint = new MultiConstraint(array($rLink->getConstraint(), $link->getConstraint()), $useConjunctive);
$link = new Link($rLink->getSource(), $rLink->getTarget(), $constraint, 'installed', $constraint->getPrettyString());
}
Expand Down
14 changes: 7 additions & 7 deletions Resources/doc/faqs.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ the installed version.
Of course, 3 solutions can work around the problem:

1. delete the `vendor` directory, do the `update`
2. disable temporarily the import filter in the `extra` section
2. disable temporarily the import filter in the `config` section
3. add the dependency in the root Composer package:
- add the dependency in the root Composer package with the required version (the version not found)
- put the option `extra.asset-optimize-with-conjunctive` to `false`,
- put the option `config.fxp-asset.optimize-with-conjunctive` to `false`,
- do the `update`,
- remove the dependency in the root Composer package
- remove the option `extra.asset-optimize-with-conjunctive`
- remove the option `config.fxp-asset.optimize-with-conjunctive`
- do the `update` to sync the lock file,

> The solution 1 is the easiest and fastest.
Expand Down Expand Up @@ -161,11 +161,11 @@ How to add a Github token in the configuration?
See the official documentation of Composer: [API rate limit and OAuth tokens]
(https://getcomposer.org/doc/articles/troubleshooting.md#api-rate-limit-and-oauth-tokens).

Why the asset VCS repositories are placed in the 'extra' section?
-----------------------------------------------------------------
Why the asset VCS repositories are placed in the 'config' section?
------------------------------------------------------------------

Because it's impossible to create the custom VCS repositories: Composer checks the type
of VCS repository before the loading of plugins, so, an exception is thrown.

The only way, is to put the config in `extra` section (see the [doc]
(https://github.com/fxpio/composer-asset-plugin/blob/master/Resources/doc/schema.md#extraasset-repositories-root-only)).
The only way, is to put the config in `config` section (see the [doc]
(https://github.com/fxpio/composer-asset-plugin/blob/master/Resources/doc/schema.md#configfxp-assetrepositories-root-only)).
Loading

0 comments on commit 9b630ce

Please sign in to comment.