<?php

namespace RodrigoPedra\ClearSaleID\Entity\Request;

use DateTime;
use InvalidArgumentException;
use RodrigoPedra\ClearSaleID\Entity\XmlEntityInterface;
use RodrigoPedra\ClearSaleID\Exception\RequiredFieldException;
use XMLWriter;

class Order implements XmlEntityInterface
{
    const ECOMMERCE_B2B    = 'b2b';
    const ECOMMERCE_B2C    = 'b2c';
    const STATUS_NEW       = 0;
    const STATUS_APPROVED  = 9;
    const STATUS_CANCELLED = 41;
    const STATUS_REJECTED  = 45;

    private static $ecommerceTypes = [
        self::ECOMMERCE_B2B,
        self::ECOMMERCE_B2C,
    ];

    private static $statuses = [
        self::STATUS_NEW,
        self::STATUS_APPROVED,
        self::STATUS_CANCELLED,
        self::STATUS_REJECTED,
    ];

    /** @var  \RodrigoPedra\ClearSaleID\Entity\Request\FingerPrint */
    private $fingerPrint;

    /** @var  string */
    private $id;

    /** @var  \DateTime */
    private $date;

    /** @var  string */
    private $email;

    /** @var  string */
    private $channel;

    /** @var  string */
    private $ecommerceType;

    /** @var  float */
    private $shippingValue;

    /** @var  float */
    private $totalItems;

    /** @var  float */
    private $totalOrder;

    /** @var  int */
    private $quantityInstallments;

    /** @var  string */
    private $deliveryTime;

    /** @var  int */
    private $quantityItems;

    /** @var  int */
    private $quantityPaymentTypes;

    /** @var  string */
    private $ip;

    /** @var  string */
    private $notes;

    /** @var  int */
    private $status;

    /** @var  string */
    private $origin;

    /** @var  \DateTime */
    private $reservationDate;

    /** @var  \RodrigoPedra\ClearSaleID\Entity\Request\CustomerBillingData */
    private $customerBillingData;

    /** @var  \RodrigoPedra\ClearSaleID\Entity\Request\CustomerShippingData */
    private $customerShippingData;

    /** @var  \RodrigoPedra\ClearSaleID\Entity\Request\Payment[] */
    private $payments;

    /** @var  \RodrigoPedra\ClearSaleID\Entity\Request\Item[] */
    private $items;

    /** @var  \RodrigoPedra\ClearSaleID\Entity\Request\Passenger[] */
    private $passengers;

    /** @var  \RodrigoPedra\ClearSaleID\Entity\Request\Connection[] */
    private $connections;

    /**
     * @param  \RodrigoPedra\ClearSaleID\Entity\Request\FingerPrint          $fingerPrint
     * @param  int                                                           $id
     * @param  \DateTime                                                     $date
     * @param  string                                                        $email
     * @param  float                                                         $totalItems
     * @param  float                                                         $totalOrder
     * @param  int                                                           $quantityInstallments
     * @param  string                                                        $ip
     * @param  string                                                        $origin
     * @param  \RodrigoPedra\ClearSaleID\Entity\Request\CustomerBillingData  $customerBillingData
     * @param  \RodrigoPedra\ClearSaleID\Entity\Request\CustomerShippingData $customerShippingData
     * @param  \RodrigoPedra\ClearSaleID\Entity\Request\Payment              $payment
     * @param  \RodrigoPedra\ClearSaleID\Entity\Request\Item                 $item
     *
     * @return \RodrigoPedra\ClearSaleID\Entity\Request\Order
     */
    public static function createEcommerceOrder(
        FingerPrint $fingerPrint,
        $id,
        DateTime $date,
        $email,
        $totalItems,
        $totalOrder,
        $quantityInstallments,
        $ip,
        $origin,
        CustomerBillingData $customerBillingData,
        CustomerShippingData $customerShippingData,
        Payment $payment,
        Item $item
    ) {
        return static::create(
            $fingerPrint,
            $id,
            $date,
            $email,
            $totalItems,
            $totalOrder,
            $quantityInstallments,
            $ip,
            $origin,
            $customerBillingData,
            $customerShippingData,
            $payment,
            $item
        );
    }

    /**
     * @param  \RodrigoPedra\ClearSaleID\Entity\Request\FingerPrint          $fingerPrint
     * @param  int                                                           $id
     * @param  \DateTime                                                     $date
     * @param  string                                                        $email
     * @param  float                                                         $totalItems
     * @param  float                                                         $totalOrder
     * @param  int                                                           $quantityInstallments
     * @param  string                                                        $ip
     * @param  string                                                        $origin
     * @param  \RodrigoPedra\ClearSaleID\Entity\Request\CustomerBillingData  $customerBillingData
     * @param  \RodrigoPedra\ClearSaleID\Entity\Request\CustomerShippingData $customerShippingData
     * @param  \RodrigoPedra\ClearSaleID\Entity\Request\Payment              $payment
     * @param  \RodrigoPedra\ClearSaleID\Entity\Request\Item                 $item
     * @param  \RodrigoPedra\ClearSaleID\Entity\Request\Passenger            $passenger
     * @param  \RodrigoPedra\ClearSaleID\Entity\Request\Connection           $connection
     *
     * @return \RodrigoPedra\ClearSaleID\Entity\Request\Order
     */
    public static function createAirlineTicketOrder(
        FingerPrint $fingerPrint,
        $id,
        DateTime $date,
        $email,
        $totalItems,
        $totalOrder,
        $quantityInstallments,
        $ip,
        $origin,
        CustomerBillingData $customerBillingData,
        CustomerShippingData $customerShippingData,
        Payment $payment,
        Item $item,
        Passenger $passenger = null,
        Connection $connection = null
    ) {
        return static::create(
            $fingerPrint,
            $id,
            $date,
            $email,
            $totalItems,
            $totalOrder,
            $quantityInstallments,
            $ip,
            $origin,
            $customerBillingData,
            $customerShippingData,
            $payment,
            $item,
            $passenger,
            $connection
        );
    }

    /**
     * @param  \RodrigoPedra\ClearSaleID\Entity\Request\FingerPrint          $fingerPrint
     * @param  int                                                           $id
     * @param  \DateTime                                                     $date
     * @param  string                                                        $email
     * @param  float                                                         $totalItems
     * @param  float                                                         $totalOrder
     * @param  int                                                           $quantityInstallments
     * @param  string                                                        $ip
     * @param  string                                                        $origin
     * @param  \RodrigoPedra\ClearSaleID\Entity\Request\CustomerBillingData  $customerBillingData
     * @param  \RodrigoPedra\ClearSaleID\Entity\Request\CustomerShippingData $shippingData
     * @param  \RodrigoPedra\ClearSaleID\Entity\Request\Payment              $payment
     * @param  \RodrigoPedra\ClearSaleID\Entity\Request\Item                 $item
     * @param  \RodrigoPedra\ClearSaleID\Entity\Request\Passenger|null       $passenger
     * @param  \RodrigoPedra\ClearSaleID\Entity\Request\Connection|null      $connection
     *
     * @return \RodrigoPedra\ClearSaleID\Entity\Request\Order
     */
    private static function create(
        FingerPrint $fingerPrint,
        $id,
        DateTime $date,
        $email,
        $totalItems,
        $totalOrder,
        $quantityInstallments,
        $ip,
        $origin,
        CustomerBillingData $customerBillingData,
        CustomerShippingData $shippingData,
        Payment $payment,
        Item $item,
        Passenger $passenger = null,
        Connection $connection = null
    ) {
        $instance = new self;

        $instance->setFingerPrint( $fingerPrint );
        $instance->setId( $id );
        $instance->setDate( $date );
        $instance->setEmail( $email );
        $instance->setTotalItems( $totalItems );
        $instance->setTotalOrder( $totalOrder );
        $instance->setQuantityInstallments( $quantityInstallments );
        $instance->setIp( $ip );
        $instance->setOrigin( $origin );
        $instance->setBillingData( $customerBillingData );
        $instance->setShippingData( $shippingData );
        $instance->addPayment( $payment );
        $instance->addItem( $item );

        if (null !== $passenger) {
            $instance->addPassenger( $passenger );
        }

        if (null !== $connection) {
            $instance->addConnection( $connection );
        }

        return $instance;
    }

    /**
     * @return \RodrigoPedra\ClearSaleID\Entity\Request\FingerPrint
     */
    public function getFingerPrint()
    {
        return $this->fingerPrint;
    }

    /**
     * @param  \RodrigoPedra\ClearSaleID\Entity\Request\FingerPrint $fingerPrint
     *
     * @return $this
     */
    public function setFingerPrint( FingerPrint $fingerPrint )
    {
        $this->fingerPrint = $fingerPrint;

        return $this;
    }

    /**
     * @return string
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * @param  int $id
     *
     * @return $this
     */
    public function setId( $id )
    {
        $this->id = $id;

        return $this;
    }

    /**
     * @return \DateTime
     */
    public function getDate()
    {
        return $this->date;
    }

    /**
     * @param  \DateTime $date
     *
     * @return $this
     */
    public function setDate( DateTime $date )
    {
        $this->date = $date;

        return $this;
    }

    /**
     * @return string
     */
    public function getEmail()
    {
        return $this->email;
    }

    /**
     * @param  string $email
     *
     * @return $this
     */
    public function setEmail( $email )
    {
        $this->email = $email;

        return $this;
    }

    /**
     * @return string
     */
    public function getChannel()
    {
        return $this->channel;
    }

    /**
     * @param  string $channel
     *
     * @return $this
     */
    public function setChannel( $channel )
    {
        $this->channel = $channel;

        return $this;
    }

    /**
     * @return string
     */
    public function getEcommerceType()
    {
        return $this->ecommerceType;
    }

    /**
     * @param  string $ecommerceType
     *
     * @return $this
     */
    public function setEcommerceType( $ecommerceType )
    {
        if (!in_array( $ecommerceType, self::$ecommerceTypes )) {
            throw new InvalidArgumentException( sprintf( 'Invalid e-commerce type (%s)', $ecommerceType ) );
        }

        $this->ecommerceType = $ecommerceType;

        return $this;
    }

    /**
     * @return float
     */
    public function getShippingValue()
    {
        return $this->shippingValue;
    }

    /**
     * @param  float $shippingValue
     *
     * @return $this
     */
    public function setShippingValue( $shippingValue )
    {
        if (preg_match( '/^(?:\d*\.)?\d+$/', $shippingValue ) !== 1) {
            throw new InvalidArgumentException( sprintf( 'Shipping value should be a non-negative number (%s)',
                $shippingValue ) );
        }

        $this->shippingValue = (float)number_format( $shippingValue, 4, '.', '' );

        return $this;
    }

