This repository has been archived by the owner on Sep 27, 2024. It is now read-only.
generated from loomkit/skeleton
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
64 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sikessem\Values\Contracts; | ||
|
||
use Closure; | ||
|
||
interface IsMixedValue | ||
{ | ||
public function get(): mixed; | ||
|
||
public function set(mixed $value): static; | ||
|
||
public function update(callable|Closure $callback): static; | ||
|
||
public static function from(mixed $value): self; | ||
} |
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,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sikessem\Values; | ||
|
||
use Closure; | ||
use Sikessem\Values\Contracts\IsMixedValue; | ||
|
||
class MixedValue implements IsMixedValue | ||
{ | ||
protected mixed $value; | ||
|
||
public function __construct(mixed $value) | ||
{ | ||
$this->set($value); | ||
} | ||
|
||
public function get(): mixed | ||
{ | ||
return $this->value; | ||
} | ||
|
||
public function set(mixed $value): static | ||
{ | ||
$this->value = $value; | ||
|
||
return $this; | ||
} | ||
|
||
public function update(callable|Closure $callback): static | ||
{ | ||
return $this->set($callback($this->get())); | ||
} | ||
|
||
public static function from(mixed $value): self | ||
{ | ||
if ($value instanceof self) { | ||
return $value; | ||
} | ||
|
||
return new self($value); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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