| 1 |
<?php |
| 2 |
|
| 3 |
namespace ipl\Orm\Common; |
| 4 |
|
| 5 |
use Closure; |
| 6 |
use Traversable; |
| 7 |
use ipl\Stdlib\Properties; |
| 8 |
|
| 9 |
trait PropertiesWithDefaults |
| 10 |
{ |
| 11 |
use Properties { |
| 12 |
Properties::getProperty as private parentGetProperty; |
| 13 |
} |
| 14 |
|
| 15 |
protected function getProperty(string $key): mixed |
| 16 |
{ |
| 17 |
if (isset($this->properties[$key]) && $this->properties[$key] instanceof Closure) { |
| 18 |
$this->setProperty($key, $this->properties[$key]($this, $key)); |
| 19 |
} |
| 20 |
|
| 21 |
return $this->parentGetProperty($key); |
| 22 |
} |
| 23 |
|
| 24 |
public function getIterator(): Traversable |
| 25 |
{ |
| 26 |
foreach ($this->properties as $key => $value) { |
| 27 |
if (! $value instanceof Closure) { |
| 28 |
yield $key => $value; |
| 29 |
} |
| 30 |
} |
| 31 |
} |
| 32 |
} |