    /**
     * @return float
     */
    public function getTotalItems()
    {
        return $this->totalItems;
    }

    /**
     * @param  float $totalItems
     *
     * @return $this
     */
    public function setTotalItems( $totalItems )
    {
        if (preg_match( '/^(?:\d*\.)?\d+$/', $totalItems ) !== 1) {
            throw new InvalidArgumentException( sprintf( 'Items total value should be a non-negative number (%s)',
                $totalItems ) );
        }

        $this->totalItems = (float)number_format( $totalItems, 4, '.', '' );

        return $this;
    }

    /**
     * @return float
     */
    public function getTotalOrder()
    {
        return $this->totalOrder;
    }

    /**
     * @param  float $totalOrder
     *
     * @return $this
     */
    public function setTotalOrder( $totalOrder )
    {
        if (preg_match( '/^(?:\d*\.)?\d+$/', $totalOrder ) !== 1) {
            throw new InvalidArgumentException( sprintf( 'Order total value should be a non-negative number (%s)',
                $totalOrder ) );
        }

        $this->totalOrder = (float)number_format( $totalOrder, 4, '.', '' );

        return $this;
    }

    /**
     * @return int
     */
    public function getQuantityInstallments()
    {
        return $this->quantityInstallments;
    }

    /**
     * @param  int $quantityInstallments
     *
     * @return $this
     */
    public function setQuantityInstallments( $quantityInstallments )
    {
        if (preg_match( '/^\d+$/', $quantityInstallments ) !== 1) {
            throw new InvalidArgumentException( sprintf( 'Installments quantity should be a non-negative integer (%s)',
                $quantityInstallments ) );
        }

        $quantityInstallments = intval( $quantityInstallments );

        if ($quantityInstallments > 99) {
            throw new InvalidArgumentException( sprintf( 'Installments quantity should be less than 99 (%s)',
                $quantityInstallments ) );
        }

        $this->quantityInstallments = $quantityInstallments;

        return $this;
    }

    /**
     * @return string
     */
    public function getDeliveryTime()
    {
        return $this->deliveryTime;
    }

    /**
     * @param  string $deliveryTime
     *
     * @return $this
     */
    public function setDeliveryTime( $deliveryTime )
    {
        $this->deliveryTime = $deliveryTime;

        return $this;
    }

    /**
     * @return int
     */
    public function getQuantityItems()
    {
        return $this->quantityItems;
    }

    /**
     * @param  int $quantityItems
     *
     * @return $this
     */
    public function setQuantityItems( $quantityItems )
    {
        if (preg_match( '/^\d+$/', $quantityItems ) !== 1) {
            throw new InvalidArgumentException( sprintf( 'Items quantity should be a non-negative integer (%s)',
                $quantityItems ) );
        }

        $this->quantityItems = intval( $quantityItems );

        return $this;
    }

    /**
     * @return int
     */
    public function getQuantityPaymentTypes()
    {
        return $this->quantityPaymentTypes;
    }

    /**
     * @param  int $quantityPaymentTypes
     *
     * @return $this
     */
    public function setQuantityPaymentTypes( $quantityPaymentTypes )
    {
        if (preg_match( '/^\d+$/', $quantityPaymentTypes ) !== 1) {
            throw new InvalidArgumentException( sprintf( 'Payment types quantity should be a non-negative integer (%s)',
                $quantityPaymentTypes ) );
        }

        $this->quantityPaymentTypes = intval( $quantityPaymentTypes );

        return $this;
    }

    /**
     * @return string
     */
    public function getIp()
    {
        return $this->ip;
    }

    /**
     * @param  string $ip
     *
     * @return $this
     */
    public function setIp( $ip )
    {
        $this->ip = $ip;

        return $this;
    }

    /**
     * @return string
     */
    public function getNotes()
    {
        return $this->notes;
    }

    /**
     * @param  string $notes
     *
     * @return $this
     */
    public function setNotes( $notes )
    {
        $this->notes = $notes;

        return $this;
    }

    /**
     * @return int
     */
    public function getStatus()
    {
        return $this->status;
    }

    /**
     * @param  int $status
     *
     * @return $this
     */
    public function setStatus( $status )
    {
        if (!in_array( intval( $status ), self::$statuses )) {
            throw new InvalidArgumentException( sprintf( 'Invalid status (%s)', $status ) );
        }

        $this->status = $status;

        return $this;
    }

    /**
     * @return string
     */
    public function getOrigin()
    {
        return $this->origin;
    }

    /**
     * @param  string $origin
     *
     * @return $this
     */
    public function setOrigin( $origin )
    {
        $this->origin = $origin;

        return $this;
    }

    /**
     * @return \DateTime
     */
    public function getReservationDate()
    {
        return $this->reservationDate;
    }

    /**
     * @param  \DateTime $reservationDate
     *
     * @return $this
     */
    public function setReservationDate( DateTime $reservationDate )
    {
        $this->reservationDate = $reservationDate;

        return $this;
    }

    /**
     * @return \RodrigoPedra\ClearSaleID\Entity\Request\CustomerBillingData
     */
    public function getBillingData()
    {
        return $this->customerBillingData;
    }

    /**
     * @param  \RodrigoPedra\ClearSaleID\Entity\Request\CustomerBillingData $customerBillingData
     *
     * @return $this
     */
    public function setBillingData( CustomerBillingData $customerBillingData )
    {
        $this->customerBillingData = $customerBillingData;

        return $this;
    }

    /**
     * @return \RodrigoPedra\ClearSaleID\Entity\Request\CustomerShippingData
     */
    public function getShippingData()
    {
        return $this->customerShippingData;
    }

    /**
     * @param  \RodrigoPedra\ClearSaleID\Entity\Request\CustomerShippingData $customerShippingData
     *
     * @return $this
     */
    public function setShippingData( CustomerShippingData $customerShippingData )
    {
        $this->customerShippingData = $customerShippingData;

        return $this;
    }

    /**
     * @return \RodrigoPedra\ClearSaleID\Entity\Request\Payment[]
     */
    public function getPayments()
    {
        return $this->payments;
    }

    /**
     * @param  \RodrigoPedra\ClearSaleID\Entity\Request\Payment[] $payments
     *
     * @return $this
     */
    public function setPayments( $payments )
    {
        foreach ($payments as $payment) {
            $this->addPayment( $payment );
        }

        return $this;
    }

    /**
     * @param  int $index
     *
     * @return \RodrigoPedra\ClearSaleID\Entity\Request\Payment
     */
    public function getPayment( $index )
    {
        return $this->payments[ $index ];
    }

    /**
     * @return \RodrigoPedra\ClearSaleID\Entity\Request\Item[]
     */
    public function getItems()
    {
        return $this->items;
    }

    /**
     * @param  \RodrigoPedra\ClearSaleID\Entity\Request\Item[] $items
     *
     * @return $this
     */
    public function setItems( $items )
    {
        foreach ($items as $item) {
            $this->addItem( $item );
        }

        return $this;
    }

    /**
     * @return \RodrigoPedra\ClearSaleID\Entity\Request\Passenger[]
     */
    public function getPassengers()
    {
        return $this->passengers;
    }

    /**
     * @param  \RodrigoPedra\ClearSaleID\Entity\Request\Passenger[] $passengers
     *
     * @return $this
     */
    public function setPassengers( $passengers )
    {
        foreach ($passengers as $passenger) {
            $this->addPassenger( $passenger );
        }

        return $this;
    }

    /**
     * @return \RodrigoPedra\ClearSaleID\Entity\Request\Connection[]
     */
    public function getConnections()
    {
        return $this->connections;
    }

    /**
     * @param  \RodrigoPedra\ClearSaleID\Entity\Request\Connection[] $connections
     *
     * @return $this
     */
    public function setConnections( $connections )
    {
        foreach ($connections as $connection) {
            $this->addConnection( $connection );
        }

        return $this;
    }

    /**
     * @param  \RodrigoPedra\ClearSaleID\Entity\Request\Payment $payment
     *
     * @return $this
     */
    public function addPayment( Payment $payment )
    {
        $this->payments[] = $payment;

        return $this;
    }

    /**
     * @param  \RodrigoPedra\ClearSaleID\Entity\Request\Item $item
     *
     * @return $this
     */
    public function addItem( Item $item )
    {
        $this->items[] = $item;

        return $this;
    }

    /**
     * @param  \RodrigoPedra\ClearSaleID\Entity\Request\Passenger $passenger
     *
     * @return $this
     */
    public function addPassenger( Passenger $passenger )
    {
        $this->passengers[] = $passenger;

        return $this;
    }

    /**
     * @param  \RodrigoPedra\ClearSaleID\Entity\Request\Connection $connection
     *
     * @return $this
     */
    public function addConnection( Connection $connection )
    {
        $this->connections[] = $connection;

        return $this;
    }

