Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【Unsolicited PR】I changed the download method to testable. #1239

Merged
merged 45 commits into from
Oct 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
913a6cf
feat: first commit
ytetsuro Sep 24, 2018
3e6a645
feat: add get status code method
ytetsuro Sep 24, 2018
8c8583a
feat: add constructor.
ytetsuro Sep 24, 2018
6e5305f
feat: add set statusCode and get reason method.
ytetsuro Sep 24, 2018
b7650c3
feat: I ported necessary method from Response
ytetsuro Sep 24, 2018
aee683e
feat: add set content type method.
ytetsuro Sep 24, 2018
4e4cd50
fix: InvalidArgumentException -> CodeIgniter\HTTP\Exceptions\HTTPExce…
ytetsuro Sep 24, 2018
912f69a
feat: add cache function.
ytetsuro Sep 24, 2018
0df8ca8
fix: add reason property.
ytetsuro Sep 24, 2018
b4489c6
feat: add filepath and binary set method.
ytetsuro Sep 24, 2018
4c17cf9
fix: filepath to CodeIgniter\Files\File
ytetsuro Sep 24, 2018
5eaa4cc
feat: add get content length method.
ytetsuro Sep 24, 2018
ac15819
feat: add set ContentType by MimeType method
ytetsuro Sep 24, 2018
45bd0f5
feat: add get DownloadFileName method.
ytetsuro Sep 24, 2018
2b9297c
feat: add get ContentDisponsition method.
ytetsuro Sep 24, 2018
4d8dfcf
feat: add build headlers method
ytetsuro Sep 24, 2018
e676e9b
fix: remove get mimetype by file instance
ytetsuro Sep 24, 2018
909c4ad
feat: add binary output method
ytetsuro Sep 24, 2018
cade13d
feat: add output by file instance method.
ytetsuro Sep 24, 2018
0ca741c
fix: rename test method.
ytetsuro Sep 24, 2018
9b166f1
fix: Fixed problem that header was not set correctly.
ytetsuro Sep 24, 2018
bd61584
test: add output body test.
ytetsuro Sep 24, 2018
a7c2cab
feat: port sendHeader method. from Response class.
ytetsuro Sep 24, 2018
454031d
feat: Changed to return DonwloadResponse by download method.
ytetsuro Sep 24, 2018
742d691
feat: Changed to exit when Controller returned DownloadResponse.
ytetsuro Sep 24, 2018
68f0d61
fix: file extension is uppercase when Android OS is less than 2.
ytetsuro Sep 24, 2018
b612379
test: add set LastModified with string case.
ytetsuro Sep 24, 2018
5f513b8
style: fix to allman style.
ytetsuro Sep 24, 2018
ddbf6d3
fix: change exception RuntimeException -> LogicException.
ytetsuro Sep 24, 2018
aa80a3b
feat: add localized message.
ytetsuro Oct 4, 2018
fa9c949
style: remove space.
ytetsuro Oct 4, 2018
fa7d8ff
feat: add DownloadException.
ytetsuro Oct 4, 2018
9cbec75
fix: remove not need argument.
ytetsuro Oct 4, 2018
ed42c71
fix: add exception message for bind point.
ytetsuro Oct 4, 2018
df83c7e
feat: add can not set cache exception.
ytetsuro Oct 4, 2018
0dc623b
refacotr: update the exception style.
ytetsuro Oct 4, 2018
77cd602
refactor: add setResponse method.
ytetsuro Oct 9, 2018
0e30902
fix: go through the after filters.
ytetsuro Oct 9, 2018
7b83fad
feat: add can not status code exception message.
ytetsuro Oct 12, 2018
53fccd5
feat: add generate exception method.
ytetsuro Oct 12, 2018
947b2a8
fix: The setStatusCode method can not be called.
ytetsuro Oct 12, 2018
a5c524b
style: remove unnecessary comment.
ytetsuro Oct 12, 2018
023c2bf
style: change return type.
ytetsuro Oct 12, 2018
8ce1da3
fix: Fix to call getReason with sendHeaders method.
ytetsuro Oct 12, 2018
e801b70
fix: Fix to doc comment by Different parts from the implementation.
ytetsuro Oct 12, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion system/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
* @since Version 3.0.0
* @filesource
*/
use CodeIgniter\HTTP\DownloadResponse;
use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\Request;
use CodeIgniter\HTTP\ResponseInterface;
Expand Down Expand Up @@ -93,7 +94,7 @@ class CodeIgniter

/**
* Current response.
* @var HTTP\Response
* @var HTTP\ResponseInterface
*/
protected $response;

Expand Down Expand Up @@ -326,6 +327,7 @@ protected function handleRequest(RouteCollectionInterface $routes = null, $cache
// so it can be used with the output.
$this->gatherOutput($cacheConfig, $returned);

$filters->setResponse($this->response);
// Run "after" filters
$response = $filters->run($uri, 'after');

Expand Down Expand Up @@ -890,6 +892,10 @@ protected function gatherOutput($cacheConfig = null, $returned = null)
ob_end_clean();
}

if ($returned instanceof DownloadResponse) {
$this->response = $returned;
return;
}
// If the controller returned a response object,
// we need to grab the body from it so it can
// be added to anything else that might have been
Expand Down
35 changes: 35 additions & 0 deletions system/Exceptions/DownloadException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php namespace CodeIgniter\Exceptions;

/**
* Class DownloadException
*
* @package CodeIgniter\Exceptions
*/
class DownloadException extends \RuntimeException implements ExceptionInterface
{

public static function forCannotSetFilePath(string $path)
{
return new static(lang('HTTP.cannotSetFilePath', [$path]));
}

public static function forCannotSetBinary()
{
return new static(lang('HTTP.cannotSetBinary'));
}

public static function forNotFoundDownloadSource()
{
return new static(lang('HTTP.notFoundDownloadSource'));
}

public static function forCannotSetCache()
{
return new static(lang('HTTP.cannotSetCache'));
}

public static function forCannotSetStatusCode(int $code, string $reason)
{
return new static(lang('HTTP.cannotSetStatusCode', [$code, $reason]));
}
}
5 changes: 5 additions & 0 deletions system/Filters/Filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ public function __construct($config, RequestInterface $request, ResponseInterfac
{
$this->config = $config;
$this->request = & $request;
$this->setResponse($response);
}

public function setResponse(ResponseInterface $response)
{
$this->response = & $response;
}

Expand Down
Loading