<?php
abstract class Library_Virtual_Abstract {
	/**
	 * jmeno objektu
	 * @var string
	 */
	protected $_name = null;
	
	/**
	 * ukazatel na predka objektu
	 * @var Library_Virtual_Abstract
	 */
	protected $_parent = null;
	
	/**
	 * cesta k objektu
	 * @var string
	 */
	protected $_path = null;
	
	public function __construct($name, Library_Virtual_Abstract $parent = null) {
		$this->_name = $name;
		$this->_parent = $parent;
	}
	
	/**
	 * vraci cestu k objektu
	 * 
	 * @return string
	 */
	public function getPath() {
		if (!is_null($this->_path)) {
			//cesta uz byla vygenerovana
			return $this->_path;
		}
		
		//poskaldani cesty
		if (is_null($this->_parent)) {
			//jedna se o korenovy dokument
			$this->_path = $this->_name;
			return $this->_path;
		}
		
		$this->_path = $this->_parent->getPath() . "/" . $this->_name;
		
		//vraceni cesty
		return $this->_path;
	}
	
	/**
	 * vraci predka objektu v hiearchii
	 * @return Library_Virtual_Abstract
	 */
	public function getParent() {
		return $this->_parent;
	}
	
	/**
	 * vraci jmeno objektu
	 * @return string
	 */
	public function getName() {
		return $this->_name;
	}
	
	/**
	 * nastavi nove jmeno objektu
	 * @param string $name
	 * @return Library_Virtual_Abstract
	 */
	public function setName($name) {
		$this->_name = $name;
		$this->_path = null;
		
		return $this;
	}
}