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/topswtwmobile.komma.pro/app/KommaApp/Shop/Routes/RouteResolver.php
<?php

namespace KommaApp\Shop\Routes;

use KommaApp\Shop\ShopResolver;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

class RouteResolver
{
    protected $table = 'routes';
    /**
     * @var ShopResolver
     */
    private $shopResolver;

    function __construct(ShopResolver $shopResolver)
    {
        $this->shopResolver = $shopResolver;
    }

    /*
     * Resolve the new route
     */
    public function resolve()
    {

        //Create route models, these can be send with any route so the model will fill automaticly
        \Route::model('order', 'KommaApp\Shop\Orders\order', function () {

            //Todo: Clean this code so it can use the laravel redirect
//            return \Redirect::url('nl/')->with(['errors' =>['We couldn\'t find this order']]);
            header('Location: /');

            exit;
        });

        // Post routes:
        \Route::post('/{lang}/checkout/process', ['uses' => 'CheckoutController@process']);
        \Route::post('/{lang}/checkout/processPending', ['uses' => 'PaymentController@processPending']);
        \Route::post('/{lang}/customer/createAccount', ['uses' => 'CustomerController@createAccount']);
        \Route::post('/{lang}/customer/login', ['uses' => 'CustomerController@login','as'=>'customer.login']);
        \Route::post('/{lang}/contact/', ['as' => 'contact.form.submit', 'uses' => 'ContactController@submit']);
        \Route::post('/{lang}/return/', ['as' => 'return.form.submit', 'uses' => 'ContactController@returningSubmit']);
        \Route::get('/{lang}/returnordervalidator/', ['as' => 'return.validate.order', 'uses' => 'ContactController@returningValidateOrder']);
        \Route::get('/{lang}/returnarticlenumbervalidator/', ['as' => 'return.validate.articlenumber', 'uses' => 'ContactController@returningValidateArticleNumber']);
        \Route::post('/{lang}/askHelp/', ['as' => 'askHelp.form.submit', 'uses' => 'ContactController@askHelpSubmit']);


        //Dpd
        \Route::post('api/dpd-parcelshops-search', ['as' => 'dpd.parcelshops.search', 'uses' => 'KommaApp\Shop\Dpd\DpdController@searchParcelShops']);
        \Route::get('api/dpd-parcelshops-search', ['as' => 'dpd.parcelshops.search', 'uses' => 'KommaApp\Shop\Dpd\DpdController@searchParcelShops']);

        // Get routes:
        \Route::get('/{lang}/customer/logout', ['uses' => 'CustomerController@logout']);
        \Route::get('/customer/logout', ['uses' => 'CustomerController@logout']);
        \Route::get('/ingenico-template', ['uses' => 'PaymentController@showPaymentProviderTemplate']);
        \Route::get('/check-vat/{vatId}', ['uses' => 'CheckoutController@checkVat']);
        \Route::get('/{lang}/reorder/order/{order}', ['uses' => 'ReOrderController@reOrderOrder', 'as' => 'reorder']);
        \Route::get('/ajax/disable-cookies', ['uses' => 'AjaxController@disableCookieBar']);
        \Route::get('/ajax/disable-language-switch', ['uses' => 'AjaxController@disableLanguageSwitch']);

        \Route::get('{lang}/ajax/translations', ['uses' => 'AjaxController@angularTranslations']);
        \Route::get('/ajax/translations', ['uses' => 'AjaxController@angularTranslations']);
        \Route::get('/api/shipping-costs/{countryCode?}', ['uses' => 'CheckoutController@getShippingCosts']);

        \Route::post('/api/orders/status', ['uses' => 'PaymentController@proccesPaymentProviderPaymentResponse']);
        \Route::get('/api/orders/status', ['uses' => 'PaymentController@proccesPaymentProviderPaymentResponse']);
        \Route::get('sitemap.xml', ['uses' => 'SitemapController@generateXml']);


        //Legacy Routes
        \Route::get('/epages/62839224.sf/{lang}_NL', ['uses' => 'legacyRouteController@redirectUrl']);
        \Route::get('/epages/62839224.sf/{lang}_BE', ['uses' => 'legacyRouteController@redirectUrl']);
        \Route::get('/epages/62839224.sf/{lang}_DE', ['uses' => 'legacyRouteController@redirectUrl']);


        // Get all the routes from the current shop

        //Get the path from the request
        $uri = \Request::path();
        //load the route based on the uri
        if ($route = $this->getRoute($uri)) {

            $routeString = '/' . $route->route . '/{any?}';
            // Replace '//' in case an empty string (f.e. home = //{any?} )
            $routeString = str_replace('//', '/', $routeString);

            \Route::any($routeString, ['as' => '/' . $route->route, function ($any = null) use ($route) {

                //Check if it is an legacy url

                //If there is no routable we return false because we cannot resolve it
                if($route->routeable) return false;

                // Get the controller name through a routable query
                $controller = $route->routable->getController();

                // Set a default method
                $method = null;
                // Check if a method is included in the controller string
                if ($controllerData = $this->parseController($controller)) {
                    $controller = $controllerData['controller'];
                    $method = $controllerData['method'];
                }
               // Return a new controller that allows dependency injection
                return \App::make($controller)->routeProcessor($any, $route, $method);
                // Make sure all the remaining parameters are injected into the method
            }])->where('any', '(.*)?');

        } else {

            if (preg_match('#^kms.*#', $uri)) return false;
            if (!$redirect = \App::make('BaseController')->getLegacyUrl(true)) return false;
            if(!is_string($redirect) && get_class($redirect) == 'Illuminate\Http\RedirectResponse'){
                return $redirect;
                exit;
            }

            $redirect = ltrim($redirect, '/');
            header("HTTP/1.1 301 Moved Permanently");
            header('Location: ' . $redirect);
            exit;
        }
        return false;
    }

    /*
     * Does the controller have a method specified
     */
    private function parseController($controller)
    {
        $temp = explode('@', $controller);
        if (count($temp) > 1) {
            return [
                'controller' => $temp[0],
                'method' => $temp[count($temp) - 1]
            ];
        }
        return false;
    }


    private function getRoute($uri)
    {
        //if uri is / (home) uri is null
        if ($uri == '/') $uri = NULL;
        //dont check kms routes
        if (preg_match('#^kms.*#', $uri)) return false;
        //Check if i can find a route
        if (!$route = Route::whereShopId($this->shopResolver->getShopId())
            ->where('route', '=', $uri)
            ->orderBy('route', 'desc')->first()
        ) {
            //Route not found, retry with a part less
            $route_parts = explode('/', $uri);
            $route_parts = array_slice($route_parts, null, -1);
            if (count($route_parts) < 2) {
                return false;
            }
            return $this->getRoute(implode('/', $route_parts));
        }
        //Route found, return
        return $route;
    }

}