/** * Sends the traveler down a pipe * * @param Pipe $pipe Pipe to send traveler down * * @return void */ public function travel(Pipe $pipe) { $pipe->setStream($this->progress->stream); $this->progress->startOfPipe($this, $pipe); $models = $pipe->flowThrough($this->bag); $pipes = $this->getPipes($models); if (count($pipes) === 0) { // END OF THE LINE \Log::info('PIPELINE FINISHED'); $this->progress->endOfPipeline($this); return; } $this->previousPipes[] = $pipe; $this->nextPipe = null; foreach ($pipes as $pipe) { $this->progress->endOfPipe($this, $pipe); $this->queueTravel($pipe); } }
/** * Updates the progress to be at the end of the pipe * * @param Traveler $traveler Traveler to store * @param Pipe $pipe Pipe the traveler is going to next * * @return void */ public function endOfPipe(Traveler $traveler, Pipe $pipe) { if ($traveler->nextPipe !== null) { // Create new traveler progress (and thus new traveler) if this // isn't the first pipe to be processed. $progress = new TravelerProgress(); $progress->initialiseProgress(); $progress->stream()->associate($this->stream); $progress->status = 'Traveling'; $progress->pipeable()->associate($pipe->getModel()); $progress->save(); $traveler->progress = $progress; return; } $this->status = 'Traveling'; $this->pipeable()->associate($pipe->getModel()); $this->save(); }