-
Notifications
You must be signed in to change notification settings - Fork 2
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 #21 from sburba/cleanup/rename-jsoncontext
Rename JsonContext to JsonPath
- Loading branch information
Showing
17 changed files
with
117 additions
and
113 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
This file was deleted.
Oops, something went wrong.
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,48 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Burba\StrictJson; | ||
|
||
/** | ||
* Represents the current state of JSON decoding. Used to identify where in the JSON errors occurred | ||
*/ | ||
class JsonPath | ||
{ | ||
private $path; | ||
|
||
private function __construct(string $path = '$') | ||
{ | ||
$this->path = $path; | ||
} | ||
|
||
/** | ||
* A JsonPath at the root of the JSON | ||
* @return JsonPath | ||
*/ | ||
public static function root() | ||
{ | ||
return new JsonPath(); | ||
} | ||
|
||
/** | ||
* @param int $index The array index | ||
* @return JsonPath A new JsonPath that represents indexing into the array of the current path | ||
*/ | ||
public function withArrayIndex(int $index) | ||
{ | ||
return new JsonPath($this->path . "[$index]"); | ||
} | ||
|
||
/** | ||
* @param string $property_name | ||
* @return JsonPath A new JsonPath that represents accessing a property of the current path | ||
*/ | ||
public function withProperty(string $property_name) | ||
{ | ||
return new JsonPath($this->path . ".$property_name"); | ||
} | ||
|
||
public function __toString() | ||
{ | ||
return $this->path == '$' ? '<json_root>' : $this->path; | ||
} | ||
} |
Oops, something went wrong.