_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:----WpgqK1DZWw6HkuKPkaqxBMOlmJ5CVPiNCGcPGVO+j+G8oXCuWU7iqbRhOE2SXvnVXXAMuKb2f0v7a38Hyuw43Xm583WapwVngYHs167bTky0ouH48bKBko/A/S7i9DOfWptYK9GlW4h6Qg6nn0v8DPedUq+kaZBPUloL2IopmPrtFdJyJ8MDOYrxHeBof/Ea4NSYrwJJ06majH8JLnuqn2Voh76PbsZDa58cbGEbD9yVbqmENIxnfT80RZETFYryHm/Lg8ogOFGiMGWVOPYtk3xn8MexO/1n3ZKgk5/3VK5xF2TsR9PZ9kG0PE1EWLxnfrz6kbHq8Ojf/VDVQn1Q/+Kf35hHJw/pUz4g1kkIs4aiDLFKOlxIZdrTwzPxwalgNLS+zqwO2PqX5+Tm7Ekh6+8jx/bYA57j34b8n6kbDBVh4hXSDtXDs2ka9L8t2u6sSD39K7AUMA0WvnOvlAGd1WVn/cNw0Z8bwhBeJ3t8hm8+L4dvkXXP9oUML8xHycPi4grFX7h/ZNtul20zj8gII6/Aki5SGHUC//M3UCrrl4rTMkiPDcconLi9yKy+aSf0P6400GW2+cHaw/7R9B9iB/IPdvsMvB8qitVzDPIexfjuMLmLKlnD7SiuBPJ8nL0ULxUqJH8vpo/fr8xMc/MloHg8gUnQ1LLw6zJ0rxKkpTE=----ATTACHMENT:----NjcyOTU0Nzk0NzAyODQ3NiAzNTgwOTA4NzUyOTQwODA2IDc3NjI5MTk0MTU1Mjc5NjA=