Created
March 29, 2015 19:35
-
-
Save kocsismate/2887c86b15413e6f7270 to your computer and use it in GitHub Desktop.
Symlink
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Symlink | |
{ | |
protected $filesystem; | |
/** | |
* Initializes the symlinkking utility. | |
* | |
* @param Filesystem $filesystem | |
*/ | |
public function __construct(Filesystem $filesystem = null) | |
{ | |
$this->filesystem = $filesystem ?: new Filesystem(); | |
} | |
/** | |
* Creates a symlink for a binary file at a given path. | |
* | |
* @param string $binPath The path of the binary file to be symlinked | |
* @param string $link The path where the symlink should be created | |
* @throws \ErrorException | |
*/ | |
public function symlinkBin($binPath, $link) | |
{ | |
$cwd = getcwd(); | |
$relativeBin = $this->filesystem->findShortestPath($link, $binPath); | |
chdir(dirname($link)); | |
$result = symlink($relativeBin, $link); | |
chdir($cwd); | |
if ($result === false) { | |
throw new \ErrorException(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment