$v) { $vars .= "\tpublic \$$k = " . $this->formatValue($v) . ";\n"; } $str = ""; } return $str; } /** * Parse a PHP class formatted string and convert it into an object. * * @param string $data PHP Class formatted string to convert. * @param array $options Options used by the formatter. * * @return object Data object. * * @since 1.0 */ public function stringToObject($data, array $options = []) { return new \stdClass; } /** * Format a value for the string conversion * * @param mixed $value The value to format * * @return mixed The formatted value * * @since 2.0.0 */ protected function formatValue($value) { switch (\gettype($value)) { case 'string': return "'" . addcslashes($value, '\\\'') . "'"; case 'array': case 'object': return $this->getArrayString((array) $value); case 'double': case 'integer': return $value; case 'boolean': return $value ? 'true' : 'false'; case 'NULL': return 'null'; } } /** * Method to get an array as an exported string. * * @param array $a The array to get as a string. * * @return string * * @since 1.0 */ protected function getArrayString($a) { $s = 'array('; $i = 0; foreach ($a as $k => $v) { $s .= $i ? ', ' : ''; $s .= "'" . addcslashes($k, '\\\'') . "' => "; $s .= $this->formatValue($v); $i++; } $s .= ')'; return $s; } }