1. <?php
  2. class TaskQueue {
  3. private $tasks = [];
  4. public function enqueue(string $textBlock, string $environment): void {
  5. // Add task to the queue
  6. $this->tasks[] = [
  7. 'text' => $textBlock,
  8. 'environment' => $environment,
  9. ];
  10. }
  11. private function processTask(array $task): void {
  12. // Simulate staging environment processing
  13. echo "Processing text block: " . $task['text'] . " for environment: " . $task['environment'] . "\n";
  14. // In a real scenario, this would involve sending the text to the staging environment
  15. }
  16. public function run(): void {
  17. // Process tasks from the queue
  18. while (!empty($this->tasks)) {
  19. $task = array_shift($this->tasks); // Get the next task
  20. $this->processTask($task);
  21. }
  22. }
  23. }
  24. // Example Usage
  25. $queue = new TaskQueue();
  26. $queue->enqueue("This is the first text block.", "staging");
  27. $queue->enqueue("Another text block for staging.", "staging");
  28. $queue->enqueue("Yet another one.", "production"); //This will be processed later
  29. $queue->run();
  30. ?>

Add your comment