Skip to content

Commit 422be02

Browse files
committed
Merge branch 'develop' into enhance/testing
2 parents 973f99b + bd7b0e6 commit 422be02

File tree

19 files changed

+413
-97
lines changed

19 files changed

+413
-97
lines changed

application/Config/Paths.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,16 @@ class Paths
7575
* with your host's needs.
7676
*/
7777
public $publicDirectory = 'public';
78+
79+
/*
80+
* ---------------------------------------------------------------
81+
* VIEW DIRECTORY NAME
82+
* ---------------------------------------------------------------
83+
*
84+
* This variable must contain the name of the directory that
85+
* contains the view files used by your application. By
86+
* default this is in `application/Views`. This value
87+
* is used when no value is provided to `Services::renderer()`.
88+
*/
89+
public $viewDirectory = 'application/Views';
7890
}

application/Views/welcome_message.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
</pre>
125125

126126
<p>If you are exploring CodeIgniter for the very first time, you
127-
should start by reading the (in progress)
127+
should start by reading the
128128
<a href="https://bcit-ci.github.io/CodeIgniter4">User Guide</a>.</p>
129129

130130
</div>

system/Autoloader/FileLocator.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@
4343
* Allows loading non-class files in a namespaced manner.
4444
* Works with Helpers, Views, etc.
4545
*
46-
* @todo sanitize filenames prior to checking them...
47-
*
46+
*
4847
* @package CodeIgniter
4948
*/
5049
class FileLocator
@@ -133,7 +132,6 @@ public function locateFile(string $file, string $folder = null, string $ext = 'p
133132
// IF we have a folder name, then the calling function
134133
// expects this file to be within that folder, like 'Views',
135134
// or 'libraries'.
136-
// @todo Allow it to check with and without the nested folder.
137135
if ( ! empty($folder) && strpos($filename, $folder) === false)
138136
{
139137
$filename = $folder . '/' . $filename;

system/CLI/CommandRunner.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<?php namespace CodeIgniter\CLI;
1+
<?php
2+
namespace CodeIgniter\CLI;
23

34
/**
45
* CodeIgniter
@@ -39,6 +40,7 @@
3940

4041
class CommandRunner extends Controller
4142
{
43+
4244
/**
4345
* Stores the info about found Commands.
4446
*
@@ -73,7 +75,6 @@ public function _remap($method, ...$params)
7375

7476
//--------------------------------------------------------------------
7577

76-
7778
/**
7879
* @param array $params
7980
*
@@ -143,12 +144,18 @@ protected function createCommandList()
143144
foreach ($files as $file)
144145
{
145146
$className = service('locator')->findQualifiedNameFromPath($file);
146-
147147
if (empty($className) || ! class_exists($className))
148148
{
149149
continue;
150150
}
151151

152+
$class = new \ReflectionClass($className);
153+
154+
if ( ! $class->isInstantiable() || ! $class->isSubclassOf(BaseCommand::class))
155+
{
156+
continue;
157+
}
158+
152159
$class = new $className($this->logger, $this);
153160

154161
// Store it!

system/CodeIgniter.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class CodeIgniter
6060
/**
6161
* The current version of CodeIgniter Framework
6262
*/
63-
const CI_VERSION = '4.0.0-alpha.1';
63+
const CI_VERSION = '4.0.0-alpha.2';
6464

6565
/**
6666
* App startup time.
@@ -274,10 +274,11 @@ protected function handleRequest(RouteCollectionInterface $routes = null, $cache
274274
$filters = Services::filters();
275275

276276
// If any filters were specified within the routes file,
277-
// we need to ensure it's active for the current request (before only)
277+
// we need to ensure it's active for the current request
278278
if (! is_null($routeFilter))
279279
{
280280
$filters->enableFilter($routeFilter, 'before');
281+
$filters->enableFilter($routeFilter, 'after');
281282
}
282283

283284
$uri = $this->request instanceof CLIRequest ? $this->request->getPath() : $this->request->uri->getPath();

system/Config/Services.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ public static function parser($viewPath = APPPATH.'Views/', $config = null, bool
482482
*
483483
* @return \CodeIgniter\View\View
484484
*/
485-
public static function renderer($viewPath = APPPATH.'Views/', $config = null, bool $getShared = true)
485+
public static function renderer($viewPath = null, $config = null, bool $getShared = true)
486486
{
487487
if ($getShared)
488488
{
@@ -494,6 +494,13 @@ public static function renderer($viewPath = APPPATH.'Views/', $config = null, bo
494494
$config = new \Config\View();
495495
}
496496

497+
if (is_null($viewPath))
498+
{
499+
$paths = config('Paths');
500+
501+
$viewPath = $paths->viewDirectory;
502+
}
503+
497504
return new \CodeIgniter\View\View($config, $viewPath, self::locator(true), CI_DEBUG, self::logger(true));
498505
}
499506

system/Database/Database.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function load(array $params = [], string $alias)
9999
*/
100100
public function loadForge(ConnectionInterface $db)
101101
{
102-
$className = strpos($db->DBDriver, '\\') === false ? '\CodeIgniter\Database\\' . $db->DBDriver . '\\Forge' : $db->DBDriver . '\\Connection';
102+
$className = strpos($db->DBDriver, '\\') === false ? '\CodeIgniter\Database\\' . $db->DBDriver . '\\Forge' : $db->DBDriver . '\\Forge';
103103

104104
// Make sure a connection exists
105105
if ( ! $db->connID)

system/Debug/Toolbar/Views/toolbar.css

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#debug-bar {
2727
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
2828
font-size: 16px;
29+
font-weight: 400;
2930
line-height: 36px;
3031
background: #fff;
3132
position: fixed;
@@ -93,7 +94,7 @@
9394
#debug-bar h1 {
9495
font-size: 16px;
9596
line-height: 36px;
96-
font-weight: 300;
97+
font-weight: 500;
9798
margin: 0 16px 0 0;
9899
padding: 0;
99100
text-align: left;
@@ -118,7 +119,7 @@
118119

119120
#debug-bar h2 {
120121
font-size: 16px;
121-
font-weight: 300;
122+
font-weight: 500;
122123
margin: 0;
123124
padding: 0;
124125
}
@@ -214,6 +215,7 @@
214215
padding: 0 10px;
215216
color: inherit;
216217
text-decoration: none;
218+
letter-spacing: normal;
217219
}
218220

219221
#debug-bar .ci-label.active {
@@ -246,7 +248,7 @@
246248

247249
#debug-bar table {
248250
margin: 0 0 10px 20px;
249-
font-size: 13px;
251+
font-size: 0.9rem;
250252
border-collapse: collapse;
251253
width: 100%;
252254
}
@@ -263,7 +265,7 @@
263265

264266
#debug-bar td {
265267
border: none;
266-
padding: 2px 10px 2px 5px;
268+
padding: 0 10px 0 5px;
267269
margin: 0;
268270
}
269271

