From 3dd0724ee2b8506bc49c37353785d1667bb1efc0 Mon Sep 17 00:00:00 2001 From: eldadfux Date: Mon, 1 Dec 2025 21:28:41 +0100 Subject: [PATCH] commit changes --- README.md | 6 +++--- src/Condition.php | 6 +++--- tests/ConditionTest.php | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 33fbcbf..7210b7b 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,7 @@ if ($rule = $firewall->getLastMatchedRule()) { ### Building Conditions -Conditions can be created fluently or by parsing JSON definitions: +Conditions can be created fluently or by encoding/decoding JSON definitions: ```php $condition = Condition::and([ @@ -76,8 +76,8 @@ $condition = Condition::and([ Condition::notEqual('path', '/health'), ]); -$json = $condition->toString(); -$parsed = Condition::parse($json); +$json = $condition->encode(); +$parsed = Condition::decode($json); ``` Available operators mirror the database query builder: `equal`, `notEqual`, `lessThan`, `greaterThan`, `contains`, `between`, `startsWith`, `endsWith`, `isNull`, `and`, `or`, and more. diff --git a/src/Condition.php b/src/Condition.php index db28855..f42de31 100644 --- a/src/Condition.php +++ b/src/Condition.php @@ -128,9 +128,9 @@ public static function isMethod(string $value): bool } /** - * Parses a JSON encoded condition. + * Decode a JSON encoded condition string. */ - public static function parse(string $payload): self + public static function decode(string $payload): self { try { $decoded = \json_decode($payload, true, flags: JSON_THROW_ON_ERROR); @@ -223,7 +223,7 @@ public function toArray(): array * * @throws ConditionException */ - public function toString(): string + public function encode(): string { try { return \json_encode($this->toArray(), flags: JSON_THROW_ON_ERROR); diff --git a/tests/ConditionTest.php b/tests/ConditionTest.php index 7930a62..aad0d25 100644 --- a/tests/ConditionTest.php +++ b/tests/ConditionTest.php @@ -162,8 +162,8 @@ public function testConditionSerializationRoundTrip(): void ]), ]); - $json = $condition->toString(); - $parsed = Condition::parse($json); + $json = $condition->encode(); + $parsed = Condition::decode($json); $this->assertTrue($parsed->matches(['ip' => '127.0.0.1', 'path' => '/api/users'])); $this->assertTrue($parsed->matches(['ip' => '127.0.0.1', 'path' => '/status.json'])); @@ -185,6 +185,6 @@ public function testParseRejectsInvalidJson(): void { $this->expectException(ConditionException::class); - Condition::parse('{"method":'); + Condition::decode('{"method":'); } }