88 lines
No EOL
1.8 KiB
PHP
88 lines
No EOL
1.8 KiB
PHP
<?php
|
|
|
|
namespace Runtime\Factory;
|
|
|
|
use Cli\Factory as CliFactory;
|
|
use Runtime\Exceptions\Exceptions\ClassNotFoundException;
|
|
use Runtime\Http\View\ViewEngine;
|
|
use Runtime\Router\Route;
|
|
use Runtime\Exceptions\ExceptionHandler;
|
|
|
|
class BootstrapFactory {
|
|
|
|
/**
|
|
* Handle Http core
|
|
*/
|
|
public function handle()
|
|
{
|
|
ExceptionHandler::register();
|
|
Route::setDefaultNamespace('\App\Http\Controllers');
|
|
|
|
require_once('../routes/web.php');
|
|
|
|
// start engines
|
|
app()->make(ViewEngine::class);
|
|
|
|
try {
|
|
Route::start();
|
|
}
|
|
catch (\Exception $e) {
|
|
ExceptionHandler::make($e);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Handle kernel core
|
|
*/
|
|
public function kernel()
|
|
{
|
|
app()->make(CliFactory::class)->handle();
|
|
}
|
|
|
|
/**
|
|
* @param $abstract
|
|
* @param array $arguments
|
|
* @return mixed
|
|
*/
|
|
public function make($abstract, $arguments = [])
|
|
{
|
|
return $this->resolve($abstract, $arguments);
|
|
}
|
|
|
|
/**
|
|
* @param $abstract
|
|
* @param $arguments
|
|
* @return mixed|null
|
|
*/
|
|
private function resolve($abstract, array $arguments) {
|
|
if(class_exists($abstract)) {
|
|
try {
|
|
$reflection = new \ReflectionClass($abstract);
|
|
return $reflection->newInstanceArgs($arguments);
|
|
}
|
|
catch (\ReflectionException $e) {
|
|
ExceptionHandler::make($e);
|
|
}
|
|
}
|
|
|
|
ExceptionHandler::make(ClassNotFoundException::class, sprintf("Class '%s' not found", $abstract));
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function resourcePath()
|
|
{
|
|
return "../resources/";
|
|
}
|
|
|
|
/**
|
|
* @return ViewEngine
|
|
*/
|
|
public function view()
|
|
{
|
|
return ViewEngine::get();
|
|
}
|
|
|
|
} |