-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Uid] Make AbstractUid
implement Ds\Hashable
if available
#57313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
/** | ||
* @author Nicolas Grekas <[email protected]> | ||
*/ | ||
abstract class AbstractUid implements \JsonSerializable, \Stringable | ||
abstract class AbstractUid implements \JsonSerializable, \Stringable, HashableInterface | ||
{ | ||
/** | ||
* The identifier in its canonic representation. | ||
|
@@ -150,7 +150,7 @@ | |
/** | ||
* Returns whether the argument is an AbstractUid and contains the same value as the current instance. | ||
*/ | ||
public function equals(mixed $other): bool | ||
Check failure on line 153 in src/Symfony/Component/Uid/AbstractUid.php
|
||
{ | ||
if (!$other instanceof self) { | ||
return false; | ||
|
@@ -159,6 +159,11 @@ | |
return $this->uid === $other->uid; | ||
} | ||
|
||
public function hash(): string | ||
{ | ||
return $this->uid; | ||
} | ||
|
||
public function compare(self $other): int | ||
{ | ||
return (\strlen($this->uid) - \strlen($other->uid)) ?: ($this->uid <=> $other->uid); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
CHANGELOG | ||
========= | ||
|
||
7.2 | ||
--- | ||
|
||
* Make `AbstractUid` implement `Ds\Hashable` if available | ||
|
||
7.1 | ||
--- | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Uid; | ||
|
||
if (interface_exists(\Ds\Hashable::class)) { | ||
/** | ||
* @internal | ||
*/ | ||
interface HashableInterface extends \Ds\Hashable | ||
Check failure on line 18 in src/Symfony/Component/Uid/HashableInterface.php
|
||
{ | ||
public function hash(): string; | ||
} | ||
nicolas-grekas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} else { | ||
/** | ||
* @internal | ||
*/ | ||
interface HashableInterface | ||
nicolas-grekas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
public function equals(mixed $other): bool; | ||
|
||
public function hash(): string; | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.