Created
March 21, 2026 17:43
-
-
Save vertexvaar/5916260f780409000483e53e707c0dc9 to your computer and use it in GitHub Desktop.
Asymmetric Property Nightmare
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
| <?php | |
| namespace VerteXVaaR; | |
| trait DelegatedProperty | |
| { | |
| public mixed $value { | |
| set(mixed $newValue) { | |
| if ($newValue instanceof PropertyContainer) { | |
| $this->value = $newValue; | |
| return; | |
| } | |
| $this->value->set($newValue); | |
| } | |
| get => $this->value->get(); | |
| } | |
| } |
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
| <?php | |
| $thing = new Thing(); | |
| $accessor = fn(mixed $value = Undefined::NONE) => $value === Undefined::NONE ? $thing->name : $thing->name = $value; | |
| $input = new Input($accessor); | |
| $input->value = 'New Value'; |
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
| <?php | |
| namespace VerteXVaaR; | |
| use Closure; | |
| use Psr\Http\Message\ServerRequestInterface; | |
| use VerteXVaaR\BlueValidation\Rule\Rule; | |
| use VerteXVaaR\BlueValidation\ValidationError; | |
| class Input | |
| { | |
| use DelegatedProperty; | |
| public function __construct(mixed &$value) | |
| { | |
| $this->value = new PropertyContainer($value); | |
| } | |
| } |
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
| <?php | |
| namespace VerteXVaaR; | |
| use Closure; | |
| class PropertyContainer | |
| { | |
| public function __construct(protected mixed &$initialValue) {} | |
| public function set(mixed $newValue): void | |
| { | |
| if ($this->initialValue instanceof Closure) { | |
| ($this->initialValue)($newValue); | |
| return; | |
| } | |
| $this->initialValue = $newValue; | |
| } | |
| public function get(): mixed | |
| { | |
| if ($this->initialValue instanceof Closure) { | |
| return ($this->initialValue)(); | |
| } | |
| return $this->initialValue; | |
| } | |
| } |
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
| <?php | |
| namespace VerteXVaaR; | |
| class Thing | |
| { | |
| public string $name { | |
| get => $this->name; | |
| set(string $cname) => $this->name = $name; | |
| } | |
| } |
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
| <?php | |
| namespace VerteXVaaR; | |
| enum Undefined | |
| { | |
| case NONE; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment