Skip to content
This repository has been archived by the owner on Jun 26, 2024. It is now read-only.

Commit

Permalink
Add BC version that supports both 7.4 and 8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
frankprins committed Oct 25, 2022
1 parent 948e206 commit e7507ab
Showing 5 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
php: [8.1, 8.0]
php: [8.1, 8.0, 7.4]
dependency-version: [prefer-lowest, prefer-stable]
os: [ubuntu-latest, windows-latest]

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@
}
],
"require": {
"php": "^8.0"
"php": "^7.4 || ^8.0"
},
"require-dev": {
"pestphp/pest": "^1.21",
4 changes: 2 additions & 2 deletions src/Backtrace.php
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ public function getObjectName(): ?string
return $this->trace['class'] ?? null;
}

public function getObject(): mixed
public function getObject()
{
if ($this->globalFunction()) {
return $this->zeroStack['file'];
@@ -46,7 +46,7 @@ public function getHash(): string
}, $this->getArguments());

$prefix = $this->getObjectName() . $this->getFunctionName();
if (str_contains($prefix, '{closure}')) {
if (strpos($prefix, '{closure}') !== false) {
$prefix = $this->zeroStack['line'];
}

16 changes: 8 additions & 8 deletions src/Cache.php
Original file line number Diff line number Diff line change
@@ -3,24 +3,24 @@
namespace Spatie\Once;

use Countable;
use WeakMap;
use SplObjectStorage;

class Cache implements Countable
{
protected static self $cache;

public WeakMap $values;
public SplObjectStorage $values;

protected bool $enabled = true;

public static function getInstance(): static
public static function getInstance(): self
{
return static::$cache ??= new static;
return static::$cache ??= new self;
}

protected function __construct()
{
$this->values = new WeakMap();
$this->values = new SplObjectStorage();
}

public function has(object $object, string $backtraceHash): bool
@@ -33,12 +33,12 @@ public function has(object $object, string $backtraceHash): bool
return array_key_exists($backtraceHash, $this->values[$object]);
}

public function get($object, string $backtraceHash): mixed
public function get($object, string $backtraceHash)
{
return $this->values[$object][$backtraceHash];
}

public function set(object $object, string $backtraceHash, mixed $value): void
public function set(object $object, string $backtraceHash, $value): void
{
$cached = $this->values[$object] ?? [];

@@ -54,7 +54,7 @@ public function forget(object $object): void

public function flush(): self
{
$this->values = new WeakMap();
$this->values = new SplObjectStorage();

return $this;
}
2 changes: 1 addition & 1 deletion src/functions.php
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
* @param (callable(): T) $callback
* @return T
*/
function once(callable $callback): mixed
function once(callable $callback)
{
$trace = debug_backtrace(
DEBUG_BACKTRACE_PROVIDE_OBJECT, 2

0 comments on commit e7507ab

Please # to comment.