45 lines
1.3 KiB
PHP
45 lines
1.3 KiB
PHP
<?php
|
|
require 'app-config.php';
|
|
|
|
if (php_sapi_name() != 'cli') {
|
|
http_response_code(404);
|
|
die('Not Found');
|
|
}
|
|
|
|
/**
|
|
* Print a line with a newline character at the end (printf + newline = printfn; surprised this isn't built in!)
|
|
*
|
|
* @param string $format The format string
|
|
* @param mixed ...$values The values for the placeholders in the string
|
|
*/
|
|
function printfn(string $format, mixed ...$values): void {
|
|
printf($format . PHP_EOL, ...$values);
|
|
}
|
|
|
|
/**
|
|
* Display a title for a CLI run
|
|
*
|
|
* @param string $title The title to display on the command line
|
|
*/
|
|
function cli_title(string $title): void {
|
|
$appTitle = 'Feed Reader Central ~ v' . FRC_VERSION;
|
|
$dashes = ' +' . str_repeat('-', strlen($title) + 2) . '+' . str_repeat('-', strlen($appTitle) + 2) . '+';
|
|
printfn($dashes);
|
|
printfn(' | %s | %s |', $title, $appTitle);
|
|
printfn($dashes . PHP_EOL);
|
|
}
|
|
|
|
/**
|
|
* Capitalize the first letter of the given string
|
|
*
|
|
* @param string $value The string to be capitalized
|
|
* @return string The given string with the first letter capitalized
|
|
*/
|
|
function init_cap(string $value): string {
|
|
return match (strlen($value)) {
|
|
0 => "",
|
|
1 => strtoupper($value),
|
|
default => strtoupper(substr($value, 0, 1)) . substr($value, 1),
|
|
};
|
|
}
|