Skip to content

Commit ba1716d

Browse files
committed
Merge branch 'develop' into enhance/testing
2 parents c171769 + ff467bd commit ba1716d

18 files changed

Lines changed: 930 additions & 120 deletions

File tree

public/index.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
<?php
22

3+
// Valid PHP Version?
4+
$minPHPVersion = '7.1';
5+
if (phpversion() < $minPHPVersion)
6+
{
7+
die("You PHP version must be {$minPHPVersion} or higher to run CodeIgniter. Current version: ". phpversion());
8+
}
9+
unset($minPHPVersion);
10+
311
// Path to the front controller (this file)
412
define('FCPATH', __DIR__.DIRECTORY_SEPARATOR);
513

system/CodeIgniter.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
* @since Version 3.0.0
3636
* @filesource
3737
*/
38+
use CodeIgniter\HTTP\DownloadResponse;
3839
use CodeIgniter\HTTP\RedirectResponse;
3940
use CodeIgniter\HTTP\Request;
4041
use CodeIgniter\HTTP\ResponseInterface;
@@ -93,7 +94,7 @@ class CodeIgniter
9394

9495
/**
9596
* Current response.
96-
* @var HTTP\Response
97+
* @var HTTP\ResponseInterface
9798
*/
9899
protected $response;
99100

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

330+
$filters->setResponse($this->response);
329331
// Run "after" filters
330332
$response = $filters->run($uri, 'after');
331333

@@ -890,6 +892,10 @@ protected function gatherOutput($cacheConfig = null, $returned = null)
890892
ob_end_clean();
891893
}
892894

895+
if ($returned instanceof DownloadResponse) {
896+
$this->response = $returned;
897+
return;
898+
}
893899
// If the controller returned a response object,
894900
// we need to grab the body from it so it can
895901
// be added to anything else that might have been

system/Commands/Server/Serve.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,13 @@
4141

4242
/**
4343
* Launch the PHP development server
44-
*
44+
*
4545
* Not testable, as it throws phpunit for a loop :-/
4646
* @codeCoverageIgnore
4747
*/
4848
class Serve extends BaseCommand
4949
{
50+
protected $minPHPVersion = '7.1';
5051

5152
protected $group = 'CodeIgniter';
5253
protected $name = 'serve';
@@ -61,6 +62,12 @@ class Serve extends BaseCommand
6162

6263
public function run(array $params)
6364
{
65+
// Valid PHP Version?
66+
if (phpversion() < $this->minPHPVersion)
67+
{
68+
die("You PHP version must be {$this->minPHPVersion} or higher to run CodeIgniter. Current version: ". phpversion());
69+
}
70+
6471
// Collect any user-supplied options and apply them
6572
$php = CLI::getOption('php') ?? PHP_BINARY;
6673
$host = CLI::getOption('host') ?? 'localhost';

system/Entity.php

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,36 @@ class Entity
6464
'casts' => []
6565
];
6666

67+
/**
68+
* Holds original copies of all class vars so
69+
* we can determine what's actually been changed
70+
* and not accidentally write nulls where we shouldn't.
71+
*
72+
* @var array
73+
*/
74+
protected $_original = [];
75+
6776
/**
6877
* Allows filling in Entity parameters during construction.
6978
*
7079
* @param array|null $data
7180
*/
7281
public function __construct(array $data = null)
7382
{
83+
// Collect any original values of things
84+
// so we can compare later to see what's changed
85+
$properties = get_object_vars($this);
86+
87+
foreach ($properties as $key => $value)
88+
{
89+
if (substr($key, 0, 1) == '_')
90+
{
91+
unset($properties[$key]);
92+
}
93+
}
94+
95+
$this->_original = $properties;
96+
7497
if (is_array($data))
7598
{
7699
$this->fill($data);
@@ -108,8 +131,12 @@ public function fill(array $data)
108131
* values of this entity as an array. All values are accessed
109132
* through the __get() magic method so will have any casts, etc
110133
* applied to them.
134+
*
135+
* @param bool $onlyChanged If true, only return values that have changed since object creation
136+
*
137+
* @return array
111138
*/
112-
public function toArray(): array
139+
public function toArray(bool $onlyChanged = false): array
113140
{
114141
$return = [];
115142

@@ -119,7 +146,12 @@ public function toArray(): array
119146

120147
foreach ($properties as $key => $value)
121148
{
122-
if ($key == '_options') continue;
149+
if (substr($key, 0, 1) == '_') continue;
150+
151+
if ($onlyChanged && $this->_original[$key] === null && $value === null)
152+
{
153+
continue;
154+
}
123155

124156
$return[$key] = $this->__get($key);
125157
}
@@ -368,7 +400,7 @@ protected function mutateDate($value)
368400
*
369401
* @return mixed
370402
*/
371-
403+
372404
protected function castAs($value, string $type)
373405
{
374406
switch($type)
@@ -422,7 +454,7 @@ protected function castAs($value, string $type)
422454
* Cast as JSON
423455
*
424456
* @param mixed $value
425-
* @param bool $asArray
457+
* @param bool $asArray
426458
*
427459
* @return mixed
428460
*/
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php namespace CodeIgniter\Exceptions;
2+
3+
/**
4+
* Class DownloadException
5+
*
6+
* @package CodeIgniter\Exceptions
7+
*/
8+
class DownloadException extends \RuntimeException implements ExceptionInterface
9+
{
10+
11+
public static function forCannotSetFilePath(string $path)
12+
{
13+
return new static(lang('HTTP.cannotSetFilePath', [$path]));
14+
}
15+
16+
public static function forCannotSetBinary()
17+
{
18+
return new static(lang('HTTP.cannotSetBinary'));
19+
}
20+
21+
public static function forNotFoundDownloadSource()
22+
{
23+
return new static(lang('HTTP.notFoundDownloadSource'));
24+
}
25+
26+
public static function forCannotSetCache()
27+
{
28+
return new static(lang('HTTP.cannotSetCache'));
29+
}
30+
31+
public static function forCannotSetStatusCode(int $code, string $reason)
32+
{
33+
return new static(lang('HTTP.cannotSetStatusCode', [$code, $reason]));
34+
}
35+
}

system/Exceptions/FrameworkException.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@
1111
class FrameworkException extends \RuntimeException implements ExceptionInterface
1212
{
1313

14-
public static function forEmptyBaseURL(): self
15-
{
16-
return new static('You have an empty or invalid base URL. The baseURL value must be set in Config\App.php, or through the .env file.');
17-
}
18-
1914
public static function forInvalidFile(string $path)
2015
{
2116
return new static(lang('Core.invalidFile', [$path]));

system/Filters/Filters.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ public function __construct($config, RequestInterface $request, ResponseInterfac
9191
{
9292
$this->config = $config;
9393
$this->request = & $request;
94+
$this->setResponse($response);
95+
}
96+
97+
public function setResponse(ResponseInterface $response)
98+
{
9499
$this->response = & $response;
95100
}
96101

0 commit comments

Comments
 (0)