    /**
     * @param  \XMLWriter $XMLWriter
     *
     * @throws \RodrigoPedra\ClearSaleID\Exception\RequiredFieldException
     */
    public function toXML( XMLWriter $XMLWriter )
    {
        $XMLWriter->startElement( 'ClearID_Input' );

        if ($this->fingerPrint) {
            $this->fingerPrint->toXML( $XMLWriter );
        } else {
            throw new RequiredFieldException( 'Field FingerPrint of the Order object is required' );
        }

        $XMLWriter->startElement( 'Pedido' );

        if ($this->id) {
            $XMLWriter->writeElement( 'PedidoID', $this->id );
        } else {
            throw new RequiredFieldException( 'Field ID of the Order object is required' );
        }

        if ($this->date) {
            $XMLWriter->writeElement( 'Data', $this->date->format( self::DATE_TIME_FORMAT ) );
        } else {
            throw new RequiredFieldException( 'Field Date of the Order object is required' );
        }

        if ($this->email) {
            $XMLWriter->writeElement( 'Email', $this->email );
        }

        if ($this->channel) {
            $XMLWriter->writeElement( 'CanalID', $this->channel );
        }

        if ($this->ecommerceType) {
            $XMLWriter->writeElement( 'B2B_B2C', $this->ecommerceType );
        }

        if ($this->shippingValue) {
            $XMLWriter->writeElement( 'ValorFrete', $this->shippingValue );
        }

        if (is_numeric( $this->totalItems )) {
            $XMLWriter->writeElement( 'ValorTotalItens', $this->totalItems );
        } else {
            throw new RequiredFieldException( 'Field TotalItems of the Order object is required' );
        }

        if (is_numeric( $this->totalOrder )) {
            $XMLWriter->writeElement( 'ValorTotalPedido', $this->totalOrder );
        } else {
            throw new RequiredFieldException( 'Field TotalOrder of the Order object is required' );
        }

        if ($this->quantityInstallments) {
            $XMLWriter->writeElement( 'QtdParcelas', $this->quantityInstallments );
        }

        if ($this->deliveryTime) {
            $XMLWriter->writeElement( 'PrazoEntrega', $this->deliveryTime );
        }

        if ($this->quantityItems) {
            $XMLWriter->writeElement( 'QtdItens', $this->quantityItems );
        }

        if ($this->quantityPaymentTypes) {
            $XMLWriter->writeElement( 'QtdFormasPagamento', $this->quantityPaymentTypes );
        }

        if ($this->ip) {
            $XMLWriter->writeElement( 'IP', $this->ip );
        }

        if ($this->notes) {
            $XMLWriter->writeElement( 'Observacao', $this->notes );
        }

        if ($this->status) {
            $XMLWriter->writeElement( 'Status', $this->status );
        }

        if ($this->origin) {
            $XMLWriter->writeElement( 'Origem', $this->origin );
        }

        if ($this->reservationDate) {
            $XMLWriter->writeElement( 'DataReserva', $this->reservationDate->format( self::DATE_TIME_FORMAT ) );
        }

        if ($this->customerBillingData) {
            $this->customerBillingData->toXML( $XMLWriter );
        } else {
            throw new RequiredFieldException( 'Field CustomerBillingData of the Order object is required' );
        }

        if ($this->customerShippingData) {
            $this->customerShippingData->toXML( $XMLWriter );
        } else {
            throw new RequiredFieldException( 'Field CustomerShippingData of the Order object is required' );
        }

        if (count( $this->payments ) > 0) {
            $XMLWriter->startElement( 'Pagamentos' );

            foreach ($this->payments as $payment) {
                $payment->toXML( $XMLWriter );
            }

            $XMLWriter->endElement();
        } else {
            throw new RequiredFieldException( 'Field Payments of the Order object is required' );
        }

        if (count( $this->items ) > 0) {
            $XMLWriter->startElement( 'Itens' );

            foreach ($this->items as $item) {
                $item->toXML( $XMLWriter );
            }

            $XMLWriter->endElement();
        } else {
            throw new RequiredFieldException( 'Field Items of the Order object is required' );
        }

        if (count( $this->passengers ) > 0) {
            $XMLWriter->startElement( 'Passageiros' );

            foreach ($this->passengers as $passenger) {
                $passenger->toXML( $XMLWriter );
            }

            $XMLWriter->endElement();
        }

        if (count( $this->connections ) > 0) {
            $XMLWriter->startElement( 'Conexoes' );

            foreach ($this->connections as $connection) {
                $connection->toXML( $XMLWriter );
            }

            $XMLWriter->endElement();
        }

        $XMLWriter->endElement(); // Pedido
        $XMLWriter->endElement(); // ClearID_Input
    }
}


<?php

namespace RodrigoPedra\ClearSaleID\Entity\Request;

use DateTime;
use InvalidArgumentException;
use RodrigoPedra\ClearSaleID\Entity\XmlEntityInterface;
use RodrigoPedra\ClearSaleID\Exception\RequiredFieldException;
use XMLWriter;

abstract class AbstractCustomer implements XmlEntityInterface
{
    const TYPE_PESSOA_FISICA   = 1;
    const TYPE_PESSOA_JURIDICA = 2;
    const SEX_MASCULINE        = 'M';
    const SEX_FEMININE         = 'F';
    protected static $customerTypes = [
        self::TYPE_PESSOA_FISICA,
        self::TYPE_PESSOA_JURIDICA,
    ];
    protected static $sexTypes      = [
        self::SEX_MASCULINE,
        self::SEX_FEMININE,
    ];

    /** @var  string */
    protected $id;

    /** @var  int */
    protected $type;

    /** @var  string */
    protected $legalDocument1;

    /** @var  string */
    protected $legalDocument2;

    /** @var  string */
    protected $name;

    /** @var  string */
    protected $email;

    /** @var  string */
    protected $sex;

    /** @var  \DateTime */
    protected $birthDate;

    /** @var  \RodrigoPedra\ClearSaleID\Entity\Request\Address */
    protected $address;

    /** @var  \RodrigoPedra\ClearSaleID\Entity\Request\Phone[] */
    protected $phones;

    /**
     * @return string
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * @param  string $id
     *
     * @return $this
     * @throws \InvalidArgumentException
     */
    public function setId( $id )
    {
        if (empty( $id )) {
            throw new InvalidArgumentException( 'The id value is empty!' );
        }

        $this->id = $id;

        return $this;
    }

    /**
     * @return string
     */
    public function getType()
    {
        return $this->type;
    }

    /**
     * @param  int $type
     *
     * @return $this
     * @throws \InvalidArgumentException
     */
    public function setType( $type )
    {
        if (!in_array( $type, self::$customerTypes )) {
            throw new InvalidArgumentException( sprintf( 'Invalid type (%s)', $type ) );
        }

        $this->type = $type;

        return $this;
    }

    /**
     * @return string
     */
    public function getLegalDocument1()
    {
        return $this->legalDocument1;
    }

    /**
     * @param  string $legalDocument1
     *
     * @return $this
     * @throws \InvalidArgumentException
     */
    public function setLegalDocument1( $legalDocument1 )
    {
        $legalDocument1 = preg_replace( '/\D/', '', $legalDocument1 );

        if (empty( $legalDocument1 )) {
            throw new InvalidArgumentException( 'LegalDocument1 is empty!' );
        }

        $this->legalDocument1 = $legalDocument1;

        return $this;
    }

    /**
     * @return string
     */
    public function getLegalDocument2()
    {
        return $this->legalDocument2;
    }

    /**
     * @param  string $legalDocument2
     *
     * @return $this
     * @throws \InvalidArgumentException
     */
    public function setLegalDocument2( $legalDocument2 )
    {
        $legalDocument2 = preg_replace( '/\D/', '', $legalDocument2 );

        if (empty( $legalDocument2 )) {
            throw new InvalidArgumentException( 'LegalDocument2 is empty!' );
        }

        $this->legalDocument2 = $legalDocument2;

        return $this;
    }

    /**
     * @return string
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * @param  string $name
     *
     * @return $this
     * @throws \InvalidArgumentException
     */
    public function setName( $name )
    {
        if (empty( $name )) {
            throw new InvalidArgumentException( 'Name is empty!' );
        }

        $this->name = $name;

        return $this;
    }

    /**
     * @return string
     */
    public function getEmail()
    {
        return $this->email;
    }

    /**
     * @param  string $email
     *
     * @return $this
     */
    public function setEmail( $email )
    {
        $this->email = $email;

        return $this;
    }

    /**
     * @return string
     */
    public function getSex()
    {
        return $this->sex;
    }

    /**
     * @param  string $sex
     *
     * @return $this
     * @throws \InvalidArgumentException
     */
    public function setSex( $sex )
    {
        if (!in_array( $sex, self::$sexTypes )) {
            throw new InvalidArgumentException( sprintf( 'Invalid sex (%s)', $sex ) );
        }

        $this->sex = $sex;

        return $this;
    }

    /**
     * @return \DateTime
     */
    public function getBirthDate()
    {
        return $this->birthDate;
    }

    /**
     * @param  \DateTime $birthDate
     *
     * @return $this
     */
    public function setBirthDate( DateTime $birthDate )
    {
        $this->birthDate = $birthDate;

        return $this;
    }

    /**
     * @return \RodrigoPedra\ClearSaleID\Entity\Request\Address
     */
    public function getAddress()
    {
        return $this->address;
    }

    /**
     * @param  \RodrigoPedra\ClearSaleID\Entity\Request\Address $address
     *
     * @return $this
     */
    public function setAddress( Address $address )
    {
        $this->address = $address;

        return $this;
    }

    /**
     * @return \RodrigoPedra\ClearSaleID\Entity\Request\Phone[]
     */
    public function getPhones()
    {
        return $this->phones;
    }

    /**
     * @param  \RodrigoPedra\ClearSaleID\Entity\Request\Phone|\RodrigoPedra\ClearSaleID\Entity\Request\Phone[] $phones
     *
     * @return $this
     */
    public function setPhones( $phones )
    {
        $phones = is_array( $phones ) ? $phones : [ $phones ];

        foreach ($phones as $phone) {
            $this->addPhone( $phone );
        }

        return $this;
    }

    /**
     * @param  \RodrigoPedra\ClearSaleID\Entity\Request\Phone $phone
     *
     * @return $this
     */
    public function addPhone( Phone $phone )
    {
        $this->phones[] = $phone;

        return $this;
    }

    /**
     * @param  \XMLWriter $XMLWriter
     *
     * @throws \RodrigoPedra\ClearSaleID\Exception\RequiredFieldException
     */
    public function toXML( XMLWriter $XMLWriter )
    {
        if ($this->id) {
            $XMLWriter->writeElement( 'UsuarioID', $this->id );
        } else {
            throw new RequiredFieldException( 'Field ID of the Customer object is required' );
        }

        if ($this->type) {
            $XMLWriter->writeElement( 'TipoUsuario', $this->type );
        } else {
            throw new RequiredFieldException( 'Field Type of the Customer object is required' );
        }

        if ($this->legalDocument1) {
            $XMLWriter->writeElement( 'DocumentoLegal1', $this->legalDocument1 );
        } else {
            throw new RequiredFieldException( 'Field LegalDocument1 of the Customer object is required' );
        }

        if ($this->legalDocument2) {
            $XMLWriter->writeElement( 'DocumentoLegal2', $this->legalDocument2 );
        }

        if ($this->name) {
            $XMLWriter->writeElement( 'Nome', $this->name );
        } else {
            throw new RequiredFieldException( 'Field name of the Customer object is required' );
        }

        if ($this->email) {
            $XMLWriter->writeElement( 'Email', $this->email );
        }

        if ($this->sex) {
            $XMLWriter->writeElement( 'Sexo', $this->sex );
        }

        if ($this->birthDate) {
            $XMLWriter->writeElement( 'Nascimento', $this->birthDate->format( self::DATE_TIME_FORMAT ) );
        }

        if ($this->address) {
            $this->address->toXML( $XMLWriter );
        } else {
            throw new RequiredFieldException( 'Field Address of the Customer object is required' );
        }

        if (count( $this->phones ) > 0) {
            $XMLWriter->startElement( 'Telefones' );

            foreach ($this->phones as $phone) {
                $phone->toXML( $XMLWriter );
            }

            $XMLWriter->endElement();
        } else {
            throw new RequiredFieldException( 'Field Phones of the Customer object is required' );
        }
    }
}


