for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace ExoUNX\Vasri;
use Illuminate\Support\Facades\File;
use Exception;
/**
* Access class for Vasri
* Class Vasri
*
* @package ExoUNX\Vasri
* @author Gaige Lama <[email protected]>
* @license MIT License
* @link https://github.com/ExoUNX/Vasri
*/
class Vasri
{
* @var Builder
private $builder;
* @var ManifestReader
private $manifestReader;
* @var array
private $vasriManifest;
* Vasri constructor.
public function __construct()
$this->builder = new Builder();
$this->manifestReader = new ManifestReader();
$this->vasriManifest = $this->manifestReader->getVasriManifest();
}
* @param string $file
* @param bool $enableVersioning
* @param bool $enableSRI
* @param string $keyword
* @return string
* @throws Exception
public function vasri(
string $file,
bool $enableVersioning = true,
bool $enableSRI = true,
string $keyword = 'anonymous'
): string {
$output = '';
if (self::isFile($file) === true) {
$output .= $this->addAttribute($file, $enableVersioning);
if ($enableSRI === true) {
$output .= $this->addSRI($file, $keyword);
return $output;
} else {
throw new Exception('Incorrect file path or file does not exist for local asset');
private function addSRI(string $file, string $keyword): string
return " integrity=\"".$this->vasriManifest[$file]['sri']."\" ".$this->builder->crossOrigin($keyword);
private function addAttribute(string $file, bool $enableVersioning)
try {
if ($enableVersioning === true) {
$output = $this->builder->attribute($file)."=\"".$file.$this->vasriManifest[$file]['version']."\"";
$output = $this->builder->attribute($file)."=\"".$file."\"";
} catch (Exception $e) {
throw new Exception($e);
* @return bool
private static function isFile(string $file): bool
return File::exists(public_path($file));