예제 #1
0
파일: RouteTest.php 프로젝트: 360i/sonno
 public function testFormSetterAndGetter()
 {
     $route = new Route(array('formParams' => array('test' => 'true')));
     $this->assertEquals(array('test' => 'true'), $route->getFormParams());
     $route = new Route(array('formParams' => array('notatest' => 'true')));
     $this->assertEquals(array('notatest' => 'true'), $route->getFormParams());
 }
예제 #2
0
파일: Dispatcher.php 프로젝트: 360i/sonno
 /**
  * Construct a flat array of method arguments for the resource method.
  *
  * @param Route            $route  The route being processed.
  * @param ReflectionMethod $method The resource class method that arguments
  *                                 are needed for.
  *
  * @return array
  */
 protected function _getResourceMethodArguments(Route $route, ReflectionMethod $method)
 {
     $clsRenderable = 'Sonno\\Application\\Renderable';
     $pathParamValues = $this->_uriInfo->getPathParameters();
     $queryParamValues = $this->_uriInfo->getQueryParameters();
     $headerParamValues = $this->_request->getHeaders();
     $pathParams = $route->getPathParams() ?: array();
     $queryParams = $route->getQueryParams() ?: array();
     $headerParams = $route->getHeaderParams() ?: array();
     $formParams = $route->getFormParams() ?: array();
     $resourceMethodArgs = array();
     parse_str($this->_request->getRequestBody(), $formParamValues);
     foreach ($method->getParameters() as $idx => $reflParam) {
         $parameterName = $reflParam->getName();
         $parameterClass = $reflParam->getClass();
         // if the parameter is a type that implements Renderable, use the
         // implementation's unrender() function to generate an instance
         // of the class from the request body as the parameter value
         if (null !== $parameterClass && $parameterClass->implementsInterface($clsRenderable)) {
             $parameterClassName = $parameterClass->getName();
             $parameterValue = $parameterClassName::unrender($this->_request->getRequestBody(), new Variant(null, null, $this->_request->getContentType()));
             $resourceMethodArgs[$idx] = $parameterValue;
         }
         // search for an argument value in the Path parameter collection
         if (in_array($parameterName, $pathParams) && isset($pathParamValues[$parameterName])) {
             $resourceMethodArgs[$idx] = $pathParamValues[$parameterName];
         }
         // search for an argument value in the Query parameter collection
         if (in_array($parameterName, $queryParams) && isset($queryParamValues[$parameterName])) {
             $resourceMethodArgs[$idx] = $queryParamValues[$parameterName];
         }
         // search for an argument value in the Header parameter collection
         if (in_array($parameterName, $headerParams) && isset($headerParamValues[$parameterName])) {
             $resourceMethodArgs[$idx] = $headerParamValues[$parameterName];
         }
         // search for an argument value in the Form parameter collection
         if (in_array($parameterName, $formParams) && isset($formParamValues[$parameterName])) {
             $resourceMethodArgs[$idx] = $formParamValues[$parameterName];
         }
     }
     return $resourceMethodArgs;
 }