Add Router to core.
This commit is contained in:
parent
246bbed148
commit
69c761c3b1
58 changed files with 6451 additions and 157 deletions
57
src/Runtime/Factory/AppFactory.php
Normal file
57
src/Runtime/Factory/AppFactory.php
Normal file
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
namespace Runtime\Factory;
|
||||
|
||||
class AppFactory {
|
||||
|
||||
protected function getHelperFunctions() {
|
||||
$file = getcwd() . '/../src/Runtime/Helpers/helpers.php';
|
||||
|
||||
$source = file_get_contents($file);
|
||||
$tokens = token_get_all($source);
|
||||
|
||||
$functions = array();
|
||||
$nextStringIsFunc = false;
|
||||
$inClass = false;
|
||||
$bracesCount = 0;
|
||||
|
||||
foreach($tokens as $token) {
|
||||
switch($token[0]) {
|
||||
case T_CLASS:
|
||||
$inClass = true;
|
||||
break;
|
||||
case T_FUNCTION:
|
||||
if(!$inClass) $nextStringIsFunc = true;
|
||||
break;
|
||||
|
||||
case T_STRING:
|
||||
if($nextStringIsFunc) {
|
||||
$nextStringIsFunc = false;
|
||||
$functions[] = $token[1];
|
||||
}
|
||||
break;
|
||||
|
||||
// Anonymous functions
|
||||
case '(':
|
||||
case ';':
|
||||
$nextStringIsFunc = false;
|
||||
break;
|
||||
|
||||
// Exclude Classes
|
||||
case '{':
|
||||
if($inClass) $bracesCount++;
|
||||
break;
|
||||
|
||||
case '}':
|
||||
if($inClass) {
|
||||
$bracesCount--;
|
||||
if($bracesCount === 0) $inClass = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $functions;
|
||||
}
|
||||
|
||||
}
|
|
@ -2,20 +2,27 @@
|
|||
|
||||
namespace Runtime\Factory;
|
||||
|
||||
use ClassNotFoundException;
|
||||
use Pecee\SimpleRouter\SimpleRouter;
|
||||
use Runtime\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()
|
||||
{
|
||||
SimpleRouter::setDefaultNamespace('\App\Http\Controllers');
|
||||
Route::setDefaultNamespace('\App\Http\Controllers');
|
||||
|
||||
require_once('../routes/web.php ');
|
||||
require_once('../routes/web.php');
|
||||
|
||||
// start engines
|
||||
app(ViewEngine::class);
|
||||
|
||||
try {
|
||||
SimpleRouter::start();
|
||||
Route::start();
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
ExceptionHandler::make($e);
|
||||
|
@ -52,4 +59,12 @@ class BootstrapFactory {
|
|||
return "../resources/";
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Environment
|
||||
*/
|
||||
public function view()
|
||||
{
|
||||
return ViewEngine::get();
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue