phpOMS/Utils/TaskSchedule/TaskFactory.php

54 lines
1.1 KiB
PHP

<?php
/**
* Orange Management
*
* PHP Version 7.1
*
* @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\OperatingSystem;
use phpOMS\System\SystemType;
/**
* Task factory.
*
* @package Framework
* @license OMS License 1.0
* @link http://website.orange-management.de
* @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
*
* @since 1.0.0
*/
public static function create(string $id = null, 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.');
}
}
}