Skip to content

Commit 9b630ce

Browse files
Move the plugin config in the config section of package
1 parent 531ffa0 commit 9b630ce

21 files changed

+606
-327
lines changed

Composer/ScriptHandler.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class ScriptHandler
2828
{
2929
/**
3030
* Remove ignored files of the installed package defined in the root
31-
* package extra section.
31+
* package config section.
3232
*
3333
* @param PackageEvent $event
3434
*/
@@ -38,19 +38,19 @@ public static function deleteIgnoredFiles(PackageEvent $event)
3838
return;
3939
}
4040

41-
$section = static::getIgnoreExtraSection();
41+
$section = static::getIgnoreConfigSection();
4242
$manager = IgnoreFactory::create($event->getComposer(), $package, null, $section);
4343
$manager->cleanup();
4444
}
4545

4646
/**
47-
* Get the root extra section of igore file patterns for each package.
47+
* Get the root config section of igore file patterns for each package.
4848
*
49-
* @return string The extra section name
49+
* @return string The config section name
5050
*/
51-
protected static function getIgnoreExtraSection()
51+
protected static function getIgnoreConfigSection()
5252
{
53-
return 'asset-ignore-files';
53+
return 'ignore-files';
5454
}
5555

5656
/**

FxpAssetPlugin.php

+6-7
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Fxp\Composer\AssetPlugin\Repository\AssetRepositoryManager;
2424
use Fxp\Composer\AssetPlugin\Repository\VcsPackageFilter;
2525
use Fxp\Composer\AssetPlugin\Util\AssetPlugin;
26+
use Fxp\Composer\AssetPlugin\Util\Config;
2627

2728
/**
2829
* Composer plugin.
@@ -77,15 +78,11 @@ public function activate(Composer $composer, IOInterface $io)
7778
$this->io = $io;
7879
$this->packageFilter = new VcsPackageFilter($composer->getPackage(), $composer->getInstallationManager(), $installedRepository);
7980
$this->assetRepositoryManager = new AssetRepositoryManager($io, $composer->getRepositoryManager(), $this->packageFilter);
80-
$extra = $composer->getPackage()->getExtra();
81-
$rm = $composer->getRepositoryManager();
8281

83-
AssetPlugin::addRegistryRepositories($this->assetRepositoryManager, $this->packageFilter, $extra);
84-
AssetPlugin::setVcsTypeRepositories($rm);
82+
AssetPlugin::addRegistryRepositories($this->assetRepositoryManager, $this->packageFilter, $composer->getPackage());
83+
AssetPlugin::setVcsTypeRepositories($composer->getRepositoryManager());
8584

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

9087
AssetPlugin::addInstallers($composer, $io);
9188
}
@@ -97,6 +94,8 @@ public function activate(Composer $composer, IOInterface $io)
9794
*/
9895
public function onPluginCommand(CommandEvent $event)
9996
{
97+
Config::validate($this->io, $this->composer->getPackage(), $event->getCommandName());
98+
10099
if (!in_array($event->getCommandName(), array('install', 'update'))) {
101100
$this->packageFilter->setEnabled(false);
102101
}

Installer/AssetInstaller.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Composer\Util\Filesystem;
1919
use Fxp\Composer\AssetPlugin\Type\AssetTypeInterface;
2020
use Fxp\Composer\AssetPlugin\Util\AssetPlugin;
21+
use Fxp\Composer\AssetPlugin\Util\Config;
2122

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

42-
$extra = $composer->getPackage()->getExtra();
43-
if (!empty($extra['asset-installer-paths'][$this->type])) {
44-
$this->vendorDir = rtrim($extra['asset-installer-paths'][$this->type], '/');
43+
$paths = Config::getArray($composer->getPackage(), 'installer-paths');
44+
45+
if (!empty($paths[$this->type])) {
46+
$this->vendorDir = rtrim($paths[$this->type], '/');
4547
} else {
4648
$this->vendorDir = rtrim($this->vendorDir.'/'.$assetType->getComposerVendorName(), '/');
4749
}

Installer/IgnoreFactory.php

+8-9
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Composer\Composer;
1515
use Composer\Package\PackageInterface;
16+
use Fxp\Composer\AssetPlugin\Util\Config;
1617

1718
/**
1819
* Factory of ignore manager patterns.
@@ -27,22 +28,20 @@ class IgnoreFactory
2728
* @param Composer $composer The composer instance
2829
* @param PackageInterface $package The package instance
2930
* @param string|null $installDir The custom installation directory
30-
* @param string|null $section The extra section of ignore patterns
31+
* @param string|null $section The config section of ignore patterns
3132
*
3233
* @return IgnoreManager
3334
*/
34-
public static function create(Composer $composer, PackageInterface $package, $installDir = null, $section = 'asset-ignore-files')
35+
public static function create(Composer $composer, PackageInterface $package, $installDir = null, $section = 'ignore-files')
3536
{
3637
$installDir = static::getInstallDir($composer, $package, $installDir);
3738
$manager = new IgnoreManager($installDir);
38-
$extra = $composer->getPackage()->getExtra();
39+
$config = Config::getArray($composer->getPackage(), $section);
3940

40-
if (isset($extra[$section])) {
41-
foreach ($extra[$section] as $packageName => $patterns) {
42-
if ($packageName === $package->getName()) {
43-
static::addPatterns($manager, $patterns);
44-
break;
45-
}
41+
foreach ($config as $packageName => $patterns) {
42+
if ($packageName === $package->getName()) {
43+
static::addPatterns($manager, $patterns);
44+
break;
4645
}
4746
}
4847

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ This allows you to manage asset dependencies in a PHP based project very easily.
3636
- 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
3737
- Add manually the [multiple versions of a same dependency in the project](Resources/doc/index.md#usage-with-multiple-version-of-a-same-dependency)
3838
- Add a [custom config of VCS Repository](Resources/doc/index.md#usage-with-vcs-repository)
39-
- 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
39+
- 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
4040
- VCS drivers for:
4141
- [Git](Resources/doc/index.md#usage-with-vcs-repository)
4242
- [GitHub](Resources/doc/index.md#usage-with-vcs-repository) (compatible with repository redirects)

Repository/BowerPrivateRegistryFactory.php

+5-8
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111

1212
namespace Fxp\Composer\AssetPlugin\Repository;
1313

14+
use Composer\Package\RootPackageInterface;
1415
use Fxp\Composer\AssetPlugin\Util\AssetPlugin;
16+
use Fxp\Composer\AssetPlugin\Util\Config;
1517

1618
/**
1719
* Factory of bower private repository registries.
@@ -23,18 +25,13 @@ class BowerPrivateRegistryFactory implements RegistryFactoryInterface
2325
/**
2426
* {@inheritdoc}
2527
*/
26-
public static function create(AssetRepositoryManager $arm, VcsPackageFilter $filter, array $extra)
28+
public static function create(AssetRepositoryManager $arm, VcsPackageFilter $filter, RootPackageInterface $package)
2729
{
28-
if (!array_key_exists('asset-private-bower-registries', $extra)
29-
|| !is_array($extra['asset-private-bower-registries'])) {
30-
return;
31-
}
32-
3330
$rm = $arm->getRepositoryManager();
34-
$registries = $extra['asset-private-bower-registries'];
31+
$registries = Config::getArray($package, 'private-bower-registries');
3532

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

4037
$rm->setRepositoryClass($registryName, 'Fxp\Composer\AssetPlugin\Repository\BowerPrivateRepository');

Repository/DefaultRegistryFactory.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Fxp\Composer\AssetPlugin\Repository;
1313

14+
use Composer\Package\RootPackageInterface;
1415
use Fxp\Composer\AssetPlugin\Assets;
1516
use Fxp\Composer\AssetPlugin\Util\AssetPlugin;
1617

@@ -24,12 +25,12 @@ class DefaultRegistryFactory implements RegistryFactoryInterface
2425
/**
2526
* {@inheritdoc}
2627
*/
27-
public static function create(AssetRepositoryManager $arm, VcsPackageFilter $filter, array $extra)
28+
public static function create(AssetRepositoryManager $arm, VcsPackageFilter $filter, RootPackageInterface $package)
2829
{
2930
$rm = $arm->getRepositoryManager();
3031

3132
foreach (Assets::getDefaultRegistries() as $assetType => $registryClass) {
32-
$config = AssetPlugin::createRepositoryConfig($arm, $filter, $extra, $assetType);
33+
$config = AssetPlugin::createRepositoryConfig($arm, $filter, $package, $assetType);
3334

3435
$rm->setRepositoryClass($assetType, $registryClass);
3536
$rm->addRepository($rm->createRepository($assetType, $config));

Repository/FilterUtil.php

+4-6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Composer\Package\RootPackageInterface;
1717
use Composer\Semver\Constraint\ConstraintInterface;
1818
use Fxp\Composer\AssetPlugin\Package\Version\VersionParser;
19+
use Fxp\Composer\AssetPlugin\Util\Config;
1920

2021
/**
2122
* Helper for Filter Package of Repository.
@@ -110,18 +111,15 @@ public static function getMinimumStabilityFlag(RootPackageInterface $package, Li
110111
}
111112

112113
/**
113-
* Check the extra option.
114+
* Check the config option.
114115
*
115116
* @param RootPackageInterface $package The root package
116117
* @param string $name The extra option name
117118
*
118119
* @return bool
119120
*/
120-
public static function checkExtraOption(RootPackageInterface $package, $name)
121+
public static function checkConfigOption(RootPackageInterface $package, $name)
121122
{
122-
$extra = $package->getExtra();
123-
124-
return !array_key_exists($name, $extra)
125-
|| true === $extra[$name];
123+
return true === Config::get($package, $name, true);
126124
}
127125
}

Repository/RegistryFactoryInterface.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Fxp\Composer\AssetPlugin\Repository;
1313

14+
use Composer\Package\RootPackageInterface;
15+
1416
/**
1517
* Interface of repository registry factory.
1618
*
@@ -21,9 +23,9 @@ interface RegistryFactoryInterface
2123
/**
2224
* Create the repository registries.
2325
*
24-
* @param AssetRepositoryManager $arm The asset repository manager
25-
* @param VcsPackageFilter $filter The vcs package filter
26-
* @param array $extra The composer extra
26+
* @param AssetRepositoryManager $arm The asset repository manager
27+
* @param VcsPackageFilter $filter The vcs package filter
28+
* @param RootPackageInterface $package The root package
2729
*/
28-
public static function create(AssetRepositoryManager $arm, VcsPackageFilter $filter, array $extra);
30+
public static function create(AssetRepositoryManager $arm, VcsPackageFilter $filter, RootPackageInterface $package);
2931
}

Repository/VcsPackageFilter.php

+7-12
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Composer\Semver\Constraint\MultiConstraint;
2222
use Fxp\Composer\AssetPlugin\Package\Version\VersionParser;
2323
use Fxp\Composer\AssetPlugin\Type\AssetTypeInterface;
24+
use Fxp\Composer\AssetPlugin\Util\Config;
2425

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

177-
if (!array_key_exists('asset-pattern-skip-version', $extra)) {
178-
$extra['asset-pattern-skip-version'] = false;
179-
}
180-
181-
if (is_string($extra['asset-pattern-skip-version'])) {
182-
return trim($extra['asset-pattern-skip-version'], '/');
183-
}
184-
185-
return false;
178+
return is_string($skip)
179+
? trim($skip, '/')
180+
: false;
186181
}
187182

188183
/**
@@ -262,7 +257,7 @@ protected function initialize()
262257
);
263258

264259
if (null !== $this->installedRepository
265-
&& FilterUtil::checkExtraOption($this->package, 'asset-optimize-with-installed-packages')) {
260+
&& FilterUtil::checkConfigOption($this->package, 'optimize-with-installed-packages')) {
266261
$this->initInstalledPackages();
267262
}
268263
}
@@ -297,7 +292,7 @@ private function includeRootConstraint(PackageInterface $package, Link $link)
297292
if (isset($this->requires[$package->getName()])) {
298293
/* @var Link $rLink */
299294
$rLink = $this->requires[$package->getName()];
300-
$useConjunctive = FilterUtil::checkExtraOption($this->package, 'asset-optimize-with-conjunctive');
295+
$useConjunctive = FilterUtil::checkConfigOption($this->package, 'optimize-with-conjunctive');
301296
$constraint = new MultiConstraint(array($rLink->getConstraint(), $link->getConstraint()), $useConjunctive);
302297
$link = new Link($rLink->getSource(), $rLink->getTarget(), $constraint, 'installed', $constraint->getPrettyString());
303298
}

Resources/doc/faqs.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,13 @@ the installed version.
101101
Of course, 3 solutions can work around the problem:
102102

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

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

164-
Why the asset VCS repositories are placed in the 'extra' section?
165-
-----------------------------------------------------------------
164+
Why the asset VCS repositories are placed in the 'config' section?
165+
------------------------------------------------------------------
166166

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

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

0 commit comments

Comments
 (0)