data = $data; } private function __clone() { ; } public static function getInstance($data = null) { if (is_null(self::$instace)) { $class = get_class(); self::$instace = new $class($data); } return self::$instace; } public function refactor() { foreach ($this->data as $field) { $function = $this->checkTypeAndGetFunction($field); if ($function) { $this->{$function}($field); } else { return $this->data; } } return $this->data; } private function checkTypeAndGetFunction($data) { if (is_array($data)) { return 'refactorArray'; } if (is_object($data)) { return 'refactorObject'; } } protected function refactorObject(&$data) { foreach ($data as $fieldName => $fieldValue) { $function = $this->checkTypeAndGetFunction($fieldValue); if ($function) { if ($fieldValue instanceof \SimpleXMLElement) { $data->{$fieldName} = $this->readXML($fieldValue); } else { $this->{$function}($fieldValue); } } } } protected function refactorArray(&$data) { foreach ($data as $fieldName => $fieldValue) { $function = $this->checkTypeAndGetFunction($fieldValue); if ($function) { $this->{$function}($fieldValue); } } } private function readXML(\SimpleXMLElement $xml) { if ($xml->count() > 0) { return $xml->{$xml->getName()}; } return ""; } }