/** * Tries to locate the resource related with the request. * * @param \AppserverIo\Psr\Servlet\ServletContextInterface $servletContext The servlet context that handles the servlets * @param string $servletPath The servlet path to return the servlet for * * @return \AppserverIo\Psr\Servlet\ServletInterface The requested servlet * @see \AppserverIo\Appserver\ServletEngine\ResourceLocator::locate() * @throws \AppserverIo\Appserver\ServletEngine\ServletNotFoundException Is thrown if no servlet can be found for the passed request */ public function locate(ServletContextInterface $servletContext, $servletPath) { // iterate over all servlets and return the matching one foreach ($servletContext->getServletMappings() as $urlPattern => $servletName) { if (fnmatch($urlPattern, $servletPath)) { return $servletContext->getServlet($servletName); } } // throw an exception if no servlet matches the servlet path throw new ServletNotFoundException(sprintf("Can't find servlet for requested path %s", $servletPath)); }