<?php

namespace PhpOffice\PhpSpreadsheet\Writer\Xlsx;

use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Shared\XMLWriter;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Worksheet\BaseDrawing;
use PhpOffice\PhpSpreadsheet\Worksheet\HeaderFooterDrawing;
use PhpOffice\PhpSpreadsheet\Writer\Exception as WriterException;

class Drawing extends WriterPart
{
    /**
     * Write drawings to XML format.
     *
     * @param \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet $pWorksheet
     * @param bool $includeCharts Flag indicating if we should include drawing details for charts
     *
     * @throws WriterException
     *
     * @return string XML Output
     */
    public function writeDrawings(\PhpOffice\PhpSpreadsheet\Worksheet\Worksheet $pWorksheet, $includeCharts = false)
    {
        // Create XML writer
        $objWriter = null;
        if ($this->getParentWriter()->getUseDiskCaching()) {
            $objWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
        } else {
            $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
        }

        // XML header
        $objWriter->startDocument('1.0', 'UTF-8', 'yes');

        // xdr:wsDr
        $objWriter->startElement('xdr:wsDr');
        $objWriter->writeAttribute('xmlns:xdr', 'http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing');
        $objWriter->writeAttribute('xmlns:a', 'http://schemas.openxmlformats.org/drawingml/2006/main');

        // Loop through images and write drawings
        $i = 1;
        $iterator = $pWorksheet->getDrawingCollection()->getIterator();
        while ($iterator->valid()) {
            $this->writeDrawing($objWriter, $iterator->current(), $i);

            $iterator->next();
            ++$i;
        }

        if ($includeCharts) {
            $chartCount = $pWorksheet->getChartCount();
            // Loop through charts and write the chart position
            if ($chartCount > 0) {
                for ($c = 0; $c < $chartCount; ++$c) {
                    $this->writeChart($objWriter, $pWorksheet->getChartByIndex($c), $c + $i);
                }
            }
        }

        $objWriter->endElement();

        // Return
        return $objWriter->getData();
    }

    /**
     * Write drawings to XML format.
     *
     * @param XMLWriter $objWriter XML Writer
     * @param \PhpOffice\PhpSpreadsheet\Chart\Chart $pChart
     * @param int $pRelationId
     */
    public function writeChart(XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Chart\Chart $pChart, $pRelationId = -1)
    {
        $tl = $pChart->getTopLeftPosition();
        $tl['colRow'] = Coordinate::coordinateFromString($tl['cell']);
        $br = $pChart->getBottomRightPosition();
        $br['colRow'] = Coordinate::coordinateFromString($br['cell']);

        $objWriter->startElement('xdr:twoCellAnchor');

        $objWriter->startElement('xdr:from');
        $objWriter->writeElement('xdr:col', Coordinate::columnIndexFromString($tl['colRow'][0]) - 1);
        $objWriter->writeElement('xdr:colOff', \PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToEMU($tl['xOffset']));
        $objWriter->writeElement('xdr:row', $tl['colRow'][1] - 1);
        $objWriter->writeElement('xdr:rowOff', \PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToEMU($tl['yOffset']));
        $objWriter->endElement();
        $objWriter->startElement('xdr:to');
        $objWriter->writeElement('xdr:col', Coordinate::columnIndexFromString($br['colRow'][0]) - 1);
        $objWriter->writeElement('xdr:colOff', \PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToEMU($br['xOffset']));
        $objWriter->writeElement('xdr:row', $br['colRow'][1] - 1);
        $objWriter->writeElement('xdr:rowOff', \PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToEMU($br['yOffset']));
        $objWriter->endElement();

        $objWriter->startElement('xdr:graphicFrame');
        $objWriter->writeAttribute('macro', '');
        $objWriter->startElement('xdr:nvGraphicFramePr');
        $objWriter->startElement('xdr:cNvPr');
        $objWriter->writeAttribute('name', 'Chart ' . $pRelationId);
        $objWriter->writeAttribute('id', 1025 * $pRelationId);
        $objWriter->endElement();
        $objWriter->startElement('xdr:cNvGraphicFramePr');
        $objWriter->startElement('a:graphicFrameLocks');
        $objWriter->endElement();
        $objWriter->endElement();
        $objWriter->endElement();

        $objWriter->startElement('xdr:xfrm');
        $objWriter->startElement('a:off');
        $objWriter->writeAttribute('x', '0');
        $objWriter->writeAttribute('y', '0');
        $objWriter->endElement();
        $objWriter->startElement('a:ext');
        $objWriter->writeAttribute('cx', '0');
        $objWriter->writeAttribute('cy', '0');
        $objWriter->endElement();
        $objWriter->endElement();

        $objWriter->startElement('a:graphic');
        $objWriter->startElement('a:graphicData');
        $objWriter->writeAttribute('uri', 'http://schemas.openxmlformats.org/drawingml/2006/chart');
        $objWriter->startElement('c:chart');
        $objWriter->writeAttribute('xmlns:c', 'http://schemas.openxmlformats.org/drawingml/2006/chart');
        $objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
        $objWriter->writeAttribute('r:id', 'rId' . $pRelationId);
        $objWriter->endElement();
        $objWriter->endElement();
        $objWriter->endElement();
        $objWriter->endElement();

        $objWriter->startElement('xdr:clientData');
        $objWriter->endElement();

        $objWriter->endElement();
    }

    /**
     * Write drawings to XML format.
     *
     * @param XMLWriter $objWriter XML Writer
     * @param BaseDrawing $pDrawing
     * @param int $pRelationId
     *
     * @throws WriterException
     */
    public function writeDrawing(XMLWriter $objWriter, BaseDrawing $pDrawing, $pRelationId = -1)
    {
        if ($pRelationId >= 0) {
            // xdr:oneCellAnchor
            $objWriter->startElement('xdr:oneCellAnchor');
            // Image location
            $aCoordinates = Coordinate::coordinateFromString($pDrawing->getCoordinates());
            $aCoordinates[0] = Coordinate::columnIndexFromString($aCoordinates[0]);

            // xdr:from
            $objWriter->startElement('xdr:from');
            $objWriter->writeElement('xdr:col', $aCoordinates[0] - 1);
            $objWriter->writeElement('xdr:colOff', \PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToEMU($pDrawing->getOffsetX()));
            $objWriter->writeElement('xdr:row', $aCoordinates[1] - 1);
            $objWriter->writeElement('xdr:rowOff', \PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToEMU($pDrawing->getOffsetY()));
            $objWriter->endElement();

            // xdr:ext
            $objWriter->startElement('xdr:ext');
            $objWriter->writeAttribute('cx', \PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToEMU($pDrawing->getWidth()));
            $objWriter->writeAttribute('cy', \PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToEMU($pDrawing->getHeight()));
            $objWriter->endElement();

            // xdr:pic
            $objWriter->startElement('xdr:pic');

            // xdr:nvPicPr
            $objWriter->startElement('xdr:nvPicPr');

            // xdr:cNvPr
            $objWriter->startElement('xdr:cNvPr');
            $objWriter->writeAttribute('id', $pRelationId);
            $objWriter->writeAttribute('name', $pDrawing->getName());
            $objWriter->writeAttribute('descr', $pDrawing->getDescription());
            $objWriter->endElement();

            // xdr:cNvPicPr
            $objWriter->startElement('xdr:cNvPicPr');

            // a:picLocks
            $objWriter->startElement('a:picLocks');
            $objWriter->writeAttribute('noChangeAspect', '1');
            $objWriter->endElement();

            $objWriter->endElement();

            $objWriter->endElement();

            // xdr:blipFill
            $objWriter->startElement('xdr:blipFill');

            // a:blip
            $objWriter->startElement('a:blip');
            $objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
            $objWriter->writeAttribute('r:embed', 'rId' . $pRelationId);
            $objWriter->endElement();

            // a:stretch
            $objWriter->startElement('a:stretch');
            $objWriter->writeElement('a:fillRect', null);
            $objWriter->endElement();

            $objWriter->endElement();

            // xdr:spPr
            $objWriter->startElement('xdr:spPr');

            // a:xfrm
            $objWriter->startElement('a:xfrm');
            $objWriter->writeAttribute('rot', \PhpOffice\PhpSpreadsheet\Shared\Drawing::degreesToAngle($pDrawing->getRotation()));
            $objWriter->endElement();

            // a:prstGeom
            $objWriter->startElement('a:prstGeom');
            $objWriter->writeAttribute('prst', 'rect');

            // a:avLst
            $objWriter->writeElement('a:avLst', null);

            $objWriter->endElement();

            if ($pDrawing->getShadow()->getVisible()) {
                // a:effectLst
                $objWriter->startElement('a:effectLst');

                // a:outerShdw
                $objWriter->startElement('a:outerShdw');
                $objWriter->writeAttribute('blurRad', \PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToEMU($pDrawing->getShadow()->getBlurRadius()));
                $objWriter->writeAttribute('dist', \PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToEMU($pDrawing->getShadow()->getDistance()));
                $objWriter->writeAttribute('dir', \PhpOffice\PhpSpreadsheet\Shared\Drawing::degreesToAngle($pDrawing->getShadow()->getDirection()));
                $objWriter->writeAttribute('algn', $pDrawing->getShadow()->getAlignment());
                $objWriter->writeAttribute('rotWithShape', '0');

                // a:srgbClr
                $objWriter->startElement('a:srgbClr');
                $objWriter->writeAttribute('val', $pDrawing->getShadow()->getColor()->getRGB());

                // a:alpha
                $objWriter->startElement('a:alpha');
                $objWriter->writeAttribute('val', $pDrawing->getShadow()->getAlpha() * 1000);
                $objWriter->endElement();

                $objWriter->endElement();

                $objWriter->endElement();

                $objWriter->endElement();
            }
            $objWriter->endElement();

            $objWriter->endElement();

            // xdr:clientData
            $objWriter->writeElement('xdr:clientData', null);

            $objWriter->endElement();
        } else {
            throw new WriterException('Invalid parameters passed.');
        }
    }

