Created
March 27, 2014 12:59
-
-
Save gnutix/9807001 to your computer and use it in GitHub Desktop.
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 SymfonyExtension\Component\HttpFoundation; | |
use Symfony\Component\HttpFoundation\Request as BaseRequest; | |
use Symfony\Component\HttpFoundation\RequestMatcher as BaseRequestMatcher; | |
/** | |
* This class improves Symfony2's RequestMatcher by adding a method to specify the scheme(s) to match. | |
*/ | |
class RequestMatcher extends BaseRequestMatcher | |
{ | |
/** @var string[] */ | |
protected $schemes; | |
/** | |
* Adds a check for the HTTP scheme. | |
* | |
* @param string|string[]|null $scheme An HTTP scheme or an array of HTTP schemes | |
*/ | |
public function matchScheme($scheme) | |
{ | |
$this->schemes = array_map('strtolower', (array) $scheme); | |
} | |
/** | |
* {@inheritDoc} | |
*/ | |
public function matches(BaseRequest $request) | |
{ | |
if ($this->schemes && !in_array($request->getScheme(), $this->schemes)) { | |
return false; | |
} | |
return parent::matches($request); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment