mirror of
https://github.com/Icinga/icinga-php-library.git
synced 2025-07-03 11:54:31 +02:00
Automatically load css/js assets from ipl-libs
This commit is contained in:
parent
c2da4d2d76
commit
b6a77e523c
52
AssetLoader.php
Normal file
52
AssetLoader.php
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class AssetLoader
|
||||||
|
{
|
||||||
|
public static function update()
|
||||||
|
{
|
||||||
|
if (is_dir('asset')) {
|
||||||
|
// Check for removed files
|
||||||
|
$fs = new Composer\Util\Filesystem();
|
||||||
|
$assets = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(
|
||||||
|
'asset',
|
||||||
|
FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::SKIP_DOTS
|
||||||
|
), RecursiveIteratorIterator::CHILD_FIRST);
|
||||||
|
foreach ($assets as $asset) {
|
||||||
|
/** @var SplFileInfo $asset */
|
||||||
|
if ($asset->isDir()) {
|
||||||
|
if ($fs->isDirEmpty($asset->getPathname())) {
|
||||||
|
rmdir($asset);
|
||||||
|
}
|
||||||
|
} elseif (! $asset->isReadable()) {
|
||||||
|
unlink($asset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for new files
|
||||||
|
$vendorLibs = new FilesystemIterator('vendor/ipl');
|
||||||
|
foreach ($vendorLibs as $vendorLib) {
|
||||||
|
/** @var SplFileInfo $vendorLib */
|
||||||
|
$assetDir = join(DIRECTORY_SEPARATOR, [$vendorLib->getRealPath(), 'asset']);
|
||||||
|
if (is_readable($assetDir) && is_dir($assetDir)) {
|
||||||
|
$libAssets = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(
|
||||||
|
$assetDir,
|
||||||
|
FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::SKIP_DOTS
|
||||||
|
), RecursiveIteratorIterator::SELF_FIRST);
|
||||||
|
foreach ($libAssets as $asset) {
|
||||||
|
/** @var SplFileInfo $asset */
|
||||||
|
$relativePath = ltrim(substr($asset->getPathname(), strlen($vendorLib->getRealPath())), '/\\');
|
||||||
|
if (file_exists($relativePath)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($asset->isDir()) {
|
||||||
|
mkdir($relativePath, 0755, true);
|
||||||
|
} elseif ($asset->isFile()) {
|
||||||
|
symlink($asset->getPathname(), $relativePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -24,5 +24,13 @@
|
|||||||
"ipl/web": "dev-master"
|
"ipl/web": "dev-master"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-0": { "AssetLoader": "" }
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"post-update-cmd": [
|
||||||
|
"AssetLoader::update"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user