    /**
     * Write VML header/footer images to XML format.
     *
     * @param \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet $pWorksheet
     *
     * @throws WriterException
     *
     * @return string XML Output
     */
    public function writeVMLHeaderFooterImages(\PhpOffice\PhpSpreadsheet\Worksheet\Worksheet $pWorksheet)
    {
        // Create XML writer
        $objWriter = null;
        if ($this->getParentWriter()->getUseDiskCaching()) {
            $objWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
        } else {
            $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
        }

        // XML header
        $objWriter->startDocument('1.0', 'UTF-8', 'yes');

        // Header/footer images
        $images = $pWorksheet->getHeaderFooter()->getImages();

        // xml
        $objWriter->startElement('xml');
        $objWriter->writeAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml');
        $objWriter->writeAttribute('xmlns:o', 'urn:schemas-microsoft-com:office:office');
        $objWriter->writeAttribute('xmlns:x', 'urn:schemas-microsoft-com:office:excel');

        // o:shapelayout
        $objWriter->startElement('o:shapelayout');
        $objWriter->writeAttribute('v:ext', 'edit');

        // o:idmap
        $objWriter->startElement('o:idmap');
        $objWriter->writeAttribute('v:ext', 'edit');
        $objWriter->writeAttribute('data', '1');
        $objWriter->endElement();

        $objWriter->endElement();

        // v:shapetype
        $objWriter->startElement('v:shapetype');
        $objWriter->writeAttribute('id', '_x0000_t75');
        $objWriter->writeAttribute('coordsize', '21600,21600');
        $objWriter->writeAttribute('o:spt', '75');
        $objWriter->writeAttribute('o:preferrelative', 't');
        $objWriter->writeAttribute('path', 'm@4@5l@4@11@9@11@9@5xe');
        $objWriter->writeAttribute('filled', 'f');
        $objWriter->writeAttribute('stroked', 'f');

        // v:stroke
        $objWriter->startElement('v:stroke');
        $objWriter->writeAttribute('joinstyle', 'miter');
        $objWriter->endElement();

        // v:formulas
        $objWriter->startElement('v:formulas');

        // v:f
        $objWriter->startElement('v:f');
        $objWriter->writeAttribute('eqn', 'if lineDrawn pixelLineWidth 0');
        $objWriter->endElement();

        // v:f
        $objWriter->startElement('v:f');
        $objWriter->writeAttribute('eqn', 'sum @0 1 0');
        $objWriter->endElement();

        // v:f
        $objWriter->startElement('v:f');
        $objWriter->writeAttribute('eqn', 'sum 0 0 @1');
        $objWriter->endElement();

        // v:f
        $objWriter->startElement('v:f');
        $objWriter->writeAttribute('eqn', 'prod @2 1 2');
        $objWriter->endElement();

        // v:f
        $objWriter->startElement('v:f');
        $objWriter->writeAttribute('eqn', 'prod @3 21600 pixelWidth');
        $objWriter->endElement();

        // v:f
        $objWriter->startElement('v:f');
        $objWriter->writeAttribute('eqn', 'prod @3 21600 pixelHeight');
        $objWriter->endElement();

        // v:f
        $objWriter->startElement('v:f');
        $objWriter->writeAttribute('eqn', 'sum @0 0 1');
        $objWriter->endElement();

        // v:f
        $objWriter->startElement('v:f');
        $objWriter->writeAttribute('eqn', 'prod @6 1 2');
        $objWriter->endElement();

        // v:f
        $objWriter->startElement('v:f');
        $objWriter->writeAttribute('eqn', 'prod @7 21600 pixelWidth');
        $objWriter->endElement();

        // v:f
        $objWriter->startElement('v:f');
        $objWriter->writeAttribute('eqn', 'sum @8 21600 0');
        $objWriter->endElement();

        // v:f
        $objWriter->startElement('v:f');
        $objWriter->writeAttribute('eqn', 'prod @7 21600 pixelHeight');
        $objWriter->endElement();

        // v:f
        $objWriter->startElement('v:f');
        $objWriter->writeAttribute('eqn', 'sum @10 21600 0');
        $objWriter->endElement();

        $objWriter->endElement();

        // v:path
        $objWriter->startElement('v:path');
        $objWriter->writeAttribute('o:extrusionok', 'f');
        $objWriter->writeAttribute('gradientshapeok', 't');
        $objWriter->writeAttribute('o:connecttype', 'rect');
        $objWriter->endElement();

        // o:lock
        $objWriter->startElement('o:lock');
        $objWriter->writeAttribute('v:ext', 'edit');
        $objWriter->writeAttribute('aspectratio', 't');
        $objWriter->endElement();

        $objWriter->endElement();

        // Loop through images
        foreach ($images as $key => $value) {
            $this->writeVMLHeaderFooterImage($objWriter, $key, $value);
        }

        $objWriter->endElement();

        // Return
        return $objWriter->getData();
    }

    /**
     * Write VML comment to XML format.
     *
     * @param XMLWriter $objWriter XML Writer
     * @param string $pReference Reference
     * @param HeaderFooterDrawing $pImage Image
     */
    private function writeVMLHeaderFooterImage(XMLWriter $objWriter, $pReference, HeaderFooterDrawing $pImage)
    {
        // Calculate object id
        preg_match('{(\d+)}', md5($pReference), $m);
        $id = 1500 + (substr($m[1], 0, 2) * 1);

        // Calculate offset
        $width = $pImage->getWidth();
        $height = $pImage->getHeight();
        $marginLeft = $pImage->getOffsetX();
        $marginTop = $pImage->getOffsetY();

        // v:shape
        $objWriter->startElement('v:shape');
        $objWriter->writeAttribute('id', $pReference);
        $objWriter->writeAttribute('o:spid', '_x0000_s' . $id);
        $objWriter->writeAttribute('type', '#_x0000_t75');
        $objWriter->writeAttribute('style', "position:absolute;margin-left:{$marginLeft}px;margin-top:{$marginTop}px;width:{$width}px;height:{$height}px;z-index:1");

        // v:imagedata
        $objWriter->startElement('v:imagedata');
        $objWriter->writeAttribute('o:relid', 'rId' . $pReference);
        $objWriter->writeAttribute('o:title', $pImage->getName());
        $objWriter->endElement();

        // o:lock
        $objWriter->startElement('o:lock');
        $objWriter->writeAttribute('v:ext', 'edit');
        $objWriter->writeAttribute('textRotation', 't');
        $objWriter->endElement();

        $objWriter->endElement();
    }

    /**
     * Get an array of all drawings.
     *
     * @param Spreadsheet $spreadsheet
     *
     * @return \PhpOffice\PhpSpreadsheet\Worksheet\Drawing[] All drawings in PhpSpreadsheet
     */
    public function allDrawings(Spreadsheet $spreadsheet)
    {
        // Get an array of all drawings
        $aDrawings = [];

        // Loop through PhpSpreadsheet
        $sheetCount = $spreadsheet->getSheetCount();
        for ($i = 0; $i < $sheetCount; ++$i) {
            // Loop through images and add to array
            $iterator = $spreadsheet->getSheet($i)->getDrawingCollection()->getIterator();
            while ($iterator->valid()) {
                $aDrawings[] = $iterator->current();

                $iterator->next();
            }
        }

        return $aDrawings;
    }
}


<?php

namespace Snaptier\API\HttpClient\Message;

use Snaptier\API\Exception\ApiLimitExceedException;
use Snaptier\API\Exception\DecodingFailedException;
use Psr\Http\Message\ResponseInterface;

/**
 * This is the response mediator class.
 *
 * @author Graham Campbell <graham@alt-three.com>
 * @author Miguel Piedrafita <soy@miguelpiedrafita.com>
 */
class ResponseMediator
{
    /**
     * Get the decoded response content.
     *
     * If the there is no response body, we will always return the empty array.
     *
     * @param \Psr\Http\Message\ResponseInterface $response
     *
     * @throws \Snaptier\API\Exception\DecodingFailedException
     *
     * @return array
     */
    public static function getContent(ResponseInterface $response)
    {
        if ($response->getStatusCode() === 204) {
            return [];
        }

        $body = (string) $response->getBody();

        if (!$body) {
            return [];
        }

        if (strpos($response->getHeaderLine('Content-Type'), 'application/json') !== 0) {
            throw new DecodingFailedException('The content type header was not application/json.');
        }

        return self::jsonDecode($body);
    }

    /**
     * Decode the given JSON string to an array.
     *
     * @param string $body
     *
     * @throws \Snaptier\API\Exception\DecodingFailedException
     *
     * @return array
     */
    private static function jsonDecode(string $body)
    {
        $content = json_decode($body, true);

        if (json_last_error() !== JSON_ERROR_NONE) {
            $msg = json_last_error_msg();

            throw new DecodingFailedException(
                'Failed to decode the json response body.'.($msg ? " {$msg}." : '')
            );
        }

        if (!is_array($content)) {
            throw new DecodingFailedException(
                'Failed to decode the json response body. Expected to decode to an array.'
            );
        }

        return $content;
    }

     /**
     * @param ResponseInterface $response
     *
     * @throws \Snaptier\API\Exception\ApiLimitExceedException
     *
     * @return null|string
     */
    public static function getApiLimit(ResponseInterface $response)
    {
        $remainingCalls = $response->getHeaderLine('X-RateLimit-Remaining');

        if (null !== $remainingCalls && 1 > $remainingCalls) {
            throw new ApiLimitExceedException($remainingCalls);
        }

        return $remainingCalls;
    }

}


<?php

namespace RodrigoPedra\ClearSaleID\Entity\Request;

use DateTime;
use RodrigoPedra\ClearSaleID\Entity\XmlEntityInterface;
use RodrigoPedra\ClearSaleID\Exception\RequiredFieldException;
use XMLWriter;

class Connection implements XmlEntityInterface
{
    /** @var  string */
    private $company;

    /** @var  string */
    private $flightNumber;

    /** @var  \DateTime */
    private $flightDate;

    /** @var  string */
    private $class;

    /** @var  string */
    private $from;

    /** @var  string */
    private $to;

    /** @var  \DateTime */
    private $departureDate;

    /** @var  \DateTime */
    private $arrivalDate;

    /**
     * @param  string    $company
     * @param  string    $flightNumber
     * @param  \DateTime $flightDate
     * @param  string    $class
     * @param  string    $from
     * @param  string    $to
     * @param  \DateTime $departureDate
     * @param  \DateTime $arrivalDate
     *
     * @return \RodrigoPedra\ClearSaleID\Entity\Request\Connection
     */
    public static function create(
        $company,
        $flightNumber,
        DateTime $flightDate,
        $class,
        $from,
        $to,
        DateTime $departureDate,
        DateTime $arrivalDate
    ) {
        $instance = new self;

        $instance->setCompany( $company );
        $instance->setFlightNumber( $flightNumber );
        $instance->setFlightDate( $flightDate );
        $instance->setClass( $class );
        $instance->setFrom( $from );
        $instance->setTo( $to );
        $instance->setDepartureDate( $departureDate );
        $instance->setArrivalDate( $arrivalDate );

        return $instance;
    }

