<commit_before><?php

namespace Pulpmedia\NgHttpBundle\HttpFoundation;

use Symfony\Component\HttpFoundation\Response;
use JMS\Serializer\Serializer;

class BaseResponse extends Response{
    protected $content;
    private $serializer;

    public function __construct(Serializer $serializer){
        $this->serializer = $serializer;
        parent::__construct();
        $this->headers->set('Content-Type','Application/Json');
    }

    public function setContent($content){
        parent::setContent($this->serializer->serialize($content,'json'));
    }
}<commit_msg>ADD: version and group serialization content<commit_after><?php

namespace Pulpmedia\NgHttpBundle\HttpFoundation;

use Symfony\Component\HttpFoundation\Response;
use JMS\Serializer\Serializer;
use JMS\Serializer\SerializationContext;

class BaseResponse extends Response{

    const EXCLUSION_DEFAULT = 0;
    const EXCLUSION_VERSION = 1;
    const EXCLUSION_GROUP = 2;

    protected $content;
    private $serializer;
    private $exclusionStrategy = self::EXCLUSION_DEFAULT;
    private $groups = array();
    protected $version = 0;
    protected $contentData;

    public function __construct(Serializer $serializer){
        $this->serializer = $serializer;
        parent::__construct();
        $this->headers->set('Content-Type','application/json');
    }

    public function setExclusionStrategy($strategy){
        $this->exclusionStrategy = $strategy;
        $this->setSerializedContent();
    }

    public function setVersion($version){
        $this->version = $version;
        $this->setSerializedContent();
    }

    public function setGroups($groups = array()){
        $this->groups = $groups;
        $this->setSerializedContent();
    }

    public function setContent($content){
        $this->contentData = $content;
        $this->setSerializedContent();
    }

    private function setSerializedContent(){
        parent::setContent($this->serializeContent($this->contentData));
    }
    private function serializeContent($content){
        $serializedContent = "";
        if($this->exclusionStrategy == self::EXCLUSION_GROUP){
            $serializedContent = $this->serializer->serialize($content,'json',SerializationContext::create()->setGroups($this->groups));
        } elseif($this->exclusionStrategy == self::EXCLUSION_VERSION){
            $serializedContent = $this->serializer->serialize($content,'json',SerializationContext::create()->setVersion($this->version));
        } else{
            $serializedContent = $this->serializer->serialize($content,'json');
        }
        return $serializedContent;
    }
}
{'fraction_non_alphanumeric': 0.1293759512937595, 'fraction_numerical': 0.0015220700152207, 'mean_word_length': 3.78, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, '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': '4308718', 'n_tokens_mistral': 702, 'n_tokens_neox': 680, 'n_words': 123}