AbstractNamespace.php 1.17 KB
Newer Older
1
<?php declare(strict_types=1);
2
/*
Guillaume Perréal's avatar
CS.    
Guillaume Perréal committed
3
4
 * Copyright (C) 2016-2017 IRSTEA
 * All rights reserved.
5
6
 */

7
namespace Irstea\PlantUmlBundle\Model\Namespace_;
8

9
10
use Irstea\PlantUmlBundle\Model\NamespaceInterface;
use Irstea\PlantUmlBundle\Model\NodeInterface;
11
use Irstea\PlantUmlBundle\Writer\WritableInterface;
12
13
14
use Irstea\PlantUmlBundle\Writer\WriterInterface;

/**
Guillaume Perréal's avatar
CS.    
Guillaume Perréal committed
15
 * Description of Namespace.
16
 */
17
abstract class AbstractNamespace implements WritableInterface, NamespaceInterface
18
19
{
    /**
20
     * @var NodeInterface[]
21
22
23
24
     */
    private $nodes = [];

    /**
25
     * @param NodeInterface $node
26
     */
27
    public function addNode(NodeInterface $node)
28
29
    {
        $this->nodes[] = $node;
Guillaume Perréal's avatar
CS.    
Guillaume Perréal committed
30

31
32
33
34
35
        return $this;
    }

    /**
     * @param WriterInterface $writer
Guillaume Perréal's avatar
CS.    
Guillaume Perréal committed
36
     *
37
38
     * @return self
     */
39
    protected function writeNodesTo(WriterInterface $writer)
40
41
    {
        foreach ($this->nodes as $node) {
42
            $node->writeTo($writer);
43
        }
Guillaume Perréal's avatar
CS.    
Guillaume Perréal committed
44

45
46
47
48
49
50
51
52
        return $this;
    }

    /**
     * @return bool
     */
    protected function isEmpty()
    {
53
        return empty($this->nodes);
54
    }
55
56
57
58
59

    public function toConfig(array &$conf)
    {
        $conf['namespace'] = static::CONF_TYPE;
    }
60
}