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