1<?php
2
3declare(strict_types = 1);
4
5namespace OomphInc\ComposerInstallersExtender\Installers;
6
7use Composer\Package\PackageInterface;
8use Composer\Installer\LibraryInstaller;
9use Composer\Installers\Installer as InstallerBase;
10
11class Installer extends InstallerBase
12{
13    /**
14     * A list of installer types.
15     *
16     * @var array
17     */
18    protected $installerTypes;
19
20    /**
21     * {@inheritDoc}
22     */
23    public function getInstallPath(PackageInterface $package): string
24    {
25        $installer = new CustomInstaller($package, $this->composer, $this->io);
26        $path = $installer->getInstallPath($package, $package->getType());
27
28        return $path ?: LibraryInstaller::getInstallPath($package);
29    }
30
31    /**
32     * {@inheritDoc}
33     */
34    public function supports($packageType): bool
35    {
36        return in_array($packageType, $this->getInstallerTypes());
37    }
38
39    /**
40     * Get a list of custom installer types.
41     *
42     * @return array
43     */
44    public function getInstallerTypes(): array
45    {
46        if (!$this->installerTypes) {
47            $extra = $this->composer->getPackage()->getExtra();
48            $this->installerTypes = $extra['installer-types'] ?? [];
49        }
50
51        return $this->installerTypes;
52    }
53}
54