Example #1
0
 /**
  * Automatically generated method, will be overridden
  *
  * @param Request $request      	
  * @return Response
  */
 public function run(Request $request)
 {
     $json = Json::decode($request->getContent());
     $path = new JSONPath($json);
     $login = $path->find('$.data.attributes.login')->first();
     $password = $path->find('$.data.attributes.password')->first();
     $domain = new SessionDomain($this->getServiceContainer());
     $payload = $domain->login($login, $password);
     return $this->responder->run($request, $payload);
 }
 /**
  * gets connection params from ENV if available
  *
  * @return array connection params
  */
 public static function getConnection()
 {
     // defaults
     $ret = ['uri' => null, 'db' => 'db'];
     if (isset($_ENV['VCAP_SERVICES'])) {
         $path = new JSONPath(json_decode($_ENV['VCAP_SERVICES'], true));
         $ret['uri'] = $path->find('$..mongodb[0].*.uri')->first();
         $ret['db'] = $path->find('$..mongodb[0].*.database')->first();
     }
     return $ret;
 }
 public function testIterating()
 {
     $data = $this->exampleData(rand(0, 1));
     $jsonPath = new JSONPath($data);
     $conferences = $jsonPath->find('.conferences.*');
     $names = array();
     foreach ($conferences as $conference) {
         $players = $conference->find('.teams.*.players[?(@.active=yes)]');
         foreach ($players as $player) {
             $names[] = $player->name;
         }
     }
     $this->assertEquals(['Joe Face', 'something'], $names);
 }
Example #4
0
 public function testBenchmark4()
 {
     $goessnerJsonPath = new PeekmoJsonPath();
     $exampleData = $this->exampleData();
     $start1 = microtime(true);
     for ($i = 0; $i < 100; $i += 1) {
         $results1 = $goessnerJsonPath->jsonPath($exampleData, '$..price');
     }
     $end1 = microtime(true);
     $exampleData = $this->exampleData(true);
     $start2 = microtime(true);
     $jsonPath = new JSONPath($exampleData);
     for ($i = 0; $i < 100; $i += 1) {
         $results2 = $jsonPath->find('$..price');
     }
     $end2 = microtime(true);
     $this->assertEquals($results1, $results2->data());
     echo "Old JsonPath: " . ($end1 - $start1) . PHP_EOL;
     echo "JSONPath: " . ($end2 - $start2) . PHP_EOL;
 }
 /**
  * @param Definition $scheme
  * @param JSONPath $jsonPath
  * @throws \RuntimeException
  */
 protected function validateScheme(Definition $scheme, JSONPath $jsonPath)
 {
     $this->flagPropertyAsRequiredFromDefinition($scheme);
     /** @var Property $property */
     foreach ($scheme->properties as $property) {
         $value = $jsonPath->find('$.' . $property->property);
         if (!$value->valid()) {
             if ($property->required) {
                 throw new RuntimeException(sprintf('Cannot find property "%s" in json', $property->property));
             } else {
                 continue;
             }
         }
         $iterable = $this->validateProperty($property, current($value->data()));
         if ($property->items && $property->items->ref) {
             $scheme = $this->getSchemeByName($property->items->ref);
             parent::assertInstanceOf(Definition::class, $scheme, sprintf('Definition "%s" not found in Swagger Scheme', $property->items->ref));
             if ($iterable) {
                 foreach (current($value->data()) as $entity) {
                     $this->validateScheme($scheme, new JSONPath($entity));
                 }
             }
         }
     }
 }
Example #6
0
 public function testLastKey()
 {
     // Array test for array
     $jsonPath = new JSONPath(array('a' => 'A', 'b' => 'B', 'c' => 'C'));
     $lastKey = $jsonPath->lastKey();
     $this->assertEquals('c', $lastKey);
     // Array test for object
     $jsonPath = new JSONPath((object) array('a' => 'A', 'b' => 'B', 'c' => 'C'));
     $lastKey = $jsonPath->lastKey();
     $this->assertEquals('c', $lastKey);
 }