From 961a386e12cd0714515143db18a55bec8239877c Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 18 Dec 2015 17:44:23 +0100 Subject: [PATCH] Split --- Asset/AssetType.php | 5 +- Log/FileLogger.php | 87 +++- Math/Algebra/PointPolygonIntersection.php | 84 ++++ Model/Html/Head.php | 20 + Module/ModuleManager.php | 4 +- Utils/SystemUtils.php | 19 +- Utils/TaskSchedule/Cron.php | 61 +++ Utils/TaskSchedule/CronJob.php | 85 ++++ Utils/TaskSchedule/Interval.php | 375 ++++++++++++++++++ .../InvalidTaskParameterExceltion.php | 37 ++ Utils/TaskSchedule/Schedule.php | 60 +++ Utils/TaskSchedule/ScheduleInterface.php | 40 ++ Utils/TaskSchedule/TaskInterface.php | 33 ++ Utils/TaskSchedule/TaskScheduler.php | 59 +++ Version/Version.php | 8 +- 15 files changed, 939 insertions(+), 38 deletions(-) create mode 100644 Math/Algebra/PointPolygonIntersection.php create mode 100644 Utils/TaskSchedule/Cron.php create mode 100644 Utils/TaskSchedule/CronJob.php create mode 100644 Utils/TaskSchedule/Interval.php create mode 100644 Utils/TaskSchedule/InvalidTaskParameterExceltion.php create mode 100644 Utils/TaskSchedule/Schedule.php create mode 100644 Utils/TaskSchedule/ScheduleInterface.php create mode 100644 Utils/TaskSchedule/TaskInterface.php create mode 100644 Utils/TaskSchedule/TaskScheduler.php diff --git a/Asset/AssetType.php b/Asset/AssetType.php index 7574b16e9..27f5e302b 100644 --- a/Asset/AssetType.php +++ b/Asset/AssetType.php @@ -32,6 +32,7 @@ use phpOMS\Datatypes\Enum; */ abstract class AssetType extends Enum { - const CSS = 'css'; - const JS = 'js'; + const CSS = 'css'; + const JS = 'js'; + const JSLATE = 'jslate'; } diff --git a/Log/FileLogger.php b/Log/FileLogger.php index c4bfbe7bc..50c93752e 100644 --- a/Log/FileLogger.php +++ b/Log/FileLogger.php @@ -32,6 +32,7 @@ use phpOMS\System\FilePathException; class FileLogger implements LoggerInterface { const MSG_BACKTRACE = '{datetime}; {level}; {ip}; {message}; {backtrace}'; + const MSG_FULL = '{datetime}; {level}; {ip}; {line}; {version}; {os}; {message}; {file}; {backtrace}'; const MSG_SIMPLE = '{datetime}; {level}; {ip}; {message};'; /** @@ -76,21 +77,21 @@ class FileLogger implements LoggerInterface * * Creates the logging object and overwrites all default values. * - * @param \string $path Path for logging + * @param \string $lpath Path for logging * * @since 1.0.0 * @author Dennis Eichhorn */ - public function __construct(\string $path) + public function __construct(\string $lpath) { - if(!file_exists($path)) { - mkdir($path); + if (!file_exists($lpath)) { + mkdir($lpath); } - $path = realpath($path); + $path = realpath($lpath); if (strpos($path, ROOT_PATH) === false) { - throw new FilePathException($path); + throw new FilePathException($lpath); } if (!file_exists($path)) { @@ -223,12 +224,11 @@ class FileLogger implements LoggerInterface $backtrace = debug_backtrace(); - if (isset($backtrace[0])) { - unset($backtrace[0]); - } - - if (isset($backtrace[1])) { - unset($backtrace[1]); + // Removing sensitive config data from logging + foreach ($backtrace as $key => $value) { + if (isset($value['args'])) { + unset($backtrace[$key]['args']); + } } $backtrace = json_encode($backtrace); @@ -237,6 +237,8 @@ class FileLogger implements LoggerInterface $replace['{datetime}'] = sprintf('%--19s', (new \DateTime('NOW'))->format('Y-m-d H:i:s')); $replace['{level}'] = sprintf('%--12s', $level); $replace['{ip}'] = sprintf('%--15s', $_SERVER['REMOTE_ADDR']); + $replace['{version}'] = sprintf('%--15s', PHP_VERSION); + $replace['{os}'] = sprintf('%--15s', PHP_OS); return strtr($message, $replace); } @@ -261,6 +263,16 @@ class FileLogger implements LoggerInterface return ($a['time'] > $b['time']) ? -1 : 1; } + /** + * Write to file. + * + * @param \string $message + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ private function write(\string $message) { $this->fp = fopen($this->path, 'a'); @@ -275,6 +287,9 @@ class FileLogger implements LoggerInterface * @param array $context * * @return null + * + * @since 1.0.0 + * @author Dennis Eichhorn */ public function emergency(\string $message, array $context = []) { @@ -291,7 +306,10 @@ class FileLogger implements LoggerInterface * @param \string $message * @param array $context * - * @return null + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn */ public function alert(\string $message, array $context = []) { @@ -307,7 +325,10 @@ class FileLogger implements LoggerInterface * @param \string $message * @param array $context * - * @return null + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn */ public function critical(\string $message, array $context = []) { @@ -322,7 +343,10 @@ class FileLogger implements LoggerInterface * @param \string $message * @param array $context * - * @return null + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn */ public function error(\string $message, array $context = []) { @@ -339,7 +363,10 @@ class FileLogger implements LoggerInterface * @param \string $message * @param array $context * - * @return null + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn */ public function warning(\string $message, array $context = []) { @@ -353,7 +380,10 @@ class FileLogger implements LoggerInterface * @param \string $message * @param array $context * - * @return null + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn */ public function notice(\string $message, array $context = []) { @@ -369,7 +399,10 @@ class FileLogger implements LoggerInterface * @param \string $message * @param array $context * - * @return null + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn */ public function info(\string $message, array $context = []) { @@ -383,7 +416,10 @@ class FileLogger implements LoggerInterface * @param \string $message * @param array $context * - * @return null + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn */ public function debug(\string $message, array $context = []) { @@ -398,7 +434,10 @@ class FileLogger implements LoggerInterface * @param \string $message * @param array $context * - * @return null + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn */ public function log(\string $level, \string $message, array $context = []) { @@ -530,8 +569,12 @@ class FileLogger implements LoggerInterface $log['datetime'] = $line[0] ?? ''; $log['level'] = $line[1] ?? ''; $log['ip'] = $line[2] ?? ''; - $log['message'] = $line[3] ?? ''; - $log['backtrace'] = $line[4] ?? ''; + $log['line'] = $line[3] ?? ''; + $log['version'] = $line[4] ?? ''; + $log['os'] = $line[5] ?? ''; + $log['message'] = $line[6] ?? ''; + $log['file'] = $line[7] ?? ''; + $log['backtrace'] = $line[8] ?? ''; break; } diff --git a/Math/Algebra/PointPolygonIntersection.php b/Math/Algebra/PointPolygonIntersection.php new file mode 100644 index 000000000..0dec9b40d --- /dev/null +++ b/Math/Algebra/PointPolygonIntersection.php @@ -0,0 +1,84 @@ + + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace phpOMS\Math\Algebra; + +class PointPolygonIntersection +{ + const EPSILON = 1E-6; + + private function __construct() + { + } + + public static function pointInPolygon(array $point, array $vertices) : \int + { + $length = count($vertices); + + // Polygon has to start and end with same point + if ($vertices[0]['x'] !== $vertices[$length - 1]['x'] || $vertices[0]['y'] !== $vertices[$length - 1]['y']) { + $vertices[] = $vertices[0]; + } + + // On vertex? + if (self::isOnVertex($point, $vertices)) { + return 0; + } + + // Inside or ontop? + $countIntersect = 0; + $vertices_count = count($vertices); + + // todo: return based on highest possibility not by first match + for ($i = 1; $i < $vertices_count; $i++) { + $vertex1 = $vertices[$i - 1]; + $vertex2 = $vertices[$i]; + + if (abs($vertex1['y'] - $vertex2['y']) < self::EPSILON && abs($vertex1['y'] - $point['y']) < self::EPSILON && $point['x'] > min($vertex1['x'], $vertex2['x']) && $point['x'] < max($vertex1['x'], $vertex2['x'])) { + return 0; // boundary + } + + if ($point['y'] > min($vertex1['y'], $vertex2['y']) && $point['y'] <= max($vertex1['y'], $vertex2['y']) && $point['x'] <= max($vertex1['x'], $vertex2['x']) && abs($vertex1['y'] - $vertex2['y']) >= self::EPSILON) { + $xinters = ($point['y'] - $vertex1['y']) * ($vertex2['x'] - $vertex1['x']) / ($vertex2['y'] - $vertex1['y']) + $vertex1['x']; + + if (abs($xinters - $point['x']) < self::EPSILON) { + return 0; // boundary + } + + if (abs($vertex1['x'] - $vertex2['x']) < self::EPSILON || $point['x'] < $xinters) { + $countIntersect++; + } + } + } + + if ($countIntersect % 2 != 0) { + return -1; + } + + return 1; + } + + private static function isOnVertex($point, $vertices) + { + foreach ($vertices as $vertex) { + if (abs($point['x'] - $vertex['x']) < self::EPSILON && abs($point['y'] - $vertex['y']) < self::EPSILON) { + return true; + } + } + + return false; + } +} + diff --git a/Model/Html/Head.php b/Model/Html/Head.php index 1110d5523..4f9ae285b 100644 --- a/Model/Html/Head.php +++ b/Model/Html/Head.php @@ -315,4 +315,24 @@ class Head implements RenderableInterface return $asset; } + + /** + * Render assets. + * + * @return \string + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function renderAssetsLate() : \string + { + $asset = ''; + foreach ($this->assets as $uri => $type) { + if ($type === AssetType::JSLATE) { + $asset .= ''; + } + } + + return $asset; + } } diff --git a/Module/ModuleManager.php b/Module/ModuleManager.php index fa844c91b..2c8c5af66 100644 --- a/Module/ModuleManager.php +++ b/Module/ModuleManager.php @@ -250,7 +250,7 @@ class ModuleManager if (file_exists($path)) { if(strpos($path, self::MODULE_PATH) === false) { - throw new FilePathException($path); + throw new FilePathException(self::MODULE_PATH . '/' . $files[$i] . '/info.json'); } $json = json_decode(file_get_contents($path), true); @@ -300,7 +300,7 @@ class ModuleManager if ($path !== false) { if(strpos($path, self::MODULE_PATH) === false) { - throw new FilePathException($path); + throw new FilePathException(self::MODULE_PATH . '/' . $module . '/' . 'info.json'); } $info = json_decode(file_get_contents($path), true); diff --git a/Utils/SystemUtils.php b/Utils/SystemUtils.php index 5fef199b2..4d78be74e 100644 --- a/Utils/SystemUtils.php +++ b/Utils/SystemUtils.php @@ -55,15 +55,18 @@ class SystemUtils { $countSize = 0; $count = 0; - $dir_array = scandir($dir); - foreach ($dir_array as $key => $filename) { - if ($filename != ".." && $filename != ".") { - if (is_dir($dir . "/" . $filename)) { - $countSize += self::getFolderSize($dir . "/" . $filename); - } else if (is_file($dir . "/" . $filename)) { - $countSize += filesize($dir . "/" . $filename); - $count++; + if(is_readable($dir)) { + $dir_array = scandir($dir); + + foreach ($dir_array as $key => $filename) { + if ($filename != ".." && $filename != ".") { + if (is_dir($dir . "/" . $filename)) { + $countSize += self::getFolderSize($dir . "/" . $filename); + } else if (is_file($dir . "/" . $filename)) { + $countSize += filesize($dir . "/" . $filename); + $count++; + } } } } diff --git a/Utils/TaskSchedule/Cron.php b/Utils/TaskSchedule/Cron.php new file mode 100644 index 000000000..56a2fc12b --- /dev/null +++ b/Utils/TaskSchedule/Cron.php @@ -0,0 +1,61 @@ + + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace phpOMS\Utils\TaskSchedule; + +/** + * Array utils. + * + * @category Framework + * @package Utils + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class Cron implements ScheduleInterface +{ + public function __construct() { + + } + + public function add(TaskInterface $task) + { + // TODO: Implement add() method. + } + + public function remove($id) + { + // TODO: Implement remove() method. + } + + public function get(\string $id) + { + // TODO: Implement get() method. + } + + public function list() + { + $output = shell_exec('crontab -l'); + + return $output; + } + + public function set(TaskInterface $task) + { + // TODO: Implement set() method. + } +} diff --git a/Utils/TaskSchedule/CronJob.php b/Utils/TaskSchedule/CronJob.php new file mode 100644 index 000000000..9a38f1445 --- /dev/null +++ b/Utils/TaskSchedule/CronJob.php @@ -0,0 +1,85 @@ + + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace phpOMS\Utils\TaskSchedule; + +/** + * Array utils. + * + * @category Framework + * @package Utils + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class CronJob implements TaskInterface +{ + + /** + * Interval. + * + * @var Interval + * @since 1.0.0 + */ + private $interval = null; + private $command = ''; + + public function __construct(\string $cronjob) + { + + } + + public function setInterval(Interval $interval) + { + $this->interval = $interval; + } + + public function setCommand(\string $command) + { + $this->command = $command; + } + + public function __toString() + { + $minute = $this->printValue($this->interval->getMinute()); + $hour = $this->printValue($this->interval->getHour()); + $dayOfMonth = $this->printValue($this->interval->getDayOfMonth()); + $month = $this->printValue($this->interval->getMonth()); + $dayOfWeek = $this->printValue($this->interval->getDayOfWeek()); + + return $minute . ' ' . $hour . ' ' . $dayOfMonth . ' ' . $month . ' ' . $dayOfWeek . ' ' . $this->command; + } + + private function printValue(array $value) : \string + { + if (($count = count($value['dayOfWeek'])) > 0) { + $parsed = implode(',', $value['dayOfWeek']); + } elseif ($value['start'] !== 0 && $value['end']) { + $parsed = $value['start'] . '-' . $value['end']; + $count = 2; + } else { + $parsed = '*'; + $count = 1; + } + + if ($count === 0 && $value['step'] !== 0) { + $parsed .= '/' . $value['step']; + } + + return $parsed; + } +} diff --git a/Utils/TaskSchedule/Interval.php b/Utils/TaskSchedule/Interval.php new file mode 100644 index 000000000..96431b61b --- /dev/null +++ b/Utils/TaskSchedule/Interval.php @@ -0,0 +1,375 @@ + + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace phpOMS\Utils\TaskSchedule; + +/** + * Array utils. + * + * @category Framework + * @package Utils + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class Interval +{ + + private $minute = []; + private $hour = []; + private $dayOfMonth = []; + private $month = []; + private $dayOfWeek = []; + private $year = []; + + public function __construct(\string $interval) + { + $this->parse($interval); + } + + public function parse(\string $interval) + { + $elements = explode(' ', $interval); + } + + public function parseMinute(\string $minute) : array + { + + } + + public function parseHour(\string $hour) : array + { + + } + + public function parseDayOfMonth(\string $dayOfMonth) : array + { + + } + + public function parseMonth(\string $month) : array + { + + } + + public function parseDayOfWeek(\string $dayOfWeek) : array + { + + } + + public function parseYear(\string $year) : array + { + + } + + public function setMinute(array $min, \int $start = 0, \int $end = 0, \int $step = 0, \bool $any = false) + { + $this->minute = [ + 'minutes' => $min, + 'start' => $start, + 'end' => $end, + 'step' => $step, + 'any' => $any, + ]; + + $this->validateMinute(); + } + + public function setHour(array $hour, \int $start = 0, \int $end = 0, \int $step = 0, \bool $any = false) + { + $this->hour = [ + 'hours' => $hour, + 'start' => $start, + 'end' => $end, + 'step' => $step, + 'any' => $any, + ]; + + $this->validateHour(); + } + + public function setDayOfMonth(array $dayOfMonth, \int $start = 0, \int $end = 0, \int $step = 0, \bool $any = false, \bool $last = false, \int $nearest = 0) + { + $this->dayOfMonth = [ + 'dayOfMonth' => $dayOfMonth, + 'start' => $start, + 'end' => $end, + 'step' => $step, + 'any' => $any, + 'last' => $last, + 'nearest' => $nearest, + ]; + + $this->validateDayOfMonth(); + } + + public function setMonth(array $month, \int $start = 0, \int $end = 0, \int $step = 0, \bool $any = false) + { + $this->month = [ + 'month' => $month, + 'start' => $start, + 'end' => $end, + 'step' => $step, + 'any' => $any, + ]; + + $this->validateMonth(); + } + + public function setDayOfWeek(array $dayOfWeek, \int $start = 0, \int $end = 0, \int $step = 0, \bool $any = false, \bool $last = false) + { + $this->dayOfWeek = [ + 'dayOfWeek' => $dayOfWeek, + 'start' => $start, + 'end' => $end, + 'step' => $step, + 'any' => $any, + 'last' => $last, + ]; + + $this->validateDayOfWeek(); + } + + public function setYear(array $year, \int $start = 0, \int $end = 0, \int $step = 0, \bool $any = false) + { + $this->year = [ + 'year' => $year, + 'start' => $start, + 'end' => $end, + 'step' => $step, + 'any' => $any, + ]; + + $this->validateYear(); + } + + public function getMinute() : array + { + return $this->minute; + } + + public function getHour() : array + { + return $this->hour; + } + + public function getDayOfMonth() : array + { + return $this->dayOfMonth; + } + + public function getDayOfWeek() : array + { + return $this->dayOfWeek; + } + + public function getMonth() : array + { + return $this->month; + } + + public function getYear() : array + { + return $this->year; + } + + public function validate() : \bool + { + if (!$this->validateMinute()) return false; + if (!$this->validateHour()) return false; + if (!$this->validateDayOfMonth()) return false; + if (!$this->validateMonth()) return false; + if (!$this->validateDayOfWeek()) return false; + if (!$this->validateYear()) return false; + + return true; + } + + private function validateMinute() : \bool + { + foreach ($this->minute['minutes'] as $minute) { + if ($minute > 59 || $minute < 0) return false; + } + + if ($this->minute['start'] > 59 || $this->minute['start'] < 0) return false; + if ($this->minute['end'] > 59 || $this->minute['end'] < 0) return false; + if ($this->minute['step'] > 59 || $this->minute['step'] < 0) return false; + + return true; + } + + private function validateHour() : \bool + { + foreach ($this->hour['hours'] as $hour) { + if ($hour > 23 || $hour < 0) return false; + } + + if ($this->hour['start'] > 23 || $this->hour['start'] < 0) return false; + if ($this->hour['end'] > 23 || $this->hour['end'] < 0) return false; + if ($this->hour['step'] > 23 || $this->hour['step'] < 0) return false; + + return true; + } + + private function validateDayOfMonth() : \bool + { + foreach ($this->dayOfMonth['dayOfMonth'] as $dayOfMonth) { + if ($dayOfMonth > 31 || $dayOfMonth < 1) return false; + } + + if ($this->dayOfMonth['start'] > 31 || $this->dayOfMonth['start'] < 1) return false; + if ($this->dayOfMonth['end'] > 31 || $this->dayOfMonth['end'] < 1) return false; + if ($this->dayOfMonth['step'] > 31 || $this->dayOfMonth['step'] < 1) return false; + if ($this->dayOfMonth['nearest'] > 31 || $this->dayOfMonth['nearest'] < 1) return false; + + return true; + } + + private function validateMonth() : \bool + { + foreach ($this->month['month'] as $month) { + if ($month > 12 || $month < 1) return false; + } + + if ($this->month['start'] > 12 || $this->month['start'] < 1) return false; + if ($this->month['end'] > 12 || $this->month['end'] < 1) return false; + if ($this->month['step'] > 12 || $this->month['step'] < 1) return false; + + return true; + } + + private function validateDayOfWeek() : \bool + { + foreach ($this->dayOfWeek['dayOfWeek'] as $dayOfWeek) { + if ($dayOfWeek > 7 || $dayOfWeek < 1) return false; + } + + if ($this->dayOfWeek['start'] > 7 || $this->dayOfWeek['start'] < 1) return false; + if ($this->dayOfWeek['end'] > 7 || $this->dayOfWeek['end'] < 1) return false; + if ($this->dayOfWeek['step'] > 5 || $this->dayOfWeek['step'] < 1) return false; + + return true; + } + + private function validateYear() : \bool + { + return true; + } + + public function __toString() + { + /* Parsing minutes */ + if (($count = count($this->minute['minutes'])) > 0) { + $minute = implode(',', $this->minute['minutes']); + } elseif ($this->minute['start'] !== 0 && $this->minute['end']) { + $minute = $this->minute['start'] . '-' . $this->minute['end']; + $count = 2; + } else { + $minute = '*'; + $count = 1; + } + + if ($count === 0 && $this->minute['step'] !== 0) { + $minute .= '/' . $this->minute['step']; + } + + /* Parsing hours */ + if (($count = count($this->hour['hours'])) > 0) { + $hour = implode(',', $this->hour['hours']); + } elseif ($this->hour['start'] !== 0 && $this->hour['end']) { + $hour = $this->hour['start'] . '-' . $this->hour['end']; + $count = 2; + } else { + $hour = '*'; + $count = 1; + } + + if ($count === 0 && $this->hour['step'] !== 0) { + $hour .= '/' . $this->hour['step']; + } + + /* Parsing day of month */ + if (($count = count($this->dayOfMonth['dayOfMonth'])) > 0) { + $dayOfMonth = implode(',', $this->dayOfMonth['dayOfMonth']); + } elseif ($this->dayOfMonth['start'] !== 0 && $this->dayOfMonth['end']) { + $dayOfMonth = $this->dayOfMonth['start'] . '-' . $this->dayOfMonth['end']; + $count = 2; + } else { + $dayOfMonth = '*'; + $count = 1; + } + + if ($count === 0 && $this->dayOfMonth['step'] !== 0) { + $dayOfMonth .= '/' . $this->dayOfMonth['step']; + } + + if ($this->dayOfMonth['last']) { + $dayOfMonth .= 'L'; + } + + /* Parsing month */ + if (($count = count($this->month['month'])) > 0) { + $month = implode(',', $this->month['month']); + } elseif ($this->month['start'] !== 0 && $this->month['end']) { + $month = $this->month['start'] . '-' . $this->month['end']; + $count = 2; + } else { + $month = '*'; + $count = 1; + } + + if ($count === 0 && $this->month['step'] !== 0) { + $month .= '/' . $this->month['step']; + } + + /* Parsing day of week */ + if (($count = count($this->dayOfWeek['dayOfWeek'])) > 0) { + $dayOfWeek = implode(',', $this->dayOfWeek['dayOfWeek']); + } elseif ($this->dayOfWeek['start'] !== 0 && $this->dayOfWeek['end']) { + $dayOfWeek = $this->dayOfWeek['start'] . '-' . $this->dayOfWeek['end']; + $count = 2; + } else { + $dayOfWeek = '*'; + $count = 1; + } + + if ($count === 0 && $this->dayOfWeek['step'] !== 0) { + $dayOfWeek .= '#' . $this->dayOfWeek['step']; + } + + if ($this->dayOfWeek['last']) { + $dayOfWeek .= 'L'; + } + + /* Parsing year */ + if (($count = count($this->year['year'])) > 0) { + $year = implode(',', $this->year['year']); + } elseif ($this->year['start'] !== 0 && $this->year['end']) { + $year = $this->year['start'] . '-' . $this->year['end']; + $count = 2; + } else { + $year = '*'; + $count = 1; + } + + if ($count === 0 && $this->year['step'] !== 0) { + $year .= '/' . $this->year['step']; + } + + return $minute . ' ' . $hour . ' ' . $dayOfMonth . ' ' . $month . ' ' . $dayOfWeek . ' ' . $year; + } +} diff --git a/Utils/TaskSchedule/InvalidTaskParameterExceltion.php b/Utils/TaskSchedule/InvalidTaskParameterExceltion.php new file mode 100644 index 000000000..f63b88979 --- /dev/null +++ b/Utils/TaskSchedule/InvalidTaskParameterExceltion.php @@ -0,0 +1,37 @@ + + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace phpOMS\Utils\TaskSchedule; + +/** + * Filesystem class. + * + * Performing operations on the file system + * + * @category System + * @package Framework + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class InvalidTaskParameterException extends \UnexpectedValueException +{ + public function __construct($message, $code = 0, \Exception $previous = null) + { + parent::__construct('The parameter "' . $message . '" is not valid for this task.', $code, $previous); + } +} diff --git a/Utils/TaskSchedule/Schedule.php b/Utils/TaskSchedule/Schedule.php new file mode 100644 index 000000000..c9252ecdc --- /dev/null +++ b/Utils/TaskSchedule/Schedule.php @@ -0,0 +1,60 @@ + + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace phpOMS\Utils\TaskSchedule; + +/** + * Array utils. + * + * @category Framework + * @package Utils + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class Schedule implements TaskInterface +{ + + /** + * Interval. + * + * @var Interval + * @since 1.0.0 + */ + private $interval = null; + private $command = ''; + + public function __construct(\string $cronjob) + { + + } + + public function setInterval(Interval $interval) + { + $this->interval = $interval; + } + + public function setCommand(\string $command) + { + $this->command = $command; + } + + public function __toString() + { + return ''; + } +} diff --git a/Utils/TaskSchedule/ScheduleInterface.php b/Utils/TaskSchedule/ScheduleInterface.php new file mode 100644 index 000000000..69960ff53 --- /dev/null +++ b/Utils/TaskSchedule/ScheduleInterface.php @@ -0,0 +1,40 @@ + + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace phpOMS\Utils\TaskSchedule; + +/** + * Array utils. + * + * @category Framework + * @package Utils + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +interface ScheduleInterface +{ + public function add(TaskInterface $task); + + public function remove($id); + + public function get(\string $id); + + public function list(); + + public function set(TaskInterface $task); +} diff --git a/Utils/TaskSchedule/TaskInterface.php b/Utils/TaskSchedule/TaskInterface.php new file mode 100644 index 000000000..efffd4dc4 --- /dev/null +++ b/Utils/TaskSchedule/TaskInterface.php @@ -0,0 +1,33 @@ + + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace phpOMS\Utils\TaskSchedule; + +/** + * Array utils. + * + * @category Framework + * @package Utils + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +interface TaskInterface +{ + public function setInterval(Interval $interval); + public function setCommand(\string $command); +} diff --git a/Utils/TaskSchedule/TaskScheduler.php b/Utils/TaskSchedule/TaskScheduler.php new file mode 100644 index 000000000..9bae4f00e --- /dev/null +++ b/Utils/TaskSchedule/TaskScheduler.php @@ -0,0 +1,59 @@ + + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace phpOMS\Utils\TaskSchedule; + +/** + * Array utils. + * + * @category Framework + * @package Utils + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class TaskScheduler implements ScheduleInterface +{ + public function __construct() { + + } + + public function add(TaskInterface $task) + { + // TODO: Implement add() method. + } + + public function remove($id) + { + // TODO: Implement remove() method. + } + + public function get(\string $id) + { + // TODO: Implement get() method. + } + + public function list() + { + // TODO: Implement list() method. + } + + public function set(TaskInterface $task) + { + // TODO: Implement set() method. + } +} diff --git a/Version/Version.php b/Version/Version.php index 247b4bb46..4c57f9a12 100644 --- a/Version/Version.php +++ b/Version/Version.php @@ -64,19 +64,19 @@ class Version /** * Loading version file. * - * @param \string $path Path to version file + * @param \string $jpath Path to version file * * @return \string[] * * @since 1.0.0 * @author Dennis Eichhorn */ - public static function getVersion(\string $path) : array + public static function getVersion(\string $jpath) : array { - $path = realpath($path); + $path = realpath($jpath); if(strpos($path, ROOT_PATH) === false || strpos($path, 'config.php') !== false) { - throw new FilePathException($path); + throw new FilePathException($jpath); } return json_decode(file_get_contents($path), true);