-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce & use custom
ObjectStorage
class
- Loading branch information
Showing
4 changed files
with
38 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?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. | ||
* | ||
* @extends SplObjectStorage<object, object|mixed> | ||
*/ | ||
class ObjectStorage extends SplObjectStorage | ||
{ | ||
public function getHash($object): string | ||
{ | ||
if ($object instanceof Task) { | ||
return $object->getUuid()->toString(); | ||
} | ||
|
||
if ($object instanceof UuidInterface) { | ||
return $object->toString(); | ||
} | ||
|
||
return parent::getHash($object); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|