protected function scalarValue($value)
    {
        if (is_array($value)) {
            $data = array();
            foreach ($value as $key => $childValue) {
                $data[$key] = $this->scalarValue($childValue);
            }

            return $data;
        } else if (is_object($value)) {
            if (method_exists($value, 'toString')) {
                $value = $value->toString();
            } else if (method_exists($value, '__toString')) {
                $value = (string) $value;
            } else {
                $value = spl_object_hash($value);
            }
        }

        return html_entity_decode($value, ENT_NOQUOTES | ENT_HTML5);
    }