mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
Merge branch 'develop' of github.com:bcit-ci/CodeIgniter4 into develop
This commit is contained in:
commit
3ffa803e9c
@ -310,9 +310,9 @@ class IncomingRequest extends Request
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getVar($index = null, $filter = null)
|
||||
public function getVar($index = null, $filter = null, $flags = null)
|
||||
{
|
||||
return $this->fetchGlobal(INPUT_REQUEST, $index, $filter);
|
||||
return $this->fetchGlobal(INPUT_REQUEST, $index, $filter, $flags);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
@ -362,9 +362,9 @@ class IncomingRequest extends Request
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getGet($index = null, $filter = null)
|
||||
public function getGet($index = null, $filter = null, $flags = null)
|
||||
{
|
||||
return $this->fetchGlobal(INPUT_GET, $index, $filter);
|
||||
return $this->fetchGlobal(INPUT_GET, $index, $filter, $flags);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
@ -377,9 +377,9 @@ class IncomingRequest extends Request
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getPost($index = null, $filter = null)
|
||||
public function getPost($index = null, $filter = null, $flags = null)
|
||||
{
|
||||
return $this->fetchGlobal(INPUT_POST, $index, $filter);
|
||||
return $this->fetchGlobal(INPUT_POST, $index, $filter, $flags);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
@ -392,12 +392,12 @@ class IncomingRequest extends Request
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getPostGet($index = null, $filter = null)
|
||||
public function getPostGet($index = null, $filter = null, $flags = null)
|
||||
{
|
||||
// Use $_POST directly here, since filter_has_var only
|
||||
// checks the initial POST data, not anything that might
|
||||
// have been added since.
|
||||
return isset($_POST[$index]) ? $this->getPost($index, $filter) : $this->getGet($index, $filter);
|
||||
return isset($_POST[$index]) ? $this->getPost($index, $filter, $flags) : $this->getGet($index, $filter, $flags);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
@ -410,12 +410,12 @@ class IncomingRequest extends Request
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getGetPost($index = null, $filter = null)
|
||||
public function getGetPost($index = null, $filter = null, $flags = null)
|
||||
{
|
||||
// Use $_GET directly here, since filter_has_var only
|
||||
// checks the initial GET data, not anything that might
|
||||
// have been added since.
|
||||
return isset($_GET[$index]) ? $this->getGet($index, $filter) : $this->getPost($index, $filter);
|
||||
return isset($_GET[$index]) ? $this->getGet($index, $filter, $flags) : $this->getPost($index, $filter, $flags);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
@ -428,9 +428,9 @@ class IncomingRequest extends Request
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCookie($index = null, $filter = null)
|
||||
public function getCookie($index = null, $filter = null, $flags = null)
|
||||
{
|
||||
return $this->fetchGlobal(INPUT_COOKIE, $index, $filter);
|
||||
return $this->fetchGlobal(INPUT_COOKIE, $index, $filter, $flags);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
@ -484,16 +484,17 @@ class IncomingRequest extends Request
|
||||
*
|
||||
* @return Files\FileCollection
|
||||
*/
|
||||
public function getFiles(): FileCollection
|
||||
public function getFiles()
|
||||
{
|
||||
if (is_null($this->files))
|
||||
{
|
||||
$this->files = new FileCollection();
|
||||
}
|
||||
|
||||
return $this->files;
|
||||
return $this->files->all(); // return all files
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
|
@ -277,9 +277,9 @@ class Request extends Message implements RequestInterface
|
||||
* @param null $filter A filter name to be applied
|
||||
* @return mixed
|
||||
*/
|
||||
public function getServer($index = null, $filter = null)
|
||||
public function getServer($index = null, $filter = null, $flags = null)
|
||||
{
|
||||
return $this->fetchGlobal(INPUT_SERVER, $index, $filter);
|
||||
return $this->fetchGlobal(INPUT_SERVER, $index, $filter, $flags);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
@ -291,9 +291,9 @@ class Request extends Message implements RequestInterface
|
||||
* @param null $filter A filter name to be applied
|
||||
* @return mixed
|
||||
*/
|
||||
public function getEnv($index = null, $filter = null)
|
||||
public function getEnv($index = null, $filter = null, $flags = null)
|
||||
{
|
||||
return $this->fetchGlobal(INPUT_ENV, $index, $filter);
|
||||
return $this->fetchGlobal(INPUT_ENV, $index, $filter, $flags);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
@ -314,7 +314,7 @@ class Request extends Message implements RequestInterface
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function fetchGlobal($type, $index = null, $filter = null)
|
||||
protected function fetchGlobal($type, $index = null, $filter = null, $flags = null )
|
||||
{
|
||||
// Null filters cause null values to return.
|
||||
if (is_null($filter))
|
||||
@ -343,7 +343,7 @@ class Request extends Message implements RequestInterface
|
||||
$values = [];
|
||||
foreach ($loopThrough as $key => $value)
|
||||
{
|
||||
$values[$key] = is_array($value) ? $this->fetchGlobal($type, $key, $filter) : filter_var($value, $filter);
|
||||
$values[$key] = is_array($value) ? $this->fetchGlobal($type, $key, $filter, $flags) : filter_var($value, $filter, $flags);
|
||||
}
|
||||
|
||||
return $values;
|
||||
@ -356,7 +356,7 @@ class Request extends Message implements RequestInterface
|
||||
|
||||
foreach ($index as $key)
|
||||
{
|
||||
$output[$key] = $this->fetchGlobal($type, $key, $filter);
|
||||
$output[$key] = $this->fetchGlobal($type, $key, $filter, $flags);
|
||||
}
|
||||
|
||||
return $output;
|
||||
@ -419,7 +419,7 @@ class Request extends Message implements RequestInterface
|
||||
return $value;
|
||||
}
|
||||
|
||||
return filter_var($value, $filter);
|
||||
return filter_var($value, $filter, $flags);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
@ -161,6 +161,20 @@ class IncomingRequestTest extends \CIUnitTestCase
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
public function testFetchGlobalFilterWithFlagValue()
|
||||
{
|
||||
$_POST = [
|
||||
'foo' => '`bar<script>',
|
||||
'bar' => 'baz',
|
||||
'xxx' => 'yyy',
|
||||
'yyy' => 'zzz'
|
||||
];
|
||||
|
||||
$this->assertEquals('bar%3Cscript%3E', $this->request->getPost('foo', FILTER_SANITIZE_ENCODED, FILTER_FLAG_STRIP_BACKTICK));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
public function testFetchGlobalReturnsAllWhenEmpty()
|
||||
{
|
||||
$post = [
|
||||
@ -196,6 +210,26 @@ class IncomingRequestTest extends \CIUnitTestCase
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
public function testFetchGlobalFilterWithFlagAllValues()
|
||||
{
|
||||
$_POST = [
|
||||
'foo' => '`bar<script>',
|
||||
'bar' => '`baz<script>',
|
||||
'xxx' => '`yyy<script>',
|
||||
'yyy' => '`zzz<script>'
|
||||
];
|
||||
$expected = [
|
||||
'foo' => 'bar%3Cscript%3E',
|
||||
'bar' => 'baz%3Cscript%3E',
|
||||
'xxx' => 'yyy%3Cscript%3E',
|
||||
'yyy' => 'zzz%3Cscript%3E'
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $this->request->getPost(null, FILTER_SANITIZE_ENCODED, FILTER_FLAG_STRIP_BACKTICK));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
public function testFetchGlobalReturnsSelectedKeys()
|
||||
{
|
||||
$_POST = [
|
||||
@ -232,6 +266,24 @@ class IncomingRequestTest extends \CIUnitTestCase
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
public function testFetchGlobalFilterWithFlagSelectedValues()
|
||||
{
|
||||
$_POST = [
|
||||
'foo' => '`bar<script>',
|
||||
'bar' => '`baz<script>',
|
||||
'xxx' => '`yyy<script>',
|
||||
'yyy' => '`zzz<script>'
|
||||
];
|
||||
$expected = [
|
||||
'foo' => 'bar%3Cscript%3E',
|
||||
'bar' => 'baz%3Cscript%3E',
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $this->request->getPost(['foo', 'bar'], FILTER_SANITIZE_ENCODED, FILTER_FLAG_STRIP_BACKTICK));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
public function testStoresDefaultLocale()
|
||||
{
|
||||
$config = new App();
|
||||
|
@ -316,10 +316,11 @@ The methods provided by the parent classes that are available are:
|
||||
:returns: True if the request is an HTTPS request, otherwise false.
|
||||
:rtype: bool
|
||||
|
||||
.. php:method:: getVar([$index = null[, $filter = null])
|
||||
.. php:method:: getVar([$index = null[, $filter = null[, $flags = null]]])
|
||||
|
||||
:param string $index: The name of the variable/key to look for.
|
||||
:param int $filter: The type of filter to apply. A list of filters can be found `here <http://php.net/manual/en/filter.filters.php>`_.
|
||||
:param int $flags: Flags to apply. A list of flags can be found `here <http://php.net/manual/en/filter.filters.flags.php>`_.
|
||||
:returns: $_REQUEST if no parameters supplied, otherwise the REQUEST value if found, or null if not
|
||||
:rtype: mixed|null
|
||||
|
||||
@ -352,28 +353,31 @@ The methods provided by the parent classes that are available are:
|
||||
|
||||
$request->getVar(['field1', 'field2'], FILTER_SANITIZE_STRING);
|
||||
|
||||
.. php:method:: getGet([$index = null[, $filter = null]])
|
||||
.. php:method:: getGet([$index = null[, $filter = null[, $flags = null]]])
|
||||
|
||||
:param string $index: The name of the variable/key to look for.
|
||||
:param int $filter: The type of filter to apply. A list of filters can be found `here <http://php.net/manual/en/filter.filters.php>`_.
|
||||
:param int $flags: Flags to apply. A list of flags can be found `here <http://php.net/manual/en/filter.filters.flags.php>`_.
|
||||
:returns: $_GET if no parameters supplied, otherwise the GET value if found, or null if not
|
||||
:rtype: mixed|null
|
||||
|
||||
This method is identical to ``getVar()``, only it fetches GET data.
|
||||
|
||||
.. php:method:: getPost([$index = null[, $filter = null]])
|
||||
.. php:method:: getPost([$index = null[, $filter = null[, $flags = null]]])
|
||||
|
||||
:param string $index: The name of the variable/key to look for.
|
||||
:param int $filter: The type of filter to apply. A list of filters can be found `here <http://php.net/manual/en/filter.filters.php>`_.
|
||||
:param int $flags: Flags to apply. A list of flags can be found `here <http://php.net/manual/en/filter.filters.flags.php>`_.
|
||||
:returns: $_POST if no parameters supplied, otherwise the POST value if found, or null if not
|
||||
:rtype: mixed|null
|
||||
|
||||
This method is identical to ``getVar()``, only it fetches POST data.
|
||||
|
||||
.. php:method:: getPostGet([$index = null[, $filter = null]])
|
||||
.. php:method:: getPostGet([$index = null[, $filter = null[, $flags = null]]])
|
||||
|
||||
:param string $index: The name of the variable/key to look for.
|
||||
:param int $filter: The type of filter to apply. A list of filters can be found `here <http://php.net/manual/en/filter.filters.php>`_.
|
||||
:param int $flags: Flags to apply. A list of flags can be found `here <http://php.net/manual/en/filter.filters.flags.php>`_.
|
||||
:returns: $_POST if no parameters supplied, otherwise the POST value if found, or null if not
|
||||
:rtype: mixed|null
|
||||
|
||||
@ -383,10 +387,11 @@ The methods provided by the parent classes that are available are:
|
||||
|
||||
$request->getPostGet('field1');
|
||||
|
||||
.. php:method:: getGetPost([$index = null[, $filter = null]])
|
||||
.. php:method:: getGetPost([$index = null[, $filter = null[, $flags = null]]])
|
||||
|
||||
:param string $index: The name of the variable/key to look for.
|
||||
:param int $filter: The type of filter to apply. A list of filters can be found `here <http://php.net/manual/en/filter.filters.php>`_.
|
||||
:param int $flags: Flags to apply. A list of flags can be found `here <http://php.net/manual/en/filter.filters.flags.php>`_.
|
||||
:returns: $_POST if no parameters supplied, otherwise the POST value if found, or null if not
|
||||
:rtype: mixed|null
|
||||
|
||||
@ -396,10 +401,11 @@ The methods provided by the parent classes that are available are:
|
||||
|
||||
$request->getGetPost('field1');
|
||||
|
||||
.. php:method:: getCookie([$index = null[, $filter = NULL]])
|
||||
.. php:method:: getCookie([$index = null[, $filter = null[, $flags = null]]])
|
||||
|
||||
:param mixed $index: COOKIE name
|
||||
:param int $filter: The type of filter to apply. A list of filters can be found `here <http://php.net/manual/en/filter.filters.php>`_.
|
||||
:param int $flags: Flags to apply. A list of flags can be found `here <http://php.net/manual/en/filter.filters.flags.php>`_.
|
||||
:returns: $_COOKIE if no parameters supplied, otherwise the COOKIE value if found or null if not
|
||||
:rtype: mixed
|
||||
|
||||
@ -416,10 +422,11 @@ The methods provided by the parent classes that are available are:
|
||||
function :php:func:`get_cookie()`, this method does NOT prepend
|
||||
your configured ``$config['cookie_prefix']`` value.
|
||||
|
||||
.. php:method:: getServer($index[, $filter = null])
|
||||
.. php:method:: getServer([$index = null[, $filter = null[, $flags = null]]])
|
||||
|
||||
:param mixed $index: Value name
|
||||
:param int $filter: The type of filter to apply. A list of filters can be found `here <http://php.net/manual/en/filter.filters.php>`_.
|
||||
:param int $flags: Flags to apply. A list of flags can be found `here <http://php.net/manual/en/filter.filters.flags.php>`_.
|
||||
:returns: $_SERVER item value if found, NULL if not
|
||||
:rtype: mixed
|
||||
|
||||
|
@ -73,10 +73,11 @@ Class Reference
|
||||
echo $request->method(FALSE); // Outputs: post
|
||||
echo $request->method(); // Outputs: post
|
||||
|
||||
.. php:method:: getServer($index[, $filter = NULL])
|
||||
.. php:method:: getServer([$index = null[, $filter = null[, $flags = null]]])
|
||||
|
||||
:param mixed $index: Value name
|
||||
:param int $filter: The type of filter to apply. A list of filters can be found `here <http://php.net/manual/en/filter.filters.php>`_.
|
||||
:param int $flags: Flags to apply. A list of flags can be found `here <http://php.net/manual/en/filter.filters.flags.php>`_.
|
||||
:returns: $_SERVER item value if found, NULL if not
|
||||
:rtype: mixed
|
||||
|
||||
|
@ -101,12 +101,26 @@ For get the file instance::
|
||||
Multiple files
|
||||
^^^^^^^^^^^^^^
|
||||
|
||||
If there are multiple files with the same name you can use ``getFile()`` ro retrieve every file individually::
|
||||
|
||||
<input type="file" name="images[]" multiple />
|
||||
|
||||
In controller::
|
||||
if($imagefile = $this->request->getFiles())
|
||||
{
|
||||
foreach($imagefile['images'] as $Im)
|
||||
{
|
||||
if ($im->isValid() && ! $im->hasMoved())
|
||||
{
|
||||
$newName = $img->getRandomName();
|
||||
$img->move(WRITEPATH.'uploads', $newName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
where the **images** is loop is from the form field name
|
||||
|
||||
If there are multiple files with the same name you can use ``getFile()`` ro retrieve every file individually::
|
||||
In controller::
|
||||
|
||||
$file1 = $this->request->getFile('images.0');
|
||||
$file2 = $this->request->getFile('images.1');
|
||||
|
||||
@ -120,7 +134,7 @@ In controller::
|
||||
$file1 = $this->request->getFile('my-form.details.avatars.0');
|
||||
$file2 = $this->request->getFile('my-form.details.avatars.1');
|
||||
|
||||
.. note:: For multiple files it is recommended to use the function ``getFiles()``
|
||||
.. note:: using ``getFiles()`` is more appropriate
|
||||
|
||||
=====================
|
||||
Working With the File
|
||||
|
Loading…
x
Reference in New Issue
Block a user