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