This repository has been archived by the owner on Feb 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from CodeIncHQ/1.x
v1.2.0
- Loading branch information
Showing
3 changed files
with
25 additions
and
17 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,29 +23,28 @@ | |
namespace CodeInc\AssetsMiddleware\Assets; | ||
use CodeInc\MediaTypes\MediaTypes; | ||
use CodeInc\Psr7Responses\StreamResponse; | ||
use enshrined\svgSanitize\Sanitizer; | ||
use function GuzzleHttp\Psr7\stream_for; | ||
use MatthiasMullie\Minify; | ||
use Psr\Http\Message\StreamInterface; | ||
use RuntimeException; | ||
|
||
|
||
/** | ||
* Class AssetMinifiedResponse | ||
* Class AssetCompressedResponse | ||
* | ||
* @uses Minify\CSS | ||
* @uses Minify\JS | ||
* @package CodeInc\AssetsMiddleware\Assets | ||
* @author Joan Fabrégat <[email protected]> | ||
*/ | ||
class AssetMinifiedResponse extends StreamResponse implements AssetResponseInterface | ||
class AssetCompressedResponse extends StreamResponse implements AssetResponseInterface | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $assetName; | ||
|
||
/** | ||
* AssetResponse constructor. | ||
* AssetCompressedResponse constructor. | ||
* | ||
* @param string $filePath | ||
* @param string $assetName | ||
|
@@ -98,12 +97,20 @@ private function getStream(string $mimeType, string $filePath):StreamInterface | |
case 'text/javascript': | ||
return stream_for((new Minify\JS($filePath))->minify()); | ||
|
||
case 'image/svg+xml': | ||
$svgContent = file_get_contents($filePath); | ||
if ($svgContent === false) { | ||
throw new RuntimeException( | ||
sprintf("Unable to read the SCF assets file '%s'", $filePath) | ||
); | ||
} | ||
return stream_for((new Sanitizer())->sanitize($svgContent)); | ||
|
||
default: | ||
$f = fopen($filePath, 'r'); | ||
if ($f === false) { | ||
throw new RuntimeException( | ||
sprintf("Unable to open the assets file '%s'", | ||
$filePath) | ||
sprintf("Unable to open the assets file '%s'", $filePath) | ||
); | ||
} | ||
return stream_for($f); | ||
|
This file contains 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