Last active
August 14, 2017 17:13
-
-
Save sebastiaanluca/4b3ac6aee3c8a0d832959b6e03a5e0c2 to your computer and use it in GitHub Desktop.
Laravel 5.5 request handling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http; | |
use SebastiaanLuca\Flow\Http\RequestHandler as BaseRequestHandler; | |
use SebastiaanLuca\Flow\Http\ShowsViews; | |
class RequestHandler extends BaseRequestHandler | |
{ | |
use ShowsViews; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace SebastiaanLuca\Flow\Http; | |
class RequestHandler | |
{ | |
/** | |
* Executed when the object itself is called as a method. | |
* | |
* Pass the call on to a handle method for improved readability. | |
* | |
* @return mixed | |
*/ | |
public function __invoke() | |
{ | |
return call_user_func_array([$this, 'handle'], func_get_args()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace SebastiaanLuca\Flow\Http; | |
use Illuminate\Contracts\View\View; | |
trait ShowsViews | |
{ | |
/** | |
* @var array | |
*/ | |
protected $viewData = []; | |
/** | |
* @param string $path | |
* @param array $data | |
* | |
* @return \Illuminate\Contracts\View\View | |
*/ | |
protected function view(string $path, array $data = []) : View | |
{ | |
return view($path, $this->viewData, $data); | |
} | |
/** | |
* @param array|string $key | |
* @param mixed $value | |
* | |
* @return $this | |
*/ | |
protected function addViewData($key, $value = null) | |
{ | |
$data = $key; | |
if (! is_array($key)) { | |
$data = [$key => $value]; | |
} | |
$this->viewData = array_merge($this->viewData, $data); | |
return $this; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Core\Http\RequestHandlers; | |
use App\Http\RequestHandler; | |
use Illuminate\Contracts\View\View; | |
class ShowHomepage extends RequestHandler | |
{ | |
/** | |
* @return \Illuminate\Contracts\View\View | |
*/ | |
public function handle() : View | |
{ | |
return $this->view('core::pages.homepage'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment