HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/douven.komma.pro/app/KommaApp/Routes/AbstractRouteService.php
<?php
namespace App\KommaApp\Routes;


use App\KommaApp\Kms\Core\AbstractTranslatableModel;
use App\KommaApp\Routes\Models\Route;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Query\Builder;

abstract class AbstractRouteService
{
    /** @var string $routeClass The regular route class*/
    private $routeClass;

    /** @var string $redirectRouteClass The route class used for http redirects */
    private $redirectRouteClass;

    public function __construct()
    {
    }

    /**
     * Creates or updates a route for a model.
     *
     * @param AbstractTranslatableModel $model
     * @return AbstractRouteService|array
     */
    abstract public function createOrUpdateRoutesForModelIfChanged(Model $model):AbstractRouteService;

    abstract public function getRouteByAlias(string $alias,bool $mustBeActive = false, string $routeInterfaceNameToReturn = null): ?Model;

    /**
     * Returns the route whom alias is /
     *
     * @throws \RuntimeException when the route does not exist
     * @return Route $route The Root route;
     */
    abstract public function getRootRoute():RouteModelInterface;

    /**
     * @return string|Builder
     */
    public function getRouteClassName(): string
    {
        return $this->routeClass;
    }

    /**
     * @param string $routeClassName
     * @return AbstractRouteService
     */
    public function setRouteClassName($routeClassName)
    {
        if(!$this->checkIfItIsARouteInstance($routeClassName)) throw new \RuntimeException("The implementation of AbstractRouteService '".get_class($this)."' expected a RouteModel class name but got a non existing one.");

        $this->routeClass = $routeClassName;
        return $this;
    }

    /**
     * @return string|Builder
     */
    public function getRedirectRouteClassName(): string
    {
        return $this->redirectRouteClass;
    }

    /**
     * @param string $redirectRouteClass
     * @return AbstractRouteService
     */
    public function setRedirectRouteClassName(string $redirectRouteClass)
    {
        if(!$this->checkIfItIsARedirectRouteClass($redirectRouteClass)) throw new \RuntimeException("The implementation of an AbstractRouteService '".get_class($this)."' expected a RedirectRouteModelInterface instance but got a non existing one.");

        $this->redirectRouteClass = $redirectRouteClass;

        return $this;
    }

    /**
     * Checks if the given class instance is a Route class. That is a class who's implementing the RouteModelInterface.
     * Returns true if it is. False otherwise
     *
     * @see RouteModelInterface
     * @param object|string $object The class to check
     * @return bool
     */
    public function checkIfItIsARouteInstance($object)
    {
        if(!is_object($object)) {
            if(class_exists($object))
                $object = new $object;
            else
                return false;
        }
        if(!is_a($object, RouteModelInterface::class)) return false;
        return true;
    }

    /**
     * Checks if the given class instance is a Redirect route class. That is a class who's implementing the RedirectRouteModelInterface.
     * Returns true if it is. False otherwise
     *
     * @see RedirectRouteModelInterface
     * @param object|string $object The class to check
     * @return bool
     */
    public function checkIfItIsARedirectRouteClass($object)
    {
        if(!is_object($object)) {
            if(class_exists($object))
                $object = new $object;
            else
                return false;
        }
        if(!is_a($object, RedirectRouteModelInterface::class)) return false;
        return true;
    }
}