litgroup/ equatable
此包已被废弃且不再维护。未建议替代包。
为PHP 7+提供EquatableInterface
v2.0.0
2016-09-21 09:34 UTC
Requires
- php: ^7.0
This package is auto-updated.
Last update: 2023-11-12 22:37:49 UTC
README
为PHP 7+提供
Equatable
接口(受Java启发)。
安装
composer require litgroup/equatable:^2.0
包含内容
interface Equatable { /** * Checks if this object is equal to another one. */ public function equals(Equatable $another): bool; }
使用示例
namespace Acme; use LitGroup\Equatable\Equatable; class User { private $username; private $email; public function __construct(string $username, string $email) { $this->username = $username; $this->email = $email; } public function getUsername(): string { return $this->username; } public function getEmail(): string { return $this->email; } /** * Example of implementation of Equatable::equals() */ public function equals(Equatable $another): bool { return $another instanceOf User && $another->getUsername() == $this->getUsername() && $another->getEmail() == $this->getEmail() ; } }
许可证
查看许可证文件。