/** * @param GetResponseForExceptionEvent $event * @return bool|void */ public function onKernelException(GetResponseForExceptionEvent $event) { static $handling; if (true === $handling) { return false; } $handling = true; $exception = $event->getException(); if ($exception instanceof AccessDeniedHttpException) { if (StringUtils::startsWith($exception->getMessage(), 'Expression "has_role(\'ROLE_')) { $message = 'Bu alana erişebilmek için kullanıcı girişi yapılmalıdır'; $statusCode = 401; } else { $message = $exception->getMessage(); $statusCode = $exception->getStatusCode(); } $exception = new HttpException($statusCode, $message, $exception); $event->setException($exception); parent::onKernelException($event); } elseif ($exception instanceof InsufficientAuthenticationException) { $exception = new AccessDeniedHttpException('Bu alana erişebilmek için geçerli bir kullanıcı kimliği belirtilmelidir', $exception); $event->setException($exception); parent::onKernelException($event); } $handling = false; return false; }
public function test_starts_with_function() { $string = 'guven'; $this->assertTrue(StringUtils::startsWith($string, 'g')); $this->assertTrue(StringUtils::startsWith($string, 'gu')); $this->assertTrue(StringUtils::startsWith($string, 'guv')); $this->assertFalse(StringUtils::startsWith($string, ' guv')); $this->assertFalse(StringUtils::startsWith($string, 'aguv')); }