3 namespace Composer\Installers;
5 use Composer\Util\Filesystem;
8 * Installer for Bitrix Framework. Supported types of extensions:
9 * - `bitrix-d7-module` — copy the module to directory `bitrix/modules/<vendor>.<name>`.
10 * - `bitrix-d7-component` — copy the component to directory `bitrix/components/<vendor>/<name>`.
11 * - `bitrix-d7-template` — copy the template to directory `bitrix/templates/<vendor>_<name>`.
13 * You can set custom path to directory with Bitrix kernel in `composer.json`:
18 * "bitrix-dir": "s1/bitrix"
23 * @author Nik Samokhvalov <nik@samokhvalov.info>
24 * @author Denis Kulichkin <onexhovia@gmail.com>
26 class BitrixInstaller extends BaseInstaller
28 protected $locations = array(
29 'module' => '{$bitrix_dir}/modules/{$name}/', // deprecated, remove on the major release (Backward compatibility will be broken)
30 'component' => '{$bitrix_dir}/components/{$name}/', // deprecated, remove on the major release (Backward compatibility will be broken)
31 'theme' => '{$bitrix_dir}/templates/{$name}/', // deprecated, remove on the major release (Backward compatibility will be broken)
32 'd7-module' => '{$bitrix_dir}/modules/{$vendor}.{$name}/',
33 'd7-component' => '{$bitrix_dir}/components/{$vendor}/{$name}/',
34 'd7-template' => '{$bitrix_dir}/templates/{$vendor}_{$name}/',
38 * @var array Storage for informations about duplicates at all the time of installation packages.
40 private static $checkedDuplicates = array();
45 public function inflectPackageVars($vars)
47 if ($this->composer->getPackage()) {
48 $extra = $this->composer->getPackage()->getExtra();
50 if (isset($extra['bitrix-dir'])) {
51 $vars['bitrix_dir'] = $extra['bitrix-dir'];
55 if (!isset($vars['bitrix_dir'])) {
56 $vars['bitrix_dir'] = 'bitrix';
59 return parent::inflectPackageVars($vars);
65 protected function templatePath($path, array $vars = array())
67 $templatePath = parent::templatePath($path, $vars);
68 $this->checkDuplicates($templatePath, $vars);
74 * Duplicates search packages.
79 protected function checkDuplicates($path, array $vars = array())
81 $packageType = substr($vars['type'], strlen('bitrix') + 1);
82 $localDir = explode('/', $vars['bitrix_dir']);
84 $localDir[] = 'local';
85 $localDir = implode('/', $localDir);
87 $oldPath = str_replace(
88 array('{$bitrix_dir}', '{$name}'),
89 array($localDir, $vars['name']),
90 $this->locations[$packageType]
93 if (in_array($oldPath, static::$checkedDuplicates)) {
97 if ($oldPath !== $path && file_exists($oldPath) && $this->io && $this->io->isInteractive()) {
99 $this->io->writeError(' <error>Duplication of packages:</error>');
100 $this->io->writeError(' <info>Package ' . $oldPath . ' will be called instead package ' . $path . '</info>');
103 switch ($this->io->ask(' <info>Delete ' . $oldPath . ' [y,n,?]?</info> ', '?')) {
105 $fs = new Filesystem();
106 $fs->removeDirectory($oldPath);
114 $this->io->writeError(array(
115 ' y - delete package ' . $oldPath . ' and to continue with the installation',
116 ' n - don\'t delete and to continue with the installation',
118 $this->io->writeError(' ? - print help');
124 static::$checkedDuplicates[] = $oldPath;