-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create ArrayIteratorTrait, move IteratorAggregate implementation to A…
…ctiveRecord (#312)
- Loading branch information
Showing
4 changed files
with
39 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\ActiveRecord\Trait; | ||
|
||
use ArrayIterator; | ||
use IteratorAggregate; | ||
|
||
/** | ||
* Trait to implement {@see IteratorAggregate} interface for ActiveRecord. | ||
* | ||
* @method array getAttributes(array|null $names = null, array $except = []) | ||
* @see ActiveRecordInterface::getAttributes() for more info. | ||
*/ | ||
trait ArrayIteratorTrait | ||
{ | ||
/** | ||
* Returns an iterator for traversing the attributes in the ActiveRecord. | ||
* | ||
* This method is required by the interface {@see IteratorAggregate}. | ||
* | ||
* @return ArrayIterator an iterator for traversing the items in the list. | ||
*/ | ||
public function getIterator(): ArrayIterator | ||
{ | ||
$attributes = $this->getAttributes(); | ||
|
||
return new ArrayIterator($attributes); | ||
} | ||
} |