Skip to content

Commit 2d8cfe5

Browse files
complete brand new project buildmymvp
1 parent 5bac6a7 commit 2d8cfe5

13 files changed

Lines changed: 2418 additions & 0 deletions
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
<?php
2+
3+
4+
error_reporting(E_ERROR | E_PARSE);
5+
6+
define('LARAVEL_START', microtime(true));
7+
8+
require_once __DIR__ . '/../autoload.php';
9+
10+
class LaravelVsCode
11+
{
12+
public static function relativePath($path)
13+
{
14+
if (!str_contains($path, base_path())) {
15+
return (string) $path;
16+
}
17+
18+
return ltrim(str_replace(base_path(), '', realpath($path) ?: $path), DIRECTORY_SEPARATOR);
19+
}
20+
21+
public static function isVendor($path)
22+
{
23+
return str_contains($path, base_path("vendor"));
24+
}
25+
26+
public static function outputMarker($key)
27+
{
28+
return '__VSCODE_LARAVEL_' . $key . '__';
29+
}
30+
31+
public static function startupError(\Throwable $e)
32+
{
33+
throw new Error(self::outputMarker('STARTUP_ERROR') . ': ' . $e->getMessage());
34+
}
35+
}
36+
37+
try {
38+
$app = require_once __DIR__ . '/../../bootstrap/app.php';
39+
} catch (\Throwable $e) {
40+
LaravelVsCode::startupError($e);
41+
exit(1);
42+
}
43+
44+
$app->register(new class($app) extends \Illuminate\Support\ServiceProvider
45+
{
46+
public function boot()
47+
{
48+
config([
49+
'logging.channels.null' => [
50+
'driver' => 'monolog',
51+
'handler' => \Monolog\Handler\NullHandler::class,
52+
],
53+
'logging.default' => 'null',
54+
]);
55+
}
56+
});
57+
58+
try {
59+
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
60+
$kernel->bootstrap();
61+
} catch (\Throwable $e) {
62+
LaravelVsCode::startupError($e);
63+
exit(1);
64+
}
65+
66+
echo LaravelVsCode::outputMarker('START_OUTPUT');
67+
68+
$routes = new class {
69+
public function all()
70+
{
71+
return collect(app('router')->getRoutes()->getRoutes())
72+
->map(fn(\Illuminate\Routing\Route $route) => $this->getRoute($route))
73+
->merge($this->getFolioRoutes());
74+
}
75+
76+
protected function getFolioRoutes()
77+
{
78+
try {
79+
$output = new \Symfony\Component\Console\Output\BufferedOutput();
80+
81+
\Illuminate\Support\Facades\Artisan::call("folio:list", ["--json" => true], $output);
82+
83+
$mountPaths = collect(app(\Laravel\Folio\FolioManager::class)->mountPaths());
84+
85+
return collect(json_decode($output->fetch(), true))->map(fn($route) => $this->getFolioRoute($route, $mountPaths));
86+
} catch (\Exception | \Throwable $e) {
87+
return [];
88+
}
89+
}
90+
91+
protected function getFolioRoute($route, $mountPaths)
92+
{
93+
if ($mountPaths->count() === 1) {
94+
$mountPath = $mountPaths[0];
95+
} else {
96+
$mountPath = $mountPaths->first(fn($mp) => file_exists($mp->path . DIRECTORY_SEPARATOR . $route['view']));
97+
}
98+
99+
$path = $route['view'];
100+
101+
if ($mountPath) {
102+
$path = $mountPath->path . DIRECTORY_SEPARATOR . $path;
103+
}
104+
105+
return [
106+
'method' => $route['method'],
107+
'uri' => $route['uri'],
108+
'name' => $route['name'],
109+
'action' => null,
110+
'parameters' => [],
111+
'filename' => $path,
112+
'line' => 0,
113+
];
114+
}
115+
116+
protected function getRoute(\Illuminate\Routing\Route $route)
117+
{
118+
try {
119+
$reflection = $this->getRouteReflection($route);
120+
} catch (\Throwable $e) {
121+
$reflection = null;
122+
}
123+
124+
return [
125+
'method' => collect($route->methods())
126+
->filter(fn($method) => $method !== 'HEAD')
127+
->implode('|'),
128+
'uri' => $route->uri(),
129+
'name' => $route->getName(),
130+
'action' => $route->getActionName(),
131+
'parameters' => $route->parameterNames(),
132+
'filename' => $reflection ? $reflection->getFileName() : null,
133+
'line' => $reflection ? $reflection->getStartLine() : null,
134+
];
135+
}
136+
137+
protected function getRouteReflection(\Illuminate\Routing\Route $route)
138+
{
139+
if ($route->getActionName() === 'Closure') {
140+
return new \ReflectionFunction($route->getAction()['uses']);
141+
}
142+
143+
if (!str_contains($route->getActionName(), '@')) {
144+
return new \ReflectionClass($route->getActionName());
145+
}
146+
147+
try {
148+
return new \ReflectionMethod($route->getControllerClass(), $route->getActionMethod());
149+
} catch (\Throwable $e) {
150+
$namespace = app(\Illuminate\Routing\UrlGenerator::class)->getRootControllerNamespace()
151+
?? (app()->getNamespace() . 'Http\Controllers');
152+
153+
return new \ReflectionMethod(
154+
$namespace . '\\' . ltrim($route->getControllerClass(), '\\'),
155+
$route->getActionMethod(),
156+
);
157+
}
158+
}
159+
};
160+
161+
echo $routes->all()->toJson();
162+
163+
echo LaravelVsCode::outputMarker('END_OUTPUT');
164+
165+
exit(0);
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
3+
4+
error_reporting(E_ERROR | E_PARSE);
5+
6+
define('LARAVEL_START', microtime(true));
7+
8+
require_once __DIR__ . '/../autoload.php';
9+
10+
class LaravelVsCode
11+
{
12+
public static function relativePath($path)
13+
{
14+
if (!str_contains($path, base_path())) {
15+
return (string) $path;
16+
}
17+
18+
return ltrim(str_replace(base_path(), '', realpath($path) ?: $path), DIRECTORY_SEPARATOR);
19+
}
20+
21+
public static function isVendor($path)
22+
{
23+
return str_contains($path, base_path("vendor"));
24+
}
25+
26+
public static function outputMarker($key)
27+
{
28+
return '__VSCODE_LARAVEL_' . $key . '__';
29+
}
30+
31+
public static function startupError(\Throwable $e)
32+
{
33+
throw new Error(self::outputMarker('STARTUP_ERROR') . ': ' . $e->getMessage());
34+
}
35+
}
36+
37+
try {
38+
$app = require_once __DIR__ . '/../../bootstrap/app.php';
39+
} catch (\Throwable $e) {
40+
LaravelVsCode::startupError($e);
41+
exit(1);
42+
}
43+
44+
$app->register(new class($app) extends \Illuminate\Support\ServiceProvider
45+
{
46+
public function boot()
47+
{
48+
config([
49+
'logging.channels.null' => [
50+
'driver' => 'monolog',
51+
'handler' => \Monolog\Handler\NullHandler::class,
52+
],
53+
'logging.default' => 'null',
54+
]);
55+
}
56+
});
57+
58+
try {
59+
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
60+
$kernel->bootstrap();
61+
} catch (\Throwable $e) {
62+
LaravelVsCode::startupError($e);
63+
exit(1);
64+
}
65+
66+
echo LaravelVsCode::outputMarker('START_OUTPUT');
67+
68+
echo collect(app()->getBindings())
69+
->filter(fn ($binding) => ($binding['concrete'] ?? null) !== null)
70+
->flatMap(function ($binding, $key) {
71+
$boundTo = new ReflectionFunction($binding['concrete']);
72+
73+
$closureClass = $boundTo->getClosureScopeClass();
74+
75+
if ($closureClass === null) {
76+
return [];
77+
}
78+
79+
return [
80+
$key => [
81+
'path' => LaravelVsCode::relativePath($closureClass->getFileName()),
82+
'class' => $closureClass->getName(),
83+
'line' => $boundTo->getStartLine(),
84+
],
85+
];
86+
})->toJson();
87+
88+
echo LaravelVsCode::outputMarker('END_OUTPUT');
89+
90+
exit(0);
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
3+
4+
error_reporting(E_ERROR | E_PARSE);
5+
6+
define('LARAVEL_START', microtime(true));
7+
8+
require_once __DIR__ . '/../autoload.php';
9+
10+
class LaravelVsCode
11+
{
12+
public static function relativePath($path)
13+
{
14+
if (!str_contains($path, base_path())) {
15+
return (string) $path;
16+
}
17+
18+
return ltrim(str_replace(base_path(), '', realpath($path) ?: $path), DIRECTORY_SEPARATOR);
19+
}
20+
21+
public static function isVendor($path)
22+
{
23+
return str_contains($path, base_path("vendor"));
24+
}
25+
26+
public static function outputMarker($key)
27+
{
28+
return '__VSCODE_LARAVEL_' . $key . '__';
29+
}
30+
31+
public static function startupError(\Throwable $e)
32+
{
33+
throw new Error(self::outputMarker('STARTUP_ERROR') . ': ' . $e->getMessage());
34+
}
35+
}
36+
37+
try {
38+
$app = require_once __DIR__ . '/../../bootstrap/app.php';
39+
} catch (\Throwable $e) {
40+
LaravelVsCode::startupError($e);
41+
exit(1);
42+
}
43+
44+
$app->register(new class($app) extends \Illuminate\Support\ServiceProvider
45+
{
46+
public function boot()
47+
{
48+
config([
49+
'logging.channels.null' => [
50+
'driver' => 'monolog',
51+
'handler' => \Monolog\Handler\NullHandler::class,
52+
],
53+
'logging.default' => 'null',
54+
]);
55+
}
56+
});
57+
58+
try {
59+
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
60+
$kernel->bootstrap();
61+
} catch (\Throwable $e) {
62+
LaravelVsCode::startupError($e);
63+
exit(1);
64+
}
65+
66+
echo LaravelVsCode::outputMarker('START_OUTPUT');
67+
68+
echo json_encode([
69+
'php_version' => phpversion(),
70+
'laravel_version' => app()->version(),
71+
]);
72+
73+
echo LaravelVsCode::outputMarker('END_OUTPUT');
74+
75+
exit(0);

0 commit comments

Comments
 (0)