- Upgraded doc intro to match new attribute uses.
This commit is contained in:
parent
c9c6a11ebd
commit
36cddf8f78
|
@ -4,7 +4,7 @@ Welcome to the official Ulmus documentation.
|
||||||
|
|
||||||
## Quick start
|
## Quick start
|
||||||
|
|
||||||
Creating a simple user entity:
|
Creating a simple user exemple entity:
|
||||||
|
|
||||||
*/app/entity/user.php*
|
*/app/entity/user.php*
|
||||||
```php
|
```php
|
||||||
|
@ -21,29 +21,19 @@ class User
|
||||||
{
|
{
|
||||||
use \Ulmus\EntityTrait;
|
use \Ulmus\EntityTrait;
|
||||||
|
|
||||||
/**
|
#[Field\Id]
|
||||||
* @Id
|
|
||||||
*/
|
|
||||||
public int $id;
|
public int $id;
|
||||||
|
|
||||||
/**
|
#[Field]
|
||||||
* @Field
|
|
||||||
*/
|
|
||||||
public string $fullname;
|
public string $fullname;
|
||||||
|
|
||||||
/**
|
#[Field]
|
||||||
* @Field
|
|
||||||
*/
|
|
||||||
public ? string $email;
|
public ? string $email;
|
||||||
|
|
||||||
/**
|
#[Field]
|
||||||
* @Field('name' => 'is_admin')
|
|
||||||
*/
|
|
||||||
public bool $isAdmin = false;
|
public bool $isAdmin = false;
|
||||||
|
|
||||||
/**
|
#[Field\Datetime]
|
||||||
* @DateTime
|
|
||||||
*/
|
|
||||||
public Datetime $birthday;
|
public Datetime $birthday;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
|
@ -58,6 +58,26 @@ class EntityCollection extends \ArrayObject {
|
||||||
return null;
|
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
|
public function iterate(Callable $callback) : self
|
||||||
{
|
{
|
||||||
foreach($this as $item) {
|
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
|
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;
|
$values = is_array($values) && $compareArray ? [ $values ] : $values;
|
||||||
|
|
||||||
foreach((array) $values as $value) {
|
foreach((array) $values as $value) {
|
||||||
foreach ($this->search($value, $field, $strict) as $item) {
|
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
|
public function diffAll(/* mixed */ $values, string $field, bool $strict = true, bool $compareArray = false) : self
|
||||||
|
|
Loading…
Reference in New Issue