*/ class CreateDirectory { /** * Thing we're creating * * @author Phil Burton */ protected $thing = "directory"; /** * Directory to create * * @var string */ protected $directory; /** * Check if the directory already exists * * @param string $filename * @author Phil Burton */ public function __construct(string $directory) { $this->directory = $directory; if (!is_writable(dirname($directory))) { throw new \Exception('Cannot create ' . $this->thing . ' at: ' . $directory); } if (file_exists($directory)) { throw new \Exception('Directory already exists at: ' . $directory); } } /** * Create the new directory * * @author Phil Burton */ public function execute() { mkdir($this->directory); } }