Skip to content

Commit

Permalink
Changed to use stripos instead of regex (#6)
Browse files Browse the repository at this point in the history
While the regex is probably faster, I'll admit I'm no regex guru, and to me regexes have horrible readability.

I encountered an issue where if I had assets with something after `.js` or `.css` it wouldn't be registered with Bonsai.

This solves that issue.
  • Loading branch information
tormjens committed Dec 6, 2020
1 parent e5f911f commit 423cc86
Showing 1 changed file with 3 additions and 23 deletions.
26 changes: 3 additions & 23 deletions src/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,6 @@

class Assets
{
/**
* Regex pattern to match CSS/JS assets.
*
* @var string
*/
protected $assetRegex = '/.\.(css|js)$/i';

/**
* Regex pattern to match CSS assets.
*
* @var string
*/
protected $cssRegex = '/.\.css$/i';

/**
* Regex pattern to match JS assets.
*
* @var string
*/
protected $jsRegex = '/.\.js$/i';

/**
* Regex pattern to match Bonsai json files.
Expand Down Expand Up @@ -144,7 +124,7 @@ public function js()
*/
protected function isAsset($asset)
{
return preg_match($this->assetRegex, $asset);
return $this->isJs($asset) || $this->isCss($asset);
}

/**
Expand All @@ -155,7 +135,7 @@ protected function isAsset($asset)
*/
protected function isJs($asset)
{
return preg_match($this->jsRegex, $asset);
return stripos($asset, '.js') !== false;
}

/**
Expand All @@ -166,7 +146,7 @@ protected function isJs($asset)
*/
protected function isCss($asset)
{
return preg_match($this->cssRegex, $asset);
return stripos($asset, '.css') !== false;
}

/**
Expand Down

0 comments on commit 423cc86

Please sign in to comment.