Ejemplo n.º 1
0
 /**
  * If this request was not cancelled, and the request's \Phruts\Config\ActionConfig
  * has not disabled validation, call the validate method of the specified
  * ActionForm, and forward back to the input form if there were any
  * errors.
  *
  * Return true if we should continue processing, or false if we have already
  * forwarded control back to the input form.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request The kernel request we are
  * processing
  * @param \Symfony\Component\HttpFoundation\Response $response The kernel response we are
  * creating
  * @param \Phruts\Action\AbstractActionForm $form The ActionForm instance we are
  * populating
  * @param \Phruts\Action\ActionMapping $mapping The \Phruts\Config\ActionConfig we are using
  * @return boolean
  */
 protected function processValidate(\Symfony\Component\HttpFoundation\Request $request, \Symfony\Component\HttpFoundation\Response $response, \Phruts\Action\AbstractActionForm $form = null, \Phruts\Action\ActionMapping $mapping)
 {
     if (is_null($form)) {
         return true;
     }
     // Was this request cancelled?
     if (!is_null($request->attributes->get(\Phruts\Util\Globals::CANCEL_KEY))) {
         if (!empty($this->log)) {
             $this->log->debug('  Cancelled transaction, skipping validation');
         }
         return true;
     }
     // Has validation been turned off for this mapping?
     if (!$mapping->getValidate()) {
         return true;
     }
     // Call the form bean's validation method
     if (!empty($this->log)) {
         $this->log->debug('  Validating input form properties');
     }
     $errors = $form->validate($mapping, $request);
     if (is_null($errors) || $errors->isEmpty()) {
         if (!empty($this->log)) {
             $this->log->debug('  No errors detected, accepting input');
         }
         return true;
     }
     // Has an input form been specified for this mapping?
     $input = $mapping->getInput();
     if (is_null($input)) {
         if (!empty($this->log)) {
             $this->log->debug('  Validation failed but no input form available');
         }
         $msg = $this->getInternal()->getMessage(null, 'noInput', $mapping->getPath());
         throw new \Phruts\Exception($msg);
     }
     // Save our error messages and return to the input form if possible
     if (!empty($this->log)) {
         $this->log->debug('  Validation failed, returning to "' . $input . '"');
     }
     $request->attributes->set(\Phruts\Util\Globals::ERROR_KEY, $errors);
     if ($this->moduleConfig->getControllerConfig()->getInputForward()) {
         $forward = $mapping->findForward($input);
         $this->processForwardConfig($request, $response, $forward);
     } else {
         // Delegate the processing of this request
         if (!empty($this->log)) {
             $this->log->debug('  Delegating via forward to "' . $input . '"');
         }
         $this->doForward($input, $request, $response);
     }
 }