carlosafonso/laravel-crud

View on GitHub
src/Responses/ResponseBuilderFactory.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php
namespace Afonso\LvCrud\Responses;

use Illuminate\Http\Request;

use Afonso\LvCrud\Controllers\CrudController;

class ResponseBuilderFactory
{
    public static function forRequest(Request $request, CrudController $controller)
    {
        if (! $controller->supportsHtml()) {
            return new JsonResponseBuilder($request);
        }

        if (! $controller->supportsJson()) {
            return new HtmlResponseBuilder($request);
        }

        if ($request->wantsJson()) {
            return new JsonResponseBuilder($request);
        }
        return new HtmlResponseBuilder($request);
    }
}