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 #16 from CodeIncHQ/1.x
v1.4.4
- Loading branch information
Showing
5 changed files
with
92 additions
and
73 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
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,79 @@ | ||
<?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: 23/02/2018 | ||
// Time: 19:15 | ||
// Project: Psr7Responses | ||
// | ||
declare(strict_types = 1); | ||
namespace CodeInc\Psr7Responses; | ||
use CodeInc\Psr7Responses\Tests\LocalFileResponseTest; | ||
use function GuzzleHttp\Psr7\stream_for; | ||
|
||
|
||
/** | ||
* Class LocalFileResponse | ||
* | ||
* @see LocalFileResponseTest | ||
* @package CodeInc\Psr7Responses | ||
* @author Joan Fabrégat <[email protected]> | ||
*/ | ||
class LocalFileResponse extends FileResponse | ||
{ | ||
/** | ||
* LocalFileResponse constructor. | ||
* | ||
* @param string $filePath Local file path | ||
* @param null|string $fileName File's name (determined from the local file path if not specified) | ||
* @param null|string $contentType File's content type (determined from the file's name if not specified) | ||
* @param bool $asAttachment Defines if the file should be sent as an attachment | ||
* @param int $status | ||
* @param array $headers | ||
* @param string $version | ||
* @param null|string $reason | ||
* @throws ResponseException | ||
* @throws \CodeInc\MediaTypes\Exceptions\MediaTypesException | ||
*/ | ||
public function __construct(string $filePath, ?string $fileName = null, ?string $contentType = null, | ||
bool $asAttachment = true, int $status = 200, array $headers = [], | ||
string $version = '1.1', ?string $reason = null) | ||
{ | ||
if (!is_file($filePath)) { | ||
throw new ResponseException( | ||
sprintf("The path \"%s\" is not a file or does not exist", $filePath), | ||
$this | ||
); | ||
} | ||
if (($f = fopen($filePath, "r")) === false) { | ||
throw new ResponseException( | ||
sprintf("Unable to open the file \"%s\" for reading", $filePath), | ||
$this | ||
); | ||
} | ||
|
||
parent::__construct( | ||
stream_for($f), | ||
$fileName ?? basename($filePath), | ||
$contentType, | ||
$asAttachment, | ||
$status, | ||
$headers, | ||
$version, | ||
$reason | ||
); | ||
} | ||
} |
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