70 lines
No EOL
1.3 KiB
PHP
70 lines
No EOL
1.3 KiB
PHP
<?php
|
|
|
|
namespace Runtime\Factory;
|
|
|
|
use Runtime\Exceptions\Exceptions\ClassNotFoundException;
|
|
use Runtime\Http\View\ViewEngine;
|
|
use Runtime\Router\Route;
|
|
use Runtime\Exceptions\ExceptionHandler;
|
|
use Runtime\Router\Router;
|
|
use Twig\Environment;
|
|
use Twig\Loader\FilesystemLoader;
|
|
|
|
class BootstrapFactory {
|
|
|
|
public function handle()
|
|
{
|
|
Route::setDefaultNamespace('\App\Http\Controllers');
|
|
|
|
require_once('../routes/web.php');
|
|
|
|
// start engines
|
|
app(ViewEngine::class);
|
|
|
|
try {
|
|
Route::start();
|
|
}
|
|
catch (\Exception $e) {
|
|
ExceptionHandler::make($e);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param $abstract
|
|
* @return mixed
|
|
*/
|
|
public function make($abstract)
|
|
{
|
|
return $this->resolve($abstract);
|
|
}
|
|
|
|
/**
|
|
* @param $abstract
|
|
* @return mixed|null
|
|
*/
|
|
private function resolve($abstract) {
|
|
if(class_exists($abstract)) {
|
|
return new $abstract;
|
|
}
|
|
|
|
ExceptionHandler::make(ClassNotFoundException::class);
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function resourcePath()
|
|
{
|
|
return "../resources/";
|
|
}
|
|
|
|
/**
|
|
* @return Environment
|
|
*/
|
|
public function view()
|
|
{
|
|
return ViewEngine::get();
|
|
}
|
|
|
|
} |