<?php
/**
 * Created by PhpStorm.
 * User: sdaoudi
 * Date: 07/11/14
 * Time: 15:06
 */

namespace Ayaline\Bundle\EzSitBundle\DwSerialiser\DataType;

use JMS\Serializer as Serializer;
use Psr\Log\LoggerInterface;

abstract class TraitementParent {
    /**
     * @var Serializer
     */
    protected $serializer;

    protected $xmlFilePath;

    protected $xmlFileContent;

    /**
     * @var \Psr\Log\LoggerInterface
     */
    protected $logger;

    public function __construct($xmlFilePath, LoggerInterface $logger) {
        $this->xmlFilePath = $xmlFilePath;
        $this->serializer = Serializer\SerializerBuilder::create()->build();
        $this->xmlFileContent = file_get_contents($this->xmlFilePath);
        $doctypeIndexStart = strpos($this->xmlFileContent, '<!DOCTYPE');
        $doctypeIndexEnd = strpos($this->xmlFileContent, '>', $doctypeIndexStart);
        $this->xmlFileContent = substr_replace($this->xmlFileContent, '', $doctypeIndexStart, $doctypeIndexEnd - $doctypeIndexStart + 1);
        $this->logger = $logger;
    }

    abstract public function deserialize();

    /**
     * @return Serializer
     */
    public function getSerializer()
    {
        return $this->serializer;
    }

    /**
     * @param Serializer $serializer
     */
    public function setSerializer($serializer)
    {
        $this->serializer = $serializer;
    }

    /**
     * @return mixed
     */
    public function getXmlFilePath()
    {
        return $this->xmlFilePath;
    }

    /**
     * @param mixed $xmlFilePath
     */
    public function setXmlFilePath($xmlFilePath)
    {
        $this->xmlFilePath = $xmlFilePath;
    }

    /**
     * @return mixed
     */
    public function getXmlFileContent()
    {
        return $this->xmlFileContent;
    }

    /**
     * @param mixed $xmlFileContent
     */
    public function setXmlFileContent($xmlFileContent)
    {
        $this->xmlFileContent = $xmlFileContent;
    }

    /**
     * Loads the Serializer.
     */
    protected function loadSerializer()
    {
        if (null === $this->serializer) {
            $this->serializer = Serializer\SerializerBuilder::create()->build();
        }
    }

}