Debian Codegraph @

lib/3rdParty/composer/illuminate/collections/HigherOrderCollectionProxy.php

raw symbols SCIP
1 <?php
2
3 namespace Illuminate\Support;
4
5 /**
6 * @template TKey of array-key
7 *
8 * @template-covariant TValue
9 *
10 * @mixin \Illuminate\Support\Enumerable<TKey, TValue>
11 * @mixin TValue
12 */
13 class HigherOrderCollectionProxy
14 {
15 /**
16 * The collection being operated on.
17 *
18 * @var \Illuminate\Support\Enumerable<TKey, TValue>
19 */
20 protected $collection;
21
22 /**
23 * The method being proxied.
24 *
25 * @var string
26 */
27 protected $method;
28
29 /**
30 * Create a new proxy instance.
31 *
32 * @param \Illuminate\Support\Enumerable<TKey, TValue> $collection
33 * @param string $method
34 */
35 public function __construct(Enumerable $collection, $method)
36 {
37 $this->method = $method;
38 $this->collection = $collection;
39 }
40
41 /**
42 * Proxy accessing an attribute onto the collection items.
43 *
44 * @param string $key
45 * @return mixed
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 * Proxy a method call onto the collection items.
56 *
57 * @param string $method
58 * @param array $parameters
59 * @return mixed
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 }