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