/** * convinience method. Throws json schema validation errors as ValidationError. * @param string $schemaName e.g. 'scheduler_index' - without path and sufix! * @param array|object $data * @return void * @throws Hypercharge\Errors\ValidationError */ static function validate($schemaName, $data) { $data = Helper::arrayToObject($data); $error = JsonSchemaValidator::validate($schemaName, $data); if (!empty($error)) { throw new Errors\ValidationError($error); } }
function testAllowedTypesShouldAllHaveSchema() { $missingSchemas = array(); foreach (TransactionRequest::getAllowedTypes() as $type) { $file = JsonSchemaValidator::schemaPathFor($type); if (!file_exists($file)) { $missingSchemas[] = $type; } } $this->assertEqual(0, sizeof($missingSchemas), "missing schemas for Transaction types: " . join($missingSchemas, ', ')); }
/** * @param string $schemaName e.g. "MobilePayment" for /json/MobilePayment.json or "sale" for /json/sale.json * @param Object $object the instance to validate against the json schema * @return mixed array containing errors or false */ static function validate($schemaName, $object) { $validator = new JsonSchemaValidator($schemaName); return $validator->check($object); }
<?php namespace Hypercharge; // workaround to load SCHEMA_VERSION JsonSchemaValidator::schemaPathFor('foo'); // workaround to load VERSION Config::ENV_LIVE; class Curl implements IHttpsClient { private $user; private $passw; /** * curl handle */ private $ch; public $timeout = 30; function __construct($user, $passw) { $this->user = $user; $this->passw = $passw; $this->init(); } function __destruct() { if (method_exists($this, 'close')) { $this->close(); } } function close() {