parent
6679da8022
commit
852be3087b
3 changed files with 58 additions and 0 deletions
53
src/ncc/Classes/BashExtension/BashRunner.php
Normal file
53
src/ncc/Classes/BashExtension/BashRunner.php
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace ncc\Classes\BashExtension;
|
||||||
|
|
||||||
|
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 BashRunner implements RunnerInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public static function processUnit(string $path, ExecutionPolicy $policy): ExecutionUnit
|
||||||
|
{
|
||||||
|
$execution_unit = new ExecutionUnit();
|
||||||
|
if(!file_exists($path) && !is_file($path))
|
||||||
|
throw new FileNotFoundException($path);
|
||||||
|
$policy->Execute->Target = null;
|
||||||
|
$execution_unit->ExecutionPolicy = $policy;
|
||||||
|
$execution_unit->Data = Base64::encode(IO::fread($path));
|
||||||
|
|
||||||
|
return $execution_unit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public static function getFileExtension(): string
|
||||||
|
{
|
||||||
|
return '.bash';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public static function prepareProcess(ExecutionPointer $pointer): Process
|
||||||
|
{
|
||||||
|
$bash_bin = PathFinder::findRunner(Runners::bash);
|
||||||
|
|
||||||
|
if($pointer->ExecutionPolicy->Execute->Options !== null && count($pointer->ExecutionPolicy->Execute->Options) > 0)
|
||||||
|
return new Process(array_merge([$bash_bin, '-c', $pointer->FilePointer], $pointer->ExecutionPolicy->Execute->Options));
|
||||||
|
return new Process([$bash_bin, '-c', $pointer->FilePointer]);
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,6 +7,7 @@
|
||||||
use Exception;
|
use Exception;
|
||||||
use ncc\Abstracts\Runners;
|
use ncc\Abstracts\Runners;
|
||||||
use ncc\Abstracts\Scopes;
|
use ncc\Abstracts\Scopes;
|
||||||
|
use ncc\Classes\BashExtension\BashRunner;
|
||||||
use ncc\Classes\PhpExtension\PhpRunner;
|
use ncc\Classes\PhpExtension\PhpRunner;
|
||||||
use ncc\Exceptions\AccessDeniedException;
|
use ncc\Exceptions\AccessDeniedException;
|
||||||
use ncc\Exceptions\ExecutionUnitNotFoundException;
|
use ncc\Exceptions\ExecutionUnitNotFoundException;
|
||||||
|
@ -140,6 +141,7 @@
|
||||||
|
|
||||||
$bin_file = $package_bin_path . DIRECTORY_SEPARATOR . hash('haval128,4', $unit->ExecutionPolicy->Name);
|
$bin_file = $package_bin_path . DIRECTORY_SEPARATOR . hash('haval128,4', $unit->ExecutionPolicy->Name);
|
||||||
$bin_file .= match ($unit->ExecutionPolicy->Runner) {
|
$bin_file .= match ($unit->ExecutionPolicy->Runner) {
|
||||||
|
Runners::bash => BashRunner::getFileExtension(),
|
||||||
Runners::php => PhpRunner::getFileExtension(),
|
Runners::php => PhpRunner::getFileExtension(),
|
||||||
default => throw new UnsupportedRunnerException('The runner \'' . $unit->ExecutionPolicy->Runner . '\' is not supported'),
|
default => throw new UnsupportedRunnerException('The runner \'' . $unit->ExecutionPolicy->Runner . '\' is not supported'),
|
||||||
};
|
};
|
||||||
|
@ -272,6 +274,7 @@
|
||||||
|
|
||||||
$process = match (strtolower($unit->ExecutionPolicy->Runner))
|
$process = match (strtolower($unit->ExecutionPolicy->Runner))
|
||||||
{
|
{
|
||||||
|
Runners::bash => BashRunner::prepareProcess($unit),
|
||||||
Runners::php => PhpRunner::prepareProcess($unit),
|
Runners::php => PhpRunner::prepareProcess($unit),
|
||||||
default => throw new UnsupportedRunnerException('The runner \'' . $unit->ExecutionPolicy->Runner . '\' is not supported'),
|
default => throw new UnsupportedRunnerException('The runner \'' . $unit->ExecutionPolicy->Runner . '\' is not supported'),
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
use Exception;
|
use Exception;
|
||||||
use ncc\Abstracts\Runners;
|
use ncc\Abstracts\Runners;
|
||||||
use ncc\Abstracts\Scopes;
|
use ncc\Abstracts\Scopes;
|
||||||
|
use ncc\Classes\BashExtension\BashRunner;
|
||||||
use ncc\Classes\PhpExtension\PhpRunner;
|
use ncc\Classes\PhpExtension\PhpRunner;
|
||||||
use ncc\Exceptions\AccessDeniedException;
|
use ncc\Exceptions\AccessDeniedException;
|
||||||
use ncc\Exceptions\FileNotFoundException;
|
use ncc\Exceptions\FileNotFoundException;
|
||||||
|
@ -257,6 +258,7 @@
|
||||||
public static function compileRunner(string $path, ExecutionPolicy $policy): ExecutionUnit
|
public static function compileRunner(string $path, ExecutionPolicy $policy): ExecutionUnit
|
||||||
{
|
{
|
||||||
return match (strtolower($policy->Runner)) {
|
return match (strtolower($policy->Runner)) {
|
||||||
|
Runners::bash => BashRunner::processUnit($path, $policy),
|
||||||
Runners::php => PhpRunner::processUnit($path, $policy),
|
Runners::php => PhpRunner::processUnit($path, $policy),
|
||||||
default => throw new UnsupportedRunnerException('The runner \'' . $policy->Runner . '\' is not supported'),
|
default => throw new UnsupportedRunnerException('The runner \'' . $policy->Runner . '\' is not supported'),
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue