/** * Populate the protected $_data SimpleXmlElement with the passed in array * Warning: no validation is done so you can end up with some crazy SimpleXmlElement objects * if you aren't careful passing in valid arrays. * * The array keys may be camelCaseWords or dash-type-words. If they are camelCaseWords, they * will be converted to dash-type-words for the SimpleXmlElement. * * @param array $data * @param string $wrapper * @return void */ public function hydrate(array $data, $wrapper) { $wrapper = SpreedlyCommon::camelToDash($wrapper); $xml = '<' . $wrapper . '/>'; $xml = new SimpleXmlElement($xml); foreach ($data as $key => $value) { $key = SpreedlyCommon::camelToDash($key); $xml->addChild($key, $value); } $this->setData($xml); }
public function __set($key, $value) { $key = SpreedlyCommon::camelToDash($key); if (array_key_exists($key, $this->_cardData)) { if ($key == 'number') { $value = preg_replace('/\\D/', '', $value); } elseif ($key == 'month') { if (!is_numeric($value) || $value < 1 || $value > 12) { $value = ''; // Do not allow invalid month numbers to be set } } elseif ($key == 'year') { $thisYear = date('Y'); if (!is_numeric($value) || $value < $thisYear) { $value = ''; // Do not allow invalid or past year numbers to be set } } $this->_cardData[$key] = $value; } }