phpOMS/Utils/TaskSchedule/TaskFactory.php
2022-02-19 13:57:39 +01:00

54 lines
1.2 KiB
PHP
Executable File

<?php
/**
* Karaka
*
* PHP Version 8.0
*
* @package phpOMS\Utils\TaskSchedule
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://karaka.app
*/
declare(strict_types=1);
namespace phpOMS\Utils\TaskSchedule;
use phpOMS\System\OperatingSystem;
use phpOMS\System\SystemType;
/**
* Task factory.
*
* @package phpOMS\Utils\TaskSchedule
* @license OMS License 1.0
* @link https://karaka.app
* @since 1.0.0
*/
final class TaskFactory
{
/**
* Create task instance.
*
* @param string $id Task id
* @param string $cmd Command to run
*
* @return TaskAbstract
*
* @throws \Exception This exception is thrown if the operating system is not supported
*
* @since 1.0.0
*/
public static function create(string $id = '', string $cmd = '') : TaskAbstract
{
switch (OperatingSystem::getSystem()) {
case SystemType::WIN:
return new Schedule($id, $cmd);
case SystemType::LINUX:
return new CronJob($id, $cmd);
default:
throw new \Exception('Unsupported system.');
}
}
}