Skip to content

Commit

Permalink
Merge pull request #177 from mezzio/3.19.x-merge-up-into-4.0.x_CKtmHqxE
Browse files Browse the repository at this point in the history
Merge release 3.19.0 into 4.0.x
  • Loading branch information
gsteel committed Feb 14, 2024
2 parents 5ee2c03 + e9bbc0a commit a407e86
Show file tree
Hide file tree
Showing 11 changed files with 250 additions and 223 deletions.
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@
"laminas/laminas-coding-standard": "~2.5.0",
"laminas/laminas-diactoros": "^3.3.0",
"laminas/laminas-servicemanager": "^3.22.1",
"mezzio/mezzio-aurarouter": "^3.6",
"mezzio/mezzio-aurarouter": "^3.7",
"mezzio/mezzio-fastroute": "^3.11",
"mezzio/mezzio-laminasrouter": "^3.8",
"phpunit/phpunit": "^10.4.2",
"mezzio/mezzio-laminasrouter": "^3.9",
"phpunit/phpunit": "^10.5.9",
"psalm/plugin-phpunit": "^0.18.4",
"vimeo/psalm": "^5.15.0"
"vimeo/psalm": "^5.21.1"
},
"conflict": {
"container-interop/container-interop": "<1.2.0",
Expand Down
409 changes: 218 additions & 191 deletions composer.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/book/v1/why-mezzio.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ about how things work, yet they're very broad and general. What’s more, it
also has several pre-wired structures in place that may either aid you &mdash;
or get in your way.

As a result, you are required to know a lot of what those things are &mdash; *if* you
As a result, you are required to know a lot of what those things are &mdash; _if_ you
want to use it optimally. And to acquire that depth of knowledge, you’re going
to need to spend a lot of time digging deep into laminas-mvc’s internals before
you begin to get the most out of it.
Expand Down
2 changes: 1 addition & 1 deletion docs/book/v2/why-mezzio.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ about how things work, yet they're very broad and general. What’s more, it
also has several pre-wired structures in place that may either aid you &mdash;
or get in your way.

As a result, you are required to know a lot of what those things are &mdash; *if* you
As a result, you are required to know a lot of what those things are &mdash; _if_ you
want to use it optimally. And to acquire that depth of knowledge, you’re going
to need to spend a lot of time digging deep into laminas-mvc’s internals before
you begin to get the most out of it.
Expand Down
2 changes: 1 addition & 1 deletion docs/book/v3/why-mezzio.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ about how things work, yet they're very broad and general. What’s more, it
also has several pre-wired structures in place that may either aid you &mdash;
or get in your way.

As a result, you are required to know a lot of what those things are &mdash; *if* you
As a result, you are required to know a lot of what those things are &mdash; _if_ you
want to use it optimally. And to acquire that depth of knowledge, you’re going
to need to spend a lot of time digging deep into laminas-mvc’s internals before
you begin to get the most out of it.
Expand Down
13 changes: 2 additions & 11 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.15.0@5c774aca4746caf3d239d9c8cadb9f882ca29352">
<files psalm-version="5.21.1@8c473e2437be8b6a8fd8f630f0f11a16b114c494">
<file src="src/Application.php">
<MixedArgumentTypeCoercion>
<code>$middleware</code>
Expand All @@ -11,32 +11,24 @@
<file src="src/Container/ApplicationConfigInjectionDelegator.php">
<DocblockTypeContradiction>
<code>! is_array($item)</code>
<code>! is_array($routes)</code>
<code>1</code>
<code>is_array($methods)</code>
<code>is_object($item)</code>
</DocblockTypeContradiction>
<MixedArgument>
<code>$name</code>
</MixedArgument>
<MixedAssignment>
<code>$name</code>
<code>$serial</code>
</MixedAssignment>
<MixedOperand>
<code>$serial</code>
</MixedOperand>
<RedundantCastGivenDocblockType>
<code>(array) $config</code>
<code>(array) $config</code>
</RedundantCastGivenDocblockType>
<RedundantConditionGivenDocblockType>
<code>gettype($item)</code>
<code><![CDATA[is_int($item['priority'])]]></code>
<code><![CDATA[isset($item['priority']) && is_int($item['priority'])]]></code>
</RedundantConditionGivenDocblockType>
<TypeDoesNotContainType>
<code><![CDATA[! is_array($config['routes'])]]></code>
</TypeDoesNotContainType>
</file>
<file src="src/Container/ApplicationFactory.php">
<MixedArgument>
Expand Down Expand Up @@ -195,7 +187,6 @@
</file>
<file src="test/Container/ApplicationConfigInjectionDelegatorTest.php">
<MixedAssignment>
<code>$middleware</code>
<code>$pipeline</code>
</MixedAssignment>
</file>
Expand Down
2 changes: 1 addition & 1 deletion src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function run(): void
*/
public function pipe($middlewareOrPath, $middleware = null): void
{
$middleware = $middleware ?: $middlewareOrPath;
$middleware = $middleware ?? $middlewareOrPath;
$path = $middleware === $middlewareOrPath ? '/' : $middlewareOrPath;

$middleware = $path !== '/'
Expand Down
20 changes: 13 additions & 7 deletions src/Container/ApplicationConfigInjectionDelegator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use function array_key_exists;
use function array_map;
use function array_reduce;
use function get_debug_type;
use function gettype;
use function is_array;
use function is_int;
Expand Down Expand Up @@ -76,10 +77,13 @@ public function __invoke(ContainerInterface $container, string $serviceName, cal
*/
$config = $container->get('config');

if (! empty($config['middleware_pipeline'])) {
$config['middleware_pipeline'] ??= [];
$config['routes'] ??= [];

if ($config['middleware_pipeline'] !== []) {
self::injectPipelineFromConfig($application, (array) $config);
}
if (! empty($config['routes'])) {
if ($config['routes'] !== []) {
self::injectRoutesFromConfig($application, (array) $config);
}

Expand Down Expand Up @@ -142,7 +146,8 @@ public function __invoke(ContainerInterface $container, string $serviceName, cal
*/
public static function injectPipelineFromConfig(Application $application, array $config): void
{
if (empty($config['middleware_pipeline'])) {
$middlewarePipeline = $config['middleware_pipeline'] ?? [];
if ($middlewarePipeline === []) {
return;
}

Expand All @@ -152,7 +157,7 @@ public static function injectPipelineFromConfig(Application $application, array
* @psalm-var SplPriorityQueue<int, MiddlewareSpec> $queue
*/
$queue = array_reduce(
array_map(self::createCollectionMapper(), $config['middleware_pipeline']),
array_map(self::createCollectionMapper(), $middlewarePipeline),
self::createPriorityQueueReducer(),
new SplPriorityQueue()
);
Expand Down Expand Up @@ -204,11 +209,12 @@ public static function injectPipelineFromConfig(Application $application, array
*/
public static function injectRoutesFromConfig(Application $application, array $config): void
{
if (empty($config['routes']) || ! is_array($config['routes'])) {
$routes = $config['routes'] ?? [];
if (! is_array($routes) || $routes === []) {
return;
}

foreach ($config['routes'] as $key => $spec) {
foreach ($routes as $key => $spec) {
if (! isset($spec['path']) || ! isset($spec['middleware'])) {
continue;
}
Expand Down Expand Up @@ -268,7 +274,7 @@ private static function createCollectionMapper(): callable
throw new InvalidArgumentException(sprintf(
'Invalid pipeline specification received; must be an array'
. ' containing a middleware key; received %s',
is_object($item) ? $item::class : gettype($item)
get_debug_type($item),
));
}
return $item;
Expand Down
6 changes: 5 additions & 1 deletion test/Container/ApplicationConfigInjectionDelegatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,16 @@ public static function assertRoute(array $spec, array $routes): void
);
}

/**
* @param class-string<MiddlewareInterface> $class
* @param iterable<array-key, MiddlewareInterface> $pipeline
*/
public static function assertPipelineContainsInstanceOf(
string $class,
iterable $pipeline,
?string $message = null
): void {
$message = $message ?: 'Did not find expected middleware class type in pipeline';
$message = $message ?? 'Did not find expected middleware class type in pipeline';
$found = false;

foreach ($pipeline as $middleware) {
Expand Down
5 changes: 2 additions & 3 deletions test/Container/WhoopsFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@ public function setUp(): void

public function assertWhoopsContainsHandler(string $type, Whoops $whoops, ?string $message = null): void
{
$message = $message ?: sprintf('Failed to assert whoops runtime composed handler of type %s', $type);
$message = $message ?? sprintf('Failed to assert whoops runtime composed handler of type %s', $type);
$r = new ReflectionProperty($whoops, 'handlerStack');
$r->setAccessible(true);
$stack = $r->getValue($whoops);
$stack = $r->getValue($whoops);

$found = false;
foreach ($stack as $handler) {
Expand Down
4 changes: 2 additions & 2 deletions test/Middleware/ErrorResponseGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public function testRendersTemplateWithoutErrorDetailsWhenRendererPresentAndNotI

$this->request->method('getUri')->willReturn(new Uri('https://example.com/foo'));

$generator = $template
$generator = $template !== null
? new ErrorResponseGenerator(false, $this->renderer, $template)
: new ErrorResponseGenerator(false, $this->renderer);

Expand Down Expand Up @@ -196,7 +196,7 @@ public function testRendersTemplateWithErrorDetailsWhenRendererPresentAndInDebug

$this->request->method('getUri')->willReturn(new Uri('https://example.com/foo'));

$generator = $template
$generator = $template !== null
? new ErrorResponseGenerator(true, $this->renderer, $template)
: new ErrorResponseGenerator(true, $this->renderer);

Expand Down

0 comments on commit a407e86

Please sign in to comment.