diff --git a/src/Progressable.php b/src/Progressable.php index 4492077..ec4691f 100644 --- a/src/Progressable.php +++ b/src/Progressable.php @@ -178,7 +178,7 @@ protected function getStorageKeyName(): string { * Retrieve the prefix storage key for the PHP function. */ protected function getPrefixStorageKey(): string { - return $this->customPrefixStorageKey ?? config('progressable.prefix', $this->defaultPrefixStorageKey); + return $this->customPrefixStorageKey ?? (function_exists('app') && app()->bound('config') ? config('progressable.prefix', $this->defaultPrefixStorageKey) : $this->defaultPrefixStorageKey); } /** @@ -554,7 +554,7 @@ protected function saveOverallProgressData(array $progressData): static { * Get the storage time-to-live in minutes. */ public function getTTL(): int { - return $this->customTTL ?? config('progressable.ttl', $this->defaultTTL); + return $this->customTTL ?? (function_exists('app') && app()->bound('config') ? config('progressable.ttl', $this->defaultTTL) : $this->defaultTTL); } /** @@ -606,7 +606,7 @@ public function setTTL(int $TTL): static { * Get the precision for progress values. */ public function getPrecision(): int { - return $this->customPrecision ?? config('progressable.precision', $this->defaultPrecision); + return $this->customPrecision ?? (function_exists('app') && app()->bound('config') ? config('progressable.precision', $this->defaultPrecision) : $this->defaultPrecision); } /** diff --git a/tests/WithoutLaravelTest.php b/tests/WithoutLaravelTest.php new file mode 100644 index 0000000..7a09f35 --- /dev/null +++ b/tests/WithoutLaravelTest.php @@ -0,0 +1,37 @@ +setCustomSaveData($saveCallback) + ->setCustomGetData($getCallback) + ->setOverallUniqueName('my-task-without-laravel') + ->resetOverallProgress() + ->setLocalProgress(25); + + $this->assertEquals(25, $obj->getLocalProgress()); + $this->assertEquals(25, $obj->getOverallProgress()); + $this->assertEquals('progressable_my-task-without-laravel', array_key_first($storage)); + } +}