Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Only indicate support for package types that are actually supported #99

Closed
wants to merge 5 commits into from

3 participants

John P. Bloch Kyle Robinson Young Andrey Savchenko
John P. Bloch

This pull request is a fix for composer/installers#98

It adds a protected method to Composer\Installers\Installer that checks the installer class for a class constant (PATTERN). The constant is defined already on BaseInstaller, so it will never be undefined. If no pattern is available, it will return the current value of '(\w+)'. Otherwise, it will return a pattern (e.g. for WordPressInstaller, the pattern is '(plugin|theme|muplugin)'. This pattern is used to match the second half of the package type after the framework's slug.

Unit tests have also been updated to reflect the new functionality.

johnpbloch added some commits
John P. Bloch johnpbloch Add a test case to verify that unsupported types do not register as s…
…upported.
83c3270
John P. Bloch johnpbloch Update supports test data to use types that are actually supported 0656108
John P. Bloch johnpbloch Restrict support to actually supported types
This adds a class constant to the BaseInstaller class and all children of the class by which a pattern for matching supported types of packages can be defined. Installer now grabs the value of this constant and uses it in the regular expression check for whether the package type is actually supported after all.
d3bac95
Kyle Robinson Young
Collaborator

Thanks for this! I think we should just expose protected $locations to public $locations and use array_keys to retrieve the types. That will keep it a bit more DRY. What do you think?

John P. Bloch

That would be fine. There's a problem with doing that and two ways to fix it (the problem being that we'd be accessing a non-static property statically):

  1. We would have to use public static $locations and access it with static::$locations to avoid an error from trying to access a non-static property statically. At the time we run supports(), we do not have access to the package object, so we can't instantiate the installer.
  2. We would want to make BaseInstaller's constructor arguments optional so we can instantiate installers without a package. This approach would even let us keep locations protected and use a getter method to return them and would require no changes to any child classes.
John P. Bloch

I'd personally be more in favor of number 2 above than of number 1.

Kyle Robinson Young
Collaborator

Number 2 sounds good to me as well. Thanks!

johnpbloch added some commits
John P. Bloch johnpbloch Revert "Restrict support to actually supported types"
This reverts commit d3bac95.
29202c5
John P. Bloch johnpbloch Implement location pattern compilation
As discussed on Github, this modifies the BaseInstaller class to make its constructor arguments optional and adds a getter method to get the locations. This allows us to re-use the locations property.
e2d3233
John P. Bloch

bump

So... is this good to go? :D

Kyle Robinson Young shama closed this in 49c8a5d
Kyle Robinson Young
Collaborator

Didn't realize you updated the PR. Thanks for the fix!

Andrey Savchenko

@shama could you please tag stable version after this fix? I want to update my guide on topic ( http://composer.rarst.net/ ) to using Jonh's installer. Thanks in advance!

Kyle Robinson Young
Collaborator

@Rarst Published as 1.0.6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 16, 2013
  1. John P. Bloch
  2. John P. Bloch
  3. John P. Bloch

    Restrict support to actually supported types

    johnpbloch authored
    This adds a class constant to the BaseInstaller class and all children of the class by which a pattern for matching supported types of packages can be defined. Installer now grabs the value of this constant and uses it in the regular expression check for whether the package type is actually supported after all.
  4. John P. Bloch
  5. John P. Bloch

    Implement location pattern compilation

    johnpbloch authored
    As discussed on Github, this modifies the BaseInstaller class to make its constructor arguments optional and adds a getter method to get the locations. This allows us to re-use the locations property.
This page is out of date. Refresh to see the latest.
12 src/Composer/Installers/BaseInstaller.php
View
@@ -16,7 +16,7 @@
* @param PackageInterface $package
* @param Composer $composer
*/
- public function __construct(PackageInterface $package, Composer $composer)
+ public function __construct(PackageInterface $package = null, Composer $composer = null)
{
$this->composer = $composer;
$this->package = $package;
@@ -78,6 +78,16 @@ public function inflectPackageVars($vars)
}
/**
+ * Gets the installer's locations
+ *
+ * @return array
+ */
+ public function getLocations()
+ {
+ return $this->locations;
+ }
+
+ /**
* Replace vars in a path
*
* @param string $path
23 src/Composer/Installers/Installer.php
View
@@ -81,7 +81,8 @@ public function supports($packageType)
return false;
}
- return preg_match('#' . $frameworkType . '-(\w+)#', $packageType, $matches) === 1;
+ $locationPattern = $this->getLocationPattern($frameworkType);
+ return preg_match('#' . $frameworkType . '-' . $locationPattern . '#', $packageType, $matches) === 1;
}
/**
@@ -103,4 +104,24 @@ protected function findFrameworkType($type)
return $frameworkType;
}
+
+ /**
+ * Get the second part of the regular expression to check for support of a
+ * package type
+ *
+ * @param string $frameworkType
+ * @return string
+ */
+ protected function getLocationPattern($frameworkType)
+ {
+ $pattern = false;
+ if (!empty($this->supportedTypes[$frameworkType])) {
+ $frameworkClass = 'Composer\\Installers\\' . $this->supportedTypes[$frameworkType];
+ /** @var BaseInstaller $framework */
+ $framework = new $frameworkClass;
+ $locations = array_keys($framework->getLocations());
+ $pattern = $locations ? '(' . implode('|', $locations) . ')' : false;
+ }
+ return $pattern ? : '(\w+)';
+ }
}
9 tests/Composer/Installers/Test/InstallerTest.php
View
@@ -90,8 +90,12 @@ public function dataForTestSupport()
array('annotatecms-service', true),
array('cakephp', false),
array('cakephp-', false),
- array('cakephp-app', true),
- array('codeigniter-app', true),
+ array('cakephp-app', false),
+ array('cakephp-plugin', true),
+ array('codeigniter-app', false),
+ array('codeigniter-library', true),
+ array('codeigniter-third-party', true),
+ array('codeigniter-module', true),
array('croogo-plugin', true),
array('croogo-theme', true),
array('drupal-module', true),
@@ -112,6 +116,7 @@ public function dataForTestSupport()
array('symfony1-plugin', true),
array('typo3-flow-plugin', true),
array('wordpress-plugin', true),
+ array('wordpress-core', false),
array('zend-library', true),
);
}
Something went wrong with that request. Please try again.