From 8b4549275b4d6a39167418e4876b797098b062b6 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 15 Jul 2020 15:35:12 +0200 Subject: [PATCH] AssetLoader: Load fontawesome files --- AssetLoader.php | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/AssetLoader.php b/AssetLoader.php index 3b7fb33..d32a33a 100644 --- a/AssetLoader.php +++ b/AssetLoader.php @@ -2,6 +2,11 @@ class AssetLoader { + public static $awesomeVendorFiles = [ + 'asset/static/font/awesome' => 'vendor/fortawesome/font-awesome/webfonts', + 'asset/css' => 'vendor/fortawesome/font-awesome/css/fontawesome.css' + ]; + public static function update() { if (is_dir('asset')) { @@ -48,5 +53,35 @@ class AssetLoader } } } + + // Register font-awesome files as assets + foreach (static::$awesomeVendorFiles as $targetPath => $sourcePath) { + $sourcePath = realpath($sourcePath); + if (! $sourcePath) { + continue; + } + + if (is_dir($sourcePath)) { + if (! is_dir($targetPath)) { + mkdir($targetPath, 0755, true); + } + + $awesomeFiles = new FilesystemIterator($sourcePath); + } else { // is_file($sourcePath) + $awesomeFiles = [new SplFileInfo($sourcePath)]; + $sourcePath = $awesomeFiles[0]->getPath(); + } + + foreach ($awesomeFiles as $awesomeFile) { + /** @var SplFileInfo $awesomeFile */ + $relativePath = join(DIRECTORY_SEPARATOR, [$targetPath, ltrim( + substr($awesomeFile->getPathname(), strlen($sourcePath)), + '/\\' + )]); + if (! file_exists($relativePath) && $awesomeFile->isFile()) { + symlink($awesomeFile->getPathname(), $relativePath); + } + } + } } }