| 1 |
<?php |
| 2 |
|
| 3 |
namespace Composer\Installers; |
| 4 |
|
| 5 |
/** |
| 6 |
* Plugin/theme installer for majima |
| 7 |
* @author David Neustadt |
| 8 |
*/ |
| 9 |
class MajimaInstaller extends BaseInstaller |
| 10 |
{ |
| 11 |
/** @var array<string, string> */ |
| 12 |
protected $locations = array( |
| 13 |
'plugin' => 'plugins/{$name}/', |
| 14 |
); |
| 15 |
|
| 16 |
/** |
| 17 |
* Transforms the names |
| 18 |
* |
| 19 |
* @param array<string, string> $vars |
| 20 |
* @return array<string, string> |
| 21 |
*/ |
| 22 |
public function inflectPackageVars(array $vars): array |
| 23 |
{ |
| 24 |
return $this->correctPluginName($vars); |
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* Change hyphenated names to camelcase |
| 29 |
* |
| 30 |
* @param array<string, string> $vars |
| 31 |
* @return array<string, string> |
| 32 |
*/ |
| 33 |
private function correctPluginName(array $vars): array |
| 34 |
{ |
| 35 |
$camelCasedName = preg_replace_callback('/(-[a-z])/', function ($matches) { |
| 36 |
return strtoupper($matches[0][1]); |
| 37 |
}, $vars['name']); |
| 38 |
|
| 39 |
if (null === $camelCasedName) { |
| 40 |
throw new \RuntimeException('Failed to run preg_replace_callback: '.preg_last_error()); |
| 41 |
} |
| 42 |
|
| 43 |
$vars['name'] = ucfirst($camelCasedName); |
| 44 |
return $vars; |
| 45 |
} |
| 46 |
} |
| 47 |
|