-
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.
JsonPointer specification is now handled with a dedicated class
- Loading branch information
Showing
9 changed files
with
123 additions
and
22 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
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,35 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace blancks\JsonPatch\json\pointer; | ||
|
||
/** | ||
* Handles JSON Pointer as per RFC-6901 | ||
* @link https://datatracker.ietf.org/doc/html/rfc6901 | ||
*/ | ||
class JsonPointer6901 implements JsonPointerHandlerInterface | ||
{ | ||
/** | ||
* Tells if the pointer is valid | ||
* @param string $pointer | ||
* @return bool | ||
*/ | ||
public function isValidPointer(string $pointer): bool | ||
{ | ||
return $pointer === '' || $pointer[0] === '/'; | ||
} | ||
|
||
/** | ||
* Returns the token list of the given $pointer | ||
* @param string $pointer the JSON Pointer | ||
* @return string[] | ||
*/ | ||
public function getTokensFromPointer(string $pointer): array | ||
{ | ||
if ($pointer !== '') { | ||
$pointer = strtr(substr($pointer, 1), ['/' => '~ ', '~1' => '/', '~0' => '~']); | ||
return explode('~ ', $pointer); | ||
} | ||
|
||
return []; | ||
} | ||
} |
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,8 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace blancks\JsonPatch\json\pointer; | ||
|
||
interface JsonPointerHandlerAwareInterface | ||
{ | ||
public function setJsonPointerHandler(JsonPointerHandlerInterface $jsonPointerHandler): void; | ||
} |
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,13 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace blancks\JsonPatch\json\pointer; | ||
|
||
trait JsonPointerHandlerAwareTrait | ||
{ | ||
protected JsonPointerHandlerInterface $jsonPointerHandler; | ||
|
||
public function setJsonPointerHandler(JsonPointerHandlerInterface $jsonPointerHandler): void | ||
{ | ||
$this->jsonPointerHandler = $jsonPointerHandler; | ||
} | ||
} |
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,15 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace blancks\JsonPatch\json\pointer; | ||
|
||
interface JsonPointerHandlerInterface | ||
{ | ||
public function isValidPointer(string $pointer): bool; | ||
|
||
/** | ||
* Should return the given JSON Pointer as an array of tokens | ||
* @param string $pointer the JSON Pointer | ||
* @return string[] | ||
*/ | ||
public function getTokensFromPointer(string $pointer): array; | ||
} |
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