Last active
October 12, 2016 19:17
-
-
Save guney/dd599ff35deb120124822d6b0e4ed4d9 to your computer and use it in GitHub Desktop.
Helper functions for using Laravel Elixir's versioning method on Lumen microframework.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Place AssetsHelper.php file to the directory you wish, favourably inside app/Helpers. | |
| // Then reference it from the composer.json. | |
| if (!function_exists('public_path')) { | |
| /** | |
| * Get the path to the public folder. | |
| * | |
| * @param string $path | |
| * | |
| * @return string | |
| */ | |
| function public_path($path = '') | |
| { | |
| return app()->basePath() . '/public' . ($path ? DIRECTORY_SEPARATOR . $path : $path); | |
| } | |
| } | |
| if (!function_exists('elixir')) { | |
| /** | |
| * Get the path to a versioned Elixir file. | |
| * | |
| * @param string $file | |
| * @param string $buildDirectory | |
| * | |
| * @return string | |
| * | |
| * @throws \InvalidArgumentException | |
| */ | |
| function elixir($file, $buildDirectory = 'build') | |
| { | |
| static $manifest; | |
| static $manifestPath; | |
| if (is_null($manifest) || $manifestPath !== $buildDirectory) { | |
| $manifest = json_decode(file_get_contents(public_path($buildDirectory . '/rev-manifest.json')), true); | |
| $manifestPath = $buildDirectory; | |
| } | |
| if (isset($manifest[$file])) { | |
| return '/' . $buildDirectory . '/' . $manifest[$file]; | |
| } | |
| throw new InvalidArgumentException("File {$file} not defined in asset manifest."); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "autoload": { | |
| "files": [ | |
| "app/Helpers/AssetsHelper.php" | |
| ] | |
| }, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment