Add Command class for structured command building with validation#2
Add Command class for structured command building with validation#2TorstenDittmann wants to merge 4 commits intomainfrom
Conversation
- Add Utopia\Command class for building shell commands safely - Support per-argument validation using Utopia\Servers\Validator or callables - Add toArray() for safe argv execution and toString() for escaped shell strings - Update Console::execute() to accept Command|array|string - Fix exit code handling for Command/array execution - Add tests for Command functionality - Update README with Command usage examples - Add utopia-php/servers dependency for Validator class
Greptile SummaryThis PR introduces a Confidence Score: 5/5
Important Files Changed
Reviews (4): Last reviewed commit: "Fix exit code handling and regenerate lo..." | Re-trigger Greptile |
- Remove bool from union types to avoid confusing error messages - Update PHP version constraint to >=8.2 (required by transitive dependency) - Implement Stringable interface with __toString() method
|
@greptile-apps Thanks for the review! I've addressed all three comments:
All tests pass and PHPStan shows no errors. Could you please take another look? |
- Remove PHP 8.1 from test matrix (now requires PHP 8.2+) - Regenerate composer.lock to sync with updated PHP version constraint
- Fix Console::execute() to use proc_get_status()['exitcode'] instead of proc_close() return value, which can be -1 on some systems - Regenerate composer.lock using PHP 8.2 to ensure dependencies are compatible with minimum PHP version
|
@greptile-apps We've pushed fixes for the CI failures:
All tests pass locally now. Could you please take another look? |
This PR introduces a new
Commandclass to provide structured command building with per-argument validation, improving security when executing shell commands.Changes
New Features
Utopia\Commandclass: A new value object for building shell commands safelyadd()method for adding arguments with optional validationUtopia\Servers\Validatorinstances or callable validatorstoArray()returns argv array for safe execution viaproc_open()toString()returns shell-escaped string for display/loggingUpdates to
Console::execute()Command|array|stringfor the command parameterCommandandarrayexecute without shell interpretation (safer)Commandandarrayexecution pathsNew Dependency
utopia-php/serversto require section for theValidatorclassTests
Commandfunctionality:toArray()returns correct argv structuretoString()properly escapes shell argumentsCommandinstead of raw stringsDocumentation
Commandusage examplesConsole::execute()signature changesSecurity Benefits
Backward Compatibility
Console::execute()still acceptsarrayandstringfor backward compatibility