PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 1.0.92
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v1.0.92
2.10.0 2.10.01 2.9.1 2.9.0 2.8.1 2.8.0 2.7.7 2.7.5 2.7.0 2.6.01 2.6.0 2.5.0 2.4.01 trunk 1.0.90 1.0.91 1.0.92 1.0.93 1.0.94 1.0.95 1.0.96 1.0.97 1.0.98 1.0.99 1.1.0 All 77 releases
fluent-community / vendor / wpfluent / framework / src / WPFluent / Support / HigherOrderCollectionProxy.php

HigherOrderCollectionProxy.php in FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses 1.0.92, at vendor/wpfluent/framework/src/WPFluent/Support/HigherOrderCollectionProxy.php

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