Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[HttpFoundation] Add a way to match a specific scheme in RequestMatcher #10556

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gnutix opened this issue Mar 27, 2014 · 0 comments
Closed

[HttpFoundation] Add a way to match a specific scheme in RequestMatcher #10556

gnutix opened this issue Mar 27, 2014 · 0 comments
Labels
Feature Good first issue Ideal for your first contribution! (some Symfony experience may be required) HttpFoundation

Comments

@gnutix
Copy link
Contributor

gnutix commented Mar 27, 2014

I've come across the need to match the scheme of a request for a security firewall and ended up with this class. I was wondering if it should be merged into the core. WDYT ?

The code is inspired by \Symfony\Component\HttpFoundation\RequestMatcher::matchMethod().

<?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);
    }
}
jjsaunier pushed a commit to jjsaunier/symfony that referenced this issue Apr 9, 2014
fabpot added a commit that referenced this issue Jun 3, 2014
…in RequestMatcher #10556 (ProPheT777)

This PR was squashed before being merged into the 2.6-dev branch (closes #10667).

Discussion
----------

[HttpFoundation] Add a way to match a specific scheme in RequestMatcher #10556

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #10556
| License       | MIT
| Doc PR        |  no

Commits
-------

787ae07 [HttpFoundation] Add a way to match a specific scheme in RequestMatcher #10556
@fabpot fabpot closed this as completed Jun 3, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Good first issue Ideal for your first contribution! (some Symfony experience may be required) HttpFoundation
Projects
None yet
Development

No branches or pull requests

3 participants