PHP code example of sbwerewolf / batch-file-scripting

1. Go to this page and download the library: Download sbwerewolf/batch-file-scripting library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sbwerewolf / batch-file-scripting example snippets


$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 */

$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 */

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