Skip to content

Commit

Permalink
Merge branch 'windows-binary'
Browse files Browse the repository at this point in the history
  • Loading branch information
joetannenbaum committed Dec 19, 2024
2 parents 9f9ae16 + 0926719 commit a888e16
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 35 deletions.
36 changes: 17 additions & 19 deletions app/Commands/AutocompleteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,39 @@

class AutocompleteCommand extends Command
{
protected $signature = 'autocomplete {code} {--debug} {--from-file=}';
use ResolvesCode;

protected $signature = 'autocomplete {code} {--from-file} {--debug} {--local-file=}';

protected $description = 'Parse the given PHP code and return the autocomplete results';

public function handle(): void
{
$code = $this->argument('code');

if ($this->option('from-file')) {
$code = file_get_contents(__DIR__ . '/../../tests/snippets/parse/' . $this->option('from-file') . '.php');
}
$code = $this->resolveCode('autocomplete');

$walker = new Walker($code, (bool) $this->option('debug'));
$result = $walker->walk();

$autocompleting = $result->findAutocompleting();

if (app()->isLocal()) {
$dir = 'local-results/autocomplete';
File::ensureDirectoryExists(storage_path($dir));
$now = now()->format('Y-m-d-H-i-s');

if (!$this->option('from-file')) {
File::put(storage_path("{$dir}/{$now}-01-code.php"), $code);
}

File::put(storage_path("{$dir}/{$now}-02-autocomplete.json"), json_encode($autocompleting?->flip() ?? [], JSON_PRETTY_PRINT));
File::put(storage_path("{$dir}/{$now}-03-full.json"), $result->toJson(JSON_PRETTY_PRINT));
$this->log($autocompleting, $result, $code);
}

echo json_encode($autocompleting?->flip() ?? [], $this->option('debug') ? JSON_PRETTY_PRINT : 0);
}

protected function log($autocompleting, $result, $code)
{
$dir = 'local-results/autocomplete';
File::ensureDirectoryExists(storage_path($dir));
$now = now()->format('Y-m-d-H-i-s');

// dd($autocompleting->flip(), 'Autocompleting');
// // $toAutocomplete = $this->findFirstAutocompleting($result->toArray()['children']);
if (!$this->option('local-file')) {
File::put(storage_path("{$dir}/{$now}-01-code.php"), $code);
}

// echo $result->toJson($this->option('debug') ? JSON_PRETTY_PRINT : 0);
File::put(storage_path("{$dir}/{$now}-02-autocomplete.json"), json_encode($autocompleting?->flip() ?? [], JSON_PRETTY_PRINT));
File::put(storage_path("{$dir}/{$now}-03-full.json"), $result->toJson(JSON_PRETTY_PRINT));
}
}
33 changes: 18 additions & 15 deletions app/Commands/DetectCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,36 @@

class DetectCommand extends Command
{
protected $signature = 'detect {code} {--debug} {--from-file=}';
use ResolvesCode;

protected $signature = 'detect {code} {--from-file} {--debug} {--local-file=}';

protected $description = 'Detect things we care about in the current code';

public function handle(): void
{
$code = $this->argument('code');

if ($this->option('from-file')) {
$code = file_get_contents(__DIR__ . '/../../tests/snippets/detect/' . $this->option('from-file') . '.php');
}
$code = $this->resolveCode('detect');

$walker = new DetectWalker($code, (bool) $this->option('debug'));
$result = $walker->walk();

if (app()->isLocal()) {
$dir = 'local-results/detect';
File::ensureDirectoryExists(storage_path($dir));
$now = now()->format('Y-m-d-H-i-s');

File::put(storage_path("{$dir}/result-{$now}.json"), $result->toJson(JSON_PRETTY_PRINT));

if (!$this->option('from-file')) {
File::put(storage_path("{$dir}/result-{$now}.php"), $code);
}
$this->log($result, $code);
}

echo $result->toJson();
}

protected function log($result, $code)
{
$dir = 'local-results/detect';
File::ensureDirectoryExists(storage_path($dir));
$now = now()->format('Y-m-d-H-i-s');

File::put(storage_path("{$dir}/result-{$now}.json"), $result->toJson(JSON_PRETTY_PRINT));

if (!$this->option('local-file')) {
File::put(storage_path("{$dir}/result-{$now}.php"), $code);
}
}
}
21 changes: 21 additions & 0 deletions app/Commands/ResolvesCode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace App\Commands;

trait ResolvesCode
{
protected function resolveCode($path): string
{
if ($this->option('local-file')) {
return file_get_contents(__DIR__ . '/../../tests/snippets/' . $path . '/' . $this->option('from-file') . '.php');
}

$code = $this->argument('code');

if ($this->option('from-file')) {
return file_get_contents($code);
}

return $code;
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"homepage": "https://laravel-zero.com",
"type": "project",
"license": "MIT",
"version": "0.1.28",
"version": "0.1.33",
"support": {
"issues": "https://github.com/laravel-zero/laravel-zero/issues",
"source": "https://github.com/laravel-zero/laravel-zero"
Expand Down

0 comments on commit a888e16

Please sign in to comment.