designcise/bitframe-whoops

View on GitHub
src/HandlerOptionsAwareTrait.php

Summary

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

/**
 * BitFrame Framework (https://www.bitframephp.com)
 *
 * @author    Daniyal Hamid
 * @copyright Copyright (c) 2017-2023 Daniyal Hamid (https://designcise.com)
 * @license   https://bitframephp.com/about/license MIT License
 */

declare(strict_types=1);

namespace BitFrame\Whoops;

use Whoops\Handler\HandlerInterface;

use function method_exists;

trait HandlerOptionsAwareTrait
{
    abstract public function getOptions(): array;

    /**
     * @param HandlerInterface $errorHandler
     */
    private function applyOptions(HandlerInterface $errorHandler): void
    {
        $options = $this->getOptions();

        foreach ($options as $optionName => $optionVal) {
            if (method_exists($errorHandler, $optionName)) {
                $errorHandler->{$optionName}(...(array) $optionVal);
            }
        }
    }
}