Yaffs site version 1.1
[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         'eliasis'      => 'EliasisInstaller',
38         'ee3'          => 'ExpressionEngineInstaller',
39         'ee2'          => 'ExpressionEngineInstaller',
40         'fuel'         => 'FuelInstaller',
41         'fuelphp'      => 'FuelphpInstaller',
42         'grav'         => 'GravInstaller',
43         'hurad'        => 'HuradInstaller',
44         'imagecms'     => 'ImageCMSInstaller',
45         'itop'         => 'ItopInstaller',
46         'joomla'       => 'JoomlaInstaller',
47         'kanboard'     => 'KanboardInstaller',
48         'kirby'        => 'KirbyInstaller',
49         'kodicms'      => 'KodiCMSInstaller',
50         'kohana'       => 'KohanaInstaller',
51         'laravel'      => 'LaravelInstaller',
52         'lavalite'     => 'LavaLiteInstaller',
53         'lithium'      => 'LithiumInstaller',
54         'magento'      => 'MagentoInstaller',
55         'mako'         => 'MakoInstaller',
56         'maya'         => 'MayaInstaller',
57         'mautic'       => 'MauticInstaller',
58         'mediawiki'    => 'MediaWikiInstaller',
59         'microweber'   => 'MicroweberInstaller',
60         'modulework'   => 'MODULEWorkInstaller',
61         'modxevo'      => 'MODXEvoInstaller',
62         'moodle'       => 'MoodleInstaller',
63         'october'      => 'OctoberInstaller',
64         'ontowiki'     => 'OntoWikiInstaller',
65         'oxid'         => 'OxidInstaller',
66         'phpbb'        => 'PhpBBInstaller',
67         'pimcore'      => 'PimcoreInstaller',
68         'piwik'        => 'PiwikInstaller',
69         'plentymarkets'=> 'PlentymarketsInstaller',
70         'ppi'          => 'PPIInstaller',
71         'puppet'       => 'PuppetInstaller',
72         'radphp'       => 'RadPHPInstaller',
73         'phifty'       => 'PhiftyInstaller',
74         'porto'        => 'PortoInstaller',
75         'redaxo'       => 'RedaxoInstaller',
76         'reindex'      => 'ReIndexInstaller',
77         'roundcube'    => 'RoundcubeInstaller',
78         'shopware'     => 'ShopwareInstaller',
79         'silverstripe' => 'SilverStripeInstaller',
80         'smf'          => 'SMFInstaller',
81         'sydes'        => 'SyDESInstaller',
82         'symfony1'     => 'Symfony1Installer',
83         'thelia'       => 'TheliaInstaller',
84         'tusk'         => 'TuskInstaller',
85         'typo3-cms'    => 'TYPO3CmsInstaller',
86         'typo3-flow'   => 'TYPO3FlowInstaller',
87         'vanilla'      => 'VanillaInstaller',
88         'whmcs'        => 'WHMCSInstaller',
89         'wolfcms'      => 'WolfCMSInstaller',
90         'wordpress'    => 'WordPressInstaller',
91         'yawik'        => 'YawikInstaller',
92         'zend'         => 'ZendInstaller',
93         'zikula'       => 'ZikulaInstaller',
94         'prestashop'   => 'PrestashopInstaller'
95     );
96
97     /**
98      * {@inheritDoc}
99      */
100     public function getInstallPath(PackageInterface $package)
101     {
102         $type = $package->getType();
103         $frameworkType = $this->findFrameworkType($type);
104
105         if ($frameworkType === false) {
106             throw new \InvalidArgumentException(
107                 'Sorry the package type of this package is not yet supported.'
108             );
109         }
110
111         $class = 'Composer\\Installers\\' . $this->supportedTypes[$frameworkType];
112         $installer = new $class($package, $this->composer, $this->getIO());
113
114         return $installer->getInstallPath($package, $frameworkType);
115     }
116
117     public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package)
118     {
119         if (!$repo->hasPackage($package)) {
120             throw new \InvalidArgumentException('Package is not installed: '.$package);
121         }
122
123         $repo->removePackage($package);
124
125         $installPath = $this->getInstallPath($package);
126         $this->io->write(sprintf('Deleting %s - %s', $installPath, $this->filesystem->removeDirectory($installPath) ? '<comment>deleted</comment>' : '<error>not deleted</error>'));
127     }
128
129     /**
130      * {@inheritDoc}
131      */
132     public function supports($packageType)
133     {
134         $frameworkType = $this->findFrameworkType($packageType);
135
136         if ($frameworkType === false) {
137             return false;
138         }
139
140         $locationPattern = $this->getLocationPattern($frameworkType);
141
142         return preg_match('#' . $frameworkType . '-' . $locationPattern . '#', $packageType, $matches) === 1;
143     }
144
145     /**
146      * Finds a supported framework type if it exists and returns it
147      *
148      * @param  string $type
149      * @return string
150      */
151     protected function findFrameworkType($type)
152     {
153         $frameworkType = false;
154
155         krsort($this->supportedTypes);
156
157         foreach ($this->supportedTypes as $key => $val) {
158             if ($key === substr($type, 0, strlen($key))) {
159                 $frameworkType = substr($type, 0, strlen($key));
160                 break;
161             }
162         }
163
164         return $frameworkType;
165     }
166
167     /**
168      * Get the second part of the regular expression to check for support of a
169      * package type
170      *
171      * @param  string $frameworkType
172      * @return string
173      */
174     protected function getLocationPattern($frameworkType)
175     {
176         $pattern = false;
177         if (!empty($this->supportedTypes[$frameworkType])) {
178             $frameworkClass = 'Composer\\Installers\\' . $this->supportedTypes[$frameworkType];
179             /** @var BaseInstaller $framework */
180             $framework = new $frameworkClass(null, $this->composer, $this->getIO());
181             $locations = array_keys($framework->getLocations());
182             $pattern = $locations ? '(' . implode('|', $locations) . ')' : false;
183         }
184
185         return $pattern ? : '(\w+)';
186     }
187
188     /**
189      * Get I/O object
190      *
191      * @return IOInterface
192      */
193     private function getIO()
194     {
195         return $this->io;
196     }
197 }