<commit_before><?php

namespace Bolt\Storage\Entity;

/**
 * Entity for TemplateFields.
 */
class TemplateFields extends Entity
{
    /**
     * Getter for templates using {{ content.get(title) }} functions.
     *
     * @param string $key
     *
     * @return mixed
     */
    public function get($key)
    {
        $accessor = 'get' . ucfirst($key);

        return $this->$accessor();
    }
}<commit_msg>add serialize support to TemplateFields<commit_after><?php

namespace Bolt\Storage\Entity;

/**
 * Entity for TemplateFields.
 */
class TemplateFields extends Entity
{
    /**
     * Getter for templates using {{ content.get(title) }} functions.
     *
     * @param string $key
     *
     * @return mixed
     */
    public function get($key)
    {
        $accessor = 'get' . ucfirst($key);

        return $this->$accessor();
    }

    public function serialize()
    {
        $fields = $this->getContenttype()->getFields();
        foreach ($fields as $field) {
            $fieldName = $field['fieldname'];
            $val = $this->$fieldName;
            if (in_array($field['type'], ['date','datetime'])) {
                $val = (string)$this->$fieldName;
            }
            if (is_callable([$val, 'serialize'])) {
                $val = $val->serialize();
            }

            $values[$fieldName] = $val;
        }

        return $values;
    }
}
{'fraction_non_alphanumeric': 0.1531791907514451, 'fraction_numerical': 0.0, 'mean_word_length': 1.9978354978354977, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5200892', 'n_tokens_mistral': 411, 'n_tokens_neox': 402, 'n_words': 89}