Registers the error handler.

@param self|null $handler The handler to register
@param bool      $replace Whether to replace or not any existing handler

@return self The registered error handler
480887
public static function register(self $handler = null, $replace = true)
    {
        if (null === self::$reservedMemory) {
            self::$reservedMemory = str_repeat('x', 10240);
            register_shutdown_function(__CLASS__.'::handleFatalError');
        }

        if ($handlerIsNew = null === $handler) {
            $handler = new static();
        }

        if (null === $prev = set_error_handler(array($handler, 'handleError'))) {
            restore_error_handler();
            // Specifying the error types earlier would expose us to https://bugs.php.net/63206
            set_error_handler(array($handler, 'handleError'), $handler->thrownErrors | $handler->loggedErrors);
            $handler->isRoot = true;
        }

        if ($handlerIsNew && is_array($prev) && $prev[0] instanceof self) {
            $handler = $prev[0];
            $replace = false;
        }
        if ($replace || !$prev) {
            $handler->setExceptionHandler(set_exception_handler(array($handler, 'handleException')));
        } else {
            restore_error_handler();
        }

        $handler->throwAt(E_ALL & $handler->thrownErrors, true);

        return $handler;
    }
730379
public function addHandler(callable $handler, $name = null)
    {
        if ($name) {
            $this->handlers[$name] = $handler;
        } else {
            $this->handlers[] = $handler;
        }

        return $this;
    }
55588
public function handleError($errNo, $errStr, $errFile, $errLine, $errContext = array(), Metadata $metadata = null)
	{
		if (0 === error_reporting())
		{
			return $this;
		}

		$error    = new ErrorException($errStr, $errNo, $errFile, $errLine, $errContext);
		$metadata = $this->getMetadata($metadata, $error);

		if (false === $this->shouldHandle($metadata))
		{
			return $this;
		}

		$categories = $metadata->getCategories();

		foreach ($this->handlerManager->all($categories) as $handler)
		{
			$handler->handleError($error, $metadata);
		}

		$this->stats->addError();

		return $this;
	}
798118
public function use_default_handler( HandlerInterface $handler = NULL ) {

		static $done = FALSE;
		if ( $done ) {
			return $this;
		}

		$done = TRUE;

		add_action(
			HandlersRegistry::ACTION_REGISTER,
			function ( HandlersRegistry $registry ) use ( $handler ) {

				$handler = DefaultHandlerFactory::with_default_handler( $handler )
					->create_default_handler();

				$registry->add_handler( $handler, HandlersRegistry::DEFAULT_NAME );
			},
			1
		);

		return $this;
	}
858816
public function instantiate(string $handler) : EventHandler
    {
        if (false === isset($this->handlers[$handler])) {
            throw new InvalidArgumentException(
                sprintf('Handler %s could not be found. Did you register it?', $handler)
            );
        }

        $callable = $this->handlers[$handler];

        return ($callable instanceof \Closure) ? $callable() : new $callable();
    }
405138
public void register(String pattern, HttpRequestHandler handler) {
        registry.register(pattern, handler);
        registry.register(pattern + "/", handler);
    }
517154
public function handler($handler, $construct = null)
    {
        $this->handler   = $handler;
        $this->construct = $construct;
        return $this;
    }
106852
public function override(string $name, $handler): void
	{
		$this->clear($name);

		$this->register($name, $handler);
	}
557529
public function add(string $signal, callable $handler): self
    {
        $this->handlers[$signal] = $handler;

        return $this;
    }
791131
public function addFatalErrorHandler($handler) {
        if ( ! $handler instanceof INativeErrorHandler && ! is_callable($handler)) {
            throw new InvalidHandlerType(
                s('Fatal error handler must be a callable or an instance of %s.',
                    INativeErrorHandler::class)
            );
        }

        if (is_callable($handler)) {
            $handler = $this->createNativeErrorHandler($handler);
        }

        $this->fatalErrorHandlers[] = $handler;
    }
670711
public function addReplace($replace, $version = '*', $overwrite = false)
    {
        if (!isset($this->getReplace()->$replace) || $overwrite) {
            $this->getReplace()->$replace = $version;
        }

        return $this;
    }
784689
public function withHandler($handler): self
    {
        return tap($this, function ($request) use ($handler) {
            return $this->handler = $handler;
        });
    }
927733
function registerHandler( $handler )
    {
        if ( !$this->isKeyBased() and $handler->isKeyBased() )
        {
            eZDebug::writeError( "Cannot register keybased handler for non-keybased group", "eZTranslatorGroup" );
            return false;
        }
        $this->Handlers[] = $handler;
        return true;
    }
101058
private function phpErrorHandler(): Closure
    {
        return static function (int $errno, string $errstr, string $errfile, int $errline): bool {
            // Ignore errors that are silenced with '@'
            if (error_reporting() & $errno) {
                throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
            }

            return true;
        };
    }
672927
function setExceptionHandler(callable $handler)
    {
        $ExceptionHandler = new TransferHandle;
        $ExceptionHandler->setWhoopsHandle($handler);
        $this->container->set(SysConst::HTTP_EXCEPTION_HANDLER, $ExceptionHandler);
    }
1291472
private function registerErrorHandler(): void
    {
        $whoops = new Run();
        $whoops->pushHandler(new PrettyPageHandler());
        $whoops->register();

        $this->errorHandler = $whoops;
    }
503508
protected function registerErrorHandler(&$config)
    {
        if (Zilf_ENABLE_ERROR_HANDLER) {
            if (!isset($config['components']['errorHandler']['class'])) {
                echo "Error: no errorHandler component is configured.\n";
                exit(1);
            }
            $this->set('errorHandler', $config['components']['errorHandler']);
            unset($config['components']['errorHandler']);
            $this->getErrorHandler()->register();
        }
    }