-
Notifications
You must be signed in to change notification settings - Fork 0
Introduce Core Value Object System #2
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,101 @@ | ||
| <?php declare(strict_types = 1); | ||
|
|
||
| /** | ||
| * This file is part of the FireHub Project ecosystem | ||
| * | ||
| * @author Danijel GaliΔ <danijel.galic@outlook.com> | ||
| * @copyright 2026-present The FireHub Project - All rights reserved | ||
| * @license https://opensource.org/license/Apache-2-0 Apache License, Version 2.0 | ||
| * | ||
| * @php-version >=8.2 | ||
| * @package Core | ||
| */ | ||
|
|
||
| namespace FireHub\Core\Type; | ||
|
|
||
| /** | ||
| * ### Base Value Object | ||
| * | ||
| * Defines the base abstraction for all Value Objects within the FireHub Core ecosystem. | ||
| * | ||
| * The ValueObject serves as a fundamental immutable contract for representing identity-less data structures based | ||
| * purely on their value semantics. It enforces consistency across the system by ensuring that all derived Value Objects | ||
| * follow strict immutability rules and structural equality behavior. | ||
| * @since 1.0.0 | ||
| * | ||
| * @template TValue | ||
| */ | ||
| abstract readonly class ValueObject { | ||
|
|
||
| /** | ||
| * ### Returns the raw value of the Value Object | ||
| * | ||
| * Provides the underlying scalar or composite value represented by this Value Object. | ||
| * | ||
| * This value is used for structural comparison and domain-level equality checks. | ||
| * @since 1.0.0 | ||
| * | ||
| * @return TValue Raw VO value. | ||
| */ | ||
| abstract public function value ():mixed; | ||
|
|
||
| /** | ||
| * ### Determines structural equality between two Value Objects | ||
| * | ||
| * Compares this Value Object with another instance of the same type using strict | ||
| * class comparison and value equality semantics. | ||
| * @since 1.0.0 | ||
| * | ||
| * @uses \FireHub\Core\Type\ValueObject::sameAs() To compare the VO types. | ||
| * @uses \FireHub\Core\Type\ValueObject::value() To compare the VO values. | ||
| * | ||
| * @param self<TValue> $other <p> | ||
| * The Value Object to compare against. | ||
| * </p> | ||
| * | ||
| * @return bool True if the VOs are equal, false otherwise. | ||
| */ | ||
| final public function equals (self $other):bool { | ||
|
|
||
| return $this->sameAs($other) | ||
| && $this->value() === $other->value(); | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * ### Checks strict identity equality of a Value Object type | ||
| * | ||
| * Ensures both objects are of the same concrete class without comparing values. | ||
| * @since 1.0.0 | ||
| * | ||
| * @param \FireHub\Core\Type\ValueObject<TValue> $other <p> | ||
| * The Value Object to compare against. | ||
| * </p> | ||
| * | ||
| * @return bool True if the objects are of the same type, false otherwise. | ||
| */ | ||
| final public function sameAs (self $other):bool { | ||
|
|
||
| return static::class === $other::class; | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * ### Enforces an invariant condition for the Value Object | ||
| * @since 1.0.0 | ||
| * | ||
| * @param callable():bool $condition <p> | ||
| * The validation condition to evaluate. | ||
| * </p> | ||
| * @param callable():\Exception $exception <p> | ||
|
danijelgalic marked this conversation as resolved.
|
||
| * Exception to be thrown when the condition fails. | ||
| * </p> | ||
| * @return void | ||
| */ | ||
| final protected function guard (callable $condition, callable $exception):void { | ||
|
|
||
| if ($condition() === false) throw $exception(); | ||
|
|
||
| } | ||
|
|
||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.