Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Http\Responses\Timeline;
- use App\Entities\Timeline\Timeline;
- use App\Http\Responses\Timeline\Segments\TransformOwner;
- use App\Http\Responses\Timeline\Segments\TransformRoutes;
- use App\Http\Responses\Timeline\Segments\TransformStatus;
- use Illuminate\Contracts\Support\Responsable;
- class TimelineInformationResponse implements Responsable
- {
- /**
- * @var \App\Entities\Timeline\Timeline
- */
- protected $timeline;
- /**
- * @var array
- */
- protected $segments = [];
- /**
- * TimelineInformationResponse constructor.
- * @param \App\Entities\Timeline\Timeline $timeline
- */
- public function __construct(Timeline $timeline)
- {
- $this->timeline = $timeline;
- $this->segments = [
- 'status' => new TransformStatus($this->timeline),
- 'routes' => new TransformRoutes($this->timeline),
- 'owner' => new TransformOwner($this->timeline),
- ];
- }
- /**
- * Return the created response
- * @param \Illuminate\Http\Request $request
- * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Response
- */
- public function toResponse($request)
- {
- return response()->json(json_decode(json_encode($this->mergeInfo())));
- }
- /**
- * Return the status information in an array
- * @return array
- */
- public function toArray()
- {
- return $this->mergeInfo();
- }
- /**
- * Merge all the information together in to an object
- * @return array
- */
- public function mergeInfo()
- {
- return array_merge(
- $this->segments['status'](),
- $this->segments['routes'](),
- $this->segments['owner']()
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement