From b6a77e523ca5af97052ccecbfe4dd1f12c04bac2 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 4 Nov 2019 17:42:29 +0100 Subject: [PATCH] Automatically load css/js assets from ipl-libs --- AssetLoader.php | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ composer.json | 8 ++++++++ 2 files changed, 60 insertions(+) create mode 100644 AssetLoader.php diff --git a/AssetLoader.php b/AssetLoader.php new file mode 100644 index 0000000..3b7fb33 --- /dev/null +++ b/AssetLoader.php @@ -0,0 +1,52 @@ +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); + } + } + } + } + } +} diff --git a/composer.json b/composer.json index be5a835..10fdcee 100644 --- a/composer.json +++ b/composer.json @@ -24,5 +24,13 @@ "ipl/web": "dev-master" }, "require-dev": { + }, + "autoload": { + "psr-0": { "AssetLoader": "" } + }, + "scripts": { + "post-update-cmd": [ + "AssetLoader::update" + ] } }