コード例 #1
0
 /**
  * Verify the message and params are not used to determine the call count
  *
  * @return void
  */
 public function testAddErrorWithSameMessage()
 {
     $rawMessage = 'Foo "%var"';
     $params = ['var' => 'Bar'];
     $expectedProcessedMessage = 'Foo "Bar"';
     $inputException = new InputException(new Phrase($rawMessage, $params));
     $this->assertEquals($rawMessage, $inputException->getRawMessage());
     $this->assertEquals($expectedProcessedMessage, $inputException->getMessage());
     $this->assertEquals($expectedProcessedMessage, $inputException->getLogMessage());
     $this->assertFalse($inputException->wasErrorAdded());
     $this->assertCount(0, $inputException->getErrors());
     $inputException->addError(new Phrase($rawMessage, $params));
     $this->assertEquals($expectedProcessedMessage, $inputException->getMessage());
     $this->assertEquals($expectedProcessedMessage, $inputException->getLogMessage());
     $this->assertTrue($inputException->wasErrorAdded());
     $this->assertCount(0, $inputException->getErrors());
     $inputException->addError(new Phrase($rawMessage, $params));
     $this->assertEquals($expectedProcessedMessage, $inputException->getMessage());
     $this->assertEquals($expectedProcessedMessage, $inputException->getLogMessage());
     $this->assertTrue($inputException->wasErrorAdded());
     $errors = $inputException->getErrors();
     $this->assertCount(2, $errors);
     $this->assertEquals($expectedProcessedMessage, $errors[0]->getMessage());
     $this->assertEquals($expectedProcessedMessage, $errors[0]->getLogMessage());
     $this->assertEquals($expectedProcessedMessage, $errors[1]->getMessage());
     $this->assertEquals($expectedProcessedMessage, $errors[1]->getLogMessage());
 }
コード例 #2
0
 /**
  * Validate user credentials
  *
  * @param string $username
  * @param string $password
  * @throws InputException
  * @return void
  */
 public function validate($username, $password)
 {
     $exception = new InputException();
     if (!is_string($username) || strlen($username) == 0) {
         $exception->addError(__('%fieldName is a required field.', ['fieldName' => 'username']));
     }
     if (!is_string($password) || strlen($password) == 0) {
         $exception->addError(__('%fieldName is a required field.', ['fieldName' => 'password']));
     }
     if ($exception->wasErrorAdded()) {
         throw $exception;
     }
 }
コード例 #3
0
 /**
  * Validate user credentials
  *
  * @param string $username
  * @param string $password
  * @throws InputException
  * @return void
  */
 public function validateCredentials($username, $password)
 {
     $exception = new InputException();
     if (!is_string($username) || strlen($username) == 0) {
         $exception->addError(InputException::REQUIRED_FIELD, ['fieldName' => 'username']);
     }
     if (!is_string($username) || strlen($password) == 0) {
         $exception->addError(InputException::REQUIRED_FIELD, ['fieldName' => 'password']);
     }
     if ($exception->wasErrorAdded()) {
         throw $exception;
     }
 }
コード例 #4
0
ファイル: PostRepository.php プロジェクト: swnsma/practice
 private function validate(PostInterface $post)
 {
     $exception = new InputException();
     if (!\Zend_Validate::is(trim($post->getTitle()), 'NotEmpty')) {
         $exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'title']));
     }
     if (!\Zend_Validate::is(trim($post->getUrlKey()), 'NotEmpty')) {
         $exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'url_key']));
     }
     $id = $this->_resourceModel->checkUrlKey($post->getUrlKey());
     if ($id && $id != $post->getId()) {
         $exception->addError(__(InputException::DEFAULT_MESSAGE));
     }
     if ($exception->wasErrorAdded()) {
         throw $exception;
     }
 }
