Skip to content

Commit

Permalink
Fix issue with none existing webspace in requestAnalyzer in asnyc pro…
Browse files Browse the repository at this point in the history
…cesses (#710)

* Fix not defined webspace in async processes

* Fix issue with none existing webspace in requestAnalyzer in asnyc processes

* Fix code style config
  • Loading branch information
alexander-schranz authored Nov 26, 2024
1 parent f92f2fb commit 5c8226f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
'phpdoc_to_comment' => [
'ignored_tags' => ['todo', 'var', 'see', 'phpstan-ignore-next-line'],
],
'trailing_comma_in_multiline' => false,
])
->setFinder($finder);

Expand Down
18 changes: 15 additions & 3 deletions Document/Structure/ContentProxyFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Sulu\Component\Content\Compat\StructureInterface;
use Sulu\Component\Content\ContentTypeManagerInterface;
use Sulu\Component\Webspace\Analyzer\Attributes\RequestAttributes;
use Sulu\Component\Webspace\Webspace;
use Symfony\Component\HttpFoundation\RequestStack;

/**
Expand Down Expand Up @@ -144,12 +145,23 @@ private function getWebspaceKey(): ?string
return null;
}

/** @var RequestAttributes $attributes */
$attributes = $request->attributes->get('_sulu');
if (!$attributes) {
if (!$attributes instanceof RequestAttributes) {
return null;
}

return $attributes->getAttribute('webspaceKey') ?? $attributes->getAttribute('webspace')->getKey();
$webspaceKey = $attributes->getAttribute('webspaceKey');
if (\is_string($webspaceKey) && '' !== $webspaceKey) {
return $webspaceKey;
}

$webspace = $attributes->getAttribute('webspace');
if ($webspace instanceof Webspace) {
return $webspace->getKey();
} elseif (\is_string($webspace) && '' !== $webspace) {
return $webspace;
}

return null;
}
}
5 changes: 0 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -1460,11 +1460,6 @@ parameters:
count: 1
path: Document/Structure/ContentProxyFactory.php

-
message: "#^Negated boolean expression is always false\\.$#"
count: 1
path: Document/Structure/ContentProxyFactory.php

-
message: "#^Parameter \\#1 \\$webspace of method Sulu\\\\Component\\\\Content\\\\Compat\\\\StructureInterface\\:\\:setWebspaceKey\\(\\) expects string, string\\|null given\\.$#"
count: 2
Expand Down

0 comments on commit 5c8226f

Please sign in to comment.