<?php

namespace App\ImportedOrder\Parser;


/**
 * The main XML parser for the importing orders.
 * @author Gabriel
 *
 */
abstract class Xml_GeneralAbstract
{

	/**
	 * The imported order XML.
	 * @var \SimpleXMLElement
	 */
	protected $xml;

	/**
	 * The current imported order object.
	 * @var \App\ImportedOrder\Order
	 */
	protected $order;

	/**
	 * Collects new messages during the parsing of the XML.
	 * @var \App\MessagesCollector
	 */
	protected $messagesCollector;

	/**
	 * The class constructor - associates the order XML and associates the imported order object (new created object or one that is attached).
	 * @param \SimpleXMLElement $xml
	 */
	public function __construct(\SimpleXMLElement $xml, ?\App\ImportedOrder\Order $order=null)
	{
		$this->xml = 	$xml;
		if ($order) {
			$this->order =	$order;
		} else {
			$this->order =	new \App\ImportedOrder\Order();
		}
		$this->messagesCollector = new \App\MessagesCollector();
	}

	/**
	 * Creates the imported order object (populated into $this->order).
	 */
	abstract public function createImportedOrder() ;

	/**
	 * Returns the imported order object.
	 * @return \App\ImportedOrder\Order
	 */
	public function getImportedOrder()
	{
		return $this->order;
	}

}