-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved installer utilities to traits and classes.
- Loading branch information
1 parent
a63b55a
commit b5f98b3
Showing
13 changed files
with
2,470 additions
and
2,400 deletions.
There are no files selected for viewing
2,413 changes: 147 additions & 2,266 deletions
2,413
.vortex/installer/src/Command/InstallCommand.php
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DrevOps\Installer; | ||
|
||
/** | ||
* Installer configuration. | ||
* | ||
* Installer config is a config of this installer script. For configs of the | ||
* project being installed, @see get_answer(). | ||
* | ||
* @package DrevOps\Installer | ||
*/ | ||
class Config { | ||
|
||
/** | ||
* Installer configuration. | ||
* | ||
* @var array<string,mixed> | ||
*/ | ||
protected array $config = []; | ||
|
||
/** | ||
* Get a configuration value or default. | ||
*/ | ||
public function get(string $name, mixed $default = NULL): mixed { | ||
return $this->config[$name] ?? $default; | ||
} | ||
|
||
/** | ||
* Set a configuration value. | ||
*/ | ||
public function set(string $name, mixed $value): void { | ||
if (!is_null($value)) { | ||
$this->config[$name] = $value; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DrevOps\Installer; | ||
|
||
/** | ||
* Converter. | ||
* | ||
* Convert strings to different formats. | ||
* | ||
* @package DrevOps\Installer | ||
*/ | ||
class Converter { | ||
|
||
public static function toCamelCase(string $value, bool $capitalise_first = FALSE): string { | ||
$value = str_replace(' ', '', ucwords((string) preg_replace('/[^a-zA-Z0-9]/', ' ', $value))); | ||
|
||
return $capitalise_first ? $value : lcfirst($value); | ||
} | ||
|
||
public static function toHumanName(string $value): ?string { | ||
$value = preg_replace('/[^a-zA-Z0-9]/', ' ', $value); | ||
$value = trim((string) $value); | ||
|
||
return preg_replace('/\s{2,}/', ' ', $value); | ||
} | ||
|
||
/** | ||
* Convert string to machine name. | ||
* | ||
* @param string $value | ||
* Value to convert. | ||
* @param array<int|string> $preserve_chars | ||
* Array of characters to preserve. | ||
* | ||
* @return string | ||
* Converted value. | ||
*/ | ||
public static function toMachineName(string $value, array $preserve_chars = []): string { | ||
$preserve = ''; | ||
foreach ($preserve_chars as $char) { | ||
$preserve .= preg_quote(strval($char), '/'); | ||
} | ||
$pattern = '/[^a-zA-Z0-9' . $preserve . ']/'; | ||
|
||
$value = preg_replace($pattern, '_', $value); | ||
|
||
return strtolower($value); | ||
} | ||
|
||
public static function toAbbreviation(string $value, int $length = 2, string $word_delim = '_'): string { | ||
$value = trim($value); | ||
$value = str_replace(' ', '_', $value); | ||
$parts = empty($word_delim) ? [$value] : explode($word_delim, $value); | ||
|
||
if (count($parts) == 1) { | ||
return strlen($parts[0]) > $length ? substr($parts[0], 0, $length) : $value; | ||
} | ||
|
||
$value = implode('', array_map(static function (string $word): string { | ||
return substr($word, 0, 1); | ||
}, $parts)); | ||
|
||
return substr($value, 0, $length); | ||
} | ||
|
||
public static function snakeToPascal(string $string): string { | ||
return str_replace(' ', '', ucwords(str_replace('_', ' ', $string))); | ||
} | ||
|
||
} |
Oops, something went wrong.
b5f98b3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀 Deployed on https://6763fc1c9331aa03fe92def5--vortex-docs.netlify.app