Beispiel #1
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);
 }
Beispiel #2
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);
 }