This commit is contained in:
a6a2f5842 2025-11-20 15:04:18 +01:00
commit 0f260ab95f
7 changed files with 122 additions and 0 deletions

2
.dockerignore Normal file
View File

@ -0,0 +1,2 @@
docker
.vscode

6
.gitattributes vendored Normal file
View File

@ -0,0 +1,6 @@
/.vscode export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/phpunit.xml.dist export-ignore
/docs export-ignore
/tests export-ignore

7
.gitignore vendored Normal file
View File

@ -0,0 +1,7 @@
reports
sandbox
vendor
composer.lock
.idea/
workbench
.phpunit.result.cache

6
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,6 @@
{
"editor.formatOnSave": true,
"[php]": {
"editor.defaultFormatter": "bmewburn.vscode-intelephense-client"
},
}

62
composer.json Normal file
View File

@ -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"
]
}
}

4
pint.json Normal file
View File

@ -0,0 +1,4 @@
{
"preset": "laravel",
"rules": {}
}

35
src/Traits/WillExpire.php Normal file
View File

@ -0,0 +1,35 @@
<?php
namespace Blax\Workkit\Traits;
trait HasExpiration
{
public static function bootWillExpire()
{
static::addGlobalScope('willExpire', function ($builder) {
$builder->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();
}
}