/** * Create a symlink pointing to this file * * @param File|string $file File object or path * * @return File * @throws \LogicException */ public function symlink($file) { if (!$file instanceof self) { $file = new self($file); } if (!$this->exists()) { throw new \LogicException(sprintf("File '%s' does not exist.", $this->path)); } $link = new self($file); if ($link->isLink()) { unlink($file); } symlink($this->getAbsolutePath(), $link->getAbsolutePath()); return $this; }
/** * Create a symlink pointing to this directory * * @param Dir|string $dir Dir object or path * @param boolean $createPaths Create paths (if does not exist) * * @return $this * @throws \InvalidArgumentException */ public function symlink($dir, $createPaths = true) { if (!$this->exists()) { throw new \InvalidArgumentException(sprintf("Cannot create a link. Directory must exist: '%s'", $this->path)); } if (!$dir instanceof self) { $dir = new self($dir); } if ($dir->isLink()) { unlink($dir->getPath()); } $parent = $dir->getParent(); if ($createPaths) { if (!$this->exists()) { $this->create(); } if (!$parent->exists()) { $parent->create(); } } symlink($this->getAbsolutePath(), $parent->getAbsolutePath() . '/' . $dir->getName()); return $this; }