sbwerewolf/batch-file-scripting

Kit of utility classes for batch file scripting

v3.0.3 2023-04-13 07:27 UTC

This package is auto-updated.

Last update: 2024-04-13 09:51:13 UTC


README

Kit of utility classes for batch file scripting.

  • EnvReader - parse the .env files to array and define constants or environment variables
  • DurationConverter - prints duration in seconds or nanoseconds with human-readable format
  • Path - glue up file system path

Code examples in test.php

How to install

composer require sbwerewolf/batch-file-scripting

How to use EnvReader

$path = (new Path())->make(['.', 'config', 'test.env',]);
/* .env file location is './config/test.env' */
$env = new SbWereWolf\Scripting\Config\EnvReader($path);

var_dump($env->getVariables());
/*
array(4) {
    'USER' =>
  string(4) "root"
  'PORT' =>
  string(2) "80"
  'DATE' =>
  string(10) "2023-01-25"
  'FLAG' =>
  string(5) "FALSE"
}
*/
$env->defineConstants();
echo constant('USER') . PHP_EOL;
/* root */

$env->defineVariables();
echo getenv('FLAG') . PHP_EOL;
/* FALSE */

How to use DurationConverter

$printer = 
new SbWereWolf\Scripting\Convert\SecondsConverter('%dd, %H:%I:%S');
echo $printer->print(100000.111) . PHP_EOL;
/* 1d, 03:46:40 */

$printer = 
new SbWereWolf\Scripting\Convert\NanosecondsConverter('%dd, %H:%I:%S.%F%N');
echo $printer->print(100000999888777.999) . PHP_EOL;
/* 1d, 03:46:40.999888778 */

$printer = 
new SbWereWolf\Scripting\Convert\NanosecondsConverter('%L ms %U mcs %N ns');
echo $printer->print(99088077.999) . PHP_EOL;
/* 099 ms 088 mcs 077 ns */

How to use Path

$pathMaker = (new SbWereWolf\Scripting\FileSystem\Path());
$path = $pathMaker->make(['.', 'config', 'test.env',]);
echo $path . PHP_EOL;
/* .\config\test.env */

Contacts

Volkhin Nikolay
e-mail ulfnew@gmail.com
phone +7-902-272-65-35
Telegram @sbwerewolf

Chat with me via messenger