File: D:/HostingSpaces/jacques-hein/jacques-hein.nl/app/Komma/Routes/RouteResolver.php
<?php
namespace Komma\Routes;
class RouteResolver
{
/**
* Resolve route
*
* @return bool
*/
public function resolve()
{
// Return false when we are in the control panel
if($this->isControlPanel()) return false;
// Maybe we are receiving an alias
// Check for a REST-route that belongs to this alias and dispatch a new Request
\Route::get(\Request::path(), function ()
{
// Return a 404 when the alias is not found in the database
if( ! $dispatch = $this->dispatchRoute()) \App::abort(404);
return $dispatch;
});
\Route::post(\Request::path(), function ()
{
// Return a 404 when the alias is not found in the database
if( ! $dispatch = $this->dispatchPostRoute()) \App::abort(404);
return $dispatch;
});
//Project Routes
\Route::get('projects', 'Komma\Projects\ProjectController@index');
\Route::get('projects/{projectId}', 'Komma\Projects\ProjectController@show');
//Project Routes
\Route::get('services', 'Komma\Services\ServiceController@index');
\Route::get('services/{serviceId}', 'Komma\Services\ServiceController@show');
//Post Routes
\Route::get('blog', 'Komma\Posts\PostController@index');
\Route::get('blog/{blogId}', 'Komma\Posts\PostController@show');
//News Routes
\Route::get('news', 'Komma\Posts\PostController@index');
\Route::get('news/{newsId}', 'Komma\Posts\PostController@show');
// Page Routes
\Route::resource('pages', 'Komma\Pages\PageController');
\Route::get('simple_pages/{pageId}', 'Komma\SimplePages\SimplePageController@show');
// Forms
\Route::post('contact/process', [
'as' => 'contact.process',
'uses' => 'Komma\Contact\ContactController@contactFormProcess'
]);
\Route::get('contact', ['as' => 'contact.form',
'uses' => 'Komma\Contact\ContactController@contactForm'
]);
\Route::get('contact/success', ['as' => 'contact.success',
'uses' => 'Komma\Contact\ContactController@contactSuccess'
]);
\Route::any('trial', [
'as' => 'trial.page',
'uses' => 'Komma\Contact\ContactController@freeTrialForm']);
\Route::post('trial/process', [
'as' => 'trial.process',
'uses' => 'Komma\Contact\ContactController@freeTrialProcess'
]);
\Route::get('trial/in-use', [
'as' => 'trial.in-use',
'uses' => 'Komma\Contact\ContactController@freeTrialSuccess'
]);
\Route::get('trial/succes', [
'as' => 'trial.success',
'uses' => 'Komma\Contact\ContactController@freeTrialSuccess'
]);
\Route::get('trial/error', [
'as' => 'trial.error',
'uses' => 'Komma\Contact\ContactController@freeTrialSuccess'
]);
\Route::post('setLanguage', 'BaseController@setCurrentLanguage');
// SEO routes
\Route::get('robots.txt', 'Komma\Sitemap\SitemapController@robots');
\Route::get('sitemap.xml', 'Komma\Sitemap\SitemapController@sitemap');
\Route::get('sitemap', [
'as' => 'sitemap',
'uses' => 'Komma\Sitemap\SitemapController@showSitemap'
]);
//404 route for maps in wwwroot
\Route::get('404', 'BaseController@abortPage');
}
/**
* Dispatch new custom event with REST-route
*
* @return mixed
*/
private function dispatchRoute()
{
$requestUri = \Request::path();
// Get route by URI
if( ! $route = \DB::table('routes')
->where('route', '=', $requestUri)
->first()
) {
return $this->redirectOldPages($requestUri);
};
// Create get request
$request = \Request::create('/' . $route->rest_route, 'GET');
// Dispatch request
return \Route::dispatch($request);
}
private function dispatchPostRoute()
{
$requestUri = \Request::path();
// Get route by URI
if( ! $route = \DB::table('routes')
->where('route', '=', $requestUri)
->first()
) return false;
if( ! in_array($route->rest_route, ['contact', 'trial'])) return false;
// Create get request
$request = \Request::create('/' . $route->rest_route, 'POST');
// Dispatch request
return \Route::dispatch($request);
}
/**
* Check if the routes starts with "KMS"
*
* @return mixed
*/
private function isControlPanel()
{
return \Str::startsWith(\Request::path(), 'kms');
}
/**
* Dispatch Old routes
*
* @return mixed
*/
private function redirectOldPages($requestUri = null)
{
// Old routes
switch ($requestUri) {
case 'doc_pechakucha.html':
case 'doc_remia2.html':
case 'doc_remia.html':
case 'doc_becam1.html':
case 'doc_becam2.html':
case 'doc_kitkat.html':
case 'doc_bhh.html':
case 'doc_neck.html':
case 'doc_abwerkt.html':
case 'doc_lmeh.html':
case 'doc_hyp.html':
case 'doc_krm.html':
case 'doc_telfort.html':
case 'doc_upc.html':
case 'doc_shf.html':
case 'doc_fotocomm.html':
case 'doc_publicaties.html':
case 'doc_alex.html':
case 'doc_gtst.html':
case 'doc_opg1.html':
case 'doc_hgh.html':
case 'doc_ofv.html':
case 'doc_opg2.html':
case 'doc_opg3.html':
case 'doc_gvb.html':
case 'doc_nab.html':
case 'doc_fotoparents.html':
case 'doc_tbm.html':
case 'doc_ns.html':
case 'doc_canon.html':
case 'doc_bkr.html':
case 'doc_ac.html':
case 'doc_gesprtrainer.html':
case 'doc_schkls.html':
case 'doc_prespitch.html':
case 'doc_oko.html':
case 'doc_vvaa.html':
case 'doc_gvw.html':
case 'doc_fotoschakels.html':
case 'doc_umw.html':
case 'doc_ot.html':
case 'doc_fotosom.html':
case 'doc_fotogvw.html':
case 'doc_fotoworkshop.html':
case 'doc_fotoportret.html':
case 'doc_fotofashion.html':
case 'doc_fotooliver.html':
case 'doc_fotozakelijk.html':
case 'doc_cc.html':
case 'doc_fotovtfun.html':
case 'doc_emoties.html':
case 'doc_audi01.html':
case 'doc_bbh.html':
case 'doc_audi02.html':
case 'doc_stemmen.html':
case 'doc_blokker.html':
case 'doc_wagner.html':
case 'doc_peugeot.html':
case 'doc_sanex.html':
case 'doc_zendium.html':
case 'doc_iglo.html':
case 'referenties.html':
case 'portfolio.html':
case 'cv_ao.html':
case 'cv_ta.html':
case 'doc_showreel.html':
case 'sub_pf.html':
case 'voice.html':
case 'doc_vp.html':
case 'cvdoc_ao.html':
case 'cvdoc_ta.html':
case 't&f.html':
case 'p&b.html':
case 'theater.html':
case 'casting.html':
return \Redirect::to('portfolio', 302);
break;
case 'index.html':
case 'sub_home.html':
case 'disclaimer.html':
return \Redirect::to('/', 302);
break;
case 'jacques-hein.html':
case 'interview.html':
case 'over.html':
case 'heintje.html':
case 'heintje2.html':
case 'c&a.html':
return \Redirect::to('/over-mij', 302);
break;
case 'nieuws.html':
case 'links.html':
case 'doc_nieuws.html':
case 'doc_archief11.html':
case 'doc-archief11.html':
case 'doc_archief02.html':
case 'doc_archief09.html':
case 'doc_archief05.html':
case 'doc_archief04.html':
case 'doc_archief01.html':
case 'doc_archief03.html':
case 'doc_archief08.html':
case 'doc_referenties.html':
case 'doc_archief07.html':
case 'doc_archief06.html':
return \Redirect::to('/nieuws', 302);
break;
case 'diensten.html':
case 'werkwijze.html':
case 'artacteur.html':
case 'trainingsacteur.html':
case 'trainingep.html':
return \Redirect::to('/acteerdiensten', 302);
break;
case 'contact.html':
return \Redirect::to('/contact', 302);
break;
case 'sitemap.html':
return \Redirect::to('/sitemap', 302);
break;
default:
break;
}
return false;
}
}