Skip to content
This repository was archived by the owner on Nov 10, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ Simple bridge between Symfony and RoadRunner without PSR7 layer (HttpClient).

```php
<?php
require __DIR__ . "/vendor/autoload.php";
require __DIR__.'/vendor/autoload.php';

if (!isset($_SERVER['APP_ENV']) && !isset($_ENV['APP_ENV'])) {
if (!isset($_SERVER['APP_ENV'], $_ENV['APP_ENV'])) {
if (!class_exists(\Symfony\Component\Dotenv\Dotenv::class)) {
throw new \RuntimeException(
'APP_ENV environment variable is not defined. You need to define environment variables for configuration or add "symfony/dotenv" as a Composer dependency to load variables from a .env file.'
);
}
(new \Symfony\Component\Dotenv\Dotenv())->load(__DIR__ . '/.env');
(new \Symfony\Component\Dotenv\Dotenv(false))->load(__DIR__ . '/.env');
}


Expand Down
48 changes: 24 additions & 24 deletions src/SymfonyIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,13 @@ public function processRequest(array $ctx, $body): array
$this->_symfonyRequest = $this->buildSymfonyRequest($ctx, $body);
$this->_symfonyResponse = $this->_kernel->handle($this->_symfonyRequest);

if (!$this->_symfonyRequest->cookies->has(\session_name())) {
$sessionName = \session_name();

if (!$this->_symfonyRequest->cookies->has($sessionName)) {
$container = $this->_kernel->getContainer();
$cookieOptions = $container->hasParameter('session.storage.options') ? $container->getParameter('session.storage.options') : [];
$this->_symfonyResponse->headers->setCookie(new Cookie(
\session_name(),
$sessionName,
\session_id(),
$cookieOptions['cookie_lifetime'] ?? 0,
$cookieOptions['cookie_path'] ?? '/',
Expand Down Expand Up @@ -179,28 +181,26 @@ private function buildResponse(Response $response): array
$body = '';
if ($response instanceof BinaryFileResponse) {
$body = file_get_contents($response->getFile()->getPathname());
} else {
if ($response instanceof StreamedResponse) {
ob_start(function ($buffer) use (&$body) {
$body .= $buffer;
} elseif ($response instanceof StreamedResponse) {
ob_start(static function ($buffer) use (&$body) {
$body .= $buffer;

return '';
});
return '';
});

$response->sendContent();
ob_end_clean();
} else {
$body = $response->getContent();
}
$response->sendContent();
ob_end_clean();
} else {
$body = $response->getContent();
}

$headers = $response->headers->all();
if (!isset($headers['Set-Cookie']) && !isset($headers['set-cookie'])) {
if (!isset($headers['Set-Cookie'], $headers['set-cookie'])) {
$cookies = $response->headers->getCookies();
if (!empty($cookies)) {
$headers['Set-Cookie'] = [];
foreach ($cookies as $cookie) {
$headers['Set-Cookie'][] = $cookie->__toString();
$headers['Set-Cookie'][] = (string) $cookie;
}
}
}
Expand Down Expand Up @@ -241,7 +241,7 @@ private function configureServer(array $ctx): array
$server['HTTP_HOST'] = $server['SERVER_NAME'] . ':' . $server['SERVER_PORT'];
foreach ($ctx['headers'] as $key => $value) {
$key = strtoupper(str_replace('-', '_', $key));
if (\in_array($key, ['CONTENT_TYPE', 'CONTENT_LENGTH'])) {
if (\in_array($key, ['CONTENT_TYPE', 'CONTENT_LENGTH'], true)) {
$server[$key] = implode(', ', $value);
} else {
$server['HTTP_' . $key] = implode(', ', $value);
Expand All @@ -257,7 +257,7 @@ private function configureServer(array $ctx): array
* @param array $uploads Array of files from RR request
* @return array $_FILES style array
*/
private function prepareFiles(array $uploads)
private function prepareFiles(array $uploads): array
{
foreach ($uploads as $key => &$file) {
$file['tmp_name'] = $file['tmpName'];
Expand All @@ -274,7 +274,7 @@ private function prepareFiles(array $uploads)
* @param string $path
* @return string
*/
private function filterPath($path)
private function filterPath(string $path): string
{
$path = preg_replace_callback(
'/(?:[^a-zA-Z0-9_\-\.~\pL)(:@&=\+\$,\/;%]+|%(?![A - Fa - f0 - 9]{2}))/u',
Expand All @@ -297,22 +297,22 @@ private function filterPath($path)
}

/**
* Filter a query string to ensure it is propertly encoded.
* Filter a query string to ensure it is properly encoded.
*
* Ensures that the values in the query string are properly urlencoded.
*
* @param string $query
* @return string
*/
private function filterQuery($query)
private function filterQuery(string $query): string
{
if ('' !== $query && strpos($query, '?') === 0) {
$query = substr($query, 1);
}

$parts = explode('&', $query);
foreach ($parts as $index => $part) {
list($key, $value) = $this->splitQueryValue($part);
[$key, $value] = $this->splitQueryValue($part);
if ($value === null) {
$parts[$index] = $this->filterQueryOrFragment($key);
continue;
Expand All @@ -333,7 +333,7 @@ private function filterQuery($query)
* @param string $value
* @return array A value with exactly two elements, key and value
*/
private function splitQueryValue($value)
private function splitQueryValue(string $value): array
{
$data = explode(' = ', $value, 2);
if (!isset($data[1])) {
Expand All @@ -348,7 +348,7 @@ private function splitQueryValue($value)
* @param string $value
* @return string
*/
private function filterQueryOrFragment($value)
private function filterQueryOrFragment(string $value): string
{
return preg_replace_callback(
' / (?:[^a-zA-Z0-9_\-\.~\pL!\$ & \'\(\)\*\+,;=%:@\/\?]+|%(?![A-Fa-f0-9]{2}))/u',
Expand All @@ -363,7 +363,7 @@ private function filterQueryOrFragment($value)
* @param array $matches
* @return string
*/
private function urlEncodeChar(array $matches)
private function urlEncodeChar(array $matches): string
{
return rawurlencode($matches[0]);
}
Expand Down