public static function check(Resource $resource) { foreach ($resource->mandatory() as $key => $value) { if (isset($value['when']['condition']) && $value['when']['condition'] === 'is_present' && $resource->hasProperty($value['when']['property']) && $resource->hasNotProperty($key)) { throw new RuntimeException("Property `" . get_class($resource) . "::\${$key}` is mandatory but not set"); } } }
public static function check(Resource $resource) { $allowed = array_merge($resource->allowed(), $resource->mandatory()); foreach ($resource->properties() as $key => $value) { if (!in_array($key, $allowed)) { $isAllowed = false; foreach ($allowed as $kk => $vv) { if (!is_numeric($kk) && $resource->hasProperty($vv['when']['property'])) { $isAllowed = true; } } if (!$isAllowed) { throw new RuntimeException("Key `" . get_class($resource) . "::\${$key}` with value `" . $value . "` is not allowed"); } } } }