public function testBasePathGetterAndSetterMethods() { $config = new Configuration(); $config->setBasePath('some/base/path'); $this->assertEquals('/some/base/path', $config->getBasePath()); $config->setBasePath('/some/other/base/path/'); $this->assertEquals('/some/other/base/path', $config->getBasePath()); }
/** * Find candidate routes for an incoming request. * * @param RequestInterface $request The incoming request * @param array $pathParameters The set of Path parameters * matched on the incoming Request * path. * * @throws \Sonno\Http\Exception\MethodNotAllowedException * @throws \Sonno\Http\Exception\NotFoundException * @throws \InvalidArgumentException * @throws \Sonno\Http\Exception\NotAcceptableException * * @return array A collection of candidate Route objects. * * @todo When filtering candidate routes by matching the incoming * media type, Sonno is ignoring any Content-Type parameters * including the charset. This should be resolved, otherwise there * will be unintended consequences while dealing with charsets and * other Content-Type parameters. */ public function match(RequestInterface $request, &$pathParameters = array()) { if (null == $request) { throw new InvalidArgumentException('Missing function argument: request'); } $candidateRoutes = array(); $allRoutes = $this->_config->getRoutes(); $requestPath = $request->getRequestUri(); $requestMethod = $request->getMethod(); $requestContentType = $request->getContentType(); // drop the base path from the beginning of the incoming path $basePath = $this->_config->getBasePath(); if ($basePath && strstr($requestPath, $basePath) !== FALSE) { $requestPath = substr($requestPath, strlen($basePath)); } // locate matching routes using the incoming request path /** @var $route \Sonno\Configuration\Route */ foreach ($allRoutes as $route) { $params = $this->_matchPath($requestPath, $route->getPath()); if (false !== $params) { $pathParameters = $params; $candidateRoutes[] = $route; } } if (empty($candidateRoutes)) { throw new NotFoundException(); } // filter candidate routes further by matching the incoming request // method $allowedMethods = array(); foreach ($candidateRoutes as $i => $route) { if ($route->getHttpMethod() != $requestMethod) { $allowedMethods[] = $route->getHttpMethod(); unset($candidateRoutes[$i]); } } if (empty($candidateRoutes)) { throw new MethodNotAllowedException($allowedMethods); } // filter candidate routes further by matching the incoming media type if (!empty($requestContentType)) { foreach ($candidateRoutes as $i => $route) { if (($offset = strpos($requestContentType, ';')) !== false) { $requestContentType = substr($requestContentType, 0, $offset); } if (!in_array($requestContentType, $route->getConsumes())) { unset($candidateRoutes[$i]); } } } if (empty($candidateRoutes)) { throw new NotAcceptableException(); } return $candidateRoutes; }
/** * Get the base URI of the application. URIs of root resource classes are * all relative to this base URI. * * @return string */ public function getBaseUri() { return $this->_config->getBasePath(); }