phpOMS/Utils/TaskSchedule/SchedulerAbstract.php

108 lines
1.9 KiB
PHP

<?php
/**
* Orange Management
*
* PHP Version 7.2
*
* @package TBD
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://website.orange-management.de
*/
declare(strict_types=1);
namespace phpOMS\Utils\TaskSchedule;
use phpOMS\System\File\PathException;
/**
* Scheduler abstract.
*
* @package Framework
* @license OMS License 1.0
* @link http://website.orange-management.de
* @since 1.0.0
* @codeCoverageIgnore
*/
abstract class SchedulerAbstract
{
/**
* Bin path.
*
* @var string
* @since 1.0.0
*/
protected static $bin = '';
/**
* Get git binary.
*
* @return string
*
* @since 1.0.0
*/
public static function getBin() : string
{
return self::$bin;
}
/**
* Set git binary.
*
* @param string $path Git path
*
* @return void
*
* @throws PathException
*
* @since 1.0.0
*/
public static function setBin(string $path) : void
{
if (realpath($path) === false) {
throw new PathException($path);
}
self::$bin = realpath($path);
}
/**
* Test git.
*
* @return bool
*
* @since 1.0.0
* @codeCoverageIgnore
*/
public static function test() : bool
{
$pipes = [];
$resource = proc_open(escapeshellarg(self::$bin), [1 => ['pipe', 'w'], 2 => ['pipe', 'w']], $pipes);
$stdout = stream_get_contents($pipes[1]);
$stderr = stream_get_contents($pipes[2]);
foreach ($pipes as $pipe) {
fclose($pipe);
}
return trim(proc_close($resource)) !== 127;
}
/**
* Create task
*
* @param TaskAbstract $task Task to create
*
* @return void
*
* @since 1.0.0
*/
public function create(TaskAbstract $task) : void
{
$this->run($task->getCommand());
}
}