Skip to content

Commit 53918b3

Browse files
committed
Merge branch 'develop' into feature/resource
2 parents 0513dbe + a8357ed commit 53918b3

12 files changed

Lines changed: 90 additions & 10 deletions

File tree

app/Common.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
/**
4+
* The goal of this file is to allow developers a location
5+
* where they can overwrite core procedural functions and
6+
* replace them with their own. This file is loaded during
7+
* the bootstrap process and is called during the frameworks
8+
* execution.
9+
*
10+
* This can be looked at as a `master helper` file that is
11+
* loaded early on, and may also contain additional functions
12+
* that you'd like to use throughout your entire application
13+
*
14+
* @link: https://codeigniter4.github.io/CodeIgniter4/
15+
*/

spark

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,9 @@ ini_set('display_errors', 1);
5353
// Show basic information before we do anything else.
5454
$console->showHeader();
5555

56-
// fire off the command the main framework.
57-
$console->run();
56+
// fire off the command in the main framework.
57+
$response = $console->run();
58+
if ($response->getStatusCode() >= 300)
59+
{
60+
exit($response->getStatusCode());
61+
}

system/CLI/CommandRunner.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class CommandRunner extends Controller
7171
* @param string $method
7272
* @param array ...$params
7373
*
74+
* @return mixed
7475
* @throws \ReflectionException
7576
*/
7677
public function _remap($method, ...$params)
@@ -81,7 +82,7 @@ public function _remap($method, ...$params)
8182
array_shift($params);
8283
}
8384

84-
$this->index($params);
85+
return $this->index($params);
8586
}
8687

8788
//--------------------------------------------------------------------

system/CodeIgniter.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,12 @@ protected function handleRequest(RouteCollectionInterface $routes = null, $cache
355355
else
356356
{
357357
$response = $this->response;
358+
359+
// Set response code for CLI command failures
360+
if (is_numeric($returned) || $returned === false)
361+
{
362+
$response->setStatusCode(400);
363+
}
358364
}
359365

360366
if ($response instanceof Response)

system/Entity.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,12 @@ public function toArray(bool $onlyChanged = false, bool $cast = true): array
182182
{
183183
foreach ($this->datamap as $from => $to)
184184
{
185-
$return[$from] = $this->__get($to);
185+
if (array_key_exists($to, $return)) {
186+
$return[$from] = $this->__get($to);
187+
}
186188
}
187189
}
190+
188191
$this->_cast = true;
189192
return $return;
190193
}
@@ -424,6 +427,15 @@ public function __unset(string $key)
424427
*/
425428
public function __isset(string $key): bool
426429
{
430+
$key = $this->mapProperty($key);
431+
432+
$method = 'get' . str_replace(' ', '', ucwords(str_replace(['-', '_'], ' ', $key)));
433+
434+
if (method_exists($this, $method))
435+
{
436+
return true;
437+
}
438+
427439
return isset($this->attributes[$key]);
428440
}
429441

system/HTTP/Response.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,8 +689,8 @@ public function send()
689689
}
690690

691691
$this->sendHeaders();
692-
$this->sendBody();
693692
$this->sendCookies();
693+
$this->sendBody();
694694

695695
return $this;
696696
}

system/Images/Handlers/ImageMagickHandler.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,10 @@ public function getVersion(): string
232232
* @param string $action
233233
* @param integer $quality
234234
*
235-
* @return ImageMagickHandler|boolean
235+
* @return array Lines of output from shell command
236+
* @throws \Exception
236237
*/
237-
protected function process(string $action, int $quality = 100)
238+
protected function process(string $action, int $quality = 100): array
238239
{
239240
// Do we have a vaild library path?
240241
if (empty($this->config->libraryPath))
@@ -303,8 +304,8 @@ public function save(string $target = null, int $quality = 90): bool
303304
$result = $this->process($action, $quality);
304305

305306
unlink($this->resource);
306-
307-
return $result;
307+
308+
return true;
308309
}
309310

310311
//--------------------------------------------------------------------

system/Test/FeatureTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
*
5454
* @package CodeIgniter\Test
5555
*/
56-
class FeatureTestCase extends CIDatabaseTestCase
56+
class FeatureTestCase extends CIUnitTestCase
5757
{
5858

5959
/**

system/bootstrap.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@
9696
require_once APPPATH . 'Config/Constants.php';
9797
}
9898

99+
// Let's see if an app/Common.php file exists
100+
if (file_exists(APPPATH . 'Common.php'))
101+
{
102+
require_once APPPATH . 'Common.php';
103+
}
104+
105+
// Require system/Common.php
99106
require_once SYSTEMPATH . 'Common.php';
100107

101108
/*

tests/system/EntityTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,7 @@ public function testAsArray()
548548
'bar' => ':bar',
549549
'default' => 'sumfin',
550550
'created_at' => null,
551+
'createdAt' => null,
551552
]);
552553
}
553554

@@ -673,6 +674,17 @@ public function testHasChangedWholeEntity()
673674
$this->assertTrue($entity->hasChanged());
674675
}
675676

677+
public function testIssetKeyMap()
678+
{
679+
$entity = $this->getEntity();
680+
681+
$entity->created_at = '12345678';
682+
$this->assertTrue(isset($entity->createdAt));
683+
684+
$entity->bar = 'foo';
685+
$this->assertTrue(isset($entity->FakeBar));
686+
}
687+
676688
protected function getEntity()
677689
{
678690
return new class extends Entity
@@ -691,6 +703,10 @@ protected function getEntity()
691703
'created_at' => null,
692704
];
693705

706+
protected $datamap = [
707+
'createdAt' => 'created_at',
708+
];
709+
694710
public function setBar($value)
695711
{
696712
$this->attributes['bar'] = "bar:{$value}";
@@ -703,6 +719,10 @@ public function getBar()
703719
return "{$this->attributes['bar']}:bar";
704720
}
705721

722+
public function getFakeBar()
723+
{
724+
return "{$this->attributes['bar']}:bar";
725+
}
706726
};
707727
}
708728

0 commit comments

Comments
 (0)