Skip to content

Commit 8708ee8

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into 4.4
2 parents f444086 + c929fc8 commit 8708ee8

File tree

10 files changed

+49
-11
lines changed

10 files changed

+49
-11
lines changed

app/Config/App.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ class App extends BaseConfig
105105
*
106106
* The default timezone that will be used in your application to display
107107
* dates with the date helper, and can be retrieved through app_timezone()
108+
*
109+
* @see https://www.php.net/manual/en/timezones.php for list of timezones supported by PHP.
108110
*/
109111
public string $appTimezone = 'UTC';
110112

system/Commands/Generators/CellGenerator.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,8 @@ public function run(array $params)
8888
// Form the view name
8989
$segments = explode('\\', $this->qualifyClassName());
9090

91-
$view = array_pop($segments);
92-
$view = str_replace('Cell', '', decamelize($view));
93-
if (strpos($view, '_cell') === false) {
94-
$view .= '_cell';
95-
}
91+
$view = array_pop($segments);
92+
$view = decamelize($view);
9693
$segments[] = $view;
9794
$view = implode('\\', $segments);
9895

system/Helpers/text_helper.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,8 @@ function reduce_multiples(string $str, string $character = ',', bool $trim = fal
538538
*
539539
* @param string $type Type of random string. basic, alpha, alnum, numeric, nozero, md5, sha1, and crypto
540540
* @param int $len Number of characters
541+
*
542+
* @deprecated The type 'basic', 'md5', and 'sha1' are deprecated. They are not cryptographically secure.
541543
*/
542544
function random_string(string $type = 'alnum', int $len = 8): string
543545
{

system/View/Cells/Cell.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,13 @@ final protected function view(?string $view, array $data = []): string
7373

7474
// If no view is specified, we'll try to guess it based on the class name.
7575
if (empty($view)) {
76-
$view = decamelize((new ReflectionClass($this))->getShortName());
77-
$view = str_replace('_cell', '', $view);
76+
// According to the docs, the name of the view file should be the
77+
// snake_cased version of the cell's class name, but for backward
78+
// compatibility, the name also accepts '_cell' being omitted.
79+
$ref = new ReflectionClass($this);
80+
$view = decamelize($ref->getShortName());
81+
$viewPath = dirname($ref->getFileName()) . DIRECTORY_SEPARATOR . $view . '.php';
82+
$view = is_file($viewPath) ? $viewPath : str_replace('_cell', '', $view);
7883
}
7984

8085
// Locate our view, preferring the directory of the class.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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\Cells;
13+
14+
use CodeIgniter\View\Cells\Cell;
15+
16+
class AwesomeCell extends Cell
17+
{
18+
public string $message = 'Found!';
19+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div><?= $message ?></div>

tests/system/Commands/CellGeneratorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function testGenerateCellSimpleName()
7373
$this->assertStringContainsString('class Another extends Cell', $contents);
7474

7575
// Check the view was generated
76-
$file = APPPATH . 'Cells/another_cell.php';
76+
$file = APPPATH . 'Cells/another.php';
7777
$this->assertStringContainsString('File created: ', $this->getStreamFilterBuffer());
7878
$this->assertFileExists($file);
7979
}

tests/system/View/ControlledCellTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use CodeIgniter\Test\CIUnitTestCase;
1515
use CodeIgniter\View\Exceptions\ViewException;
1616
use Tests\Support\View\Cells\AdditionCell;
17+
use Tests\Support\View\Cells\AwesomeCell;
1718
use Tests\Support\View\Cells\ColorsCell;
1819
use Tests\Support\View\Cells\GreetingCell;
1920
use Tests\Support\View\Cells\ListerCell;
@@ -36,6 +37,13 @@ public function testCellRendersDefaultValues()
3637
$this->assertStringContainsString('Hello World', $result);
3738
}
3839

40+
public function testCellRendersViewWithActualClassName()
41+
{
42+
$result = view_cell(AwesomeCell::class);
43+
44+
$this->assertStringContainsString('Found!', $result);
45+
}
46+
3947
public function testCellWithNamedView()
4048
{
4149
$result = view_cell(SimpleNotice::class);

user_guide_src/source/changelogs/v4.3.4.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ Changes
2121
Deprecations
2222
************
2323

24+
- **Text Helper:** :php:func:`random_string()`'s type ``basic``, ``md5``, and
25+
``sha1`` are deprecated. They are not cryptographically secure.
26+
2427
Bugs Fixed
2528
**********
2629

user_guide_src/source/helpers/text_helper.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,18 @@ The following functions are available:
3333
.. warning:: For types: **basic**, **md5**, and **sha1**, generated strings
3434
are not cryptographically secure. Therefore, these types cannot be used
3535
for cryptographic purposes or purposes requiring unguessable return values.
36+
Since v4.3.3, these types are deprecated.
3637

3738
The first parameter specifies the type of string, the second parameter
3839
specifies the length. The following choices are available:
3940

4041
- **alpha**: A string with lower and uppercase letters only.
4142
- **alnum**: Alphanumeric string with lower and uppercase characters.
42-
- **basic**: A random number based on ``mt_rand()`` (length ignored).
43+
- **basic**: [deprecated] A random number based on ``mt_rand()`` (length ignored).
4344
- **numeric**: Numeric string.
4445
- **nozero**: Numeric string with no zeros.
45-
- **md5**: An encrypted random number based on ``md5()`` (fixed length of 32).
46-
- **sha1**: An encrypted random number based on ``sha1()`` (fixed length of 40).
46+
- **md5**: [deprecated] An encrypted random number based on ``md5()`` (fixed length of 32).
47+
- **sha1**: [deprecated] An encrypted random number based on ``sha1()`` (fixed length of 40).
4748
- **crypto**: A random string based on ``random_bytes()``.
4849

4950
.. note:: When you use **crypto**, you must set an even number to the second parameter.

0 commit comments

Comments
 (0)