コード例 #5
0
 /**
  * Validate TaxClass Data
  *
  * @param \Magento\Tax\Api\Data\TaxClassInterface $taxClass
  * @return void
  * @throws InputException
  */
 protected function validateTaxClassData(\Magento\Tax\Api\Data\TaxClassInterface $taxClass)
 {
     $exception = new InputException();
     if (!\Zend_Validate::is(trim($taxClass->getClassName()), 'NotEmpty')) {
         $exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => TaxClassInterface::KEY_NAME]));
     }
     $classType = $taxClass->getClassType();
     if (!\Zend_Validate::is(trim($classType), 'NotEmpty')) {
         $exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => TaxClassInterface::KEY_TYPE]));
     } elseif ($classType !== TaxClassManagementInterface::TYPE_CUSTOMER && $classType !== TaxClassManagementInterface::TYPE_PRODUCT) {
         $exception->addError(__(InputException::INVALID_FIELD_VALUE, ['fieldName' => TaxClassInterface::KEY_TYPE, 'value' => $classType]));
     }
     if ($exception->wasErrorAdded()) {
         throw $exception;
     }
 }
コード例 #6
0
 /**
  * Validate tax rule
  *
  * @param TaxRule $rule
  * @return void
  * @throws InputException
  *
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 private function validate(TaxRule $rule)
 {
     $exception = new InputException();
     if (!\Zend_Validate::is(trim($rule->getSortOrder()), 'GreaterThan', [-1])) {
         $exception->addError(InputException::INVALID_FIELD_MIN_VALUE, ['fieldName' => TaxRule::SORT_ORDER, 'value' => $rule->getSortOrder(), 'minValue' => 0]);
     }
     if (!\Zend_Validate::is(trim($rule->getPriority()), 'GreaterThan', [-1])) {
         $exception->addError(InputException::INVALID_FIELD_MIN_VALUE, ['fieldName' => TaxRule::PRIORITY, 'value' => $rule->getPriority(), 'minValue' => 0]);
     }
     // Code is required
     if (!\Zend_Validate::is(trim($rule->getCode()), 'NotEmpty')) {
         $exception->addError(InputException::REQUIRED_FIELD, ['fieldName' => TaxRule::CODE]);
     }
     // customer tax class ids is required
     if ($rule->getCustomerTaxClassIds() === null || !$rule->getCustomerTaxClassIds()) {
         $exception->addError(InputException::REQUIRED_FIELD, ['fieldName' => TaxRule::CUSTOMER_TAX_CLASS_IDS]);
     }
     // product tax class ids is required
     if ($rule->getProductTaxClassIds() === null || !$rule->getProductTaxClassIds()) {
         $exception->addError(InputException::REQUIRED_FIELD, ['fieldName' => TaxRule::PRODUCT_TAX_CLASS_IDS]);
     }
     // tax rate ids is required
     if ($rule->getTaxRateIds() === null || !$rule->getTaxRateIds()) {
         $exception->addError(InputException::REQUIRED_FIELD, ['fieldName' => TaxRule::TAX_RATE_IDS]);
     }
     // throw exception if errors were found
     if ($exception->wasErrorAdded()) {
         throw $exception;
     }
 }
コード例 #7
0
 /**
  * Validate thesaurus values
  *
  * @param \Smile\ElasticsuiteThesaurus\Api\Data\ThesaurusInterface $thesaurus the thesaurus to validate
  *
  * @return void
  * @throws \Magento\Framework\Exception\InputException
  */
 protected function validate(\Smile\ElasticsuiteThesaurus\Api\Data\ThesaurusInterface $thesaurus)
 {
     $exception = new \Magento\Framework\Exception\InputException();
     $validator = new \Zend_Validate();
     if (!$validator->is(trim($thesaurus->getName()), 'NotEmpty')) {
         $exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'name']));
     }
     if ($exception->wasErrorAdded()) {
         throw $exception;
     }
 }
コード例 #8
0
 /**
  * Process an input error
  *
  * @param array $inputError
  * @return void
  * @throws InputException
  */
 protected function processInputError($inputError)
 {
     if (!empty($inputError)) {
         $exception = new InputException();
         foreach ($inputError as $errorParamField) {
             $exception->addError(new Phrase(InputException::REQUIRED_FIELD, ['fieldName' => $errorParamField]));
         }
         if ($exception->wasErrorAdded()) {
             throw $exception;
         }
     }
 }
コード例 #9
0
 /**
  * Validate group values.
  *
  * @param \Magento\Customer\Api\Data\GroupInterface $group
  * @throws InputException
  * @return void
  *
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 private function _validate($group)
 {
     $exception = new InputException();
     if (!\Zend_Validate::is($group->getCode(), 'NotEmpty')) {
         $exception->addError(__('%fieldName is a required field.', ['fieldName' => 'code']));
     }
     if ($exception->wasErrorAdded()) {
         throw $exception;
     }
 }
コード例 #10
0
ファイル: RateRepository.php プロジェクト: opexsw/magento2
 /**
  * Validate tax rate
  *
  * @param \Magento\Tax\Api\Data\TaxRateInterface $taxRate
  * @throws InputException
  * @return void
  *
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 private function validate(\Magento\Tax\Api\Data\TaxRateInterface $taxRate)
 {
     $exception = new InputException();
     $countryCode = $taxRate->getTaxCountryId();
     if (!\Zend_Validate::is($countryCode, 'NotEmpty')) {
         $exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'country_id']));
     } elseif (!\Zend_Validate::is($this->countryFactory->create()->loadByCode($countryCode)->getId(), 'NotEmpty')) {
         $exception->addError(__(InputException::INVALID_FIELD_VALUE, ['fieldName' => 'country_id', 'value' => $countryCode]));
     }
     $regionCode = $taxRate->getTaxRegionId();
     // if regionCode eq 0 (all regions *), do not validate with existing region list
     if (\Zend_Validate::is($regionCode, 'NotEmpty') && $regionCode != "0" && !\Zend_Validate::is($this->regionFactory->create()->load($regionCode)->getId(), 'NotEmpty')) {
         $exception->addError(__(InputException::INVALID_FIELD_VALUE, ['fieldName' => 'region_id', 'value' => $regionCode]));
     }
     if (!\Zend_Validate::is($taxRate->getRate(), 'NotEmpty')) {
         $exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'percentage_rate']));
     }
     if (!\Zend_Validate::is(trim($taxRate->getCode()), 'NotEmpty')) {
         $exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'code']));
     }
     if ($taxRate->getZipIsRange()) {
         $zipRangeFromTo = ['zip_from' => $taxRate->getZipFrom(), 'zip_to' => $taxRate->getZipTo()];
         foreach ($zipRangeFromTo as $key => $value) {
             if (!is_numeric($value) || $value < 0) {
                 $exception->addError(__(InputException::INVALID_FIELD_VALUE, ['fieldName' => $key, 'value' => $value]));
             }
         }
         if ($zipRangeFromTo['zip_from'] > $zipRangeFromTo['zip_to']) {
             $exception->addError(__('Range To should be equal or greater than Range From.'));
         }
     } else {
         if (!\Zend_Validate::is(trim($taxRate->getTaxPostcode()), 'NotEmpty')) {
             $exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'postcode']));
         }
     }
     if ($exception->wasErrorAdded()) {
         throw $exception;
     }
 }
コード例 #11
0
    /**
     * Convert the input array from key-value format to a list of parameters suitable for the specified class / method.
     *
     * The input array should have the field name as the key, and the value will either be a primitive or another
     * key-value array.  The top level of this array needs keys that match the names of the parameters on the
     * service method.
     *
     * Mismatched types are caught by the PHP runtime, not explicitly checked for by this code.
     *
     * @param string $serviceClassName name of the service class that we are trying to call
     * @param string $serviceMethodName name of the method that we are trying to call
     * @param array $inputArray data to send to method in key-value format
     * @return array list of parameters that can be used to call the service method
     * @throws InputException if no value is provided for required parameters
     */
    public function process($serviceClassName, $serviceMethodName, array $inputArray)
    {
        $inputData = [];
        $inputError = [];
        foreach ($this->getMethodParams($serviceClassName, $serviceMethodName) as $param) {
            $paramName = $param['name'];
            $snakeCaseParamName = strtolower(preg_replace("/(?<=\\w)(?=[A-Z])/", "_$1", $paramName));
            if (isset($inputArray[$paramName]) || isset($inputArray[$snakeCaseParamName])) {
                $paramValue = isset($inputArray[$paramName])
                    ? $inputArray[$paramName]
                    : $inputArray[$snakeCaseParamName];

                $inputData[] = $this->_convertValue($paramValue, $param['type']);
            } else {
                if ($param['isDefaultValueAvailable']) {
                    $inputData[] = $param['defaultValue'];
                } else {
                    $inputError[] = $paramName;
                }
            }
        }

        if (!empty($inputError)) {
            $exception = new InputException();
            foreach ($inputError as $errorParamField) {
                $exception->addError(new Phrase(InputException::REQUIRED_FIELD, ['fieldName' => $errorParamField]));
            }
            if ($exception->wasErrorAdded()) {
                throw $exception;
            }
        }

        return $inputData;
    }
コード例 #12
0
 /**
  * Validate customer attribute values.
  *
  * @param CustomerModel $customerModel
  * @throws InputException
  * @return void
  *
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 private function validate(CustomerModel $customerModel)
 {
     $exception = new InputException();
     if (!\Zend_Validate::is(trim($customerModel->getFirstname()), 'NotEmpty')) {
         $exception->addError(InputException::REQUIRED_FIELD, ['fieldName' => 'firstname']);
     }
     if (!\Zend_Validate::is(trim($customerModel->getLastname()), 'NotEmpty')) {
         $exception->addError(InputException::REQUIRED_FIELD, ['fieldName' => 'lastname']);
     }
     if (!\Zend_Validate::is($customerModel->getEmail(), 'EmailAddress')) {
         $exception->addError(InputException::INVALID_FIELD_VALUE, ['fieldName' => 'email', 'value' => $customerModel->getEmail()]);
     }
     $dob = $this->getAttributeMetadata('dob');
     if (!is_null($dob) && $dob->isRequired() && '' == trim($customerModel->getDob())) {
         $exception->addError(InputException::REQUIRED_FIELD, ['fieldName' => 'dob']);
     }
     $taxvat = $this->getAttributeMetadata('taxvat');
     if (!is_null($taxvat) && $taxvat->isRequired() && '' == trim($customerModel->getTaxvat())) {
         $exception->addError(InputException::REQUIRED_FIELD, ['fieldName' => 'taxvat']);
     }
     $gender = $this->getAttributeMetadata('gender');
     if (!is_null($gender) && $gender->isRequired() && '' == trim($customerModel->getGender())) {
         $exception->addError(InputException::REQUIRED_FIELD, ['fieldName' => 'gender']);
     }
     if ($exception->wasErrorAdded()) {
         throw $exception;
     }
 }
コード例 #13
0
ファイル: GroupRepository.php プロジェクト: nja78/magento2
 /**
  * Validate group values.
  *
  * @param \Magento\Customer\Api\Data\GroupInterface $group
  * @throws InputException
  * @return void
  *
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 private function _validate($group)
 {
     $exception = new InputException();
     if (!\Zend_Validate::is($group->getCode(), 'NotEmpty')) {
         $exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'code']));
     }
     if ($exception->wasErrorAdded()) {
         throw $exception;
     }
 }
コード例 #14
0
ファイル: TaxRateService.php プロジェクト: aiesh/magento2
 /**
  * Validate tax rate
  *
  * @param TaxRateDataObject $taxRate
  * @throws InputException
  * @return void
  *
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 private function validate(TaxRateDataObject $taxRate)
 {
     $exception = new InputException();
     $countryCode = $taxRate->getCountryId();
     if (!\Zend_Validate::is($countryCode, 'NotEmpty')) {
         $exception->addError(InputException::REQUIRED_FIELD, ['fieldName' => 'country_id']);
     } else {
         if (!\Zend_Validate::is($this->countryFactory->create()->loadByCode($countryCode)->getId(), 'NotEmpty')) {
             $exception->addError(InputException::INVALID_FIELD_VALUE, ['fieldName' => 'country_id', 'value' => $countryCode]);
         }
     }
     $regionCode = $taxRate->getRegionId();
     if (\Zend_Validate::is($regionCode, 'NotEmpty') && !\Zend_Validate::is($this->regionFactory->create()->load($regionCode)->getId(), 'NotEmpty')) {
         $exception->addError(InputException::INVALID_FIELD_VALUE, ['fieldName' => 'region_id', 'value' => $regionCode]);
     }
     if (!\Zend_Validate::is($taxRate->getPercentageRate(), 'NotEmpty')) {
         $exception->addError(InputException::REQUIRED_FIELD, ['fieldName' => 'percentage_rate']);
     }
     if (!\Zend_Validate::is(trim($taxRate->getCode()), 'NotEmpty')) {
         $exception->addError(InputException::REQUIRED_FIELD, ['fieldName' => 'code']);
     }
     if ($taxRate->getZipRange()) {
         $zipRangeFromTo = ['zip_from' => $taxRate->getZipRange()->getFrom(), 'zip_to' => $taxRate->getZipRange()->getTo()];
         foreach ($zipRangeFromTo as $key => $value) {
             if (!is_numeric($value) || $value < 0) {
                 $exception->addError(InputException::INVALID_FIELD_VALUE, ['fieldName' => $key, 'value' => $value]);
             }
         }
         if ($zipRangeFromTo['zip_from'] > $zipRangeFromTo['zip_to']) {
             $exception->addError('Range To should be equal or greater than Range From.');
         }
     } else {
         if (!\Zend_Validate::is(trim($taxRate->getPostcode()), 'NotEmpty')) {
             $exception->addError(InputException::REQUIRED_FIELD, ['fieldName' => 'postcode']);
         }
     }
     if ($exception->wasErrorAdded()) {
         throw $exception;
     }
 }
コード例 #15
0
ファイル: TaxRuleService.php プロジェクト: aiesh/magento2
 /**
  * Validate tax rule
  *
  * @param TaxRule $rule
  * @return void
  * @throws InputException
  *
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 private function validate(TaxRule $rule)
 {
     $exception = new InputException();
     // SortOrder is required and must be 0 or greater
     if (!\Zend_Validate::is(trim($rule->getSortOrder()), 'NotEmpty')) {
         $exception->addError(InputException::REQUIRED_FIELD, ['fieldName' => TaxRule::SORT_ORDER]);
     }
     if (!\Zend_Validate::is(trim($rule->getSortOrder()), 'GreaterThan', [-1])) {
         $exception->addError(InputException::INVALID_FIELD_MIN_VALUE, ['fieldName' => TaxRule::SORT_ORDER, 'value' => $rule->getSortOrder(), 'minValue' => 0]);
     }
     // Priority is required and must be 0 or greater
     if (!\Zend_Validate::is(trim($rule->getPriority()), 'NotEmpty')) {
         $exception->addError(InputException::REQUIRED_FIELD, ['fieldName' => TaxRule::PRIORITY]);
     }
     if (!\Zend_Validate::is(trim($rule->getPriority()), 'GreaterThan', [-1])) {
         $exception->addError(InputException::INVALID_FIELD_MIN_VALUE, ['fieldName' => TaxRule::PRIORITY, 'value' => $rule->getPriority(), 'minValue' => 0]);
     }
     // Code is required
     if (!\Zend_Validate::is(trim($rule->getCode()), 'NotEmpty')) {
         $exception->addError(InputException::REQUIRED_FIELD, ['fieldName' => TaxRule::CODE]);
     }
     // customer tax class ids is required
     if ($rule->getCustomerTaxClassIds() === null || !$rule->getCustomerTaxClassIds()) {
         $exception->addError(InputException::REQUIRED_FIELD, ['fieldName' => TaxRule::CUSTOMER_TAX_CLASS_IDS]);
     } else {
         // see if the customer tax class ids exist
         $customerTaxClassIds = $rule->getCustomerTaxClassIds();
         foreach ($customerTaxClassIds as $customerTaxClassId) {
             try {
                 $taxClass = $this->taxClassService->getTaxClass($customerTaxClassId);
                 if (is_null($taxClass) || !($taxClass->getClassType() == TaxClassModel::TAX_CLASS_TYPE_CUSTOMER)) {
                     $exception->addError(NoSuchEntityException::MESSAGE_SINGLE_FIELD, ['fieldName' => TaxRule::CUSTOMER_TAX_CLASS_IDS, 'value' => $customerTaxClassId]);
                 }
             } catch (NoSuchEntityException $e) {
                 $exception->addError($e->getRawMessage(), $e->getParameters());
             }
         }
     }
     // product tax class ids is required
     if ($rule->getProductTaxClassIds() === null || !$rule->getProductTaxClassIds()) {
         $exception->addError(InputException::REQUIRED_FIELD, ['fieldName' => TaxRule::PRODUCT_TAX_CLASS_IDS]);
     } else {
         // see if the product tax class ids exist
         $productTaxClassIds = $rule->getProductTaxClassIds();
         foreach ($productTaxClassIds as $productTaxClassId) {
             try {
                 $taxClass = $this->taxClassService->getTaxClass($productTaxClassId);
                 if (is_null($taxClass) || !($taxClass->getClassType() == TaxClassModel::TAX_CLASS_TYPE_PRODUCT)) {
                     $exception->addError(NoSuchEntityException::MESSAGE_SINGLE_FIELD, ['fieldName' => TaxRule::PRODUCT_TAX_CLASS_IDS, 'value' => $productTaxClassId]);
                 }
             } catch (NoSuchEntityException $e) {
                 $exception->addError($e->getRawMessage(), $e->getParameters());
             }
         }
     }
     // tax rate ids is required
     if ($rule->getTaxRateIds() === null || !$rule->getTaxRateIds()) {
         $exception->addError(InputException::REQUIRED_FIELD, ['fieldName' => TaxRule::TAX_RATE_IDS]);
     }
     // throw exception if errors were found
     if ($exception->wasErrorAdded()) {
         throw $exception;
     }
 }
コード例 #16
0
 /**
  * Validate Slider Item values.
  *
  * @param \Stepzerosolutions\Tbslider\Api\Data\SlideritemsInterface $slider
  * @throws InputException
  * @return void
  *
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 private function _validate($slider)
 {
     $exception = new InputException();
     if (!\Zend_Validate::is($slider->getSlideritemTitle(), 'NotEmpty')) {
         $exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'slideritem_title']));
     }
     if ($exception->wasErrorAdded()) {
         throw $exception;
     }
 }
コード例 #17
0
 /**
  * Validate customer attribute values.
  *
  * @param \Magento\Customer\Api\Data\CustomerInterface $customer
  * @throws InputException
  * @return void
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 private function validate(\Magento\Customer\Api\Data\CustomerInterface $customer)
 {
     $exception = new InputException();
     if (!\Zend_Validate::is(trim($customer->getFirstname()), 'NotEmpty')) {
         $exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'firstname']));
     }
     if (!\Zend_Validate::is(trim($customer->getLastname()), 'NotEmpty')) {
         $exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'lastname']));
     }
     $isEmailAddress = \Zend_Validate::is($customer->getEmail(), 'EmailAddress');
     if (!$isEmailAddress) {
         $exception->addError(__(InputException::INVALID_FIELD_VALUE, ['fieldName' => 'email', 'value' => $customer->getEmail()]));
     }
     $dob = $this->getAttributeMetadata('dob');
     if ($dob !== null && $dob->isRequired() && '' == trim($customer->getDob())) {
         $exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'dob']));
     }
     $taxvat = $this->getAttributeMetadata('taxvat');
     if ($taxvat !== null && $taxvat->isRequired() && '' == trim($customer->getTaxvat())) {
         $exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'taxvat']));
     }
     $gender = $this->getAttributeMetadata('gender');
     if ($gender !== null && $gender->isRequired() && '' == trim($customer->getGender())) {
         $exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'gender']));
     }
     if ($exception->wasErrorAdded()) {
         throw $exception;
     }
 }
コード例 #18
0
ファイル: Repository.php プロジェクト: Doability/magento2dev
 /**
  * Validate TaxClass Data
  *
  * @param \Magento\Tax\Api\Data\TaxClassInterface $taxClass
  * @return void
  * @throws InputException
  */
 protected function validateTaxClassData(\Magento\Tax\Api\Data\TaxClassInterface $taxClass)
 {
     $exception = new InputException();
     if (!\Zend_Validate::is(trim($taxClass->getClassName()), 'NotEmpty')) {
         $exception->addError(__('%fieldName is a required field.', ['fieldName' => ClassModel::KEY_NAME]));
     }
     $classType = $taxClass->getClassType();
     if (!\Zend_Validate::is(trim($classType), 'NotEmpty')) {
         $exception->addError(__('%fieldName is a required field.', ['fieldName' => ClassModel::KEY_TYPE]));
     } elseif ($classType !== TaxClassManagementInterface::TYPE_CUSTOMER && $classType !== TaxClassManagementInterface::TYPE_PRODUCT) {
         $exception->addError(__('Invalid value of "%value" provided for the %fieldName field.', ['fieldName' => ClassModel::KEY_TYPE, 'value' => $classType]));
     }
     if ($exception->wasErrorAdded()) {
         throw $exception;
     }
 }
