Created
September 8, 2016 23:59
-
-
Save guiwoda/1977d1911698fe8a91dc235db1709cee to your computer and use it in GitHub Desktop.
Wrap a middleware inside another
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 | |
class IPDependentMiddleware { | |
private $wrapped; | |
public function __construct($wrapped){ | |
$this->wrapped = $wrapped; | |
} | |
public function handle($request, $next) | |
{ | |
if ($request->ip() == '127.0.0.1'){ | |
// lookup in configuration probably | |
return $next($request); | |
} | |
return $this->wrapped->handle($request, $next); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wrapped could be any other middleware. You could build it like so: