code-snippets
/
vendor
/
composer
/
installers
/
src
/
Composer
/
Installers
/
TastyIgniterInstaller.php
TastyIgniterInstaller.php in Code Snippets 3.10.0, at vendor/composer/installers/src/Composer/Installers/TastyIgniterInstaller.php
| 1 | <?php |
| 2 | |
| 3 | namespace Composer\Installers; |
| 4 | |
| 5 | class TastyIgniterInstaller extends BaseInstaller |
| 6 | { |
| 7 | /** @var array<string, string> */ |
| 8 | protected $locations = [ |
| 9 | 'module' => 'app/{$name}/', |
| 10 | 'extension' => 'extensions/{$vendor}/{$name}/', |
| 11 | 'theme' => 'themes/{$name}/', |
| 12 | ]; |
| 13 | |
| 14 | /** |
| 15 | * Format package name. |
| 16 | * |
| 17 | * Cut off leading 'ti-ext-' or 'ti-theme-' if present. |
| 18 | * Strip vendor name of characters that is not alphanumeric or an underscore |
| 19 | * |
| 20 | */ |
| 21 | public function inflectPackageVars(array $vars): array |
| 22 | { |
| 23 | $extra = $this->package->getExtra(); |
| 24 | |
| 25 | if ($vars['type'] === 'tastyigniter-module') { |
| 26 | return $this->inflectModuleVars($vars); |
| 27 | } |
| 28 | |
| 29 | if ($vars['type'] === 'tastyigniter-extension') { |
| 30 | return $this->inflectExtensionVars($vars, $extra); |
| 31 | } |
| 32 | |
| 33 | if ($vars['type'] === 'tastyigniter-theme') { |
| 34 | return $this->inflectThemeVars($vars, $extra); |
| 35 | } |
| 36 | |
| 37 | return $vars; |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * @param array<string, string> $vars |
| 42 | * @return array<string, string> |
| 43 | */ |
| 44 | protected function inflectModuleVars(array $vars): array |
| 45 | { |
| 46 | $vars['name'] = $this->pregReplace('/^ti-module-/', '', $vars['name']); |
| 47 | |
| 48 | return $vars; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * @param array<string, string> $vars |
| 53 | * @param array<string, mixed> $extra |
| 54 | * @return array<string, string> |
| 55 | */ |
| 56 | protected function inflectExtensionVars(array $vars, array $extra): array |
| 57 | { |
| 58 | if (!empty($extra['tastyigniter-extension']['code'])) { |
| 59 | $parts = explode('.', $extra['tastyigniter-extension']['code']); |
| 60 | $vars['vendor'] = (string)$parts[0]; |
| 61 | $vars['name'] = (string)($parts[1] ?? ''); |
| 62 | } |
| 63 | |
| 64 | $vars['vendor'] = $this->pregReplace('/[^a-z0-9_]/i', '', $vars['vendor']); |
| 65 | $vars['name'] = $this->pregReplace('/^ti-ext-/', '', $vars['name']); |
| 66 | |
| 67 | return $vars; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * @param array<string, string> $vars |
| 72 | * @param array<string, mixed> $extra |
| 73 | * @return array<string, string> |
| 74 | */ |
| 75 | protected function inflectThemeVars(array $vars, array $extra): array |
| 76 | { |
| 77 | if (!empty($extra['tastyigniter-theme']['code'])) { |
| 78 | $vars['name'] = $extra['tastyigniter-theme']['code']; |
| 79 | } |
| 80 | |
| 81 | $vars['name'] = $this->pregReplace('/^ti-theme-/', '', $vars['name']); |
| 82 | |
| 83 | return $vars; |
| 84 | } |
| 85 | } |
| 86 |