k911/swoole-bundle

View on GitHub
src/Bridge/Symfony/ErrorHandler/ThrowableHandlerFactory.php

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
<?php

declare(strict_types=1);

namespace K911\Swoole\Bridge\Symfony\ErrorHandler;

use ReflectionClass;
use ReflectionMethod;
use Symfony\Component\HttpKernel\HttpKernel;

final class ThrowableHandlerFactory
{
    public static function newThrowableHandler(): ReflectionMethod
    {
        $kernelReflection = new ReflectionClass(HttpKernel::class);
        $method = $kernelReflection->hasMethod('handleThrowable') ?
            $kernelReflection->getMethod('handleThrowable') : $kernelReflection->getMethod('handleException');
        $method->setAccessible(true);

        return $method;
    }
}