File: D:/HostingSpaces/SBogers10/ijzerenman.komma.pro/app/Custom/Routes/RouteResolver.php
<?php
namespace Komma\Routes;
use Komma\Pages\PageEntity;
class RouteResolver
{
/**
* @var PageEntity
*/
private $pageEntity;
/**
* @var RouteRepository
*/
private $routeRepository;
/**
* @param PageEntity $pageEntity
* @param RouteRepository $routeRepository
*/
public function __construct(PageEntity $pageEntity, RouteRepository $routeRepository)
{
$this->pageEntity = $pageEntity;
$this->routeRepository = $routeRepository;
}
/*
* Resolve the new route
*/
public function resolve()
{
// // Fetch other domains
// $this->redirectOtherDomains();
// // Fetch old routes
// $this->redirectOldPages();
\Route::get('robots.txt', ['uses'=>'Komma\Seo\SEOController@robots']);
// Ajax calls
\Route::get('updateMenu', ['uses' => 'Komma\Controllers\AjaxController@updateMenu']);
\Route::get('updateBreadcrumb', ['uses' => 'Komma\Controllers\AjaxController@updateBreadcrumb']);
// Form submits
\Route::post('form/reservation/process', ['as' => 'form.reserve.process', 'uses' => 'Komma\Forms\Types\ReservationController@process']);
\Route::post('form/call-me-back/process', ['as' => 'form.callMeBack.process', 'uses' => 'Komma\Forms\Types\CallMeBackController@process']);
\Route::post('form/offer/process', ['as' => 'form.offer.process', 'uses' => 'Komma\Forms\Types\OfferController@process']);
\Route::post('form/contact/process', ['as' => 'form.contact.process', 'uses' => 'Komma\Forms\Types\ContactController@process']);
\Route::post('newsletter/subscribe',['as' => 'newsletter.subscribe', 'uses' => 'Komma\Forms\Types\NewsletterController@subscribe']);
//Sitemap
\Route::get('sitemap.xml',['uses'=>'Komma\Sitemap\SitemapController@generateXml']);
// Get all routes
$routes = $this->routeRepository->all();
// Add extra route for the homepage
$home = $this->routeRepository->getHome();
$home->route = '';
$routes[] = $home;
foreach($routes as $route => $data)
{
// Search for the route
\Route::get($data->route, [ 'as' => '/' . $data->route, function($any = null) use ($data)
{
// Get the controller name through a routable query
$controller = $data->routable->getController();
if(empty($controller)) $controller = 'Komma\Pages\PageController';
// 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($data,$method);
}])->where('any', '(.*)?');
}
}
/**
* @param $pages
* @return array
*/
private function sortRoutes($pages)
{
$sort = [];
foreach($pages as $page => $data)
{
$route = \Lang::get('pages.' . $page . '.route');
$exploded = explode('/',$route);
$numSlashes = count($exploded) - 1;
$sort[$numSlashes][$page] = $data;
}
krsort($sort);
$pages = [];
foreach($sort as $data)
{
$pages = array_merge($pages,$data);
}
return $pages;
}
/*
* 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;
}
/**
* Redirect old links to the new pages
*/
private function redirectOldPages()
{
$location = false;
switch(\Request::path())
{
case 'acties/ijzerenman':
$location = '';
break;
case 'acties/ijzeren-man-strandbad':
$location = 'strandbad';
break;
case 'acties/strandhuys':
$location = 'strandhuys';
break;
case 'acties/strandpaviljoen-vught':
$location = 'strandpaviljoen';
break;
case 'acties/openingstijdenym':
$location = 'strandbad/openingstijden';
break;
case 'acties/vacatures-ijzeren-man':
$location = 'ijzeren-man/vacatures';
break;
case 'acties/teambuilding-groepsuitjes':
$location = 'stranduitjes';
break;
case 'acties/ijzerenmanfaq':
$location = 'strandbad/veelgestelde-vragen';
break;
case 'acties/contactym':
$location = 'ijzeren-man/contact';
break;
}
if($location !== false)
{
header("HTTP/1.1 301 Moved Permanently");
header("Location: /" . $location);
}
}
/**
* Redirect other domains to ijzerenman.nl
*/
function redirectOtherDomains()
{
$location = false;
switch($_SERVER['HTTP_HOST'])
{
//case 'domain':
// $location = 'ijzerenman.nl';
}
if($location !== false)
{
header("HTTP/1.1 301 Moved Permanently");
header("Location: " . $location . $_SERVER['REQUEST_URI']);
}
}
}