Skip to content
AbstractComposite.php 1.11 KiB
Newer Older
<?php

include_once 'CompositeInterface.php';

/**
 * Class AbstractComposite
 *
 * Date: 25.03.13
 * Time: 10:05
 * @author Thomas Joußen <tjoussen@databay.de>
Michael Jansen's avatar
Michael Jansen committed
 */
abstract class AbstractComposite implements CompositeInterface
{
Michael Jansen's avatar
Michael Jansen committed
    /**
     * @var AbstractComposite[]
     */
    public $nodes = array();
Michael Jansen's avatar
Michael Jansen committed
    /**
     * Adds an CompositeInterface object to the node array which represents the condition tree structure
     *
     * @param CompositeInterface $node
     */
    public function addNode(CompositeInterface $node)
    {
        $this->nodes[] = $node;
    }
Michael Jansen's avatar
Michael Jansen committed
    /**
     * Describes a Composite tree Structure as human readable string
     * @return string
     */
    public function describe()
    {
        $description = "";
        if (is_array($this->nodes)) {
            if (\count($this->nodes) > 0) {
                $description .= "(" . $this->nodes[0]->describe();
            }
            $description .= $this->getDescription();
            if (\count($this->nodes) > 0) {
                $description .= $this->nodes[1]->describe() . ") ";
            }
        }
        return $description;
    }