-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from opencorero/dev
Checking route mechanism changed
- Loading branch information
Showing
45 changed files
with
801 additions
and
259 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
/* | ||
* Created on Fri Jan 23 2020 by DaRock | ||
* | ||
* Copyright (c) Aweb Design | ||
* https://www.awebdesign.ro | ||
*/ | ||
|
||
namespace App\Console\Commands; | ||
|
||
use Illuminate\Support\Facades\Artisan; | ||
use Illuminate\Console\Command; | ||
|
||
class ClearCacheCommand extends Command | ||
{ | ||
/** | ||
* The console command name. | ||
* | ||
* @var string | ||
*/ | ||
protected $name = 'opencore:clear-cache'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Clear all cache options'; | ||
|
||
/** | ||
* Create a new route command instance. | ||
* | ||
* @param \Illuminate\Routing\Router $router | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return void | ||
*/ | ||
public function handle() | ||
{ | ||
Artisan::call('config:clear'); | ||
Artisan::call('route:clear'); | ||
Artisan::call('view:clear'); | ||
Artisan::call('cache:clear'); | ||
|
||
return $this->info("Cache has been deleted!"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
<?php | ||
/* | ||
* Created on Fri Jan 23 2020 by DaRock | ||
* | ||
* Copyright (c) Aweb Design | ||
* https://www.awebdesign.ro | ||
*/ | ||
|
||
namespace App\Console\Commands; | ||
|
||
use Illuminate\Support\Facades\Artisan; | ||
use Illuminate\Routing\Router; | ||
use Illuminate\Console\Command; | ||
use OpenCore\Support\Entities\OpencoreRoute; | ||
|
||
class RegisterRoutesCommand extends Command | ||
{ | ||
/** | ||
* The console command name. | ||
* | ||
* @var string | ||
*/ | ||
protected $name = 'opencore:register-routes'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Register all routes into databse'; | ||
|
||
/** | ||
* Ignore methods | ||
*/ | ||
protected $ignore_methods = [ | ||
'HEAD' | ||
]; | ||
|
||
/** | ||
* The router instance. | ||
* | ||
* @var \Illuminate\Routing\Router | ||
*/ | ||
protected $router; | ||
|
||
/** | ||
* Create a new route command instance. | ||
* | ||
* @param \Illuminate\Routing\Router $router | ||
* @return void | ||
*/ | ||
public function __construct(Router $router) | ||
{ | ||
parent::__construct(); | ||
|
||
$this->router = $router; | ||
} | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return void | ||
*/ | ||
public function handle() | ||
{ | ||
$this->router->compiled = false; | ||
Artisan::call('cache:clear'); | ||
Artisan::call('route:clear'); | ||
|
||
// $this->router->setRoutes($this->router->getRoutes()); | ||
if (empty($this->router->getRoutes())) { | ||
$this->deleteAllRoutes(); | ||
|
||
return $this->error("Your application doesn't have any routes."); | ||
} | ||
|
||
$this->registerRoutes(); | ||
|
||
return $this->info("Your route have been registered."); | ||
} | ||
|
||
/** | ||
* Register all routes into database | ||
* | ||
* @return void | ||
*/ | ||
protected function registerRoutes() | ||
{ | ||
$registeredRoutes = OpencoreRoute::get()->pluck('id', 'unique_key')->toArray(); | ||
|
||
$keep = []; | ||
$routes = $this->router->getRoutes(); | ||
foreach ($routes as $route) { | ||
foreach ($route->methods() as $method) { | ||
if (!in_array($method, $this->ignore_methods)) { | ||
$data = [ | ||
'method' => $method, | ||
'uri' => $route->uri(), | ||
'name' => $route->getName() | ||
]; | ||
|
||
$key = implode('', $data); | ||
|
||
$id = $registeredRoutes[$key] ?? null; | ||
if (is_null($id)) { | ||
$id = OpencoreRoute::insertGetId($data); | ||
} | ||
$keep[] = $id; | ||
} | ||
} | ||
} | ||
|
||
OpencoreRoute::whereNotIn('id', $keep)->delete(); | ||
} | ||
|
||
/** | ||
* Delete all routes from database | ||
* | ||
* @return void | ||
*/ | ||
protected function deleteAllRoutes() | ||
{ | ||
OpencoreRoute::truncate(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.