1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace ICanBoogie\Composer;
13
14 use Composer\Package\PackageInterface;
15 use Composer\Installer\LibraryInstaller;
16
17 class ModuleInstaller extends LibraryInstaller
18 {
19 const PACKAGE_PREFIX = 'module-';
20
21 22 23
24 public function getInstallPath(PackageInterface $package)
25 {
26 $name = $package->getPrettyName();
27 $name = basename($name);
28
29 if (strpos($name, self::PACKAGE_PREFIX) !== 0)
30 {
31 throw new \InvalidArgumentException
32 (
33 'Unable to install module, ICanBoogie module should always start their package name with "' . self::PACKAGE_PREFIX . '"'
34 );
35 }
36
37 $module_id = strtr(substr($name, strlen(self::PACKAGE_PREFIX)), '-', '.');
38
39 return ($this->vendorDir ? $this->vendorDir . '/' : '') . 'icanboogie-modules/' . $module_id;
40 }
41
42 43 44
45 public function supports($packageType)
46 {
47 return 'icanboogie-module' === $packageType;
48 }
49 }