mirror of
https://github.com/bitinflow/expose.git
synced 2026-03-13 21:45:55 +00:00
wip
This commit is contained in:
@@ -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