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) { foreach ($resource->mandatory() as $key => $value) { if (is_numeric($key) && $resource->hasNotProperty($value) && !isset($resource->defaults()[$value])) { throw new RuntimeException("Property `" . get_class($resource) . "::\${$value}` is mandatory but not set. " . "Mandatory fields are: " . join(',', $resource->mandatory()) . "."); } } }
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'); } } } } }