PluginProbe ʕ •ᴥ•ʔ
Kirki – Freeform Page Builder, Website Builder & Customizer / 6.0.13
Kirki – Freeform Page Builder, Website Builder & Customizer v6.0.13
6.1.1 6.1.0 6.0.14 6.0.13 6.0.12 6.0.11 6.0.10 6.0.9 6.0.8 6.0.7 6.0.6 6.0.5 6.0.4 6.0.3 6.0.2 6.0.1 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 4.0.19 4.0.20 4.0.21 4.0.22 4.0.23 4.0.24 4.1 4.2.0 5.0.0 5.1.0 5.1.1 5.2.0 5.2.1 5.2.2 5.2.3 6.0.0 trunk 3.0.40 3.0.41 3.0.42 3.0.43 3.0.44 3.0.45 3.1.0 3.1.1 3.1.2
kirki / libraries / framework / Collections / HigherOrderCollectionProxy.php
kirki / libraries / framework / Collections Last commit date
Concerns 3 weeks ago Collection.php 3 weeks ago HigherOrderCollectionProxy.php 3 weeks ago
HigherOrderCollectionProxy.php
80 lines
1 <?php
2
3 /**
4 * Provides property-style access on collection items by delegating to a named collection method such as pluck or map.
5 * Lets callers write concise syntax like $collection->pluck->name instead of wrapping closures manually.
6 * Returns the transformed collection result for each accessed key.
7 *
8 * @package Framework
9 * @subpackage Collections
10 * @since 1.0.0
11 */
12 namespace Kirki\Framework\Collections;
13
14 \defined('ABSPATH') || exit;
15 class HigherOrderCollectionProxy
16 {
17 /**
18 * The collection instance.
19 *
20 * @var Collection
21 *
22 * @since 1.0.0
23 */
24 protected $collection;
25 /**
26 * The method to call on the collection.
27 *
28 * @var string
29 *
30 * @since 1.0.0
31 */
32 protected $method;
33 /**
34 * Create a new higher order collection proxy instance.
35 *
36 * @param Collection $collection The collection instance.
37 * @param string $method The method to call on the collection.
38 *
39 * @return void
40 *
41 * @since 1.0.0
42 */
43 public function __construct(Collection $collection, string $method)
44 {
45 $this->collection = $collection;
46 $this->method = $method;
47 }
48 /**
49 * Get the value of the property.
50 *
51 * @param string $key The key of the property.
52 *
53 * @return mixed
54 *
55 * @since 1.0.0
56 */
57 public function __get($key)
58 {
59 return $this->collection->{$this->method}(function ($value) use($key) {
60 return \is_array($value) ? $value[$key] : $value->{$key};
61 });
62 }
63 /**
64 * Call the method on the collection.
65 *
66 * @param string $method The method to call on the collection.
67 * @param array $parameters The parameters to pass to the method.
68 *
69 * @return mixed
70 *
71 * @since 1.0.0
72 */
73 public function __call($method, $parameters)
74 {
75 return $this->collection->{$this->method}(function ($value) use($method, $parameters) {
76 return \is_string($value) ? $value::$method(...$parameters) : $value->{$method}(...$parameters);
77 });
78 }
79 }
80