rosavox/lib/alveolata/tools/functions.php
2025-05-23 07:33:29 +00:00

65 lines
920 B
PHP

<?php
namespace alveolata\tools;
/**
* @author Christian Fraß <frass@greenscale.de>
*/
function input(
string $message
)
{
error_log($message);
$handle = fopen('php://stdin','r');
$input = fgets($handle);
return $input;
}
/**
* @author Christian Fraß <frass@greenscale.de>
*/
function confirm(
string $message
)
{
return (trim(input($message . ' [y/n]')) === 'y');
}
/**
* halts the excution until ENTER is pressed
*
* @author Christian Fraß <frass@greenscale.de>
*/
function pause(
)
{
error_log('-- PAUSED -- press <ENTER> to continue');
$handle = fopen('php://stdin','r');
fgets($handle);
}
/**
* wraps a procedure with try-catch
*
* @author Christian Fraß <frass@greenscale.de>
*/
function soften(
\Closure $procedure,
bool $silent = false
) : void
{
try {
$procedure();
}
catch (\Throwable $throwable) {
if (! $silent) {
error_log(strval($throwable));
}
}
}
?>