-
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.
Merge pull request #61 from sroehrl/computed-values
Enhance model via computed values
- Loading branch information
Showing
7 changed files
with
251 additions
and
138 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
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,30 @@ | ||
<?php | ||
|
||
namespace Neoan\Model\Attributes; | ||
|
||
use Attribute; | ||
use Neoan\Enums\AttributeType; | ||
use Neoan\Model\Interfaces\ModelAttribute; | ||
use Neoan\Model\Model; | ||
|
||
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_ALL)] | ||
class Computed implements ModelAttribute | ||
{ | ||
public mixed $initial; | ||
|
||
public function __construct(mixed $initial = null) | ||
{ | ||
$this->initial = $initial; | ||
} | ||
|
||
function __invoke(Model &$currentModel, string $method) | ||
{ | ||
$currentModel->{$method} = $currentModel->{$method}($this->initial); | ||
|
||
} | ||
|
||
public function getType(): AttributeType | ||
{ | ||
return AttributeType::PRIVATE; | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.