    /**
     * @return string
     */
    public function getCompany()
    {
        return $this->company;
    }

    /**
     * @param  string $company
     *
     * @return $this
     */
    public function setCompany( $company )
    {
        $this->company = $company;

        return $this;
    }

    /**
     * @return string
     */
    public function getFlightNumber()
    {
        return $this->flightNumber;
    }

    /**
     * @param  string $flightNumber
     *
     * @return $this
     */
    public function setFlightNumber( $flightNumber )
    {
        $this->flightNumber = $flightNumber;

        return $this;
    }

    /**
     * @return \DateTime
     */
    public function getFlightDate()
    {
        return $this->flightDate;
    }

    /**
     * @param  \DateTime $flightDate
     *
     * @return $this
     */
    public function setFlightDate( DateTime $flightDate )
    {
        $this->flightDate = $flightDate;

        return $this;
    }

    /**
     * @return string
     */
    public function getClass()
    {
        return $this->class;
    }

    /**
     * @param  string $class
     *
     * @return $this
     */
    public function setClass( $class )
    {
        $this->class = $class;

        return $this;
    }

    /**
     * @return string
     */
    public function getFrom()
    {
        return $this->from;
    }

    /**
     * @param  string $from
     *
     * @return $this
     */
    public function setFrom( $from )
    {
        $this->from = $from;

        return $this;
    }

    /**
     * @return string
     */
    public function getTo()
    {
        return $this->to;
    }

    /**
     * @param  string $to
     *
     * @return $this
     */
    public function setTo( $to )
    {
        $this->to = $to;

        return $this;
    }

    /**
     * @return \DateTime
     */
    public function getDepartureDate()
    {
        return $this->departureDate;
    }

    /**
     * @param  \DateTime $departureDate
     *
     * @return $this
     */
    public function setDepartureDate( DateTime $departureDate )
    {
        $this->departureDate = $departureDate;

        return $this;
    }

    /**
     * @return \DateTime
     */
    public function getArrivalDate()
    {
        return $this->arrivalDate;
    }

    /**
     * @param  \DateTime $arrivalDate
     *
     * @return $this
     */
    public function setArrivalDate( DateTime $arrivalDate )
    {
        $this->arrivalDate = $arrivalDate;

        return $this;
    }

    /**
     * @param  \XMLWriter $XMLWriter
     *
     * @throws \RodrigoPedra\ClearSaleID\Exception\RequiredFieldException
     */
    public function toXML( XMLWriter $XMLWriter )
    {
        $XMLWriter->startElement( 'Conexao' );

        if ($this->company) {
            $XMLWriter->writeElement( 'Companhia', $this->company );
        } else {
            throw new RequiredFieldException( 'Field Company of the Connection object is required' );
        }

        if ($this->flightNumber) {
            $XMLWriter->writeElement( 'NumeroVoo', $this->flightNumber );
        } else {
            throw new RequiredFieldException( 'Field FlightNumber of the Connection object is required' );
        }

        if ($this->flightDate) {
            $XMLWriter->writeElement( 'DataVoo', $this->flightDate->format( self::DATE_TIME_FORMAT ) );
        } else {
            throw new RequiredFieldException( 'Field FlightDate of the Connection object is required' );
        }

        if ($this->class) {
            $XMLWriter->writeElement( 'Classe', $this->class );
        } else {
            throw new RequiredFieldException( 'Field Class of the Connection object is required' );
        }

        if ($this->from) {
            $XMLWriter->writeElement( 'Origem', $this->from );
        } else {
            throw new RequiredFieldException( 'Field FROM of the Connection object is required' );
        }

        if ($this->to) {
            $XMLWriter->writeElement( 'Destino', $this->to );
        } else {
            throw new RequiredFieldException( 'Field To of the Connection object is required' );
        }

        if ($this->departureDate) {
            $XMLWriter->writeElement( 'DataPartida', $this->departureDate->format( self::DATE_TIME_FORMAT ) );
        } else {
            throw new RequiredFieldException( 'Field DepartureDate of the Connection object is required' );
        }

        if ($this->arrivalDate) {
            $XMLWriter->writeElement( 'DataChegada', $this->arrivalDate->format( self::DATE_TIME_FORMAT ) );
        } else {
            throw new RequiredFieldException( 'Field ArrivalDate of the Connection object is required' );
        }

        $XMLWriter->endElement();
    }
}


<?php

namespace PhpOffice\PhpSpreadsheet\Worksheet;

class Row
{
    /**
     * \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet.
     *
     * @var Worksheet
     */
    private $worksheet;

    /**
     * Row index.
     *
     * @var int
     */
    private $rowIndex = 0;

    /**
     * Create a new row.
     *
     * @param Worksheet $worksheet
     * @param int $rowIndex
     */
    public function __construct(Worksheet $worksheet = null, $rowIndex = 1)
    {
        // Set parent and row index
        $this->worksheet = $worksheet;
        $this->rowIndex = $rowIndex;
    }

    /**
     * Destructor.
     */
    public function __destruct()
    {
        unset($this->worksheet);
    }

    /**
     * Get row index.
     *
     * @return int
     */
    public function getRowIndex()
    {
        return $this->rowIndex;
    }

    /**
     * Get cell iterator.
     *
     * @param string $startColumn The column address at which to start iterating
     * @param string $endColumn Optionally, the column address at which to stop iterating
     *
     * @return RowCellIterator
     */
    public function getCellIterator($startColumn = 'A', $endColumn = null)
    {
        return new RowCellIterator($this->worksheet, $this->rowIndex, $startColumn, $endColumn);
    }

    /**
     * Returns bound worksheet.
     *
     * @return Worksheet
     */
    public function getWorksheet()
    {
        return $this->worksheet;
    }
}


<?php

namespace PhpOffice\PhpSpreadsheet\Writer\Xlsx;

use PhpOffice\PhpSpreadsheet\Shared\XMLWriter;
use PhpOffice\PhpSpreadsheet\Spreadsheet;

/**
 * @category   PhpSpreadsheet
 *
 * @copyright  Copyright (c) 2006 - 2016 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet)
 */
class Theme extends WriterPart
{
    /**
     * Map of Major fonts to write.
     *
     * @var array of string
     */
    private static $majorFonts = [
        'Jpan' => 'ＭＳ Ｐゴシック',
        'Hang' => '맑은 고딕',
        'Hans' => '宋体',
        'Hant' => '新細明體',
        'Arab' => 'Times New Roman',
        'Hebr' => 'Times New Roman',
        'Thai' => 'Tahoma',
        'Ethi' => 'Nyala',
        'Beng' => 'Vrinda',
        'Gujr' => 'Shruti',
        'Khmr' => 'MoolBoran',
        'Knda' => 'Tunga',
        'Guru' => 'Raavi',
        'Cans' => 'Euphemia',
        'Cher' => 'Plantagenet Cherokee',
        'Yiii' => 'Microsoft Yi Baiti',
        'Tibt' => 'Microsoft Himalaya',
        'Thaa' => 'MV Boli',
        'Deva' => 'Mangal',
        'Telu' => 'Gautami',
        'Taml' => 'Latha',
        'Syrc' => 'Estrangelo Edessa',
        'Orya' => 'Kalinga',
        'Mlym' => 'Kartika',
        'Laoo' => 'DokChampa',
        'Sinh' => 'Iskoola Pota',
        'Mong' => 'Mongolian Baiti',
        'Viet' => 'Times New Roman',
        'Uigh' => 'Microsoft Uighur',
        'Geor' => 'Sylfaen',
    ];

    /**
     * Map of Minor fonts to write.
     *
     * @var array of string
     */
    private static $minorFonts = [
        'Jpan' => 'ＭＳ Ｐゴシック',
        'Hang' => '맑은 고딕',
        'Hans' => '宋体',
        'Hant' => '新細明體',
        'Arab' => 'Arial',
        'Hebr' => 'Arial',
        'Thai' => 'Tahoma',
        'Ethi' => 'Nyala',
        'Beng' => 'Vrinda',
        'Gujr' => 'Shruti',
        'Khmr' => 'DaunPenh',
        'Knda' => 'Tunga',
        'Guru' => 'Raavi',
        'Cans' => 'Euphemia',
        'Cher' => 'Plantagenet Cherokee',
        'Yiii' => 'Microsoft Yi Baiti',
        'Tibt' => 'Microsoft Himalaya',
        'Thaa' => 'MV Boli',
        'Deva' => 'Mangal',
        'Telu' => 'Gautami',
        'Taml' => 'Latha',
        'Syrc' => 'Estrangelo Edessa',
        'Orya' => 'Kalinga',
        'Mlym' => 'Kartika',
        'Laoo' => 'DokChampa',
        'Sinh' => 'Iskoola Pota',
        'Mong' => 'Mongolian Baiti',
        'Viet' => 'Arial',
        'Uigh' => 'Microsoft Uighur',
        'Geor' => 'Sylfaen',
    ];

    /**
     * Map of core colours.
     *
     * @var array of string
     */
    private static $colourScheme = [
        'dk2' => '1F497D',
        'lt2' => 'EEECE1',
        'accent1' => '4F81BD',
        'accent2' => 'C0504D',
        'accent3' => '9BBB59',
        'accent4' => '8064A2',
        'accent5' => '4BACC6',
        'accent6' => 'F79646',
        'hlink' => '0000FF',
        'folHlink' => '800080',
    ];

