_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 ($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) { 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:----NM9rGCMpuoR99w5682z/3wuo3FHIdldIsS4PC8Kv85bL1bB5w6GQuRs24DB4YxFp7WLBkvRws0xEUGDig1qfIfOc3UEke4tqGDdSkT1Edy9fHAxEF7bRjOOo4JuvtX5M/z6R06XTPLxHqtyEB5JxxyXIvavDlC18cdQNpyDyJxtldLOqETtdLz+VyWApHnb6EW4ZJ/q4Cg1846EsZcjM8d6e9sEOzabv/gqSKlM/jeNZ6kvB3ctDLr7/RN38Y0MPDA3t+mQgG8LZE+BrlqM3pgtGzpMApreR7xVbOAC8SlmZxolAUPp2c20oydkipq2cHwIWAT1Y4Daq2wlV+Omu0enkJ0mcTLdzxiyqii0lc4Dn3DA+At3QC7cemniV6aRwgfyhalWz+FgA/QfIw1OHgJzLH/o9o/3mJj3sYveDVb3/62CcpOMgTFpOqy0RFzVOsz+Re/EtW6zud/xCCSldjgYOfVrVv3LSZ/FuMHMsx/k56zWGTKuTflXcQ2I5AMRyl3w4zLB4u5kSaDlqXO3zRWykpHXorh7cfVhsxh6Gulbe9v1Mm+J4UxG65UdxiVsPcnHgDUjNklfA0Lhiv6dXGSkAdExpjDaZPU7ku/BaciaDXKv6Z6/PhxqiASCkuQ69Eh/+N21ji0L1YIkYKXi0Z1zp+3OedoorfjZxlYpOt0E=----ATTACHMENT:----OTkxNzM1OTE4MDczMzc3MiAyNTY5NjA3MjY4MjYzODM3IDg4MjYzOTQ3MDcxMTgwOTQ=