@@ -272,7 +274,7 @@
272274
}
273275

274276
#debug-bar tr td:first-child {
275-
width: 20%;
277+
max-width: 20%;
276278
}
277279

278280
#debug-bar tr td:first-child.narrow {
@@ -315,9 +317,9 @@
315317
#debug-bar table.timeline .timer {
316318
position: absolute;
317319
display: inline-block;
318-
padding: 3px;
319-
bottom: 9px;
320-
border-radius: 3px;
320+
padding: 5px;
321+
top: 40%;
322+
border-radius: 4px;
321323
background-color: #999;
322324
}
323325

system/Router/RouteCollection.php

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<?php namespace CodeIgniter\Router;
1+
<?php
2+
namespace CodeIgniter\Router;
23

34
/**
45
* CodeIgniter
@@ -132,16 +133,16 @@ class RouteCollection implements RouteCollectionInterface
132133
* @var array
133134
*/
134135
protected $routes = [
135-
'*' => [],
136-
'options' => [],
137-
'get' => [],
138-
'head' => [],
139-
'post' => [],
140-
'put' => [],
141-
'delete' => [],
142-
'trace' => [],
143-
'connect' => [],
144-
'cli' => [],
136+
'*' => [],
137+
'options' => [],
138+
'get' => [],
139+
'head' => [],
140+
'post' => [],
141+
'put' => [],
142+
'delete' => [],
143+
'trace' => [],
144+
'connect' => [],
145+
'cli' => [],
145146
];
146147

147148
/**
@@ -383,7 +384,8 @@ public function get404Override()
383384
*/
384385
protected function discoverRoutes()
385386
{
386-
if ($this->didDiscover) return;
387+
if ($this->didDiscover)
388+
return;
387389

388390
// We need this var in local scope
389391
// so route files can access it.
@@ -520,8 +522,11 @@ public function getRoutes($verb = null): array
520522
{
521523
// Keep current verb's routes at the beginning so they're matched
522524
// before any of the generic, "add" routes.
523-
$collection = array_merge($this->routes[$verb], $this->routes['*']);
524-
525+
if (isset($this->routes['*']))
526+
{
527+
$extraRules = array_diff_key($this->routes['*'], $this->routes[$verb]);
528+
$collection = array_merge($this->routes[$verb], $extraRules);
529+
}
525530
foreach ($collection as $r)
526531
{
527532
$key = key($r['route']);
@@ -806,13 +811,13 @@ public function resource(string $name, array $options = null): RouteCollectionIn
806811

807812
$methods = isset($options['only']) ? is_string($options['only']) ? explode(',', $options['only']) : $options['only'] : ['index', 'show', 'create', 'update', 'delete', 'new', 'edit'];
808813

809-
if(isset($options['except']))
814+
if (isset($options['except']))
810815
{
811816
$options['except'] = is_array($options['except']) ? $options['except'] : explode(',', $options['except']);
812817
$c = count($methods);
813-
for($i = 0; $i < $c; $i++)
818+
for ($i = 0; $i < $c; $i ++)
814819
{
815-
if(in_array($methods[$i], $options['except']))
820+
if (in_array($methods[$i], $options['except']))
816821
{
817822
unset($methods[$i]);
818823
}
@@ -822,16 +827,16 @@ public function resource(string $name, array $options = null): RouteCollectionIn
822827
if (in_array('index', $methods))
823828
$this->get($name, $new_name . '::index', $options);
824829
if (in_array('new', $methods))
825-
$this->get($name. '/new', $new_name . '::new', $options);
830+
$this->get($name . '/new', $new_name . '::new', $options);
826831
if (in_array('edit', $methods))
827-
$this->get($name . '/' . $id. '/edit', $new_name . '::edit/$1', $options);
832+
$this->get($name . '/' . $id . '/edit', $new_name . '::edit/$1', $options);
828833
if (in_array('show', $methods))
829834
$this->get($name . '/' . $id, $new_name . '::show/$1', $options);
830835
if (in_array('create', $methods))
831836
$this->post($name, $new_name . '::create', $options);
832837
if (in_array('update', $methods))
833838
$this->put($name . '/' . $id, $new_name . '::update/$1', $options);
834-
$this->patch($name . '/' . $id, $new_name . '::update/$1', $options);
839+
$this->patch($name . '/' . $id, $new_name . '::update/$1', $options);
835840
if (in_array('delete', $methods))
836841
$this->delete($name . '/' . $id, $new_name . '::delete/$1', $options);
837842

@@ -1137,7 +1142,7 @@ public function isFiltered(string $search): bool
11371142
*/
11381143
public function getFilterForRoute(string $search): string
11391144
{
1140-
if (! $this->isFiltered($search))
1145+
if ( ! $this->isFiltered($search))
11411146
{
11421147
return '';
11431148
}
@@ -1211,10 +1216,10 @@ protected function create(string $verb, string $from, $to, array $options = null
12111216
$from = trim($from, '/');
12121217
}
12131218

1214-
$options = array_merge((array)$this->currentOptions, (array)$options);
1219+
$options = array_merge((array) $this->currentOptions, (array) $options);
12151220

12161221
// Hostname limiting?
1217-
if (! empty($options['hostname']))
1222+
if ( ! empty($options['hostname']))
12181223
{
12191224
// @todo determine if there's a way to whitelist hosts?
12201225
if (strtolower($_SERVER['HTTP_HOST']) != strtolower($options['hostname']))
@@ -1245,7 +1250,8 @@ protected function create(string $verb, string $from, $to, array $options = null
12451250
for ($i = (int) $options['offset'] + 1; $i < (int) $options['offset'] + 7; $i ++ )
12461251
{
12471252
$to = preg_replace_callback(
1248-
'/\$X/', function ($m) use ($i) {
1253+
'/\$X/', function ($m) use ($i)
1254+
{
12491255
return '$' . $i;
12501256
}, $to, 1
12511257
);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
namespace Tests\Support\Commands;
3+
4+
use CodeIgniter\CLI\BaseCommand;
5+
use CodeIgniter\CLI\CLI;
6+
use CodeIgniter\CodeIgniter;
7+
8+
abstract class AbstractInfo extends BaseCommand
9+
{
10+
11+
protected $group = 'demo';
12+
protected $name = 'app:pablo';
13+
protected $description = 'Displays basic application information.';
14+
15+
}

0 commit comments

Comments
 (0)