Merge remote-tracking branch 'upstream/develop' into 4.4

This commit is contained in:
kenjis 2023-07-04 08:07:47 +09:00
commit 6c09f352c6
No known key found for this signature in database
GPG Key ID: BD254878922AF198
15 changed files with 112 additions and 82 deletions

View File

@ -53,12 +53,12 @@ class Cache extends BaseConfig
* Whether to take the URL query string into consideration when generating
* output cache files. Valid options are:
*
* false = Disabled
* true = Enabled, take all query parameters into account.
* Please be aware that this may result in numerous cache
* files generated for the same page over and over again.
* array('q') = Enabled, but only take into account the specified list
* of query parameters.
* false = Disabled
* true = Enabled, take all query parameters into account.
* Please be aware that this may result in numerous cache
* files generated for the same page over and over again.
* ['q'] = Enabled, but only take into account the specified list
* of query parameters.
*
* @var bool|string[]
*/

View File

@ -155,11 +155,6 @@ parameters:
count: 1
path: system/Helpers/filesystem_helper.php
-
message: "#^Binary operation \"\\+\" between 0 and string results in an error\\.$#"
count: 1
path: system/Helpers/number_helper.php
-
message: "#^Property CodeIgniter\\\\Images\\\\Handlers\\\\BaseHandler\\:\\:\\$image \\(CodeIgniter\\\\Images\\\\Image\\) in empty\\(\\) is not falsy\\.$#"
count: 1

View File

@ -19,7 +19,7 @@ interface FormatterInterface
/**
* Takes the given data and formats it.
*
* @param array|string $data
* @param array|object|string $data
*
* @return false|string
*/

View File

@ -239,7 +239,7 @@ trait ResponseTrait
/**
* Converts the $body into JSON and sets the Content Type header.
*
* @param array|string $body
* @param array|object|string $body
*
* @return $this
*/
@ -304,8 +304,8 @@ trait ResponseTrait
* Handles conversion of the data into the appropriate format,
* and sets the correct Content-Type header for our response.
*
* @param array|string $body
* @param string $format Valid: json, xml
* @param array|object|string $body
* @param string $format Valid: json, xml
*
* @return mixed
*

View File

