Created
July 8, 2022 11:20
-
-
Save sorenmalling/0420a7afdf9b71a8ddb6a943459df5b1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace Dafis\Application\Middleware; | |
use Psr\Http\Message\ResponseInterface; | |
use Psr\Http\Server\MiddlewareInterface; | |
use Psr\Http\Message\ServerRequestInterface; | |
use Psr\Http\Server\RequestHandlerInterface; | |
use TYPO3\CMS\Core\Utility\MathUtility; | |
class CompanyIdentifierResolver implements MiddlewareInterface | |
{ | |
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface | |
{ | |
$path = ltrim($request->getUri()->getPath(), '/'); | |
if (empty($path)) { | |
return $handler->handle($request); | |
} | |
$pathParts = explode('/', $path); | |
$companyCandidate = $pathParts[0]; | |
if (MathUtility::canBeInterpretedAsInteger($companyCandidate)) { | |
$request = $request->withAttribute('company_id', (int) $companyCandidate); | |
$uri = $request->getUri(); | |
array_shift($pathParts); | |
$uri = $uri->withPath('/' . implode('/', $pathParts)); | |
$request = $request->withUri($uri); | |
} | |
return $handler->handle($request); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
return [ | |
'frontend' => [ | |
'dafis/application/company-identifier-resolver' => [ | |
'target' => \Dafis\Application\Middleware\CompanyIdentifierResolver::class, | |
'before' => [ | |
'typo3/cms-frontend/site' | |
] | |
] | |
] | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment