Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php namespace Pagekit\Kernel\Event; use Pagekit\Kernel\Exception\HttpException; use Sy..

Decoded Output download

<?php

namespace Pagekit\Kernel\Event;

use Pagekit\Kernel\Exception\HttpException;
use Symfony\Component\HttpFoundation\Response;

class ExceptionListenerWrapper
{
    protected $callback;

    /**
     * Constructor.
     *
     * @param mixed $callback
     */
    public function __construct($callback)
    {
        $this->callback = $callback;
    }

    public function __invoke($event)
    {
        $exception = $event->getException();

        if (!$this->shouldRun($exception)) {
            return;
        }

        $code = $exception instanceof HttpException ? $exception->getCode() : 500;

        $response = call_user_func($this->callback, $exception, $code);

        if ($response instanceof Response) {
            $event->setResponse($response);
        }
    }

    protected function shouldRun(\Exception $exception)
    {
        if (is_array($this->callback)) {
            $callbackReflection = new \ReflectionMethod($this->callback[0], $this->callback[1]);
        } elseif (is_object($this->callback) && !$this->callback instanceof \Closure) {
            $callbackReflection = new \ReflectionObject($this->callback);
            $callbackReflection = $callbackReflection->getMethod('__invoke');
        } else {
            $callbackReflection = new \ReflectionFunction($this->callback);
        }

        if ($callbackReflection->getNumberOfParameters() > 0) {
            $parameters = $callbackReflection->getParameters();
            $expectedException = $parameters[0];
            if ($expectedException->getClass() && !$expectedException->getClass()->isInstance($exception)) {
                return false;
            }
        }

        return true;
    }
}
 ?>

Did this file decode correctly?

Original Code

<?php

namespace Pagekit\Kernel\Event;

use Pagekit\Kernel\Exception\HttpException;
use Symfony\Component\HttpFoundation\Response;

class ExceptionListenerWrapper
{
    protected $callback;

    /**
     * Constructor.
     *
     * @param mixed $callback
     */
    public function __construct($callback)
    {
        $this->callback = $callback;
    }

    public function __invoke($event)
    {
        $exception = $event->getException();

        if (!$this->shouldRun($exception)) {
            return;
        }

        $code = $exception instanceof HttpException ? $exception->getCode() : 500;

        $response = call_user_func($this->callback, $exception, $code);

        if ($response instanceof Response) {
            $event->setResponse($response);
        }
    }

    protected function shouldRun(\Exception $exception)
    {
        if (is_array($this->callback)) {
            $callbackReflection = new \ReflectionMethod($this->callback[0], $this->callback[1]);
        } elseif (is_object($this->callback) && !$this->callback instanceof \Closure) {
            $callbackReflection = new \ReflectionObject($this->callback);
            $callbackReflection = $callbackReflection->getMethod('__invoke');
        } else {
            $callbackReflection = new \ReflectionFunction($this->callback);
        }

        if ($callbackReflection->getNumberOfParameters() > 0) {
            $parameters = $callbackReflection->getParameters();
            $expectedException = $parameters[0];
            if ($expectedException->getClass() && !$expectedException->getClass()->isInstance($exception)) {
                return false;
            }
        }

        return true;
    }
}

Function Calls

None

Variables

None

Stats

MD5 4815ad77100e6e282a2d8f6a884a66f6
Eval Count 0
Decode Time 84 ms