-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from transprime-research/feature-make-shorter-s…
…yntaxes Feature make shorter syntaxes
- Loading branch information
Showing
8 changed files
with
304 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,9 @@ php: | |
- 7.2 | ||
- 7.3 | ||
- 7.4 | ||
- 8.0 | ||
- 8.1 | ||
- 8.2 | ||
|
||
before_script: | ||
- composer self-update | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Transprime\Piper; | ||
|
||
class CallablePiper implements \ArrayAccess | ||
{ | ||
private Piper $piper; | ||
|
||
public function __construct(Piper $piper) | ||
{ | ||
$this->piper = $piper->to(fn($vl) => $vl); | ||
} | ||
|
||
/** | ||
* @param callable|array|null $callable | ||
* @return mixed|self | ||
*/ | ||
public function __invoke(...$callable): mixed | ||
{ | ||
return $callable ? $this->to(...$callable) : $this->up(); | ||
} | ||
|
||
public function to(callable $action, ...$extraParameters): static | ||
{ | ||
$this->piper->to($action, ...$extraParameters); | ||
|
||
return $this; | ||
} | ||
|
||
public function up(callable $action = null) | ||
{ | ||
return $this->piper->up($action); | ||
} | ||
|
||
public function p(callable ...$callable) | ||
{ | ||
return $this->__invoke(...$callable); | ||
} | ||
|
||
public function _(callable ...$callable) | ||
{ | ||
return $this->__invoke(...$callable); | ||
} | ||
|
||
public function fn(callable ...$callable) | ||
{ | ||
return $this->__invoke(...$callable); | ||
} | ||
|
||
public function offsetExists(mixed $offset): bool | ||
{ | ||
return true; | ||
} | ||
|
||
public function offsetGet(mixed ...$offset): mixed | ||
{ | ||
if (is_array($offset[0])) { | ||
return $this->__invoke(...$offset[0]); | ||
} | ||
|
||
return $this->__invoke(...$offset); | ||
} | ||
|
||
public function offsetSet(mixed $offset, mixed $value): void {} | ||
|
||
public function offsetUnset(mixed $offset): void {} | ||
|
||
/** | ||
* @return mixed|self | ||
*/ | ||
public function __call(string $name, array $arguments) | ||
{ | ||
return $this->__invoke($name, ...$arguments); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Transprime\Piper; | ||
|
||
trait On | ||
{ | ||
/** | ||
* @param callable|array ...$functions | ||
* @return mixed|string | ||
* @throws Exceptions\PiperException | ||
*/ | ||
public function ln(...$functions) | ||
{ | ||
foreach ($functions as $function) { | ||
$callables = is_array($function) ? $function : [$function]; | ||
$this->to(...$callables); | ||
} | ||
|
||
return $this->up(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ | |
|
||
class Piper | ||
{ | ||
use On; | ||
|
||
private $piped = []; | ||
|
||
private $extraParameters = []; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters