From 12936e7c7aec05b3aa471a1732eda985112ec5ae Mon Sep 17 00:00:00 2001 From: Constantine Karnaukhov Date: Sun, 17 Mar 2019 22:14:51 +0400 Subject: [PATCH] feat(ModuleInstaller): support symlinks and ignore files by patterns --- src/ModuleInstaller.php | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/ModuleInstaller.php b/src/ModuleInstaller.php index b9f39da..4a0d1a0 100644 --- a/src/ModuleInstaller.php +++ b/src/ModuleInstaller.php @@ -12,6 +12,7 @@ trait ModuleInstaller { protected $DEV_LINKS = []; protected $INSTALL_PATHS = []; + protected $IGNORE_PATTERNS = []; protected $INSTALLER_DIR = __DIR__; /** @@ -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); + } } } } @@ -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) {