Example #1
0
 /**
  * Restores request object and errors list from session (restore form variables)
  *
  */
 public function restore()
 {
     @session_start();
     $this->errorList = $_SESSION['validatorData'][$this->name]['error'];
     //$this->restoredData =  $_SESSION['validatorData'][$this->name]['data'];
     $this->restoredRequest = new Request();
     $this->restoredRequest->setValueArray($_SESSION['validatorData'][$this->name]['data']);
     unset($_SESSION['validatorData'][$this->name]);
 }
Example #2
0
 public function loadRequestModel(Request $request, $key = '')
 {
     $json = $request->getJSON();
     if ($key) {
         $json = $json[$key];
     }
     $modelReq = new Request();
     $modelReq->setValueArray($json);
     if (!empty($json['attributes']) && is_array($json['attributes'])) {
         foreach ($json['attributes'] as $key => $value) {
             if (!empty($value['valueIDs'])) {
                 foreach (json_decode($value['valueIDs']) as $valueID) {
                     $modelReq->set('specItem_' . $valueID, 'on');
                 }
                 if (!empty($value['newValues'])) {
                     foreach (json_decode($value['newValues']) as $newVal) {
                         $others = $modelReq->get('other', array());
                         $others[$key][] = $newVal;
                         $modelReq->set('other', $others);
                     }
                 }
                 $modelReq->set('removeEmpty_' . $key, 'on');
             } else {
                 if (isset($value['ID'])) {
                     $modelReq->set('specField_' . $key, $value['ID']);
                     if (!empty($value['newValue'])) {
                         $others = $modelReq->get('other', array());
                         $others[$key] = $value['newValue'];
                         $modelReq->set('other', $others);
                     }
                 } else {
                     $modelReq->set('specField_' . $key, $value['value']);
                     foreach (self::getApplication()->getLanguageArray() as $lang) {
                         if (!empty($value['value_' . $lang])) {
                             $modelReq->set('specField_' . $key . '_' . $lang, $value['value_' . $lang]);
                         }
                     }
                 }
             }
         }
     }
     $this->loadRequestData($modelReq);
 }
 public function isValid($validatorName = 'eavValidator')
 {
     ClassLoader::import('framework.request.validator.RequestValidator');
     $request = new Request();
     $request->setValueArray($this->getFormData());
     $validator = new RequestValidator($validatorName, $request);
     $this->setValidation($validator);
     return $validator->isValid();
 }
Example #4
0
 /**
  * Connects a new route to some URL pattern.
  * URLPattern might have "variables", which has a ":" at the beggining. e.x. ":action"
  *
  * E.x.:
  * <code>
  * $router->connect(":controller/:action/:id", array(), array("id" => "[0-9]+"));
  * </code>
  *
  * The route above will map to following URL's:
  * item/add/34
  * post/view/9233
  *
  * But not to these:
  * item/add/AC331
  * post/view
  *
  * URLPattern variables :controller :action :id by default might have value from
  * a range [_.a-zA-Z0-9]. When you pass array("id" => "[0-9]") as varRequirements
  * id is required to be only numeric.
  *
  *
  * @link http://www.symfony-project.com/book/trunk/routing
  *
  * @param string $URLPattern
  * @param array $defaultValueList
  * @param array $varRequirements
  *
  */
 public function mapToRoute($URLStr, Request $request)
 {
     if ('/' == substr($URLStr, -1)) {
         $URLStr = substr($URLStr, 0, -1);
     }
     if (empty($URLStr) || !$this->isURLRewriteEnabled) {
         if (!$request->isValueSet("action")) {
             $request->set("action", $this->defaultAction);
         }
         if (!$request->isValueSet("controller")) {
             $request->set("controller", $this->defaultController);
         }
         return false;
     }
     foreach ($this->routeList as $route) {
         $routePattern = str_replace('\\047', '\\/', $route->getRecognitionPattern());
         $routePattern = str_replace('.', '\\.', $routePattern);
         if (preg_match("/^" . $routePattern . "\$/U", $URLStr, $result)) {
             unset($result[0]);
             $varList = $route->getVariableList();
             foreach ($varList as $key => $value) {
                 $request->set($value, $result[$key + 1]);
             }
             $requestValueAssigments = $route->getRequestValueAssigments();
             $request->sanitizeArray($requestValueAssigments);
             $request->setValueArray($requestValueAssigments);
             return $route;
         }
     }
     throw new RouterException("Unable to map to any route");
 }