@ -41,7 +41,7 @@ if (! function_exists('_array_search_dot')) {
*
* @internal This should not be used on its own.
*
* @return mixed
* @return array|bool|float|int|object|string|null
*/
function _array_search_dot(array $indexes, array $array)
{
@ -103,9 +103,9 @@ if (! function_exists('array_deep_search')) {
/**
* Returns the value of an element at a key in an array of uncertain depth.
*
* @param mixed $key
* @param int|string $key
*
* @return mixed|null
* @return array|bool|float|int|object|string|null
*/
function array_deep_search($key, array $array)
{

View File

@ -83,7 +83,7 @@ if (! function_exists('delete_cookie')) {
/**
* Delete a cookie
*
* @param mixed $name
* @param string $name
* @param string $domain the cookie domain. Usually: .yourdomain.com
* @param string $path the cookie path
* @param string $prefix the cookie prefix

View File

@ -292,8 +292,8 @@ if (! function_exists('get_file_info')) {
* Options are: name, server_path, size, date, readable, writable, executable, fileperms
* Returns false if the file cannot be found.
*
* @param string $file Path to file
* @param mixed $returnedValues Array or comma separated string of information returned
* @param string $file Path to file
* @param array|string $returnedValues Array or comma separated string of information returned
*
* @return array|null
*/

View File

@ -15,8 +15,8 @@ if (! function_exists('number_to_size')) {
/**
* Formats a numbers as bytes, based on size, and adds the appropriate suffix
*
* @param mixed $num Will be cast as int
* @param string $locale
* @param int|string $num Will be cast as int
* @param string $locale
*
* @return bool|string
*/
@ -69,7 +69,7 @@ if (! function_exists('number_to_amount')) {
*
* @see https://simple.wikipedia.org/wiki/Names_for_large_numbers
*
* @param string $num
* @param int|string $num
*
* @return bool|string
*/
@ -77,6 +77,7 @@ if (! function_exists('number_to_amount')) {
{
// Strip any formatting & ensure numeric input
try {
// @phpstan-ignore-next-line
$num = 0 + str_replace(',', '', $num);
} catch (ErrorException $ee) {
return false;

View File

@ -410,10 +410,10 @@ if (! function_exists('ellipsize')) {
*
* This function will strip tags from a string, split it at its max_length and ellipsize
*
* @param string $str String to ellipsize
* @param int $maxLength Max length of string
* @param mixed $position int (1|0) or float, .5, .2, etc for position to split
* @param string $ellipsis ellipsis ; Default '...'
* @param string $str String to ellipsize
* @param int $maxLength Max length of string
* @param float|int $position int (1|0) or float, .5, .2, etc for position to split
* @param string $ellipsis ellipsis ; Default '...'
*
* @return string Ellipsized string
*/
@ -446,9 +446,9 @@ if (! function_exists('strip_slashes')) {
*
* Removes slashes contained in a string or in an array
*
* @param mixed $str string or array
* @param array|string $str string or array
*
* @return mixed string or array
* @return array|string string or array
*/
function strip_slashes($str)
{

View File

@ -390,20 +390,6 @@ final class FeatureTestTraitTest extends CIUnitTestCase
$response->assertJSONExact(['foo' => 'bar']);
}
public function testCallWithJsonRequestObject()
{
$this->withRoutes([
[
'post',
'home',
'\Tests\Support\Controllers\Popcorn::echoJson',
],
]);
$response = $this->withBodyFormat('json')->call('post', 'home', ['foo' => 'bar']);
$response->assertOK();
$response->assertJSONExact((object) ['foo' => 'bar']);
}
public function testSetupRequestBodyWithParams()
{
$request = $this->setupRequest('post', 'home');

View File

@ -299,13 +299,15 @@ final class TestResponseTest extends CIUnitTestCase
public function testGetJSON()
{
$this->getTestResponse(['foo' => 'bar']);
$formatter = Services::format()->getFormatter('application/json');
$data = ['foo' => 'bar'];
$this->getTestResponse('');
$this->response->setJSON($data, true);
$this->assertSame($formatter->format(['foo' => 'bar']), $this->testResponse->getJSON());
$formatter = Services::format()->getFormatter('application/json');
$this->assertSame($formatter->format($data), $this->testResponse->getJSON());
}
public function testEmptyJSON()
public function testGetJSONEmptyJSON()
{
$this->getTestResponse('<h1>Hello World</h1>');
$this->response->setJSON('', true);
@ -314,7 +316,7 @@ final class TestResponseTest extends CIUnitTestCase
$this->assertSame('""', $this->testResponse->getJSON());
}
public function testFalseJSON()
public function testGetJSONFalseJSON()
{
$this->getTestResponse('<h1>Hello World</h1>');
$this->response->setJSON(false, true);
@ -323,7 +325,7 @@ final class TestResponseTest extends CIUnitTestCase
$this->assertSame('false', $this->testResponse->getJSON());
}
public function testTrueJSON()
public function testGetJSONTrueJSON()
{
$this->getTestResponse('<h1>Hello World</h1>');
$this->response->setJSON(true, true);
@ -332,7 +334,7 @@ final class TestResponseTest extends CIUnitTestCase
$this->assertSame('true', $this->testResponse->getJSON());
}
public function testInvalidJSON()
public function testGetJSONInvalidJSON()
{
$tmp = ' test " case ';
$this->getTestResponse('<h1>Hello World</h1>');
@ -344,20 +346,24 @@ final class TestResponseTest extends CIUnitTestCase
public function testGetXML()
{
$this->getTestResponse(['foo' => 'bar']);
$formatter = Services::format()->getFormatter('application/xml');
$data = ['foo' => 'bar'];
$this->getTestResponse('');
$this->response->setXML($data);
$this->assertSame($formatter->format(['foo' => 'bar']), $this->testResponse->getXML());
$formatter = Services::format()->getFormatter('application/xml');
$this->assertSame($formatter->format($data), $this->testResponse->getXML());
}
public function testJsonFragment()
public function testAssertJSONFragment()
{
$this->getTestResponse([
$data = [
'config' => [
'key-a',
'key-b',
],
]);
];
$this->getTestResponse('');
$this->response->setJSON($data, true);
$this->testResponse->assertJSONFragment(['config' => ['key-a']]);
$this->testResponse->assertJSONFragment(['config' => ['key-a']], true);
@ -365,9 +371,11 @@ final class TestResponseTest extends CIUnitTestCase
public function testAssertJSONFragmentFollowingAssertArraySubset()
{
$this->getTestResponse([
$data = [
'config' => '124',
]);
];
$this->getTestResponse('');
$this->response->setJSON($data, true);
$this->testResponse->assertJSONFragment(['config' => 124]); // must fail on strict
$this->testResponse->assertJSONFragment(['config' => '124'], true);
@ -383,7 +391,7 @@ final class TestResponseTest extends CIUnitTestCase
$this->testResponse->assertJSONFragment(['foo' => 'bar']);
}
public function testJsonExact()
public function testAssertJsonExactArray()
{
$data = [
'config' => [
@ -391,13 +399,27 @@ final class TestResponseTest extends CIUnitTestCase
'key-b',
],
];
$this->getTestResponse($data);
$this->getTestResponse('');
$this->response->setJSON($data, true);
$this->testResponse->assertJSONExact($data);
}
public function testJsonExactString()
public function testAssertJsonExactObject()
{
$data = (object) [
'config' => [
'key-a',
'key-b',
],
];
$this->getTestResponse('');
$this->response->setJSON($data, true);
$this->testResponse->assertJSONExact($data);
}
public function testAssertJsonExactString()
{
$data = [
'config' => [
@ -405,14 +427,14 @@ final class TestResponseTest extends CIUnitTestCase
'key-b',
],
];
$this->getTestResponse('');
$this->response->setJSON($data, true);
$this->getTestResponse($data);
$formatter = Services::format()->getFormatter('application/json');
$this->testResponse->assertJSONExact($formatter->format($data));
}
protected function getTestResponse($body = null, array $responseOptions = [], array $headers = [])
protected function getTestResponse(?string $body = null, array $responseOptions = [], array $headers = [])
{
$this->response = new Response(new App());
$this->response->setBody($body);

View File

@ -21,8 +21,8 @@ How Does Caching Work?
Caching can be enabled on a per-page basis, and you can set the length
of time that a page should remain cached before being refreshed. When a
page is loaded for the first time, the file will be cached using the
currently configured cache engine. On subsequent page loads, the cache file
page is loaded for the first time, the page will be cached using the
currently configured cache engine. On subsequent page loads, the cache
will be retrieved and sent to the requesting user's browser. If it has
expired, it will be deleted and refreshed before being sent to the
browser.
@ -30,6 +30,33 @@ browser.
.. note:: The Benchmark tag is not cached so you can still view your page
load speed when caching is enabled.
Configuring Caching
===================
Setting Cache Engine
--------------------
Before using Web Page Caching, you must set the cache engine up by editing
**app/Config/Cache.php**. See :ref:`libraries-caching-configuring-the-cache`
for details.
Setting $cacheQueryString
-------------------------
You can set whether or not to include the query string when generating the cache
with ``Config\Cache::$cacheQueryString``.
Valid options are:
- ``false``: (default) Disabled. The query string is not taken into account; the
same cache is returned for requests with the same URI path but different query
strings.
- ``true``: Enabled, take all query parameters into account. Be aware that this
may result in numerous cache generated for the same page over and over
again.
- **array**: Enabled, but only take into account the specified list of query
parameters. E.g., ``['q', 'page']``.
Enabling Caching
================
@ -46,15 +73,12 @@ the order that it appears, so place it wherever it seems most logical to
you. Once the tag is in place, your pages will begin being cached.
.. important:: If you change configuration options that might affect
your output, you have to manually delete your cache files.
.. note:: Before the cache files can be written you must set the cache
engine up by editing **app/Config/Cache.php**.
your output, you have to manually delete your cache.
Deleting Caches
===============
If you no longer wish to cache a file you can remove the caching tag and
If you no longer wish to cache a page you can remove the caching tag and
it will no longer be refreshed when it expires.
.. note:: Removing the tag will not delete the cache immediately. It will

View File

@ -23,6 +23,8 @@ You can grab an instance of the cache engine directly through the Services class
.. literalinclude:: caching/002.php
.. _libraries-caching-configuring-the-cache:
*********************
Configuring the Cache
*********************

View File

@ -377,16 +377,18 @@ destroy()
---------
To clear the current session (for example, during a logout), you may
simply use either PHP's `session_destroy() <https://www.php.net/session_destroy>`_
function, or the library's ``destroy()`` method. Both will work in exactly the
same way:
simply use the library's ``destroy()`` method:
.. literalinclude:: sessions/037.php
.. note:: This must be the last session-related operation that you do
during the same request. All session data (including flashdata and
tempdata) will be destroyed permanently and functions will be
unusable during the same request after you destroy the session.
This method will work in exactly the same way as PHP's
`session_destroy() <https://www.php.net/session_destroy>`_ function.
This must be the last session-related operation that you do during the same request.
All session data (including flashdata and tempdata) will be destroyed permanently.
.. note:: You do not have to call this method from usual code. Cleanup session
data rather than destroying the session.
.. _session-stop:

View File

@ -1,5 +1,3 @@
<?php
session_destroy();
// or
$session->destroy();