Exemple #1
0
 /**
  * Validates the object and all objects related to this table.
  *
  * @see        getValidationFailures()
  * @param      ValidatorInterface|null $validator A Validator class instance
  * @return     boolean Whether all objects pass validation.
  */
 public function validate(ValidatorInterface $validator = null)
 {
     if (null === $validator) {
         $validator = new RecursiveValidator(new ExecutionContextFactory(new IdentityTranslator()), new LazyLoadingMetadataFactory(new StaticMethodLoader()), new ConstraintValidatorFactory());
     }
     $failureMap = new ConstraintViolationList();
     if (!$this->alreadyInValidation) {
         $this->alreadyInValidation = true;
         $retval = null;
         // We call the validate method on the following object(s) if they
         // were passed to this object by their corresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         // If validate() method exists, the validate-behavior is configured for related object
         if (method_exists($this->aOwner, 'validate')) {
             if (!$this->aOwner->validate($validator)) {
                 $failureMap->addAll($this->aOwner->getValidationFailures());
             }
         }
         $retval = $validator->validate($this);
         if (count($retval) > 0) {
             $failureMap->addAll($retval);
         }
         if (null !== $this->collPackPermissions) {
             foreach ($this->collPackPermissions as $referrerFK) {
                 if (method_exists($referrerFK, 'validate')) {
                     if (!$referrerFK->validate($validator)) {
                         $failureMap->addAll($referrerFK->getValidationFailures());
                     }
                 }
             }
         }
         if (null !== $this->collUserGroups) {
             foreach ($this->collUserGroups as $referrerFK) {
                 if (method_exists($referrerFK, 'validate')) {
                     if (!$referrerFK->validate($validator)) {
                         $failureMap->addAll($referrerFK->getValidationFailures());
                     }
                 }
             }
         }
         $this->alreadyInValidation = false;
     }
     $this->validationFailures = $failureMap;
     return (bool) (!(count($this->validationFailures) > 0));
 }
 protected function validateOne()
 {
     setContentType("json");
     $user = new User();
     $given = array_keys($_POST);
     $response["error"] = null;
     if (count($given) == 1) {
         if ($given[0] == "username") {
             $user->setUsername($_POST["username"]);
         } else {
             if ($given[0] == "password") {
                 $user->setPassword($_POST["password"]);
             } else {
                 if ($given[0] == "email") {
                     $user->setEmail($_POST["email"]);
                 } else {
                     if ($given[0] == "name") {
                         $user->setName($_POST["name"]);
                     } else {
                         if ($given[0] == "surname") {
                             $user->setSurname($_POST["surname"]);
                         } else {
                             setHTTPStatusCode("400");
                             return;
                         }
                     }
                 }
             }
         }
         if (!$user->validate()) {
             foreach ($user->getValidationFailures() as $failure) {
                 if ($given[0] == $failure->getPropertyPath()) {
                     $response["error"] = array("name" => $failure->getPropertyPath(), "message" => $failure->getMessage());
                 }
             }
         }
         $this->viewString(json_encode($response));
     } else {
         setHTTPStatusCode("400");
     }
 }