| Total Complexity | 5 |
| Total Lines | 38 |
| Duplicated Lines | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 11 | class SymlinkMethod implements ExposeMethod |
||
| 12 | { |
||
| 13 | const NAME = 'symlink'; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @var Filesystem |
||
| 17 | */ |
||
| 18 | protected $filesystem = null; |
||
| 19 | |||
| 20 | public function __construct(Filesystem $filesystem = null) |
||
| 21 | { |
||
| 22 | $this->filesystem = $filesystem ?: new Filesystem(); |
||
| 23 | } |
||
| 24 | |||
| 25 | public function exposeDirectory($source, $target) |
||
| 26 | { |
||
| 27 | // Remove destination directory to ensure it is clean |
||
| 28 | $this->filesystem->removeDirectory($target); |
||
| 29 | |||
| 30 | // Ensure parent dir exist |
||
| 31 | $parent = dirname($target); |
||
| 32 | $this->filesystem->ensureDirectoryExists($parent); |
||
| 33 | |||
| 34 | // Ensure symlink exists |
||
| 35 | $this->createLink($source, $target); |
||
| 36 | } |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Create symlink |
||
| 40 | * |
||
| 41 | * @param string $source File source |
||
| 42 | * @param string $target Place to put symlink |
||
| 43 | */ |
||
| 44 | protected function createLink($source, $target) |
||
| 49 | } |
||
| 50 | } |
||
| 51 | } |
||
| 52 |