mirror of
https://github.com/bitinflow/expose.git
synced 2026-03-13 13:35:54 +00:00
wip
This commit is contained in:
30
app/Commands/PublishCommand.php
Normal file
30
app/Commands/PublishCommand.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class PublishCommand extends Command
|
||||
{
|
||||
protected $signature = 'publish';
|
||||
|
||||
protected $description = 'Publish the expose configuration file';
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$configFile = implode(DIRECTORY_SEPARATOR, [
|
||||
$_SERVER['HOME'],
|
||||
'.expose',
|
||||
'config.php'
|
||||
]);
|
||||
|
||||
if (file_exists($configFile)) {
|
||||
$this->error('Expose configuration file already exists at '.$configFile);
|
||||
return;
|
||||
}
|
||||
|
||||
file_put_contents($configFile, file_get_contents(base_path('config/expose.php')));
|
||||
|
||||
$this->info('Published expose configuration file to: ' . $configFile);
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ use React\EventLoop\LoopInterface;
|
||||
|
||||
class ServeCommand extends Command
|
||||
{
|
||||
protected $signature = 'serve {host=0.0.0.0} {hostname=localhost} {--validateAuthTokens}';
|
||||
protected $signature = 'serve {hostname=localhost} {host=0.0.0.0} {--validateAuthTokens}';
|
||||
|
||||
protected $description = 'Start the shaft server';
|
||||
|
||||
|
||||
@@ -28,6 +28,6 @@ class ShareCurrentWorkingDirectoryCommand extends ShareCommand
|
||||
return $valetConfig->tld;
|
||||
}
|
||||
|
||||
return 'test';
|
||||
return config('expose.default_tld', 'test');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,14 @@
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
use App\Client\Support\TokenNodeVisitor;
|
||||
use Illuminate\Console\Command;
|
||||
use PhpParser\Lexer\Emulative;
|
||||
use PhpParser\NodeTraverser;
|
||||
use PhpParser\NodeVisitor\CloningVisitor;
|
||||
use PhpParser\Parser\Php7;
|
||||
use PhpParser\ParserFactory;
|
||||
use PhpParser\PrettyPrinter\Standard;
|
||||
|
||||
class StoreAuthenticationTokenCommand extends Command
|
||||
{
|
||||
@@ -17,17 +24,20 @@ class StoreAuthenticationTokenCommand extends Command
|
||||
if (!is_null($this->argument('token'))) {
|
||||
$this->info('Setting the expose authentication token to "' . $this->argument('token') . '"');
|
||||
|
||||
$config['auth_token'] = $this->argument('token');
|
||||
|
||||
$configFile = implode(DIRECTORY_SEPARATOR, [
|
||||
$_SERVER['HOME'],
|
||||
'.expose',
|
||||
'config.php'
|
||||
]);
|
||||
|
||||
@mkdir(dirname($configFile), 0777, true);
|
||||
if (! file_exists($configFile)) {
|
||||
@mkdir(dirname($configFile), 0777, true);
|
||||
$updatedConfigFile = $this->modifyConfigurationFile(base_path('config/expose.php'), $this->argument('token'));
|
||||
} else {
|
||||
$updatedConfigFile = $this->modifyConfigurationFile($configFile, $this->argument('token'));
|
||||
}
|
||||
|
||||
file_put_contents($configFile, '<?php return ' . var_export($config, true) . ';');
|
||||
file_put_contents($configFile, $updatedConfigFile);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -37,4 +47,32 @@ class StoreAuthenticationTokenCommand extends Command
|
||||
$this->info('Current authentication token: ' . $token);
|
||||
}
|
||||
}
|
||||
|
||||
protected function modifyConfigurationFile(string $configFile, string $token)
|
||||
{
|
||||
$lexer = new Emulative([
|
||||
'usedAttributes' => [
|
||||
'comments',
|
||||
'startLine', 'endLine',
|
||||
'startTokenPos', 'endTokenPos',
|
||||
],
|
||||
]);
|
||||
$parser = new Php7($lexer);
|
||||
|
||||
$oldStmts = $parser->parse(file_get_contents($configFile));
|
||||
$oldTokens = $lexer->getTokens();
|
||||
|
||||
$nodeTraverser = new NodeTraverser;
|
||||
$nodeTraverser->addVisitor(new CloningVisitor());
|
||||
$newStmts = $nodeTraverser->traverse($oldStmts);
|
||||
|
||||
$nodeTraverser = new NodeTraverser;
|
||||
$nodeTraverser->addVisitor(new TokenNodeVisitor($token));
|
||||
|
||||
$newStmts = $nodeTraverser->traverse($newStmts);
|
||||
|
||||
$prettyPrinter = new Standard();
|
||||
|
||||
return $prettyPrinter->printFormatPreserving($newStmts, $oldStmts, $oldTokens);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user