public static function check(Resource $resource) { foreach ($resource->properties() as $key => $value) { if (isset($resource->rewrites()[$key])) { $when = $resource->rewrites()[$key]['when']; $set = $resource->rewrites()[$key]['set']; if (isset($when['greater_than'])) { if ($resource->get($key) > $resource->get($when['greater_than'])) { $resource->set($key, $resource->get($set['equals_to'])); } } } } }
public static function check(Resource $resource) { foreach ($resource->properties() as $key => $value) { if (isset($resource->rules()[$key])) { $rule = $resource->rules()[$key]; if (gettype($resource->get($key)) !== key($rule)) { $expectedType = isset($rule['object']) ? $rule['object'] : 'undefined'; throw new RuntimeException('Attribute `' . $key . '` must be of type `' . (key($rule) == 'scalar' ? current($rule) : $expectedType) . '` with value `' . $value . '`'); } if (!$resource->get($key) instanceof \Sensorario\Resources\Resource && get_class($resource->get($key)) != current($rule)) { if ('array' !== current($rule)) { throw new RuntimeException('Attribute `' . $key . '` must be an object of type ' . current($rule)); } } } } }
public static function check(Resource $resource) { foreach ($resource->mandatory() as $key => $value) { if (isset($value['when']['has_value'])) { $propertyName = $value['when']['property']; $propertyValue = $value['when']['has_value']; if (is_array($propertyValue)) { foreach ($propertyValue as $value) { if ($resource->get($propertyName) === $value && $resource->hasNotProperty($key)) { throw new RuntimeException('When property `' . $key . '` has value ' . '`' . $value . '` also `' . $key . '` is mandatory'); } } } else { if ($resource->get($propertyName) === $propertyValue && $resource->hasNotProperty($key)) { throw new RuntimeException('When property `' . $propertyName . '` has value ' . '`' . $propertyValue . '` also `' . $key . '` is mandatory'); } } } } }