| 1 |
<?php |
| 2 |
|
| 3 |
namespace Illuminate\Support; |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
class HigherOrderCollectionProxy |
| 14 |
{ |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
protected $collection; |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
protected $method; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
public function __construct(Enumerable $collection, $method) |
| 36 |
{ |
| 37 |
$this->method = $method; |
| 38 |
$this->collection = $collection; |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
public function __get($key) |
| 48 |
{ |
| 49 |
return $this->collection->{$this->method}(function ($value) use ($key) { |
| 50 |
return is_array($value) ? $value[$key] : $value->{$key}; |
| 51 |
}); |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
public function __call($method, $parameters) |
| 62 |
{ |
| 63 |
return $this->collection->{$this->method}(function ($value) use ($method, $parameters) { |
| 64 |
return is_string($value) |
| 65 |
? $value::{$method}(...$parameters) |
| 66 |
: $value->{$method}(...$parameters); |
| 67 |
}); |
| 68 |
} |
| 69 |
} |