コード例 #1
0
ファイル: ConfigurationTest.php プロジェクト: 360i/sonno
 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());
 }
コード例 #2
0
ファイル: Router.php プロジェクト: 360i/sonno
 /**
  * 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;
 }
コード例 #3
0
ファイル: UriBuilder.php プロジェクト: 360i/sonno
 /**
  * Append the path from a Path-annotated class and/or method to the
  * existing path.
  *
  * @param string $resourceClassName  The FQNS and class name of the
  *                                    Path-annotated class
  * @param string $resourceMethodName The name of the Path-annotated method
  * @return \Sonno\Uri\UriBuilder
  */
 public function resourcePath($resourceClassName, $resourceMethodName = null)
 {
     $foundClass = false;
     /** @var $route \Sonno\Configuration\Route */
     foreach ($this->_config->getRoutes() as $route) {
         if ($resourceClassName == $route->getResourceClassName()) {
             if (!$foundClass) {
                 $foundClass = true;
                 $this->path($route->getClassPath());
             }
             if ($resourceMethodName == $route->getResourceMethodName()) {
                 $this->path($route->getMethodPath());
                 return $this;
             }
         }
     }
     return $this;
 }
コード例 #4
0
ファイル: UriInfo.php プロジェクト: 360i/sonno
 /**
  * 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();
 }