Skip to content

Commit

Permalink
Improved code quality
Browse files Browse the repository at this point in the history
Co-Authored-By: Paweł Niedzielski <Steveb-p@users.noreply.github.com>
  • Loading branch information
alongosz and Steveb-p committed Nov 13, 2024
1 parent 298aeab commit e293296
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/bundle/Core/Fragment/DecoratedFragmentRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

class DecoratedFragmentRenderer implements FragmentRendererInterface, SiteAccessAware
{
/** @var \Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface */
private FragmentRendererInterface $innerRenderer;

private ?SiteAccess $siteAccess;
Expand Down
4 changes: 2 additions & 2 deletions src/bundle/Core/Routing/DefaultRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
class DefaultRouter extends Router implements SiteAccessAware
{
protected ?SiteAccess $siteAccess;
protected ?SiteAccess $siteAccess = null;

/** @var string[] */
protected array $nonSiteAccessAwareRoutes = [];
Expand Down Expand Up @@ -80,7 +80,7 @@ public function matchRequest(Request $request): array
*/
public function generate(string $name, array $parameters = [], int $referenceType = self::ABSOLUTE_PATH): string
{
$siteAccess = $this->siteAccess ?? null;
$siteAccess = $this->siteAccess;
$originalContext = $context = $this->getContext();
$isSiteAccessAware = $this->isSiteAccessAwareRoute($name);

Expand Down
17 changes: 15 additions & 2 deletions src/bundle/IO/BinaryStreamResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public function __construct(

/**
* @phpstan-param \Symfony\Component\HttpFoundation\ResponseHeaderBag::DISPOSITION_*|null $contentDisposition
*
* @return $this
*/
public function setFile(BinaryFile $file, ?string $contentDisposition = null, bool $autoLastModified = true): static
{
Expand All @@ -79,6 +81,8 @@ public function getFile(): BinaryFile

/**
* Automatically sets the Last-Modified header according the file modification date.
*
* @return $this
*/
public function setAutoLastModified(): static
{
Expand All @@ -94,6 +98,8 @@ public function setAutoLastModified(): static
*
* @param string $filename Optionally use this filename instead of the real name of the file
* @param string $filenameFallback A fallback filename, containing only ASCII characters. Defaults to an automatically encoded filename
*
* @return $this
*/
public function setContentDisposition(string $disposition, string $filename = '', string $filenameFallback = ''): BinaryStreamResponse
{
Expand All @@ -111,6 +117,9 @@ public function setContentDisposition(string $disposition, string $filename = ''
return $this;
}

/**
* @return $this
*/
public function prepare(Request $request): static
{
$this->headers->set('Content-Length', (string)$this->file->size);
Expand Down Expand Up @@ -144,6 +153,8 @@ public function prepare(Request $request): static
* Sends the file.
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
*
* @return $this
*/
public function sendContent(): static
{
Expand All @@ -170,6 +181,8 @@ public function sendContent(): static

/**
* @throws \LogicException when the content is not null
*
* @return $this
*/
public function setContent(?string $content): static
{
Expand Down Expand Up @@ -216,12 +229,12 @@ private function processRangeRequest(Request $request): void
if ($start < 0 || $end > $fileSize - 1) {
$this->setStatusCode(
Response::HTTP_REQUESTED_RANGE_NOT_SATISFIABLE
); // HTTP_REQUESTED_RANGE_NOT_SATISFIABLE
);
} elseif ($start !== 0 || $end !== $fileSize - 1) {
$this->maxlen = $end < $fileSize ? $end - $start + 1 : -1;
$this->offset = $start;

$this->setStatusCode(Response::HTTP_PARTIAL_CONTENT); // HTTP_PARTIAL_CONTENT
$this->setStatusCode(Response::HTTP_PARTIAL_CONTENT);
$this->headers->set('Content-Range', sprintf('bytes %s-%s/%s', $start, $end, $fileSize));
$this->headers->set('Content-Length', $end - $start + 1);
}
Expand Down

0 comments on commit e293296

Please sign in to comment.