Last active
August 29, 2015 13:56
-
-
Save texdc/9093869 to your computer and use it in GitHub Desktop.
Abstract custom Composer installer - https://getcomposer.org/doc/articles/custom-installers.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace My\Composer\Installer; | |
| use Composer\Package\PackageInterface; | |
| use Composer\Installer\LibraryInstaller; | |
| use My\Composer\Installer\Exception\InvalidPackageName; | |
| abstract class AbstractInstaller extends LibraryInstaller | |
| { | |
| /** | |
| * @var string vendor/foo- | |
| */ | |
| protected $prefix; | |
| /** | |
| * @var string path/to/my/install/dir/ | |
| */ | |
| protected $installPath; | |
| /** | |
| * {@inheritDoc} | |
| * @throws InvalidPackageName | |
| */ | |
| public function getPackageBasePath(PackageInterface $package) | |
| { | |
| $prefixLength = strlen($this->prefix); | |
| $packageName = $package->getPrettyName(); | |
| if ($this->prefix !== substr($packageName, 0, $prefixLength)) { | |
| throw new InvalidPackageName($packageName, $this->prefix); | |
| } | |
| return $this->installPath . substr($packageName, $prefixLength); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "name": "vendor/foo-bar", | |
| "type": "composer-plugin", | |
| "license": "MIT", | |
| "autoload": { | |
| "psr-4": {"My\\Composer": "src/"} | |
| }, | |
| "extra": { | |
| "class": [ | |
| "My\\Composer\\Installer\\FooInstaller", | |
| "My\\Composer\\Installer\\BarInstaller" | |
| ] | |
| }, | |
| "require": { | |
| "composer-plugin-api": "~1.0" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment