47 lines
1007 B
PHP
47 lines
1007 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Csv\CsvReader;
|
|
use App\Csv\CsvWriter;
|
|
use App\CsvCalculationService;
|
|
use App\Logger\FileLogger;
|
|
use App\MathOperationFactory;
|
|
use App\Options\CliOption;
|
|
use App\Options\Long;
|
|
use App\Options\Short;
|
|
|
|
require __DIR__ . '/vendor/autoload.php';
|
|
|
|
if (count($argv) < 4) {
|
|
echo 'Usage: php console.php -a <action> -f <file>' . PHP_EOL;
|
|
exit(1);
|
|
}
|
|
|
|
|
|
$options = getopt(Short::asString(), Long::asArray());
|
|
|
|
if (!$options) {
|
|
echo 'Error getting arguments' . PHP_EOL;
|
|
exit(1);
|
|
}
|
|
|
|
try {
|
|
$cliOption = CliOption::fromArray($options);
|
|
} catch (RuntimeException $e) {
|
|
echo $e->getMessage();
|
|
exit(1);
|
|
}
|
|
|
|
try {
|
|
$csvCalculationService = new CsvCalculationService(
|
|
new CsvReader(__DIR__ . '/test.csv'),
|
|
new CsvWriter(__DIR__ . '/result.csv'),
|
|
MathOperationFactory::getOperationFromCliOption($cliOption),
|
|
new FileLogger(),
|
|
);
|
|
$csvCalculationService->execute();
|
|
} catch (Exception $e) {
|
|
echo $e->getMessage();
|
|
}
|