Skip to content

Commit f4e39a9

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into 4.3
Conflicts: system/Test/FeatureTestTrait.php user_guide_src/source/changelogs/index.rst user_guide_src/source/models/model.rst user_guide_src/source/tutorial/create_news_items.rst
2 parents 10bbd5a + 8ebf360 commit f4e39a9

25 files changed

Lines changed: 211 additions & 120 deletions

File tree

system/Autoloader/FileLocator.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ public function locateFile(string $file, ?string $folder = null, string $ext = '
7171
$namespaces = $this->autoloader->getNamespace();
7272

7373
foreach (array_keys($namespaces) as $namespace) {
74-
if (substr($file, 0, strlen($namespace)) === $namespace) {
74+
if (substr($file, 0, strlen($namespace) + 1) === $namespace . '\\') {
75+
$fileWithoutNamespace = substr($file, strlen($namespace));
76+
7577
// There may be sub-namespaces of the same vendor,
7678
// so overwrite them with namespaces found later.
77-
$paths = $namespaces[$namespace];
78-
79-
$fileWithoutNamespace = substr($file, strlen($namespace));
80-
$filename = ltrim(str_replace('\\', '/', $fileWithoutNamespace), '/');
79+
$paths = $namespaces[$namespace];
80+
$filename = ltrim(str_replace('\\', '/', $fileWithoutNamespace), '/');
8181
}
8282
}
8383

system/Test/FeatureTestTrait.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
use CodeIgniter\HTTP\IncomingRequest;
1616
use CodeIgniter\HTTP\Request;
1717
use CodeIgniter\HTTP\URI;
18-
use CodeIgniter\HTTP\UserAgent;
1918
use CodeIgniter\Router\Exceptions\RedirectException;
2019
use CodeIgniter\Router\RouteCollection;
20+
use Config\App;
2121
use Config\Services;
2222
use Exception;
2323
use ReflectionException;
@@ -285,8 +285,8 @@ public function options(string $path, ?array $params = null)
285285
protected function setupRequest(string $method, ?string $path = null): IncomingRequest
286286
{
287287
$path = URI::removeDotSegments($path);
288-
$config = config('App');
289-
$request = new IncomingRequest($config, new URI(), null, new UserAgent());
288+
$config = config(App::class);
289+
$request = Services::request($config, true);
290290

291291
// $path may have a query in it
292292
$parts = explode('?', $path);

tests/system/Autoloader/FileLocatorTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ protected function setUp(): void
4444
'CodeIgniter\\Devkit' => [
4545
TESTPATH . '_support/',
4646
],
47+
'Acme\SampleProject' => TESTPATH . '_support',
48+
'Acme\Sample' => TESTPATH . '_support/does/not/exists',
4749
]);
4850

4951
$this->locator = new FileLocator($autoloader);
@@ -151,6 +153,15 @@ public function testLocateFileNotFoundWithBadNamespace()
151153
$this->assertFalse($this->locator->locateFile($file, 'Views'));
152154
}
153155

156+
public function testLocateFileWithProperNamespace()
157+
{
158+
$file = 'Acme\SampleProject\View\Views\simple';
159+
160+
$expected = ROOTPATH . 'tests/_support/View/Views/simple.php';
161+
162+
$this->assertSame($expected, $this->locator->locateFile($file, 'Views'));
163+
}
164+
154165
public function testSearchSimple()
155166
{
156167
$expected = APPPATH . 'Config/App.php';

user_guide_src/source/changelogs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ See all the changes.
1313
:titlesonly:
1414

1515
v4.3.0
16+
v4.2.11
1617
v4.2.10
1718
v4.2.9
1819
v4.2.8
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Version 4.2.11
2+
##############
3+
4+
Release Date: Unreleased
5+
6+
**4.2.11 release of CodeIgniter4**
7+
8+
.. contents::
9+
:local:
10+
:depth: 2
11+
12+
Bugs Fixed
13+
**********
14+
15+
- Fixed a ``FileLocator::locateFile()`` bug where a similar namespace name could be replaced by another, causing a failure to find a file that exists.
16+
17+
See the repo's `CHANGELOG.md <https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md>`_ for a complete list of bugs fixed.

user_guide_src/source/cli/cli_controllers.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ works exactly like a normal route definition:
4141

4242
For more information, see the :ref:`Routes <command-line-only-routes>` page.
4343

44-
.. warning:: If you enable :ref:`auto-routing` and place the command file in **app/Controllers**,
45-
anyone could access the command with the help of auto-routing via HTTP.
44+
.. warning:: If you enable :ref:`auto-routing-legacy` and place the command file in **app/Controllers**,
45+
anyone could access the command with the help of :ref:`auto-routing-legacy` via HTTP.
4646

4747
Run via CLI
4848
===========

user_guide_src/source/concepts/services.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,14 @@ CodeIgniter's classes provide an interface that they adhere to. When you want to
106106
core classes, you only need to ensure you meet the requirements of the interface and you know that
107107
the classes are compatible.
108108

109-
For example, the ``RouterCollection`` class implements the ``RouterCollectionInterface``. When you
109+
For example, the ``RouteCollection`` class implements the ``RouteCollectionInterface``. When you
110110
want to create a replacement that provides a different way to create routes, you just need to
111-
create a new class that implements the ``RouterCollectionInterface``:
111+
create a new class that implements the ``RouteCollectionInterface``:
112112

113113
.. literalinclude:: services/006.php
114114

115-
Finally, modify **app/Config/Services.php** to create a new instance of ``MyRouter``
116-
instead of ``CodeIgniter\Router\RouterCollection``:
115+
Finally, add the ``routes()`` method to **app/Config/Services.php** to create a new instance of ``MyRouteCollection``
116+
instead of ``CodeIgniter\Router\RouteCollection``:
117117

118118
.. literalinclude:: services/007.php
119119

user_guide_src/source/concepts/services/006.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use CodeIgniter\Router\RouteCollectionInterface;
66

7-
class MyRouter implements RouteCollectionInterface
7+
class MyRouteCollection implements RouteCollectionInterface
88
{
99
// Implement required methods here.
1010
}

user_guide_src/source/concepts/services/007.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
class Services extends BaseService
88
{
9+
// ...
10+
911
public static function routes()
1012
{
11-
return new \App\Router\MyRouter();
13+
return new \App\Router\MyRouteCollection(static::locator(), config('Modules'));
1214
}
13-
14-
// ...
1515
}

user_guide_src/source/concepts/services/008.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
class Services extends BaseService
88
{
9+
// ...
10+
911
public static function renderer($viewPath = APPPATH . 'views/')
1012
{
1113
return new \CodeIgniter\View\View($viewPath);
1214
}
13-
14-
// ...
1515
}

0 commit comments

Comments
 (0)