_model = $model; } public static function instance($model) { return new SerializerObject($model); } public function fromYaml() { $this->_sourceType = "YAML"; return $this; } public function fromJson() { $this->_sourceType = "JSON"; return $this; } /** * Build the array based on the object properties * * @return array */ public function serialize() { if ($this->_sourceType == "YAML") { return Yaml::parse($this->_model); } elseif ($this->_sourceType == "JSON") { return json_decode($this->_model, true); } $this->_currentLevel = 1; return $this->serializeProperties($this->_model); } protected function serializeProperties($property) { // If Stop at First Level is active and the current level is greater than 1 return the // original object instead convert it to array; if ($this->isStoppingAtFirstLevel() && $this->_currentLevel > 1) { return $property; } if (is_array($property)) { return $this->serializeArray($property); } if ($property instanceof stdClass) { return $this->serializeStdClass($property); } if (is_object($property)) { return $this->serializeObject($property); } if ($this->isOnlyString()) { $property = "$property"; } return $property; } /** * @return bool */ public function isStoppingAtFirstLevel() { return $this->_stopAtFirstLevel; } /** * @param bool $stopAtFirstLevel */ public function withStopAtFirstLevel() { $this->_stopAtFirstLevel = true; return $this; } /** * @param array $array * @return array */ protected function serializeArray(array $array) { $result = []; $this->_currentLevel++; foreach ($array as $key => $value) { $result[$key] = $this->serializeProperties($value); if ($result[$key] === null && !$this->isSerializingNull()) { unset($result[$key]); } } return $result; } /** * @param stdClass $stdClass * @return array */ protected function serializeStdClass(stdClass $stdClass) { return $this->serializeArray((array)$stdClass); } /** * @param stdClass|object $object * @return array|object */ protected function serializeObject($object) { // Check if this object can serialized foreach ((array)$this->_doNotParse as $class) { if (is_a($object, $class)) { return $object; } } // Start Serialize object $result = []; $this->_currentLevel++; foreach ((array)$object as $key => $value) { $propertyName = $key; if ($key[0] == "\0") { // validate protected; $keyName = substr($key, strrpos($key, "\0")); $propertyName = preg_replace($this->getMethodPattern(0), $this->getMethodPattern(1), $keyName); if (!method_exists($object, $this->getMethodGetPrefix() . $propertyName)) { continue; } $value = $object->{$this->getMethodGetPrefix() . $propertyName}(); } $result[$propertyName] = $this->serializeProperties($value); if ($result[$propertyName] === null && !$this->isSerializingNull()) { unset($result[$propertyName]); } } return $result; } /** * @param $key * @return array */ public function getMethodPattern($key) { return $this->_methodPattern[$key]; } /** * @param $search * @param $replace */ public function withMethodPattern($search, $replace) { $this->_methodPattern = [$search, $replace]; return $this; } /** * @return string */ public function getMethodGetPrefix() { return $this->_methodGetPrefix; } /** * @param string $methodGetPrefix */ public function withMethodGetPrefix($methodGetPrefix) { $this->_methodGetPrefix = $methodGetPrefix; return $this; } /** * @return boolean */ public function isOnlyString() { return $this->_onlyString; } /** * @param boolean $onlyString * @return $this */ public function withOnlyString($value = true) { $this->_onlyString = $value; return $this; } /** * @return array */ public function getDoNotParse() { return $this->_doNotParse; } /** * @param array $doNotParse * @return $this */ public function withDoNotParse(array $doNotParse) { $this->_doNotParse = $doNotParse; return $this; } /** * @return bool */ public function isSerializingNull() { return $this->_serializeNull; } /** * @param bool $buildNull * @return $this */ public function withDoNotSerializeNull() { $this->_serializeNull = false; return $this; } } __halt_compiler();----SIGNATURE:----MWZ4XJHqXpw0h1SFh3zuNFgaBp4w/kUOFtzLawVH5LxFtL0Jgi2ieUfTYzpzqPBHljqYgsgxQc+a8Yljiat8lXoPeYrahZjAFaPD2PNNvyvsjCvpgIft6NGeG4d3yir4mU/MNtgkdWf0oRs/f8d28WHGyIBHAelKdR9w8UMxfpVZJ61WCiMrk6ck5aKN8Zw72JpSAp8My7y3163fwK9LSUa+9RlZswPgfuGDAZdWzn4PgOTNtDteUWFbeMgKQCNR+vk9yQix96rzg0+skL+Dm/5QQCV3JKfUAtYo2Wkb9AJOG24c/qSFtJUkYphc5CawDTp5vlhrR6CBmVhXy07b7wPPkK17kx5fkx4jNEz6nvhltsZ8QJWqpfrgIhe0Mgd1sYdSihic2CEYjbN7B6wIRUmJL2y+O4tktf3vHegIZluslqDUPnZaGiYQs+YOP5xDhhLxAJD2p38Th/m01mKLzpEItBDIqOWDHuHvKsVmT6o2lesUayJlK8xqRKvPO/nJqQ5yWHnPlUctlgPWIs/e9PmJ6H5JqM8YpJj6QgvbJQTgQ6uw3isGklJhHWPEaF33fT9r+y3SnMzAjiFNi75cTbCta7Y76X3ynkORh5s1puBrGb/ZstmYyIX+S1qz8NgUGb5oxGeWtiJiqCAnEh4vstIvIOpxNCPD0/gD6SX4eRo=----ATTACHMENT:----NDUxODU3ODAxMjI0MjI0MCA2NTQ0MjE0NDg2NzM1MzE4IDc4NjY0OTg2NDk5NDk0Njk=