Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

Commit

Permalink
feat(ModuleInstaller): support symlinks and ignore files by patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
tntrex committed Mar 17, 2019
1 parent dbe32c6 commit 12936e7
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/ModuleInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ trait ModuleInstaller
{
protected $DEV_LINKS = [];
protected $INSTALL_PATHS = [];
protected $IGNORE_PATTERNS = [];
protected $INSTALLER_DIR = __DIR__;

/**
Expand Down Expand Up @@ -66,8 +67,13 @@ public function installFiles(): void
throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir));
}
}
if (!copy($from, $to)) {
throw new FileOpenException($to);

if (is_link($from)) {
symlink(readlink($from), $to);
} else {
if (!copy($from, $to)) {
throw new FileOpenException($to);
}
}
}
}
Expand Down Expand Up @@ -136,10 +142,23 @@ private function getRecursiveFiles($path): array
);

$result = [];
/**
* @var string $filePath
* @var \SplFileInfo $item
*/
foreach ($iter as $filePath => $item) {
if ($item->isFile()) {
$result[$filePath] = str_replace($dirFromDocRoot, '', $filePath);
if (!$item->isFile() && !$item->isLink()) {
continue;
}

// Skip ignored files
foreach ($this->IGNORE_PATTERNS as $pattern) {
if (preg_match($pattern, $filePath) > 0) {
continue 2;
}
}

$result[$filePath] = str_replace($dirFromDocRoot, '', $filePath);
}

uasort($result, function ($a, $b) {
Expand Down

0 comments on commit 12936e7

Please sign in to comment.