-
Notifications
You must be signed in to change notification settings - Fork 4
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 #4 from aiglesiasn/master
Add LazyProps capability to Inertia class
- Loading branch information
Showing
3 changed files
with
143 additions
and
3 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,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cherif\InertiaPsr15\Model; | ||
|
||
/** | ||
* NOTE: this is similar to Laravel Inertia\LazyProp | ||
*/ | ||
final class LazyProp | ||
{ | ||
/** | ||
* @var callable $callback | ||
*/ | ||
protected $callback; | ||
|
||
public function __construct( | ||
callable $callable | ||
) { | ||
$this->callback = $callable; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function __invoke() | ||
{ | ||
return call_user_func($this->callback); | ||
} | ||
} |
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