public function evaluate(Json $json, $expression) { if ($this->evaluationMode === 'javascript') { $expression = str_replace('->', '.', $expression); } try { return $json->read($expression, $this->accessor); } catch (\Exception $e) { throw new \Exception("Failed to evaluate expression '{$expression}'"); } }
public function validate(Json $json, Validator $validator) { $validator->check($json->getContent(), $this->getContent()); if (!$validator->isValid()) { $msg = "JSON does not validate. Violations:" . PHP_EOL; foreach ($validator->getErrors() as $error) { $msg .= sprintf(" - [%s] %s" . PHP_EOL, $error['property'], $error['message']); } throw new \Exception($msg); } return true; }
public function test_should_read_valid_expression() { $this->given($accessor = PropertyAccess::createPropertyAccessor(), $json = new TestedClass('{"foo":"bar"}'))->when($result = $json->read('foo', $accessor))->string($result)->isEqualTo('bar'); }
public function __construct($content, $uri = null) { $this->uri = $uri; parent::__construct($content); }