for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace mindplay\sql\model\types;
use mindplay\sql\model\schema\Type;
use RuntimeException;
class JSONType implements Type
{
/**
* @var int options for json_encode()
*
* @see json_encode()
*/
public $json_encode_options = JSON_UNESCAPED_UNICODE;
public function convertToSQL($value)
if ($value === null || $value === '') {
return null;
}
$json = json_encode($value, $this->json_encode_options);
if ($json === false) {
throw new RuntimeException(json_last_error_msg());
return $json;
public function convertToPHP($value)
if (is_string($value)) {
return json_decode($value, true);
throw new RuntimeException("expected JSON string, got: " . gettype($value));