Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class User {}
- class UserReduced {
- public function __construct(User $user) {
- $this->user = $user;
- }
- }
- class CustomUserCollection extends ArrayObject {
- public function __construct($input = [], $flags = 0, $iteratorClass = 'ArrayIterator') {
- // magic
- $input = array_map(function ($user) {
- return new UserReduced($user);
- }, $input);
- parent::__construct($input, $flags, $iteratorClass);
- }
- }
- $users = [];
- for ($i = 0; $i < 10; ++$i) {
- $users[] = new User();
- }
- // Case
- $userReduces = iterator_to_array(new CustomUserCollection($users));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement