/** * @param string $jsonString * * @return Filter[] */ public static function getFiltersFromJSONString($jsonString) { return Helper::makeArrayOfObjectsFromJsonString($jsonString, ['property', 'value'], function ($rawObj) { $value = $rawObj->value; if ($value === 'null') { $value = null; } return new Filter($rawObj->property, $value, isset($rawObj->operator) ? $rawObj->operator : Filter::OP_EQ); }, 'Filter'); }
public function testMakeArrayOfObjectsWithFilteredObjectCreator() { $data = [['property' => 'id', 'value' => '2'], ['property' => 'name', 'value' => 'some']]; $f = function ($data) { $obj = new \stdClass(); if ($data->property == "name") { return null; } $obj->property = $data->property; $obj->value = $data->value; return $obj; }; $objects = Helper::makeArrayOfObjectsFromJsonString(json_encode($data), ['property', 'value'], $f); $this->assertCount(1, $objects); $this->assertNotNull($objects[0]); }