SHARE
TWEET

Untitled

a guest May 22nd, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. class User {}
  4. class UserReduced {
  5.     public function __construct(User $user) {
  6.         $this->user = $user;
  7.     }
  8. }
  9. class CustomUserCollection extends ArrayObject {
  10.     public function __construct($input = [], $flags = 0, $iteratorClass = 'ArrayIterator') {
  11.         // magic
  12.         $input = array_map(function ($user) {
  13.             return new UserReduced($user);
  14.         }, $input);
  15.  
  16.         parent::__construct($input, $flags, $iteratorClass);
  17.     }
  18. }
  19.  
  20. $users = [];
  21. for ($i = 0; $i < 10; ++$i) {
  22.     $users[] = new User();
  23. }
  24.  
  25. // Case
  26. $userReduces = iterator_to_array(new CustomUserCollection($users));
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top