auth = $auth; $this->router = $router; $this->userTable = $userTable; $this->session = $session; } public function process(ServerRequestInterface $request, DelegateInterface $delegate): ResponseInterface { $url_part = explode('/',$request->getServerParams()['HTTP_REFERER'] ?? '/'); $username = $url_part[5]; if (is_null($username)) { $user = $this->auth->getUser() ?: $this->userTable->findBy('username', $request->getAttribute('user')); } else { $user = $this->auth->getUser() ?: $this->userTable->findBy('username', $username); } if (is_null($user)) { (new FlashService($this->session))->error('Vous devez vous connecter pour accéder à cette page'); return new RedirectResponse($this->router->generateUri('auth.login')); } return $delegate->process($request->withAttribute('user', $user)); } }