Пример #1
0
 /**
  * Sanitize
  *
  * @param mixed $data Daa
  *
  * @return mixed
  */
 public function sanitize($data)
 {
     // Get country
     $countryCodeValidator = new \XLite\Core\Validator\Pair\Simple();
     $countryCodeValidator->setName('country');
     $countryCodeValidator->setValidator(new \XLite\Core\Validator\String\ObjectId\Country(true));
     $country = $countryCodeValidator->getValidator()->sanitize($data['country']);
     // Get state
     $customState = isset($data['is_custom_state']) ? (bool) $data['is_custom_state'] : false;
     if ($customState) {
         $state = new \XLite\Model\State();
         $state->setState($data['state']);
         $state->setCountry($country);
     } else {
         $stateValidator = new \XLite\Core\Validator\String\ObjectId\State(true);
         $state = $stateValidator->sanitize($data['state']);
     }
     return array('country' => $country, 'state' => $state);
 }
Пример #2
0
 /**
  * Add pair validator
  *
  * @param mixed                            $name       Cell name or pair validator
  * @param \XLite\Core\Validator\AValidator $validator  Cell validator OPTIONAL
  * @param string                           $mode       Pair validation mode OPTIONAL
  * @param string                           $publicName Cell public name OPTIONAL
  *
  * @return \XLite\Core\Validator\AValidator
  */
 public function addPair($name, \XLite\Core\Validator\AValidator $validator = null, $mode = \XLite\Core\Validator\Pair\APair::STRICT, $publicName = null)
 {
     $result = null;
     if (is_object($name) && $name instanceof \XLite\Core\Validator\Pair\APair) {
         $result = $name;
     } elseif ($name && $validator) {
         $result = new \XLite\Core\Validator\Pair\Simple($mode);
         $result->setName($name);
         $result->setValidator($validator);
         if ($publicName) {
             $result->setPublicName($publicName);
         }
     }
     if ($result) {
         $this->pairs[] = $result;
         if (method_exists($result, 'getValidator')) {
             $result = $result->getValidator();
         }
     }
     return $result;
 }
Пример #3
0
 /**
  * Sanitize
  *
  * @param mixed $data Daa
  *
  * @return mixed
  */
 public function sanitize($data)
 {
     // Check country
     if (!isset($data[static::FIELD_COUNTRY]) && !$this->isFieldAvailable(static::FIELD_COUNTRY)) {
         $data[static::FIELD_COUNTRY] = \XLite\Model\Address::getDefaultFieldValue('country')->getCode();
     }
     // Get country
     $countryCodeValidator = new \XLite\Core\Validator\Pair\Simple();
     $countryCodeValidator->setName(static::FIELD_COUNTRY);
     $countryCodeValidator->setValidator(new \XLite\Core\Validator\String\ObjectId\Country(true));
     $country = $countryCodeValidator->getValidator()->sanitize($data[static::FIELD_COUNTRY]);
     // Get state
     if ($country->hasStates()) {
         $stateValidator = new \XLite\Core\Validator\String\ObjectId\State(true);
         $state = $stateValidator->sanitize($data[static::FIELD_STATE]);
     } elseif (!empty($data[static::FIELD_CUSTOM_STATE])) {
         $state = new \XLite\Model\State();
         $state->setState($data[static::FIELD_CUSTOM_STATE]);
         $state->setCountry($country);
         $data[static::FIELD_STATE] = $data[static::FIELD_CUSTOM_STATE];
     } else {
         $state = null;
     }
     return array('country' => $country, 'state' => $state, static::FIELD_COUNTRY => $data[static::FIELD_COUNTRY], static::FIELD_STATE => $state ? $data[static::FIELD_STATE] : null);
 }