Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into 4.5
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Oct 10, 2023
2 parents 3e98e2b + 815b802 commit 6f63602
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 35 deletions.
14 changes: 9 additions & 5 deletions system/Autoloader/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,21 @@ public function initialize(Autoload $config, Modules $modules)
}

if (is_file(COMPOSER_PATH)) {
$this->loadComposerInfo($modules);
$this->loadComposerAutoloader($modules);
}

return $this;
}

private function loadComposerInfo(Modules $modules): void
private function loadComposerAutoloader(Modules $modules): void
{
/**
* @var ClassLoader $composer
*/
// The path to the vendor directory.
// We do not want to enforce this, so set the constant if Composer was used.
if (! defined('VENDORPATH')) {
define('VENDORPATH', dirname(COMPOSER_PATH) . DIRECTORY_SEPARATOR);
}

/** @var ClassLoader $composer */
$composer = include COMPOSER_PATH;

$this->loadComposerClassmap($composer);
Expand Down
22 changes: 11 additions & 11 deletions system/CLI/CLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public static function init()
* Named options must be in the following formats:
* php index.php user -v --v -name=John --name=John
*
* @param string $prefix You may specify a string with which to prompt the user.
* @param string|null $prefix You may specify a string with which to prompt the user.
*/
public static function input(?string $prefix = null): string
{
Expand Down Expand Up @@ -210,9 +210,9 @@ public static function input(?string $prefix = null): string
* // Do not provide options but requires a valid email
* $email = CLI::prompt('What is your email?', null, 'required|valid_email');
*
* @param string $field Output "field" question
* @param array|string $options String to a default value, array to a list of options (the first option will be the default value)
* @param array|string $validation Validation rules
* @param string $field Output "field" question
* @param array|string $options String to a default value, array to a list of options (the first option will be the default value)
* @param array|string|null $validation Validation rules
*
* @return string The user input
*
Expand Down Expand Up @@ -258,7 +258,7 @@ public static function prompt(string $field, $options = null, $validation = null
$input = trim(static::input()) ?: $default;

if ($validation) {
while (! static::validate(trim($field), $input, $validation)) {
while (! static::validate('"' . trim($field) . '"', $input, $validation)) {
$input = static::prompt($field, $options, $validation);
}
}
Expand Down Expand Up @@ -448,7 +448,7 @@ public static function print(string $text = '', ?string $foreground = null, ?str
}

/**
* Outputs a string to the cli on it's own line.
* Outputs a string to the cli on its own line.
*
* @return void
*/
Expand Down Expand Up @@ -574,10 +574,10 @@ public static function clearScreen()
* Returns the given text with the correct color codes for a foreground and
* optionally a background color.
*
* @param string $text The text to color
* @param string $foreground The foreground color
* @param string $background The background color
* @param string $format Other formatting to apply. Currently only 'underline' is understood
* @param string $text The text to color
* @param string $foreground The foreground color
* @param string|null $background The background color
* @param string|null $format Other formatting to apply. Currently only 'underline' is understood
*
* @return string The color coded string
*/
Expand Down Expand Up @@ -834,7 +834,7 @@ public static function showProgress($thisStep = 1, int $totalSteps = 10)
* width.
*
* If an int is passed into $pad_left, then all strings after the first
* will padded with that many spaces to the left. Useful when printing
* will pad with that many spaces to the left. Useful when printing
* short descriptions that need to start on an existing line.
*/
public static function wrap(?string $string = null, int $max = 0, int $padLeft = 0): string
Expand Down
5 changes: 5 additions & 0 deletions system/CLI/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace CodeIgniter\CLI;

use CodeIgniter\CodeIgniter;
use Config\App;
use Config\Services;
use Exception;

Expand All @@ -31,6 +32,10 @@ class Console
*/
public function run()
{
// Create CLIRequest
$appConfig = config(App::class);
Services::createRequest($appConfig, true);

$runner = Services::commands();
$params = array_merge(CLI::getSegments(), CLI::getOptions());
$params = $this->parseParamsForHelpOption($params);
Expand Down
2 changes: 1 addition & 1 deletion system/Commands/Utilities/Routes/FilterCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function get(string $method, string $uri): array
];
}

$request = Services::request(null, false);
$request = Services::incomingrequest(null, false);
$request->setMethod($method);

$router = $this->createRouter($request);
Expand Down
2 changes: 2 additions & 0 deletions system/Filters/Filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ public function __construct($config, RequestInterface $request, ResponseInterfac
*
* Sample :
* $filters->aliases['custom-auth'] = \Acme\Blob\Filters\BlobAuth::class;
*
* @deprecated 4.4.2 Use Registrar instead.
*/
private function discoverFilters(): void
{
Expand Down
4 changes: 2 additions & 2 deletions system/Test/ControllerTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ protected function setUpControllerTestTrait(): void
}

if (empty($this->request)) {
// Do some acrobatics so we can use the Request service with our own URI
// Do some acrobatics, so we can use the Request service with our own URI
$tempUri = Services::uri();
Services::injectMock('uri', $this->uri);

$this->withRequest(Services::request($this->appConfig, false));
$this->withRequest(Services::incomingrequest($this->appConfig, false));

// Restore the URI service
Services::injectMock('uri', $tempUri);
Expand Down
2 changes: 1 addition & 1 deletion system/Test/ControllerTester.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ protected function setUpControllerTester(): void
$tempUri = Services::uri();
Services::injectMock('uri', $this->uri);

$this->withRequest(Services::request($this->appConfig, false)->setBody($this->body));
$this->withRequest(Services::incomingrequest($this->appConfig, false)->setBody($this->body));

// Restore the URI service
Services::injectMock('uri', $tempUri);
Expand Down
2 changes: 1 addition & 1 deletion system/Test/FeatureTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ protected function setupRequest(string $method, ?string $path = null): IncomingR

Services::injectMock('uri', $uri);

$request = Services::request($config, false);
$request = Services::incomingrequest($config, false);

$request->setMethod($method);
$request->setProtocolVersion('1.1');
Expand Down
14 changes: 0 additions & 14 deletions system/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,3 @@
// Initialize and register the loader with the SPL autoloader stack.
Services::autoloader()->initialize(new Autoload(), new Modules())->register();
Services::autoloader()->loadHelpers();

// Now load Composer's if it's available
if (is_file(COMPOSER_PATH)) {
/*
* The path to the vendor directory.
*
* We do not want to enforce this, so set the constant if Composer was used.
*/
if (! defined('VENDORPATH')) {
define('VENDORPATH', dirname(COMPOSER_PATH) . DIRECTORY_SEPARATOR);
}

require_once COMPOSER_PATH;
}
6 changes: 6 additions & 0 deletions user_guide_src/source/changelogs/v4.4.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,17 @@ Changes
Deprecations
************

- **Filters:** The Auto-Discovery for Filters and ``Filters::discoverFilters()``
is deprecated. Use :ref:`registrars` instead. See :ref:`modules-filters` for
details.

Bugs Fixed
**********

- **CodeIgniter:** Fixed a bug that returned "200 OK" response status code when
Page Not Found.
- **Spark:** Fixed a bug that caused spark to not display exceptions in the
production mode or to display backtrace in json when an exception occurred.

See the repo's
`CHANGELOG.md <https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md>`_
Expand Down
9 changes: 9 additions & 0 deletions user_guide_src/source/general/modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,18 @@ the **Modules** config file, described above.
When working with modules, it can be a problem if the routes in the application contain wildcards.
In that case, see :ref:`routing-priority`.

.. _modules-filters:

Filters
=======

.. deprecated:: 4.4.2

.. note:: This feature is deprecated. Use :ref:`registrars` instead like the
following:

.. literalinclude:: modules/015.php

By default, :doc:`filters <../incoming/filters>` are automatically scanned for within modules.
It can be turned off in the **Modules** config file, described above.

Expand Down
22 changes: 22 additions & 0 deletions user_guide_src/source/general/modules/015.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace CodeIgniter\Shield\Config;

use CodeIgniter\Shield\Filters\SessionAuth;
use CodeIgniter\Shield\Filters\TokenAuth;

class Registrar
{
/**
* Registers the Shield filters.
*/
public static function Filters(): array
{
return [
'aliases' => [
'session' => SessionAuth::class,
'tokens' => TokenAuth::class,
],
];
}
}

0 comments on commit 6f63602

Please sign in to comment.