jeyroik/extas-api

View on GitHub
src/components/routes/THasDispatcher.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php
namespace extas\components\routes;

use extas\components\exceptions\MissedOrUnknown;
use extas\components\THasClass;

trait THasDispatcher
{
    use THasClass;

    public function buildDispatcher(...$params): mixed
    {
        $params[] = $this;
        $className = $this->getClass();
        $class = class_exists($className)
            ? new $className(...$params)
            : $this->getByMagic($className, $params);

        if (!$class) {
            throw new MissedOrUnknown('class "' . $className . '"');
        }

        return $class;
    }
}