-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
ObjectStorage
class
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace ipl\Scheduler; | ||
|
||
use ipl\Scheduler\Contract\Task; | ||
use Ramsey\Uuid\UuidInterface; | ||
use SplObjectStorage; | ||
|
||
/** | ||
* ObjectStorage provides custom implementation of the internal PHP hash method and doesn't depend on the | ||
* `spl_object_hash()` function used by `SplObjectStorage` class. | ||
*/ | ||
class ObjectStorage extends SplObjectStorage | ||
Check failure on line 13 in src/ObjectStorage.php GitHub Actions / Static analysis for PHP 7.2 on ubuntu-latest
Check failure on line 13 in src/ObjectStorage.php GitHub Actions / Static analysis for PHP 7.3 on ubuntu-latest
Check failure on line 13 in src/ObjectStorage.php GitHub Actions / Static analysis for PHP 7.4 on ubuntu-latest
Check failure on line 13 in src/ObjectStorage.php GitHub Actions / Static analysis for PHP 8.0 on ubuntu-latest
Check failure on line 13 in src/ObjectStorage.php GitHub Actions / Static analysis for PHP 8.1 on ubuntu-latest
|
||
{ | ||
public function getHash($object): string | ||
{ | ||
if ($object instanceof Task) { | ||
return $object->getUuid()->toString(); | ||
} | ||
|
||
if ($object instanceof UuidInterface) { | ||
return $object->toString(); | ||
} | ||
|
||
return parent::getHash($object); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,6 @@ | |
use React\EventLoop\Loop; | ||
use React\Promise; | ||
use React\Promise\ExtendedPromiseInterface; | ||
use SplObjectStorage; | ||
use Throwable; | ||
|
||
class Scheduler | ||
|
@@ -124,15 +123,15 @@ class Scheduler | |
*/ | ||
public const ON_TASK_EXPIRED = 'task-expired'; | ||
|
||
/** @var SplObjectStorage<Task, null> The scheduled tasks of this scheduler */ | ||
/** @var ObjectStorage<Task, null> The scheduled tasks of this scheduler */ | ||
protected $tasks; | ||
Check failure on line 127 in src/Scheduler.php GitHub Actions / Static analysis for PHP 7.2 on ubuntu-latest
Check failure on line 127 in src/Scheduler.php GitHub Actions / Static analysis for PHP 7.3 on ubuntu-latest
Check failure on line 127 in src/Scheduler.php GitHub Actions / Static analysis for PHP 7.4 on ubuntu-latest
Check failure on line 127 in src/Scheduler.php GitHub Actions / Static analysis for PHP 8.0 on ubuntu-latest
Check failure on line 127 in src/Scheduler.php GitHub Actions / Static analysis for PHP 8.1 on ubuntu-latest
Check failure on line 127 in src/Scheduler.php GitHub Actions / Static analysis for PHP 8.2 on ubuntu-latest
|
||
|
||
public function __construct() | ||
{ | ||
$this->tasks = new SplObjectStorage(); | ||
$this->tasks = new ObjectStorage(); | ||
|
||
$this->promises = new SplObjectStorage(); | ||
$this->timers = new SplObjectStorage(); | ||
$this->promises = new ObjectStorage(); | ||
$this->timers = new ObjectStorage(); | ||
|
||
$this->init(); | ||
} | ||
|
@@ -177,7 +176,7 @@ public function removeTasks(): self | |
$this->cancelTask($task); | ||
} | ||
|
||
$this->tasks = new SplObjectStorage(); | ||
$this->tasks = new ObjectStorage(); | ||
|
||
return $this; | ||
} | ||
|