5b6c553a831ec02236ca71ad7366c7e87333ba0e
[yaffs-website] / vendor / composer / installers / src / Composer / Installers / Installer.php
1 <?php
2 namespace Composer\Installers;
3
4 use Composer\IO\IOInterface;
5 use Composer\Installer\LibraryInstaller;
6 use Composer\Package\PackageInterface;
7 use Composer\Repository\InstalledRepositoryInterface;
8
9 class Installer extends LibraryInstaller
10 {
11     /**
12      * Package types to installer class map
13      *
14      * @var array
15      */
16     private $supportedTypes = array(
17         'aimeos'       => 'AimeosInstaller',
18         'asgard'       => 'AsgardInstaller',
19         'attogram'     => 'AttogramInstaller',
20         'agl'          => 'AglInstaller',
21         'annotatecms'  => 'AnnotateCmsInstaller',
22         'bitrix'       => 'BitrixInstaller',
23         'bonefish'     => 'BonefishInstaller',
24         'cakephp'      => 'CakePHPInstaller',
25         'chef'         => 'ChefInstaller',
26         'ccframework'  => 'ClanCatsFrameworkInstaller',
27         'cockpit'      => 'CockpitInstaller',
28         'codeigniter'  => 'CodeIgniterInstaller',
29         'concrete5'    => 'Concrete5Installer',
30         'craft'        => 'CraftInstaller',
31         'croogo'       => 'CroogoInstaller',
32         'dokuwiki'     => 'DokuWikiInstaller',
33         'dolibarr'     => 'DolibarrInstaller',
34         'decibel'      => 'DecibelInstaller',
35         'drupal'       => 'DrupalInstaller',
36         'elgg'         => 'ElggInstaller',
37         'ee3'          => 'ExpressionEngineInstaller',
38         'ee2'          => 'ExpressionEngineInstaller',
39         'fuel'         => 'FuelInstaller',
40         'fuelphp'      => 'FuelphpInstaller',
41         'grav'         => 'GravInstaller',
42         'hurad'        => 'HuradInstaller',
43         'imagecms'     => 'ImageCMSInstaller',
44         'joomla'       => 'JoomlaInstaller',
45         'kirby'        => 'KirbyInstaller',
46         'kodicms'      => 'KodiCMSInstaller',
47         'kohana'       => 'KohanaInstaller',
48         'laravel'      => 'LaravelInstaller',
49         'lithium'      => 'LithiumInstaller',
50         'magento'      => 'MagentoInstaller',
51         'mako'         => 'MakoInstaller',
52         'mautic'       => 'MauticInstaller',
53         'mediawiki'    => 'MediaWikiInstaller',
54         'microweber'   => 'MicroweberInstaller',
55         'modulework'   => 'MODULEWorkInstaller',
56         'modxevo'      => 'MODXEvoInstaller',
57         'moodle'       => 'MoodleInstaller',
58         'october'      => 'OctoberInstaller',
59         'oxid'         => 'OxidInstaller',
60         'phpbb'        => 'PhpBBInstaller',
61         'pimcore'      => 'PimcoreInstaller',
62         'piwik'        => 'PiwikInstaller',
63         'plentymarkets'=> 'PlentymarketsInstaller',
64         'ppi'          => 'PPIInstaller',
65         'puppet'       => 'PuppetInstaller',
66         'radphp'       => 'RadPHPInstaller',
67         'phifty'       => 'PhiftyInstaller',
68         'redaxo'       => 'RedaxoInstaller',
69         'reindex'      => 'ReIndexInstaller',
70         'roundcube'    => 'RoundcubeInstaller',
71         'shopware'     => 'ShopwareInstaller',
72         'silverstripe' => 'SilverStripeInstaller',
73         'smf'          => 'SMFInstaller',
74         'symfony1'     => 'Symfony1Installer',
75         'thelia'       => 'TheliaInstaller',
76         'tusk'         => 'TuskInstaller',
77         'typo3-cms'    => 'TYPO3CmsInstaller',
78         'typo3-flow'   => 'TYPO3FlowInstaller',
79         'vanilla'      => 'VanillaInstaller',
80         'whmcs'        => 'WHMCSInstaller',
81         'wolfcms'      => 'WolfCMSInstaller',
82         'wordpress'    => 'WordPressInstaller',
83         'yawik'        => 'YawikInstaller',
84         'zend'         => 'ZendInstaller',
85         'zikula'       => 'ZikulaInstaller',
86         'prestashop'   => 'PrestashopInstaller'
87     );
88
89     /**
90      * {@inheritDoc}
91      */
92     public function getInstallPath(PackageInterface $package)
93     {
94         $type = $package->getType();
95         $frameworkType = $this->findFrameworkType($type);
96
97         if ($frameworkType === false) {
98             throw new \InvalidArgumentException(
99                 'Sorry the package type of this package is not yet supported.'
100             );
101         }
102
103         $class = 'Composer\\Installers\\' . $this->supportedTypes[$frameworkType];
104         $installer = new $class($package, $this->composer, $this->getIO());
105
106         return $installer->getInstallPath($package, $frameworkType);
107     }
108
109     public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package)
110     {
111         if (!$repo->hasPackage($package)) {
112             throw new \InvalidArgumentException('Package is not installed: '.$package);
113         }
114
115         $repo->removePackage($package);
116
117         $installPath = $this->getInstallPath($package);
118         $this->io->write(sprintf('Deleting %s - %s', $installPath, $this->filesystem->removeDirectory($installPath) ? '<comment>deleted</comment>' : '<error>not deleted</error>'));
119     }
120
121     /**
122      * {@inheritDoc}
123      */
124     public function supports($packageType)
125     {
126         $frameworkType = $this->findFrameworkType($packageType);
127
128         if ($frameworkType === false) {
129             return false;
130         }
131
132         $locationPattern = $this->getLocationPattern($frameworkType);
133
134         return preg_match('#' . $frameworkType . '-' . $locationPattern . '#', $packageType, $matches) === 1;
135     }
136
137     /**
138      * Finds a supported framework type if it exists and returns it
139      *
140      * @param  string $type
141      * @return string
142      */
143     protected function findFrameworkType($type)
144     {
145         $frameworkType = false;
146
147         krsort($this->supportedTypes);
148
149         foreach ($this->supportedTypes as $key => $val) {
150             if ($key === substr($type, 0, strlen($key))) {
151                 $frameworkType = substr($type, 0, strlen($key));
152                 break;
153             }
154         }
155
156         return $frameworkType;
157     }
158
159     /**
160      * Get the second part of the regular expression to check for support of a
161      * package type
162      *
163      * @param  string $frameworkType
164      * @return string
165      */
166     protected function getLocationPattern($frameworkType)
167     {
168         $pattern = false;
169         if (!empty($this->supportedTypes[$frameworkType])) {
170             $frameworkClass = 'Composer\\Installers\\' . $this->supportedTypes[$frameworkType];
171             /** @var BaseInstaller $framework */
172             $framework = new $frameworkClass(null, $this->composer, $this->getIO());
173             $locations = array_keys($framework->getLocations());
174             $pattern = $locations ? '(' . implode('|', $locations) . ')' : false;
175         }
176
177         return $pattern ? : '(\w+)';
178     }
179
180     /**
181      * Get I/O object
182      *
183      * @return IOInterface
184      */
185     private function getIO()
186     {
187         return $this->io;
188     }
189 }