/**
  * Determines the action method and assures that the method exists.
  *
  * @return string The action method name
  * @throws \F3\FLOW3\MVC\Exception\NoSuchActionException if the action specified in the request object does not exist (and if there's no default action either).
  * @author Robert Lemke <*****@*****.**>
  */
 protected function resolveActionMethodName()
 {
     if ($this->request->getControllerActionName() === 'index') {
         $actionName = 'index';
         switch ($this->request->getMethod()) {
             case 'GET':
                 $actionName = $this->request->hasArgument('id') ? 'show' : 'list';
                 break;
             case 'POST':
                 $actionName = 'create';
                 break;
             case 'PUT':
                 if (!$this->request->hasArgument('id')) {
                     $this->throwStatus(400, NULL, 'Missing identifier');
                 }
                 $actionName = 'update';
                 break;
             case 'DELETE':
                 if (!$this->request->hasArgument('id')) {
                     $this->throwStatus(400, NULL, 'Missing identifier');
                 }
                 $actionName = 'delete';
                 break;
         }
         $this->request->setControllerActionName($actionName);
     }
     return parent::resolveActionMethodName();
 }
 /**
  * @test
  * @author Bastian Waidelich <*****@*****.**>
  */
 public function buildPrependsBaseUriIfCreateAbsoluteUriIsSet()
 {
     $this->router->expects($this->once())->method('resolve')->will($this->returnValue('resolvedUri'));
     $this->request->expects($this->once())->method('getBaseUri')->will($this->returnValue('BaseUri/'));
     $this->uriBuilder->setCreateAbsoluteUri(TRUE);
     $expectedResult = 'BaseUri/resolvedUri';
     $actualResult = $this->uriBuilder->build();
     $this->assertEquals($expectedResult, $actualResult);
 }
 /**
  * @test
  * @author Bastian Waidelich <*****@*****.**>
  */
 public function buildSetsPOSTArgumentsFromRequest()
 {
     $this->setUpRequestBuilder();
     $argument = NULL;
     $setArgumentCallback = function () use(&$argument) {
         $args = func_get_args();
         if ($args[0] === 'someArgument') {
             $argument = $args[1];
         }
     };
     $this->mockRequest->expects($this->any())->method('getMethod')->will($this->returnValue('POST'));
     $this->mockEnvironment->expects($this->any())->method('getRawPostArguments')->will($this->returnValue(array('someArgument' => 'POSTArgument')));
     $this->mockEnvironment->expects($this->any())->method('getUploadedFiles')->will($this->returnValue(array()));
     $this->mockRequest->expects($this->exactly(2))->method('setArgument')->will($this->returnCallback($setArgumentCallback));
     $this->builder->build();
     $this->assertEquals('POSTArgument', $argument);
 }
 /**
  * Sets package key, subpackage key, controller name, action name and format
  * of the current request.
  *
  * @param array $arguments
  * @return void
  * @author Bastian Waidelich <*****@*****.**>
  * @author Karsten Dambekalns <*****@*****.**>
  * @see \F3\FLOW3\MVC\Web\Request
  * @api
  */
 protected function setControllerKeysAndFormat(array $arguments)
 {
     foreach ($arguments as $argumentName => $argumentValue) {
         switch ($argumentName) {
             case '@package':
                 $this->request->setControllerPackageKey($argumentValue);
                 break;
             case '@subpackage':
                 $this->request->setControllerSubpackageKey($argumentValue);
                 break;
             case '@controller':
                 $this->request->setControllerName($argumentValue);
                 break;
             case '@action':
                 $this->request->setControllerActionName(lcfirst($argumentValue));
                 break;
             case '@format':
                 $this->request->setFormat(strtolower($argumentValue));
                 break;
         }
     }
 }
 /**
  * Builds the URI
  *
  * @return string The URI
  * @api
  * @author Bastian Waidelich <*****@*****.**>
  */
 public function build()
 {
     $arguments = array();
     if ($this->addQueryString === TRUE) {
         $arguments = $this->request->getArguments();
         foreach ($this->argumentsToBeExcludedFromQueryString as $argumentToBeExcluded) {
             unset($arguments[$argumentToBeExcluded]);
         }
     }
     $arguments = \F3\FLOW3\Utility\Arrays::arrayMergeRecursiveOverrule($arguments, $this->arguments);
     $uri = $this->router->resolve($arguments);
     $this->lastArguments = $arguments;
     if ($this->section !== '') {
         $uri .= '#' . $this->section;
     }
     if (!$this->environment->isRewriteEnabled()) {
         $uri = 'index.php/' . $uri;
     }
     if ($this->createAbsoluteUri === TRUE) {
         $uri = $this->request->getBaseUri() . $uri;
     }
     return $uri;
 }
 /**
  * Verify the request. Checks if there is an __hmac argument, and if yes, tries to validate and verify it.
  *
  * In the end, $request->setHmacVerified is set depending on the value.
  * @param \F3\FLOW3\MVC\Web\Request $request The request to verify
  * @return void
  * @author Sebastian Kurfürst <*****@*****.**>
  */
 public function verifyRequest(\F3\FLOW3\MVC\Web\Request $request)
 {
     if (!$request->hasArgument('__hmac')) {
         $request->setHmacVerified(FALSE);
         return;
     }
     $hmac = $request->getArgument('__hmac');
     if (strlen($hmac) < 40) {
         throw new \F3\FLOW3\Security\Exception\SyntacticallyWrongRequestHashException('Request hash too short. This is a probably manipulation attempt!', 1255089361);
     }
     $serializedFieldNames = substr($hmac, 0, -40);
     // TODO: Constant for hash length needs to be introduced
     $hash = substr($hmac, -40);
     if ($this->hashService->validateHmac($serializedFieldNames, $hash)) {
         $requestArguments = $request->getArguments();
         // Unset framework arguments
         unset($requestArguments['__referrer']);
         unset($requestArguments['__hmac']);
         if ($this->checkFieldNameInclusion($requestArguments, unserialize($serializedFieldNames))) {
             $request->setHmacVerified(TRUE);
         } else {
             $request->setHmacVerified(FALSE);
         }
     } else {
         $request->setHmacVerified(FALSE);
     }
 }
 /**
  * Takes the raw request data and - depending on the request method
  * maps them into the request object. Afterwards all mapped arguments
  * can be retrieved by the getArgument(s) method, no matter if they
  * have been GET, POST or PUT arguments before.
  *
  * @param \F3\FLOW3\MVC\Web\Request $request The web request which will contain the arguments
  * @return void
  * @author Robert Lemke <*****@*****.**>
  */
 protected function setArgumentsFromRawRequestData(\F3\FLOW3\MVC\Web\Request $request)
 {
     foreach ($request->getRequestUri()->getArguments() as $argumentName => $argumentValue) {
         $request->setArgument($argumentName, $argumentValue);
     }
     switch ($request->getMethod()) {
         case 'POST':
             foreach ($this->environment->getRawPostArguments() as $argumentName => $argumentValue) {
                 $request->setArgument($argumentName, $argumentValue);
             }
             foreach ($this->environment->getUploadedFiles() as $argumentName => $argumentValue) {
                 if ($request->hasArgument($argumentName)) {
                     $existingArgumentValue = $request->getArgument($argumentName);
                     if (is_array($existingArgumentValue)) {
                         $request->setArgument($argumentName, \F3\FLOW3\Utility\Arrays::arrayMergeRecursiveOverrule($existingArgumentValue, $argumentValue));
                     }
                 } else {
                     $request->setArgument($argumentName, $argumentValue);
                 }
             }
             break;
             #			case 'PUT' :
             #				$putArguments = array();
             #				parse_str(file_get_contents("php://input"), $putArguments);
             #				foreach ($putArguments as $argumentName => $argumentValue) {
             #					$request->setArgument($argumentName, $argumentValue);
             #				}
             #			break;
     }
 }