Symfony\Component\Validator\Context\ExecutionContext::getPropertyPath PHP Method

getPropertyPath() public method

public getPropertyPath ( $subPath = '' )
    public function getPropertyPath($subPath = '')
    {
        return PropertyPath::append($this->propertyPath, $subPath);
    }

Usage Example

Example #1
0
 public function constraintValidation(ExecutionContext $context)
 {
     $customNotBlankConstraint = new NotBlank();
     $customNotBlankConstraint->message = "Este valor no puede estar vacio";
     $customLengthConstraint = new Length(16);
     $customLengthConstraint->minMessage = "cardNoMinLength";
     $customLengthConstraint->maxMessage = "cardNoMaxLength";
     $collectionConstraint = new Collection(array("firstname" => array($customNotBlankConstraint), "lastname" => array($customNotBlankConstraint), "cardNo" => array(new Regex("/^\\d+\$/"), $customNotBlankConstraint, $customLengthConstraint), "cardType" => array($customNotBlankConstraint), "CVV" => array($customNotBlankConstraint)));
     /**
      * validateValue expects either a scalar value and its constraint or an array and a constraint Collection
      */
     $errors = $this->validator->validateValue(array("firstname" => $this->firstname, "lastname" => $this->lastname, "cardNo" => $this->cardNo, "cardType" => $this->cardType, "CVV" => $this->CVV), $collectionConstraint);
     /**
      * Count is used as this is not an array but a ConstraintViolationList
      */
     if (count($errors) !== 0) {
         $path = $context->getPropertyPath();
         foreach ($errors as $error) {
             $string = str_replace('[', '', $error->getPropertyPath());
             $string = str_replace(']', '', $string);
             $propertyPath = $path . '.' . $string;
             $context->addViolationAt($string, $error->getMessage(), array(), null);
         }
     }
 }