parent
852be3087b
commit
71cda91c42
3 changed files with 58 additions and 0 deletions
53
src/ncc/Classes/PerlExtension/PerlRunner.php
Normal file
53
src/ncc/Classes/PerlExtension/PerlRunner.php
Normal file
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
namespace ncc\Classes\PerlExtension;
|
||||
|
||||
use ncc\Abstracts\Runners;
|
||||
use ncc\Exceptions\FileNotFoundException;
|
||||
use ncc\Interfaces\RunnerInterface;
|
||||
use ncc\Objects\ExecutionPointers\ExecutionPointer;
|
||||
use ncc\Objects\Package\ExecutionUnit;
|
||||
use ncc\Objects\ProjectConfiguration\ExecutionPolicy;
|
||||
use ncc\ThirdParty\Symfony\Process\Process;
|
||||
use ncc\Utilities\Base64;
|
||||
use ncc\Utilities\IO;
|
||||
use ncc\Utilities\PathFinder;
|
||||
|
||||
class PerlRunner implements RunnerInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function processUnit(string $path, ExecutionPolicy $policy): ExecutionUnit
|
||||
{
|
||||
$execution_unit = new ExecutionUnit();
|
||||
$policy->Execute->Target = null;
|
||||
if(!file_exists($path) && !is_file($path))
|
||||
throw new FileNotFoundException($path);
|
||||
$execution_unit->ExecutionPolicy = $policy;
|
||||
$execution_unit->Data = Base64::encode(IO::fread($path));
|
||||
|
||||
return $execution_unit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function getFileExtension(): string
|
||||
{
|
||||
return '.pl';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function prepareProcess(ExecutionPointer $pointer): Process
|
||||
{
|
||||
$perl_bin = PathFinder::findRunner(Runners::perl);
|
||||
|
||||
if($pointer->ExecutionPolicy->Execute->Options !== null && count($pointer->ExecutionPolicy->Execute->Options) > 0)
|
||||
return new Process(array_merge([$perl_bin, $pointer->FilePointer], $pointer->ExecutionPolicy->Execute->Options));
|
||||
return new Process([$perl_bin, $pointer->FilePointer]);
|
||||
}
|
||||
}
|
|
@ -8,6 +8,7 @@
|
|||
use ncc\Abstracts\Runners;
|
||||
use ncc\Abstracts\Scopes;
|
||||
use ncc\Classes\BashExtension\BashRunner;
|
||||
use ncc\Classes\PerlExtension\PerlRunner;
|
||||
use ncc\Classes\PhpExtension\PhpRunner;
|
||||
use ncc\Exceptions\AccessDeniedException;
|
||||
use ncc\Exceptions\ExecutionUnitNotFoundException;
|
||||
|
@ -143,6 +144,7 @@
|
|||
$bin_file .= match ($unit->ExecutionPolicy->Runner) {
|
||||
Runners::bash => BashRunner::getFileExtension(),
|
||||
Runners::php => PhpRunner::getFileExtension(),
|
||||
Runners::perl => PerlRunner::getFileExtension(),
|
||||
default => throw new UnsupportedRunnerException('The runner \'' . $unit->ExecutionPolicy->Runner . '\' is not supported'),
|
||||
};
|
||||
|
||||
|
@ -276,6 +278,7 @@
|
|||
{
|
||||
Runners::bash => BashRunner::prepareProcess($unit),
|
||||
Runners::php => PhpRunner::prepareProcess($unit),
|
||||
Runners::perl => PerlRunner::prepareProcess($unit),
|
||||
default => throw new UnsupportedRunnerException('The runner \'' . $unit->ExecutionPolicy->Runner . '\' is not supported'),
|
||||
};
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
use ncc\Abstracts\Runners;
|
||||
use ncc\Abstracts\Scopes;
|
||||
use ncc\Classes\BashExtension\BashRunner;
|
||||
use ncc\Classes\PerlExtension\PerlRunner;
|
||||
use ncc\Classes\PhpExtension\PhpRunner;
|
||||
use ncc\Exceptions\AccessDeniedException;
|
||||
use ncc\Exceptions\FileNotFoundException;
|
||||
|
@ -260,6 +261,7 @@
|
|||
return match (strtolower($policy->Runner)) {
|
||||
Runners::bash => BashRunner::processUnit($path, $policy),
|
||||
Runners::php => PhpRunner::processUnit($path, $policy),
|
||||
Runners::perl => PerlRunner::processUnit($path, $policy),
|
||||
default => throw new UnsupportedRunnerException('The runner \'' . $policy->Runner . '\' is not supported'),
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue