File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -178,7 +178,8 @@ protected function determineClass(string $library): array
178178 }
179179
180180 // locate and return an instance of the cell
181- $ object = Factories::cells ($ class );
181+ // @TODO extend Factories to be able to load classes with the same short name.
182+ $ object = class_exists ($ class ) ? new $ class () : Factories::cells ($ class );
182183
183184 if (! is_object ($ object )) {
184185 throw ViewException::forInvalidCellClass ($ class );
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /**
4+ * This file is part of CodeIgniter 4 framework.
5+ *
6+ * (c) CodeIgniter Foundation <admin@codeigniter.com>
7+ *
8+ * For the full copyright and license information, please view
9+ * the LICENSE file that was distributed with this source code.
10+ */
11+
12+ namespace Tests \Support \View \OtherCells ;
13+
14+ /**
15+ * Two classes with the same short name.
16+ *
17+ * - Tests\Support\View\SampleClass
18+ * - Tests\Support\View\OtherCells\SampleClass
19+ */
20+ class SampleClass
21+ {
22+ public function hello ()
23+ {
24+ return 'Good-bye! ' ;
25+ }
26+ }
Original file line number Diff line number Diff line change @@ -113,6 +113,17 @@ public function testDisplayRendersWithNamespacedClass()
113113 $ this ->assertSame ($ expected , $ this ->cell ->render ('\Tests\Support\View\SampleClass::hello ' ));
114114 }
115115
116+ public function testDisplayRendersTwoCellsWithSameShortName ()
117+ {
118+ $ output = $ this ->cell ->render ('\Tests\Support\View\SampleClass::hello ' );
119+
120+ $ this ->assertSame ('Hello ' , $ output );
121+
122+ $ output = $ this ->cell ->render ('\Tests\Support\View\OtherCells\SampleClass::hello ' );
123+
124+ $ this ->assertSame ('Good-bye! ' , $ output );
125+ }
126+
116127 public function testDisplayRendersWithValidParamString ()
117128 {
118129 $ params = 'one=two,three=four ' ;
You can’t perform that action at this time.
0 commit comments