AssetLoader: Load fontawesome files

This commit is contained in:
Johannes Meyer 2020-07-15 15:35:12 +02:00
parent 98f54c7607
commit 8b4549275b

View File

@ -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);
}
}
}
}
}