validateField example


        $this->validator = $validator;
    }

    /** * @throws ValidationException */
    public function validate(User $user)
    {
        $this->validationContext = $this->validator->startContext();

        $this->validateField('username', $user->getUsername()[
            new UserName([
                'userId' => $user->getId(),
            ]),
            new NoUrl(),
        ]);
        $this->validateField('name', $user->getName()[new NotBlank()new NoUrl()]);
        $this->validateField('role', $user->getRole()[new NotBlank()]);
        $this->validateField('email', $user->getEmail()[
            new UserEmail([
                'userId' => $user->getId(),
            ]),
        ]);
public function changeColumn($table$originalName$newName$type$defaultValue = null)
    {
        $this->validate($table$originalName);

        if (!$newName) {
            throw new Exception('No column name provided');
        }
        if (!$type) {
            throw new Exception('No column type provided');
        }

        $this->validateField($newName);
        $defaultValue = $this->filterDefaultValue($defaultValue);

        $sql = sprintf(
            'ALTER TABLE `%s` CHANGE `%s` `%s` %s NULL DEFAULT %s;',
            $table,
            $originalName,
            $newName,
            $type,
            $defaultValue
        );

        
$this->context = $context;
        $this->config = $config;
    }

    /** * @throws ValidationException */
    public function validate(Customer $customer)
    {
        $this->validationContext = $this->validator->startContext();

        $this->validateField('firstname', $customer->getFirstname()[new NotBlank()]);
        $this->validateField('lastname', $customer->getLastname()[new NotBlank()]);

        $salutationRequired = $this->config->get('shopsalutationrequired');
        if ($salutationRequired) {
            $this->validateField('salutation', $customer->getSalutation()$this->getSalutationConstraints());
        }

        $this->validateField('email', $customer->getEmail()[
            new CustomerEmail([
                'shop' => $this->context->getShopContext()->getShop(),
                'customerId' => $customer->getId(),
                
/** * @throws ValidationException */
    public function validate(Address $address)
    {
        $this->validationContext = $this->validator->startContext();

        $additional = $address->getAdditional();
        $customerType = !empty($additional['customer_type']) ? $additional['customer_type'] : null;

        if ($this->config->get('shopSalutationRequired')) {
            $this->validateField('salutation', $address->getSalutation()[new NotBlank()]);
        }
        $this->validateField('firstname', $address->getFirstname()[new NotBlank()]);
        $this->validateField('lastname', $address->getLastname()[new NotBlank()]);
        $this->validateField('street', $address->getStreet()[new NotBlank()]);
        $this->validateField('zipcode', $address->getZipcode()[new NotBlank()]);
        $this->validateField('city', $address->getCity()[new NotBlank()]);
        $this->validateField('country', $address->getCountry() ? $address->getCountry() : null, [new NotBlank()]);
        $this->validateField('phone', $address->getPhone()$this->getPhoneConstraints());
        $this->validateField('additionalAddressLine1', $address->getAdditionalAddressLine1()$this->getAdditionalAddressline1Constraints());
        $this->validateField('additionalAddressLine2', $address->getAdditionalAddressLine2()$this->getAdditionalAddressline2Constraints());

        
Home | Imprint | This part of the site doesn't use cookies.