Skip to content

Instantly share code, notes, and snippets.

@guney
Last active October 12, 2016 19:17
Show Gist options
  • Select an option

  • Save guney/dd599ff35deb120124822d6b0e4ed4d9 to your computer and use it in GitHub Desktop.

Select an option

Save guney/dd599ff35deb120124822d6b0e4ed4d9 to your computer and use it in GitHub Desktop.
Helper functions for using Laravel Elixir's versioning method on Lumen microframework.
<?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.");
}
}
"autoload": {
"files": [
"app/Helpers/AssetsHelper.php"
]
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment