Skip to content

Commit 6ba1916

Browse files
committed
feat(hom): support higher order messaging
1 parent 0b142f4 commit 6ba1916

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

src/HigherOrderMessage.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the PHP-UNDERSCORE package.
5+
*
6+
* (c) Jitendra Adhikari <[email protected]>
7+
* <https://github.com/adhocore>
8+
*
9+
* Licensed under MIT license.
10+
*/
11+
12+
namespace Ahc\Underscore;
13+
14+
/**
15+
* Source: Laravel HigherOrderProxy
16+
*
17+
* @link https://github.com/laravel/framework/pull/16267
18+
*/
19+
class HigherOrderMessage
20+
{
21+
protected $underscore;
22+
protected $method;
23+
24+
public function __construct(UnderscoreBase $underscore, $method)
25+
{
26+
$this->underscore = $underscore;
27+
$this->method = $method;
28+
}
29+
30+
public function __call($method, $args)
31+
{
32+
$this->underscore->{$this->method}(function ($item) use ($method, $args) {
33+
return \call_user_func_array([$item, $method], $args);
34+
});
35+
}
36+
37+
public function __get($prop)
38+
{
39+
$this->underscore->{$this->method}(function ($item) use ($prop) {
40+
$props = \array_column([$item], $prop);
41+
42+
return $props ? $props[0] : null;
43+
});
44+
}
45+
}

0 commit comments

Comments
 (0)