| 1 |
<?php |
| 2 |
|
| 3 |
namespace Composer\Installers; |
| 4 |
|
| 5 |
use Composer\Package\PackageInterface; |
| 6 |
|
| 7 |
class OxidInstaller extends BaseInstaller |
| 8 |
{ |
| 9 |
const VENDOR_PATTERN = '/^modules\/(?P<vendor>.+)\/.+/'; |
| 10 |
|
| 11 |
/** @var array<string, string> */ |
| 12 |
protected $locations = array( |
| 13 |
'module' => 'modules/{$name}/', |
| 14 |
'theme' => 'application/views/{$name}/', |
| 15 |
'out' => 'out/{$name}/', |
| 16 |
); |
| 17 |
|
| 18 |
public function getInstallPath(PackageInterface $package, string $frameworkType = ''): string |
| 19 |
{ |
| 20 |
$installPath = parent::getInstallPath($package, $frameworkType); |
| 21 |
$type = $this->package->getType(); |
| 22 |
if ($type === 'oxid-module') { |
| 23 |
$this->prepareVendorDirectory($installPath); |
| 24 |
} |
| 25 |
return $installPath; |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* Makes sure there is a vendormetadata.php file inside |
| 30 |
* the vendor folder if there is a vendor folder. |
| 31 |
*/ |
| 32 |
protected function prepareVendorDirectory(string $installPath): void |
| 33 |
{ |
| 34 |
$matches = ''; |
| 35 |
$hasVendorDirectory = preg_match(self::VENDOR_PATTERN, $installPath, $matches); |
| 36 |
if (!$hasVendorDirectory) { |
| 37 |
return; |
| 38 |
} |
| 39 |
|
| 40 |
$vendorDirectory = $matches['vendor']; |
| 41 |
$vendorPath = getcwd() . '/modules/' . $vendorDirectory; |
| 42 |
if (!file_exists($vendorPath)) { |
| 43 |
mkdir($vendorPath, 0755, true); |
| 44 |
} |
| 45 |
|
| 46 |
$vendorMetaDataPath = $vendorPath . '/vendormetadata.php'; |
| 47 |
touch($vendorMetaDataPath); |
| 48 |
} |
| 49 |
} |
| 50 |
|