コード例 #1
0
 public function getItemsOf($collection)
 {
     if (file_exists($this->dataFilePath)) {
         $dataJSON = $this->fileGetJSON();
         $jsonObject = new JsonObject($dataJSON);
         $jsonResult = $jsonObject->get('$.' . $collection . '[*]');
         if ($jsonResult) {
             return $jsonResult;
         }
         return [];
     } else {
         $this->initDataFile();
     }
 }
コード例 #2
0
 public function testGetJsonObjects()
 {
     $jsonObject = new JsonObject($this->json);
     $childs = $jsonObject->getJsonObjects('$.store.book[*]');
     foreach ($childs as $key => $book) {
         $book->set('$.price', $key);
         $this->assertEquals($jsonObject->{'$.store.book[' . $key . ']'}[0], $book->getValue());
     }
     $this->assertEquals(4, count($childs));
     $jsonObject = new JsonObject($this->json, true);
     $bike = $jsonObject->getJsonObjects('$.store.bicycle');
     $bike->set('$.price', 412);
     $this->assertEquals($jsonObject->{'$.store.bicycle'}, $bike->getValue());
     $this->assertFalse($jsonObject->getJsonObjects('$.abc'));
 }
コード例 #3
0
ファイル: test.php プロジェクト: javibravo/JsonPath-PHP
  ]
}
';
switch (count($argv)) {
    case 1:
        print "Usage: {$argv['0']} <jsonpath> [<file to json>]\n";
        print "If no json file is given it defaults to the json specified in http://goessner.net/articles/JsonPath/index.html#e3\n";
        die;
        break;
    case 3:
        $json = file_get_contents($argv[2]);
    default:
        $jsonPath = $argv[1];
}
try {
    $jsonObject = new JsonObject($json);
} catch (InvalidJsonException $e) {
    print "Invalid JSON error: '" . $e->getMessage() . "'\r\n";
    die;
}
try {
    $r = $jsonObject->get($jsonPath);
} catch (InvalidJsonPathException $e) {
    print "Invalid JSONPath error: '" . $e->getMessage() . "'\r\n";
    die;
}
if ($r === false) {
    print "false";
} else {
    print json_encode($r);
}
コード例 #4
0
ファイル: JsonPath.php プロジェクト: synaq/mockery-extras
 public function match(&$actual)
 {
     $json = new JsonObject($actual, true);
     $actualValue = $json->get($this->jsonPathSelector);
     return $actualValue == $this->_expected;
 }