コード例 #19
0
ファイル: OptionRepository.php プロジェクト: kid17/magento2
 /**
  * Ensure that all necessary data is available for a new option creation.
  *
  * @param OptionInterface $option
  * @return void
  * @throws InputException
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function validateNewOptionData(OptionInterface $option)
 {
     $inputException = new InputException();
     if (!$option->getAttributeId()) {
         $inputException->addError(__('Option attribute ID is not specified.'));
     }
     if (!$option->getLabel()) {
         $inputException->addError(__('Option label is not specified.'));
     }
     if (!$option->getValues()) {
         $inputException->addError(__('Option values are not specified.'));
     } else {
         foreach ($option->getValues() as $optionValue) {
             if (!$optionValue->getValueIndex()) {
                 $inputException->addError(__('Value index is not specified for an option.'));
             }
             if (null === $optionValue->getPricingValue()) {
                 $inputException->addError(__('Price is not specified for an option.'));
             }
             if (null === $optionValue->getIsPercent()) {
                 $inputException->addError(__('Percent/absolute is not specified for an option.'));
             }
         }
     }
     if ($inputException->wasErrorAdded()) {
         throw $inputException;
     }
 }
コード例 #20
0
 /**
  * Process an input error
  *
  * @param array $inputError
  * @return void
  * @throws InputException
  */
 protected function processInputError($inputError)
 {
     if (!empty($inputError)) {
         $exception = new InputException();
         foreach ($inputError as $errorParamField) {
             $exception->addError(new Phrase('%fieldName is a required field.', ['fieldName' => $errorParamField]));
         }
         if ($exception->wasErrorAdded()) {
             throw $exception;
         }
     }
 }