<?php
namespace Bitrix\Main\IO;

abstract class DirectoryEntry
	extends FileSystemEntry
{
	public function __construct($path)
	{
		parent::__construct($path);
	}

	public function Create()
	{
		if ($this->IsExists())
			return;

		$arMissingDirs = array($this->GetName());
		$dir = $this->GetDirectory();
		while (!$dir->IsExists())
		{
			$arMissingDirs[] = $dir->GetName();
			$dir = $dir->GetDirectory();
		}

		$arMissingDirs = array_reverse($arMissingDirs);
		foreach ($arMissingDirs as $dirName)
			$dir = $dir->CreateSubdirectory($dirName);
	}

	/**
	 * @return FileSystemEntry[]
	 */
	abstract public function GetChildren();

	/**
	 * @param string $path
	 * @return DirectoryEntry
	 */
	abstract public function CreateSubdirectory($name);

	public function IsDirectory()
	{
		return true;
	}

	public function IsFile()
	{
		return false;
	}

	public function IsLink()
	{
		return false;
	}
}
