/**
* Method that searches if file exists in given path and returns the relative path. If a minified version exists it will be preferred.
*
* @param string $path The actual path of the file
* @param string $ext The extension of the file
* @param boolean $debugMode Signifies if debug is enabled
*
* @return string The relative path of the file
*
* @since 4.0.0
*/
protected static function addFileToBuffer($path = '', $ext = '', $debugMode = false)
{
$position = strrpos($path, '.min.');
// We are handling a name.min.ext file:
if ($position !== false) {
$minifiedPath = $path;
$nonMinifiedPath = substr_replace($path, '', $position, 4);
if ($debugMode) {
return self::checkFileOrder($minifiedPath, $nonMinifiedPath);
}
return self::checkFileOrder($nonMinifiedPath, $minifiedPath);
}
$minifiedPath = pathinfo($path, PATHINFO_DIRNAME) . '/' . pathinfo($path, PATHINFO_FILENAME) . '.min.' . $ext;
if ($debugMode) {
return self::checkFileOrder($minifiedPath, $path);
}
return self::checkFileOrder($path, $minifiedPath);
}