diff --git a/docs/00-intro.md b/docs/00-intro.md index bacf7ff..a4caa1e 100644 --- a/docs/00-intro.md +++ b/docs/00-intro.md @@ -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; } ``` diff --git a/src/EntityCollection.php b/src/EntityCollection.php index 9d4d165..0a6179e 100644 --- a/src/EntityCollection.php +++ b/src/EntityCollection.php @@ -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