- Upgraded doc intro to match new attribute uses.

This commit is contained in:
Dave M. 2023-02-23 17:16:22 +00:00
parent c9c6a11ebd
commit 36cddf8f78
2 changed files with 29 additions and 19 deletions

View File

@ -4,7 +4,7 @@ Welcome to the official Ulmus documentation.
## Quick start
Creating a simple user entity:
Creating a simple user exemple entity:
*/app/entity/user.php*
```php
@ -21,29 +21,19 @@ class User
{
use \Ulmus\EntityTrait;
/**
* @Id
*/
#[Field\Id]
public int $id;
/**
* @Field
*/
#[Field]
public string $fullname;
/**
* @Field
*/
#[Field]
public ? string $email;
/**
* @Field('name' => 'is_admin')
*/
#[Field]
public bool $isAdmin = false;
/**
* @DateTime
*/
#[Field\Datetime]
public Datetime $birthday;
}
```

View File

@ -58,6 +58,26 @@ class EntityCollection extends \ArrayObject {
return null;
}
public function extract(Callable $callback) : self
{
$idx = 0;
$replace = [];
$collection = new static();
foreach($this as $key => $item) {
if ( $callback($item, $key, $idx++) ) {
$collection->append($item);
}
else {
$replace[] = $item;
}
}
$this->replaceWith($replace);
return $collection;
}
public function iterate(Callable $callback) : self
{
foreach($this as $item) {
@ -117,17 +137,17 @@ class EntityCollection extends \ArrayObject {
public function searchAll(/* mixed*/ $values, string $field, bool $strict = true, bool $compareArray = false) : self
{
$obj = new static();
$collection = new static();
$values = is_array($values) && $compareArray ? [ $values ] : $values;
foreach((array) $values as $value) {
foreach ($this->search($value, $field, $strict) as $item) {
$obj->append($item);
$collection->append($item);
}
}
return $obj;
return $collection;
}
public function diffAll(/* mixed */ $values, string $field, bool $strict = true, bool $compareArray = false) : self