mrcnpdlk/grandstream-xmlapp

View on GitHub
src/AddressBook/AddressBook.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php
/**
 * Grandstream-XMLApp
 *
 * Copyright (c) 2017 pudelek.org.pl
 *
 * @license MIT License (MIT)
 *
 * For the full copyright and license information, please view source file
 * that is bundled with this package in the file LICENSE
 *
 * @author  Marcin Pudełek <marcin@pudelek.org.pl>
 */

namespace mrcnpdlk\Grandstream\XMLApp\AddressBook;

use mrcnpdlk\Grandstream\XMLApp\AddressBook\Model\Contact;
use mrcnpdlk\Grandstream\XMLApp\MyXML;

/**
 * Class AddressBook
 *
 * @package mrcnpdlk\Grandstream\XMLApp\AddressBook
 */
class AddressBook implements ModelInterface
{

    /**
     * @var Contact[]
     */
    private $tContacts = [];


    /**
     * @param Contact $oContact
     *
     * @return AddressBook
     */
    public function addContact(Contact $oContact)
    {
        $this->tContacts[] = $oContact;

        return $this;
    }

    /**
     * @return MyXML
     */
    public function getXml(): MyXML
    {
        $oXml = new MyXML('AddressBook');
        foreach ($this->tContacts as $oContact) {
            $oXml->insertChild($oContact->getXml()->asObject());
        }

        return $oXml;
    }
}