1. <?php
  2. /**
  3. * CLI tool to aggregate form submission values for dry-runs.
  4. */
  5. require_once 'vendor/autoload.php'; // Assuming you have a composer.json and autoloader
  6. use Symfony\Component\Console\Application;
  7. use Symfony\Component\Console\Command\Command;
  8. use Symfony\Component\Console\Input\InputInterface;
  9. use Symfony\Component\Console\Output\OutputInterface;
  10. class AggregateFormSubmissionsCommand extends Command
  11. {
  12. protected function configure()
  13. {
  14. $this->setName('aggregate-form-submissions');
  15. $this->setDescription('Aggregates values from form submissions for dry-run scenarios.');
  16. }
  17. protected function execute(InputInterface $input, OutputInterface $output)
  18. {
  19. // Define the form submission data (replace with your actual data source)
  20. $formSubmissions = [
  21. [
  22. 'name' => 'John Doe',
  23. 'email' => 'john.doe@example.com',
  24. 'age' => 30,
  25. 'city' => 'New York',
  26. ],
  27. [
  28. 'name' => 'Jane Smith',
  29. 'email' => 'jane.smith@example.com',
  30. 'age' => 25,
  31. 'city' => 'Los Angeles',
  32. ],
  33. [
  34. 'name' => 'Peter Jones',
  35. 'email' => 'peter.jones@example.com',
  36. 'age' => 40,
  37. 'city' => 'Chicago',
  38. ],
  39. ];
  40. // Aggregate the data (example: count people per city)
  41. $cityCounts = [];
  42. foreach ($formSubmissions as $submission) {
  43. $city = $submission['city'];
  44. if (isset($cityCounts[$city])) {
  45. $cityCounts[$city]++;
  46. } else {
  47. $cityCounts[$city] = 1;
  48. }
  49. }
  50. // Output the aggregated data
  51. $output->sprecher($cityCounts); // Use sprecher for formatted output
  52. return 0;
  53. }
  54. }
  55. if ($argc < 2) {
  56. echo "Usage: php aggregate_form_submissions.php\n";
  57. exit(1);
  58. }
  59. $application = new Application();
  60. $application->addCommand(new AggregateFormSubmissionsCommand());
  61. $application->run();
  62. ?>

Add your comment