From 0f260ab95fb8af9c79902b5ff01a7f732fed34ec Mon Sep 17 00:00:00 2001 From: a6a2f5842 Date: Thu, 20 Nov 2025 15:04:18 +0100 Subject: [PATCH] init --- .dockerignore | 2 ++ .gitattributes | 6 ++++ .gitignore | 7 +++++ .vscode/settings.json | 6 ++++ composer.json | 62 +++++++++++++++++++++++++++++++++++++++ pint.json | 4 +++ src/Traits/WillExpire.php | 35 ++++++++++++++++++++++ 7 files changed, 122 insertions(+) create mode 100644 .dockerignore create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 .vscode/settings.json create mode 100644 composer.json create mode 100644 pint.json create mode 100644 src/Traits/WillExpire.php diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..930be90 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +docker +.vscode \ No newline at end of file diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..e5743dc --- /dev/null +++ b/.gitattributes @@ -0,0 +1,6 @@ +/.vscode export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore +/phpunit.xml.dist export-ignore +/docs export-ignore +/tests export-ignore \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b39bae1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +reports +sandbox +vendor +composer.lock +.idea/ +workbench +.phpunit.result.cache \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..977478f --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "editor.formatOnSave": true, + "[php]": { + "editor.defaultFormatter": "bmewburn.vscode-intelephense-client" + }, +} \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..6739e03 --- /dev/null +++ b/composer.json @@ -0,0 +1,62 @@ +{ + "name": "blax-software/laravel-workkit", + "type": "library", + "description": "Laravel collection of helpers and utilities to speed up development.", + "keywords": [], + "homepage": "http://www.blax.at", + "license": "MIT", + "authors": [ + { + "name": "Fabian Wagner", + "email": "fabian@blax.at", + "homepage": "https://www.blax.at", + "role": "Developer" + } + ], + "autoload": { + "psr-4": { + "Blax\\Workkit\\": "src" + } + }, + "config": { + "sort-packages": true + }, + "require": { + "php": ">=8.0", + "laravel/framework": "*" + }, + "require-dev": { + "laravel/pint": "^1.22" + }, + "extra": { + "laravel": { + "providers": [] + } + }, + "minimum-stability": "dev", + "prefer-stable": true, + "autoload-dev": { + "psr-4": {} + }, + "scripts": { + "post-autoload-dump": [ + "@clear", + "@prepare" + ], + "clear": "@php vendor/bin/testbench package:purge-skeleton --ansi", + "prepare": "@php vendor/bin/testbench package:discover --ansi", + "build": "@php vendor/bin/testbench workbench:build --ansi", + "serve": [ + "Composer\\Config::disableProcessTimeout", + "@build", + "@php vendor/bin/testbench serve --ansi" + ], + "lint": [ + "@php vendor/bin/pint --ansi" + ], + "test": [ + "@clear", + "@php vendor/bin/phpunit" + ] + } +} \ No newline at end of file diff --git a/pint.json b/pint.json new file mode 100644 index 0000000..4ee3110 --- /dev/null +++ b/pint.json @@ -0,0 +1,4 @@ +{ + "preset": "laravel", + "rules": {} +} \ No newline at end of file diff --git a/src/Traits/WillExpire.php b/src/Traits/WillExpire.php new file mode 100644 index 0000000..c1475fd --- /dev/null +++ b/src/Traits/WillExpire.php @@ -0,0 +1,35 @@ +where(function ($query) { + $query->whereNull('expires_at') + ->orWhere('expires_at', '>', now()); + }); + }); + } + + public function isExpired(): bool + { + return $this->expires_at && $this->expires_at->isPast(); + } + + public function extendByHours(int $hours, bool $expire_if_null = false): void + { + if ($this->expires_at === null && !$expire_if_null) { + // Do not add expiration if it does not expire + return; + } elseif ($this->expires_at->isPast()) { + $this->expires_at = now()->addHours($hours); + } else { + $this->expires_at = $this->expires_at->addHours($hours); + } + + $this->save(); + } +}