/** * Creates a new directory. Throws exceptions if target is not * writable, dir already exists etc... * * @param mixed sfFilebasePluginFile | string $path * @throws sfFilebasePluginException * @return sfFilebasePluginFile $file */ public function mkDir($path, $perms = null) { // Wrap around, because isDir() returs false on non-existing files. $path = new sfFilebasePluginDirectory($this->getFilebaseFile($path), $this); $dest = new sfFilebasePluginDirectory($path->getPath(), $this); if (!$dest->fileExists()) { throw new sfFilebasePluginException(sprintf('Destination directory %s does not exist.', $dest->getPathname())); } if (!$dest->isDir()) { throw new sfFilebasePluginException(sprintf('Destination %s is not a directory.', $dest->getPathname())); } if (!$dest->isWritable()) { throw new sfFilebasePluginException(sprintf('Destination directory %s is write protected.', $dest->getPathname())); } if (!$this->isInFilebase($dest)) { throw new sfFilebasePluginException(sprintf('Destination directory %s does not belong to filebase %s, access forbidden due to security issues.', $dest->getPathname(), $this->getPathname())); } if ($path->fileExists()) { throw new sfFilebasePluginException(sprintf('Directory %s already exists', $path->getPathname())); } if (!@mkdir($path->getPathname())) { throw new sfFilebasePluginException(sprintf('Error creating directory %s', $path->getPathname()), 2010); } if ($perms !== null) { // Chmodde dir $path->chmod($perms); } return $path; }