-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
432 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,5 @@ test.* | |
server | ||
lang | ||
cache | ||
bootstrap | ||
bootstrap | ||
routes |
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,126 @@ | ||
<?php | ||
|
||
namespace Hermes\Commands; | ||
|
||
|
||
use Hermes\Core\Console\Command; | ||
use Illuminate\Filesystem\Filesystem; | ||
use Hermes\Core\Contracts\Console\Kernel; | ||
use Hermes\Core\Routing\ActionCollection; | ||
|
||
class ActionCacheCommand extends Command | ||
{ | ||
|
||
/** | ||
* The console command name. | ||
* | ||
* @var string | ||
*/ | ||
protected $name = 'action:cache'; | ||
|
||
/** | ||
* The console command description | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Create an action cache file for faster action registration.'; | ||
|
||
/** | ||
* The filesystem instance. | ||
* | ||
* @var \Illuminate\Filesystem\Filesystem | ||
*/ | ||
protected $files; | ||
|
||
/** | ||
* Create a new action command instance. | ||
* | ||
* @param \Illuminate\Filesystem\Filesystem $files | ||
*/ | ||
public function __construct(Filesystem $files) | ||
{ | ||
|
||
parent::__construct(); | ||
$this->files = $files; | ||
|
||
} | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function fire() | ||
{ | ||
|
||
$this->call('action:clear'); | ||
|
||
$actions = $this->getFreshApplicationActions(); | ||
|
||
if(count($actions) == 0) { | ||
$this->error("Your application doesn't have any actions."); | ||
return; | ||
} | ||
|
||
foreach ($actions as $action) | ||
{ | ||
|
||
$action->prepareForSerialization(); | ||
|
||
} | ||
|
||
$this->files->put( | ||
$this->hermes->getCachedActionsPath(), $this->buildActionCacheFile($actions) | ||
); | ||
|
||
$this->info('Actions cached successfully!'); | ||
|
||
} | ||
|
||
/** | ||
* Boot a fresh copy of the application and get the actions. | ||
* | ||
* @return \Hermes\Core\Routing\ActionCollection | ||
*/ | ||
protected function getFreshApplicationActions() | ||
{ | ||
|
||
return tap($this->getFreshApplication()['hermes.router']->getActions(), function($actions) { | ||
|
||
$actions->refreshNameLookups(); | ||
$actions->refreshActionLookups(); | ||
|
||
}); | ||
|
||
} | ||
|
||
/** | ||
* Get a fresh application instance. | ||
* | ||
* @return \Hermes\Core\Application | ||
*/ | ||
protected function getFreshApplication() | ||
{ | ||
|
||
$app = require $this->hermes->bootstrapPath().'/app.php'; | ||
|
||
return tap($app, function($app) { | ||
$app->make(Kernel::class)->bootstrap(); | ||
}); | ||
|
||
} | ||
|
||
/** | ||
* Build the action cache file. | ||
* | ||
* @param \Hermes\Core\Routing\ActionCollection $actions | ||
* | ||
* @return string | ||
*/ | ||
protected function buildActionCacheFile(ActionCollection $actions) | ||
{ | ||
|
||
$stub = $this->files->get(__DIR__.'/stubs/actions.stub'); | ||
|
||
return str_replace('{{actions}}', base64_encode(serialize($actions)), $stub); | ||
} | ||
|
||
} |
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,54 @@ | ||
<?php | ||
|
||
namespace Hermes\Commands; | ||
|
||
use Hermes\Core\Console\Command; | ||
use Illuminate\Filesystem\Filesystem; | ||
|
||
class ActionClearCommand extends Command | ||
{ | ||
/** | ||
* The console command name. | ||
* | ||
* @var string | ||
*/ | ||
protected $name = 'action:clear'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Remove the action cache file'; | ||
|
||
/** | ||
* The filesystem instance. | ||
* | ||
* @var \Illuminate\Filesystem\Filesystem | ||
*/ | ||
protected $files; | ||
|
||
/** | ||
* Create a new action clear command instance. | ||
* | ||
* @param \Illuminate\Filesystem\Filesystem $files | ||
*/ | ||
public function __construct(Filesystem $files) | ||
{ | ||
parent::__construct(); | ||
|
||
$this->files = $files; | ||
} | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return void | ||
*/ | ||
public function fire() | ||
{ | ||
$this->files->delete($this->hermes->getCachedActionsPath()); | ||
|
||
$this->info('Action cache cleared!'); | ||
} | ||
} |
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,16 @@ | ||
<?php | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Load The Cached Routes | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Here we will decode and unserialize the RouteCollection instance that | ||
| holds all of the route information for an application. This allows | ||
| us to instantaneously load the entire route map into the router. | ||
| | ||
*/ | ||
|
||
app('hermes.router')->setActions( | ||
unserialize(base64_decode('{{actions}}')) | ||
); |
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,74 @@ | ||
<?php | ||
|
||
namespace Hermes\Core\Contracts\Routing; | ||
|
||
|
||
use Hermes\Ink\Action; | ||
|
||
interface Router | ||
{ | ||
|
||
/** | ||
* Register a new GET action with the router. | ||
* | ||
* @param string $uri | ||
* @param \Closure|array|string|null $action | ||
* @return Action | ||
*/ | ||
public function get($uri, $action = null); | ||
|
||
/** | ||
* Register a new POST action with the router. | ||
* | ||
* @param string $uri | ||
* @param \Closure|array|string|null $action | ||
* @return Action | ||
*/ | ||
public function post($uri, $action = null); | ||
|
||
/** | ||
* Register a new PUT action with the router. | ||
* | ||
* @param string $uri | ||
* @param \Closure|array|string|null $action | ||
* @return Action | ||
*/ | ||
public function put($uri, $action = null); | ||
|
||
/** | ||
* Register a new PATCH action with the router. | ||
* | ||
* @param string $uri | ||
* @param \Closure|array|string|null $action | ||
* @return Action | ||
*/ | ||
public function patch($uri, $action = null); | ||
|
||
/** | ||
* Register a new DELETE action with the router. | ||
* | ||
* @param string $uri | ||
* @param \Closure|array|string|null $action | ||
* @return Action | ||
*/ | ||
public function delete($uri, $action = null); | ||
|
||
/** | ||
* Register a new OPTIONS action with the router. | ||
* | ||
* @param string $uri | ||
* @param \Closure|array|string|null $action | ||
* @return Action | ||
*/ | ||
public function options($uri, $action = null); | ||
|
||
/** | ||
* Create an action group with shared attributes. | ||
* | ||
* @param array $attributes | ||
* @param \Closure|string $actions | ||
* @return void | ||
*/ | ||
public function group(array $attributes, $actions); | ||
|
||
} |
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
Oops, something went wrong.