Symfony\Component\Security\Http\HttpUtils::checkRequestPath PHP Method

checkRequestPath() public method

Checks that a given path matches the Request.
public checkRequestPath ( Request $request, string $path ) : boolean
$request Symfony\Component\HttpFoundation\Request A Request instance
$path string A path (an absolute path (/foo), an absolute URL (http://...), or a route name (foo))
return boolean true if the path is the same as the one from the Request, false otherwise
    public function checkRequestPath(Request $request, $path)
    {
        if ('/' !== $path[0]) {
            try {
                $parameters = $this->router->match($request->getPathInfo());

                return $path === $parameters['_route'];
            } catch (\Exception $e) {
                return false;
            }
        }

        return $path === $request->getPathInfo();
    }

Usage Example

 /**
  * Gets the appropriate resource owner for a request.
  *
  * @param Request $request
  *
  * @return null|array
  */
 public function getResourceOwnerByRequest(Request $request)
 {
     foreach ($this->resourceOwners as $name => $checkPath) {
         if ($this->httpUtils->checkRequestPath($request, $checkPath)) {
             return array($this->getResourceOwnerByName($name), $checkPath);
         }
     }
 }
All Usage Examples Of Symfony\Component\Security\Http\HttpUtils::checkRequestPath