Skip to content

Commit 5dd2214

Browse files
committed
feat: ajout de nouveaux traits et mixins
tappable, higherodertapproxy
1 parent 163920a commit 5dd2214

2 files changed

Lines changed: 62 additions & 0 deletions

File tree

Mixins/HigherOrderTapProxy.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
/**
4+
* This file is part of Blitz PHP framework.
5+
*
6+
* (c) 2022 Dimitri Sitchet Tomkeu <devcode.dst@gmail.com>
7+
*
8+
* For the full copyright and license information, please view
9+
* the LICENSE file that was distributed with this source code.
10+
*/
11+
12+
namespace BlitzPHP\Traits\Mixins;
13+
14+
class HigherOrderTapProxy
15+
{
16+
/**
17+
* Créez une nouvelle instance de proxy tactile.
18+
*
19+
* @param mixed $target La cible étant tapée.
20+
*/
21+
public function __construct(public mixed $target)
22+
{
23+
24+
}
25+
26+
/**
27+
* Passez dynamiquement les appels de méthode à la cible.
28+
*/
29+
public function __call(string $method, array $parameters = []): mixed
30+
{
31+
$this->target->{$method}(...$parameters);
32+
33+
return $this->target;
34+
}
35+
}

Support/Tappable.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
/**
4+
* This file is part of Blitz PHP framework.
5+
*
6+
* (c) 2022 Dimitri Sitchet Tomkeu <devcode.dst@gmail.com>
7+
*
8+
* For the full copyright and license information, please view
9+
* the LICENSE file that was distributed with this source code.
10+
*/
11+
12+
namespace BlitzPHP\Traits\Support;
13+
14+
use BlitzPHP\Utilities\Helpers;
15+
16+
trait Tappable
17+
{
18+
/**
19+
* Appelez la Closure donnée avec cette instance puis renvoyez l'instance.
20+
*
21+
* @return $this|\BlitzPHP\Traits\Mixins\HigherOrderTapProxy
22+
*/
23+
public function tap(?callable $callback = null)
24+
{
25+
return Helpers::tap($this, $callback);
26+
}
27+
}

0 commit comments

Comments
 (0)