    /**
     * Write theme to XML format.
     *
     * @param Spreadsheet $spreadsheet
     *
     * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
     *
     * @return string XML Output
     */
    public function writeTheme(Spreadsheet $spreadsheet)
    {
        // Create XML writer
        $objWriter = null;
        if ($this->getParentWriter()->getUseDiskCaching()) {
            $objWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
        } else {
            $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
        }

        // XML header
        $objWriter->startDocument('1.0', 'UTF-8', 'yes');

        // a:theme
        $objWriter->startElement('a:theme');
        $objWriter->writeAttribute('xmlns:a', 'http://schemas.openxmlformats.org/drawingml/2006/main');
        $objWriter->writeAttribute('name', 'Office Theme');

        // a:themeElements
        $objWriter->startElement('a:themeElements');

        // a:clrScheme
        $objWriter->startElement('a:clrScheme');
        $objWriter->writeAttribute('name', 'Office');

        // a:dk1
        $objWriter->startElement('a:dk1');

        // a:sysClr
        $objWriter->startElement('a:sysClr');
        $objWriter->writeAttribute('val', 'windowText');
        $objWriter->writeAttribute('lastClr', '000000');
        $objWriter->endElement();

        $objWriter->endElement();

        // a:lt1
        $objWriter->startElement('a:lt1');

        // a:sysClr
        $objWriter->startElement('a:sysClr');
        $objWriter->writeAttribute('val', 'window');
        $objWriter->writeAttribute('lastClr', 'FFFFFF');
        $objWriter->endElement();

        $objWriter->endElement();

        // a:dk2
        $this->writeColourScheme($objWriter);

        $objWriter->endElement();

        // a:fontScheme
        $objWriter->startElement('a:fontScheme');
        $objWriter->writeAttribute('name', 'Office');

        // a:majorFont
        $objWriter->startElement('a:majorFont');
        $this->writeFonts($objWriter, 'Cambria', self::$majorFonts);
        $objWriter->endElement();

        // a:minorFont
        $objWriter->startElement('a:minorFont');
        $this->writeFonts($objWriter, 'Calibri', self::$minorFonts);
        $objWriter->endElement();

        $objWriter->endElement();

        // a:fmtScheme
        $objWriter->startElement('a:fmtScheme');
        $objWriter->writeAttribute('name', 'Office');

        // a:fillStyleLst
        $objWriter->startElement('a:fillStyleLst');

        // a:solidFill
        $objWriter->startElement('a:solidFill');

        // a:schemeClr
        $objWriter->startElement('a:schemeClr');
        $objWriter->writeAttribute('val', 'phClr');
        $objWriter->endElement();

        $objWriter->endElement();

        // a:gradFill
        $objWriter->startElement('a:gradFill');
        $objWriter->writeAttribute('rotWithShape', '1');

        // a:gsLst
        $objWriter->startElement('a:gsLst');

        // a:gs
        $objWriter->startElement('a:gs');
        $objWriter->writeAttribute('pos', '0');

        // a:schemeClr
        $objWriter->startElement('a:schemeClr');
        $objWriter->writeAttribute('val', 'phClr');

        // a:tint
        $objWriter->startElement('a:tint');
        $objWriter->writeAttribute('val', '50000');
        $objWriter->endElement();

        // a:satMod
        $objWriter->startElement('a:satMod');
        $objWriter->writeAttribute('val', '300000');
        $objWriter->endElement();

        $objWriter->endElement();

        $objWriter->endElement();

        // a:gs
        $objWriter->startElement('a:gs');
        $objWriter->writeAttribute('pos', '35000');

        // a:schemeClr
        $objWriter->startElement('a:schemeClr');
        $objWriter->writeAttribute('val', 'phClr');

        // a:tint
        $objWriter->startElement('a:tint');
        $objWriter->writeAttribute('val', '37000');
        $objWriter->endElement();

        // a:satMod
        $objWriter->startElement('a:satMod');
        $objWriter->writeAttribute('val', '300000');
        $objWriter->endElement();

        $objWriter->endElement();

        $objWriter->endElement();

        // a:gs
        $objWriter->startElement('a:gs');
        $objWriter->writeAttribute('pos', '100000');

        // a:schemeClr
        $objWriter->startElement('a:schemeClr');
        $objWriter->writeAttribute('val', 'phClr');

        // a:tint
        $objWriter->startElement('a:tint');
        $objWriter->writeAttribute('val', '15000');
        $objWriter->endElement();

        // a:satMod
        $objWriter->startElement('a:satMod');
        $objWriter->writeAttribute('val', '350000');
        $objWriter->endElement();

        $objWriter->endElement();

        $objWriter->endElement();

        $objWriter->endElement();

        // a:lin
        $objWriter->startElement('a:lin');
        $objWriter->writeAttribute('ang', '16200000');
        $objWriter->writeAttribute('scaled', '1');
        $objWriter->endElement();

        $objWriter->endElement();

        // a:gradFill
        $objWriter->startElement('a:gradFill');
        $objWriter->writeAttribute('rotWithShape', '1');

        // a:gsLst
        $objWriter->startElement('a:gsLst');

        // a:gs
        $objWriter->startElement('a:gs');
        $objWriter->writeAttribute('pos', '0');

        // a:schemeClr
        $objWriter->startElement('a:schemeClr');
        $objWriter->writeAttribute('val', 'phClr');

        // a:shade
        $objWriter->startElement('a:shade');
        $objWriter->writeAttribute('val', '51000');
        $objWriter->endElement();

        // a:satMod
        $objWriter->startElement('a:satMod');
        $objWriter->writeAttribute('val', '130000');
        $objWriter->endElement();

        $objWriter->endElement();

        $objWriter->endElement();

        // a:gs
        $objWriter->startElement('a:gs');
        $objWriter->writeAttribute('pos', '80000');

        // a:schemeClr
        $objWriter->startElement('a:schemeClr');
        $objWriter->writeAttribute('val', 'phClr');

        // a:shade
        $objWriter->startElement('a:shade');
        $objWriter->writeAttribute('val', '93000');
        $objWriter->endElement();

        // a:satMod
        $objWriter->startElement('a:satMod');
        $objWriter->writeAttribute('val', '130000');
        $objWriter->endElement();

        $objWriter->endElement();

        $objWriter->endElement();

        // a:gs
        $objWriter->startElement('a:gs');
        $objWriter->writeAttribute('pos', '100000');

        // a:schemeClr
        $objWriter->startElement('a:schemeClr');
        $objWriter->writeAttribute('val', 'phClr');

        // a:shade
        $objWriter->startElement('a:shade');
        $objWriter->writeAttribute('val', '94000');
        $objWriter->endElement();

        // a:satMod
        $objWriter->startElement('a:satMod');
        $objWriter->writeAttribute('val', '135000');
        $objWriter->endElement();

        $objWriter->endElement();

        $objWriter->endElement();

        $objWriter->endElement();

        // a:lin
        $objWriter->startElement('a:lin');
        $objWriter->writeAttribute('ang', '16200000');
        $objWriter->writeAttribute('scaled', '0');
        $objWriter->endElement();

        $objWriter->endElement();

        $objWriter->endElement();

        // a:lnStyleLst
        $objWriter->startElement('a:lnStyleLst');

        // a:ln
        $objWriter->startElement('a:ln');
        $objWriter->writeAttribute('w', '9525');
        $objWriter->writeAttribute('cap', 'flat');
        $objWriter->writeAttribute('cmpd', 'sng');
        $objWriter->writeAttribute('algn', 'ctr');

        // a:solidFill
        $objWriter->startElement('a:solidFill');

        // a:schemeClr
        $objWriter->startElement('a:schemeClr');
        $objWriter->writeAttribute('val', 'phClr');

        // a:shade
        $objWriter->startElement('a:shade');
        $objWriter->writeAttribute('val', '95000');
        $objWriter->endElement();

        // a:satMod
        $objWriter->startElement('a:satMod');
        $objWriter->writeAttribute('val', '105000');
        $objWriter->endElement();

        $objWriter->endElement();

        $objWriter->endElement();

        // a:prstDash
        $objWriter->startElement('a:prstDash');
        $objWriter->writeAttribute('val', 'solid');
        $objWriter->endElement();

        $objWriter->endElement();

        // a:ln
        $objWriter->startElement('a:ln');
        $objWriter->writeAttribute('w', '25400');
        $objWriter->writeAttribute('cap', 'flat');
        $objWriter->writeAttribute('cmpd', 'sng');
        $objWriter->writeAttribute('algn', 'ctr');

        // a:solidFill
        $objWriter->startElement('a:solidFill');

        // a:schemeClr
        $objWriter->startElement('a:schemeClr');
        $objWriter->writeAttribute('val', 'phClr');
        $objWriter->endElement();

        $objWriter->endElement();

        // a:prstDash
        $objWriter->startElement('a:prstDash');
        $objWriter->writeAttribute('val', 'solid');
        $objWriter->endElement();

        $objWriter->endElement();

        // a:ln
        $objWriter->startElement('a:ln');
        $objWriter->writeAttribute('w', '38100');
        $objWriter->writeAttribute('cap', 'flat');
        $objWriter->writeAttribute('cmpd', 'sng');
        $objWriter->writeAttribute('algn', 'ctr');

        // a:solidFill
        $objWriter->startElement('a:solidFill');

        // a:schemeClr
        $objWriter->startElement('a:schemeClr');
        $objWriter->writeAttribute('val', 'phClr');
        $objWriter->endElement();

        $objWriter->endElement();

        // a:prstDash
        $objWriter->startElement('a:prstDash');
        $objWriter->writeAttribute('val', 'solid');
        $objWriter->endElement();

        $objWriter->endElement();

        $objWriter->endElement();

        // a:effectStyleLst
        $objWriter->startElement('a:effectStyleLst');

        // a:effectStyle
        $objWriter->startElement('a:effectStyle');

        // a:effectLst
        $objWriter->startElement('a:effectLst');

        // a:outerShdw
        $objWriter->startElement('a:outerShdw');
        $objWriter->writeAttribute('blurRad', '40000');
        $objWriter->writeAttribute('dist', '20000');
        $objWriter->writeAttribute('dir', '5400000');
        $objWriter->writeAttribute('rotWithShape', '0');

        // a:srgbClr
        $objWriter->startElement('a:srgbClr');
        $objWriter->writeAttribute('val', '000000');

        // a:alpha
        $objWriter->startElement('a:alpha');
        $objWriter->writeAttribute('val', '38000');
        $objWriter->endElement();

        $objWriter->endElement();

        $objWriter->endElement();

        $objWriter->endElement();

        $objWriter->endElement();

        // a:effectStyle
        $objWriter->startElement('a:effectStyle');

        // a:effectLst
        $objWriter->startElement('a:effectLst');

        // a:outerShdw
        $objWriter->startElement('a:outerShdw');
        $objWriter->writeAttribute('blurRad', '40000');
        $objWriter->writeAttribute('dist', '23000');
        $objWriter->writeAttribute('dir', '5400000');
        $objWriter->writeAttribute('rotWithShape', '0');

        // a:srgbClr
        $objWriter->startElement('a:srgbClr');
        $objWriter->writeAttribute('val', '000000');

        // a:alpha
        $objWriter->startElement('a:alpha');
        $objWriter->writeAttribute('val', '35000');
        $objWriter->endElement();

        $objWriter->endElement();

        $objWriter->endElement();

        $objWriter->endElement();

        $objWriter->endElement();

        // a:effectStyle
        $objWriter->startElement('a:effectStyle');

        // a:effectLst
        $objWriter->startElement('a:effectLst');

        // a:outerShdw
        $objWriter->startElement('a:outerShdw');
        $objWriter->writeAttribute('blurRad', '40000');
        $objWriter->writeAttribute('dist', '23000');
        $objWriter->writeAttribute('dir', '5400000');
        $objWriter->writeAttribute('rotWithShape', '0');

        // a:srgbClr
        $objWriter->startElement('a:srgbClr');
        $objWriter->writeAttribute('val', '000000');

        // a:alpha
        $objWriter->startElement('a:alpha');
        $objWriter->writeAttribute('val', '35000');
        $objWriter->endElement();

        $objWriter->endElement();

        $objWriter->endElement();

        $objWriter->endElement();

        // a:scene3d
        $objWriter->startElement('a:scene3d');

        // a:camera
        $objWriter->startElement('a:camera');
        $objWriter->writeAttribute('prst', 'orthographicFront');

        // a:rot
        $objWriter->startElement('a:rot');
        $objWriter->writeAttribute('lat', '0');
        $objWriter->writeAttribute('lon', '0');
        $objWriter->writeAttribute('rev', '0');
        $objWriter->endElement();

        $objWriter->endElement();

        // a:lightRig
        $objWriter->startElement('a:lightRig');
        $objWriter->writeAttribute('rig', 'threePt');
        $objWriter->writeAttribute('dir', 't');

        // a:rot
        $objWriter->startElement('a:rot');
        $objWriter->writeAttribute('lat', '0');
        $objWriter->writeAttribute('lon', '0');
        $objWriter->writeAttribute('rev', '1200000');
        $objWriter->endElement();

        $objWriter->endElement();

        $objWriter->endElement();

        // a:sp3d
        $objWriter->startElement('a:sp3d');

        // a:bevelT
        $objWriter->startElement('a:bevelT');
        $objWriter->writeAttribute('w', '63500');
        $objWriter->writeAttribute('h', '25400');
        $objWriter->endElement();

        $objWriter->endElement();

        $objWriter->endElement();

        $objWriter->endElement();

        // a:bgFillStyleLst
        $objWriter->startElement('a:bgFillStyleLst');

        // a:solidFill
        $objWriter->startElement('a:solidFill');

        // a:schemeClr
        $objWriter->startElement('a:schemeClr');
        $objWriter->writeAttribute('val', 'phClr');
        $objWriter->endElement();

        $objWriter->endElement();

        // a:gradFill
        $objWriter->startElement('a:gradFill');
        $objWriter->writeAttribute('rotWithShape', '1');

        // a:gsLst
        $objWriter->startElement('a:gsLst');

        // a:gs
        $objWriter->startElement('a:gs');
        $objWriter->writeAttribute('pos', '0');

        // a:schemeClr
        $objWriter->startElement('a:schemeClr');
        $objWriter->writeAttribute('val', 'phClr');

        // a:tint
        $objWriter->startElement('a:tint');
        $objWriter->writeAttribute('val', '40000');
        $objWriter->endElement();

        // a:satMod
        $objWriter->startElement('a:satMod');
        $objWriter->writeAttribute('val', '350000');
        $objWriter->endElement();

        $objWriter->endElement();

        $objWriter->endElement();

        // a:gs
        $objWriter->startElement('a:gs');
        $objWriter->writeAttribute('pos', '40000');

        // a:schemeClr
        $objWriter->startElement('a:schemeClr');
        $objWriter->writeAttribute('val', 'phClr');

        // a:tint
        $objWriter->startElement('a:tint');
        $objWriter->writeAttribute('val', '45000');
        $objWriter->endElement();

        // a:shade
        $objWriter->startElement('a:shade');
        $objWriter->writeAttribute('val', '99000');
        $objWriter->endElement();

        // a:satMod
        $objWriter->startElement('a:satMod');
        $objWriter->writeAttribute('val', '350000');
        $objWriter->endElement();

        $objWriter->endElement();

        $objWriter->endElement();

        // a:gs
        $objWriter->startElement('a:gs');
        $objWriter->writeAttribute('pos', '100000');

        // a:schemeClr
        $objWriter->startElement('a:schemeClr');
        $objWriter->writeAttribute('val', 'phClr');

        // a:shade
        $objWriter->startElement('a:shade');
        $objWriter->writeAttribute('val', '20000');
        $objWriter->endElement();

        // a:satMod
        $objWriter->startElement('a:satMod');
        $objWriter->writeAttribute('val', '255000');
        $objWriter->endElement();

        $objWriter->endElement();

        $objWriter->endElement();

        $objWriter->endElement();

        // a:path
        $objWriter->startElement('a:path');
        $objWriter->writeAttribute('path', 'circle');

        // a:fillToRect
        $objWriter->startElement('a:fillToRect');
        $objWriter->writeAttribute('l', '50000');
        $objWriter->writeAttribute('t', '-80000');
        $objWriter->writeAttribute('r', '50000');
        $objWriter->writeAttribute('b', '180000');
        $objWriter->endElement();

        $objWriter->endElement();

        $objWriter->endElement();

        // a:gradFill
        $objWriter->startElement('a:gradFill');
        $objWriter->writeAttribute('rotWithShape', '1');

        // a:gsLst
        $objWriter->startElement('a:gsLst');

        // a:gs
        $objWriter->startElement('a:gs');
        $objWriter->writeAttribute('pos', '0');

        // a:schemeClr
        $objWriter->startElement('a:schemeClr');
        $objWriter->writeAttribute('val', 'phClr');

        // a:tint
        $objWriter->startElement('a:tint');
        $objWriter->writeAttribute('val', '80000');
        $objWriter->endElement();

        // a:satMod
        $objWriter->startElement('a:satMod');
        $objWriter->writeAttribute('val', '300000');
        $objWriter->endElement();

        $objWriter->endElement();

        $objWriter->endElement();

        // a:gs
        $objWriter->startElement('a:gs');
        $objWriter->writeAttribute('pos', '100000');

        // a:schemeClr
        $objWriter->startElement('a:schemeClr');
        $objWriter->writeAttribute('val', 'phClr');

        // a:shade
        $objWriter->startElement('a:shade');
        $objWriter->writeAttribute('val', '30000');
        $objWriter->endElement();

        // a:satMod
        $objWriter->startElement('a:satMod');
        $objWriter->writeAttribute('val', '200000');
        $objWriter->endElement();

        $objWriter->endElement();

        $objWriter->endElement();

        $objWriter->endElement();

        // a:path
        $objWriter->startElement('a:path');
        $objWriter->writeAttribute('path', 'circle');

        // a:fillToRect
        $objWriter->startElement('a:fillToRect');
        $objWriter->writeAttribute('l', '50000');
        $objWriter->writeAttribute('t', '50000');
        $objWriter->writeAttribute('r', '50000');
        $objWriter->writeAttribute('b', '50000');
        $objWriter->endElement();

        $objWriter->endElement();

        $objWriter->endElement();

        $objWriter->endElement();

        $objWriter->endElement();

        $objWriter->endElement();

        // a:objectDefaults
        $objWriter->writeElement('a:objectDefaults', null);

        // a:extraClrSchemeLst
        $objWriter->writeElement('a:extraClrSchemeLst', null);

        $objWriter->endElement();

        // Return
        return $objWriter->getData();
    }

