File "LazyDataStructureProperty.php"
Full Path: /var/www/html/back/vendor/spatie/laravel-data/src/Support/LazyDataStructureProperty.php
File size: 705 bytes
MIME-type: text/x-php
Charset: utf-8
<?php
namespace Spatie\LaravelData\Support;
use Closure;
/**
* @template-covariant T
*/
class LazyDataStructureProperty extends DataStructureProperty
{
/**
* @param Closure(): T $value
*/
public function __construct(
protected Closure $value
) {
}
/**
* @return T
*/
public function resolve()
{
if (! isset($this->resolved)) {
$this->resolved = ($this->value)();
}
return $this->resolved;
}
public function toDataStructureProperty(): DataStructureProperty
{
$property = new DataStructureProperty();
$property->setResolved($this->resolve());
return $property;
}
}