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 #3 from CodeIncHQ/1.x
v1.1.0
- Loading branch information
Showing
4 changed files
with
168 additions
and
25 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 |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?php | ||
// | ||
// +---------------------------------------------------------------------+ | ||
// | CODE INC. SOURCE CODE | | ||
// +---------------------------------------------------------------------+ | ||
// | Copyright (c) 2017 - Code Inc. SAS - All Rights Reserved. | | ||
// | Visit https://www.codeinc.fr for more information about licensing. | | ||
// +---------------------------------------------------------------------+ | ||
// | NOTICE: All information contained herein is, and remains the | | ||
// | property of Code Inc. SAS. The intellectual and technical concepts | | ||
// | contained herein are proprietary to Code Inc. SAS are protected by | | ||
// | trade secret or copyright law. Dissemination of this information or | | ||
// | reproduction of this material is strictly forbidden unless prior | | ||
// | written permission is obtained from Code Inc. SAS. | | ||
// +---------------------------------------------------------------------+ | ||
// | ||
// Author: Joan Fabrégat <[email protected]> | ||
// Date: 03/05/2018 | ||
// Time: 16:30 | ||
// Project: AssetsMiddleware | ||
// | ||
declare(strict_types=1); | ||
namespace CodeInc\AssetsMiddleware\Assets; | ||
use CodeInc\MediaTypes\MediaTypes; | ||
use CodeInc\Psr7Responses\StreamResponse; | ||
use function GuzzleHttp\Psr7\stream_for; | ||
use MatthiasMullie\Minify; | ||
|
||
|
||
/** | ||
* Class AssetMinifiedResponse | ||
* | ||
* @uses Minify\CSS | ||
* @uses Minify\JS | ||
* @package CodeInc\AssetsMiddleware\Assets | ||
* @author Joan Fabrégat <[email protected]> | ||
*/ | ||
class AssetMinifiedResponse extends StreamResponse implements AssetResponseInterface | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $assetName; | ||
|
||
/** | ||
* AssetResponse constructor. | ||
* | ||
* @param string $filePath | ||
* @param string $assetName | ||
* @param null|string $fileName | ||
* @param null|string $mimeType | ||
* @param bool $asAttachment | ||
* @param int $status | ||
* @param array $headers | ||
* @param string $version | ||
* @param null|string $reason | ||
* @throws \CodeInc\MediaTypes\Exceptions\MediaTypesException | ||
*/ | ||
public function __construct(string $filePath, string $assetName, ?string $fileName = null, ?string $mimeType = null, | ||
bool $asAttachment = false, int $status = 200, array $headers = [], | ||
string $version = '1.1', ?string $reason = null) | ||
{ | ||
$this->assetName = $assetName; | ||
|
||
if (!$fileName) { | ||
$fileName = basename($assetName); | ||
} | ||
if (!$mimeType) { | ||
$mimeType = MediaTypes::getFilenameMediaType($fileName); | ||
} | ||
|
||
switch ($mimeType) { | ||
case 'text/css': | ||
$stream = stream_for((new Minify\CSS($filePath))->minify()); | ||
break; | ||
|
||
case 'text/javascript': | ||
$stream = stream_for((new Minify\JS($filePath))->minify()); | ||
break; | ||
|
||
default: | ||
$stream = stream_for($filePath); | ||
break; | ||
} | ||
|
||
parent::__construct( | ||
$stream, | ||
$mimeType, | ||
null, | ||
$fileName, | ||
$asAttachment, | ||
$status, | ||
$headers, | ||
$version, | ||
$reason | ||
); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
* @return string | ||
*/ | ||
public function getAssetName():string | ||
{ | ||
return $this->assetName; | ||
} | ||
} |
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