PluginProbe
PostNL for WooCommerce / 4.4.1
PostNL for WooCommerce v4.4.1
5.9.12 5.9.11 5.9.10 5.9.9 5.9.8 5.9.7 5.9.6 trunk 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 3.1.4 3.1.5 3.1.6 3.1.7 4.0.0 4.0.1 4.0.2 4.3.2 4.3.3 4.4.0 4.4.1 All 72 releases
woo-postnl / vendor / myparcelnl / sdk / src / Support / HigherOrderCollectionProxy.php

HigherOrderCollectionProxy.php in PostNL for WooCommerce 4.4.1, at vendor/myparcelnl/sdk/src/Support/HigherOrderCollectionProxy.php

63 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php declare(strict_types=1);
2
3 namespace MyParcelNL\Sdk\src\Support;
4
5 /**
6 * @mixin Collection
7 */
8 class HigherOrderCollectionProxy
9 {
10 /**
11 * The collection being operated on.
12 *
13 * @var Collection
14 */
15 protected $collection;
16
17 /**
18 * The method being proxied.
19 *
20 * @var string
21 */
22 protected $method;
23
24 /**
25 * Create a new proxy instance.
26 *
27 * @param Collection $collection
28 * @param string $method
29 */
30 public function __construct(Collection $collection, $method)
31 {
32 $this->method = $method;
33 $this->collection = $collection;
34 }
35
36 /**
37 * Proxy accessing an attribute onto the collection items.
38 *
39 * @param string $key
40 * @return mixed
41 */
42 public function __get($key)
43 {
44 return $this->collection->{$this->method}(function ($value) use ($key) {
45 return is_array($value) ? $value[$key] : $value->{$key};
46 });
47 }
48
49 /**
50 * Proxy a method call onto the collection items.
51 *
52 * @param string $method
53 * @param array $parameters
54 * @return mixed
55 */
56 public function __call($method, $parameters)
57 {
58 return $this->collection->{$this->method}(function ($value) use ($method, $parameters) {
59 return $value->{$method}(...$parameters);
60 });
61 }
62 }
63