Skip to content

Commit

Permalink
Add static constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
bajb committed Dec 11, 2019
1 parent 4f7ea93 commit 5a4d0b9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/FuncCondition.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ public function __construct(callable $func)
$this->_func = $func;
}

public static function i(callable $func)
{
return new static($func);
}

public function match(Context $context): bool
{
return ($this->_func)($context);
Expand Down
2 changes: 1 addition & 1 deletion tests/FuncConditionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ public function testInstance()
{
$c = $this->_makeContext();
self::assertTrue((new FuncCondition(function (Context $ctx) { return $ctx->meta()->has('a'); }))->match($c));
self::assertFalse((new FuncCondition(function (Context $ctx) { return $ctx->meta()->has('b'); }))->match($c));
self::assertFalse((FuncCondition::i(function (Context $ctx) { return $ctx->meta()->has('b'); }))->match($c));
}
}

0 comments on commit 5a4d0b9

Please sign in to comment.