feat(storage): add deleteSourceObjects option to Bucket::compose()#9211
feat(storage): add deleteSourceObjects option to Bucket::compose()#9211salilg-eng wants to merge 8 commits into
Conversation
| throw new \InvalidArgumentException('A content type could not be detected and must be provided manually.'); | ||
| } | ||
|
|
||
| $deleteSourceObjects = $options['deleteSourceObjects'] ?? false; |
There was a problem hiding this comment.
If the option is a bool we should enforce the bool:
if (!$deleteSourceObjects instanceof bool) {
throw new \InvalidArgumentException('The deleteSourceObjects option should be a boolean');
}currently If the user passes a ['deleteSourceObjects'] = 52 the check for $deleteSourceObjects would be "true" even if the value is not a boolean.
It might behave as expected, but I strongly believe we should let the user know that a parameter is the wrong parameter.
There was a problem hiding this comment.
Thank you for the excellent feedback! Enforcing strict type checking for deleteSourceObjects is a great safety addition to prevent loose 'truthy' evaluations.
Regarding the implementation: in PHP, the instanceof operator is reserved only for checking objects against class/interface structures and does not support checking primitive types (like bool, string, int). Calling $val instanceof bool on a real boolean will look for a class named bool, return false, and therefore always throw the exception.
To resolve this, I've implemented the validation using PHP's built-in primitive validation function is_bool():
if (!is_bool($deleteSourceObjects)) {
throw new \InvalidArgumentException('The deleteSourceObjects option should be a boolean.');
}There was a problem hiding this comment.
Oh yeah! My bad! haha it is in fact not instanceof bool but is_bool, you got it!
This PR introduces the
deleteSourceObjectsoption (boolean) to theBucket::compose()method. When set totrue, the library takes care of auto-deleting the source objects immediately and safely following a successful composition.Transaction Safe: Cleanup is only triggered if composition succeeds. If composition fails and throws a
ServiceException, the source files are safely preserved.Polymorphic Handling: The deletion loop correctly handles lists containing both plain string paths (
string[]) and typedStorageObjectinstances.API Definition Consistency:
deleteSourceObjectsis added as a schema query parameter in the API Service Definition (storage-v1.json), ensuring consistent serialization down to the REST connection level.