    /**
     * Write fonts to XML format.
     *
     * @param XMLWriter $objWriter
     * @param string $latinFont
     * @param array of string                $fontSet
     *
     * @return string XML Output
     */
    private function writeFonts($objWriter, $latinFont, $fontSet)
    {
        // a:latin
        $objWriter->startElement('a:latin');
        $objWriter->writeAttribute('typeface', $latinFont);
        $objWriter->endElement();

        // a:ea
        $objWriter->startElement('a:ea');
        $objWriter->writeAttribute('typeface', '');
        $objWriter->endElement();

        // a:cs
        $objWriter->startElement('a:cs');
        $objWriter->writeAttribute('typeface', '');
        $objWriter->endElement();

        foreach ($fontSet as $fontScript => $typeface) {
            $objWriter->startElement('a:font');
            $objWriter->writeAttribute('script', $fontScript);
            $objWriter->writeAttribute('typeface', $typeface);
            $objWriter->endElement();
        }
    }

    /**
     * Write colour scheme to XML format.
     *
     * @param XMLWriter $objWriter
     *
     * @return string XML Output
     */
    private function writeColourScheme($objWriter)
    {
        foreach (self::$colourScheme as $colourName => $colourValue) {
            $objWriter->startElement('a:' . $colourName);

            $objWriter->startElement('a:srgbClr');
            $objWriter->writeAttribute('val', $colourValue);
            $objWriter->endElement();

            $objWriter->endElement();
        }
    }
}


<?php

namespace XQueue\Maileon\API\Contacts;

/**
 * The wrapper class for a Maileon synchronization mode. 1 = UPDATE, 2 = IGNORE.
 *
 * @author Marcus Ständer | Trusted Mails GmbH | marcus.staender@trusted-mails.com
 */
class SynchronizationMode
{

    public static $UPDATE;
    public static $IGNORE;
    private static $initialized = false;

    public $code;

    /**
     * This is the initialization method for the synchronization modes. This must be called once in the beginning.
     */
    static function init()
    {
        if (self::$initialized == false) {
            self::$UPDATE = new SynchronizationMode(1);
            self::$IGNORE = new SynchronizationMode(2);
            self::$initialized = true;
        }
    }

    /**
     * Constructor initializing the code of the synchronization mode.
     *
     * @param number $code
     *  The code to use for the constructed synchronization mode.
     */
    function __construct($code = 0)
    {
        $this->code = $code;
    }

    /**
     * Get the code of this synchronization mode. 1 = UPDATE, 2 = IGNORE.
     *
     * @return \em number
     *  the code of the synchronization mode object
     */
    function getCode()
    {
        return $this->code;
    }

    /**
     * Get the synchronization mode from the code
     *
     * @param int $code
     *  the code to get the synchronization mode for
     * @return \em com_maileon_api_contacts_SynchronizationMode
     *  the synchronization mode for the given code
     */
    static function getSynchronizationMode($code)
    {
        switch ($code) {
            case 1:
                return self::$UPDATE;
            case 2:
                return self::$IGNORE;

            default:
                return self::$IGNORE;
        }
    }
}