-
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
5 changed files
with
40 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
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