Commit 099e873f by 杨树贤

合同附件

parent 74a96fb1
......@@ -706,7 +706,7 @@ class DataService
if (empty($skuName)) {
dump('sku_id找不到');
}
dump($skuName);
dump($skuName);
}
});
});
......
......@@ -236,6 +236,7 @@ return [
'certification_notice' => '认证通知书',
'supplier_survey' => '供应商调查表',
'confidentiality_agreement' => '保密协议',
'yunxin_agreement' => '芯链合作协议',
'other_attachment' => '其它附件',
],
......
<?php
error_reporting(E_ERROR | E_PARSE);
define('LARAVEL_START', microtime(true));
require_once __DIR__ . '/../autoload.php';
class LaravelVsCode
{
public static function relativePath($path)
{
if (!str_contains($path, base_path())) {
return (string) $path;
}
return ltrim(str_replace(base_path(), '', realpath($path) ?: $path), DIRECTORY_SEPARATOR);
}
public static function isVendor($path)
{
return str_contains($path, base_path("vendor"));
}
public static function outputMarker($key)
{
return '__VSCODE_LARAVEL_' . $key . '__';
}
public static function startupError(\Throwable $e)
{
throw new Error(self::outputMarker('STARTUP_ERROR') . ': ' . $e->getMessage());
}
}
try {
$app = require_once __DIR__ . '/../../bootstrap/app.php';
} catch (\Throwable $e) {
LaravelVsCode::startupError($e);
exit(1);
}
$app->register(new class($app) extends \Illuminate\Support\ServiceProvider
{
public function boot()
{
config([
'logging.channels.null' => [
'driver' => 'monolog',
'handler' => \Monolog\Handler\NullHandler::class,
],
'logging.default' => 'null',
]);
}
});
try {
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
$kernel->bootstrap();
} catch (\Throwable $e) {
LaravelVsCode::startupError($e);
exit(1);
}
echo LaravelVsCode::outputMarker('START_OUTPUT');
if (class_exists('\phpDocumentor\Reflection\DocBlockFactory')) {
$factory = \phpDocumentor\Reflection\DocBlockFactory::createInstance();
} else {
$factory = null;
}
$docblocks = new class($factory) {
public function __construct(protected $factory) {}
public function forMethod($method)
{
if ($this->factory !== null) {
$docblock = $this->factory->create($method->getDocComment());
$params = collect($docblock->getTagsByName("param"))->map(fn($p) => (string) $p)->all();
$return = (string) $docblock->getTagsByName("return")[0] ?? null;
return [$params, $return];
}
$params = collect($method->getParameters())
->map(function (\ReflectionParameter $param) {
$types = match ($param?->getType()) {
null => [],
default => method_exists($param->getType(), "getTypes")
? $param->getType()->getTypes()
: [$param->getType()]
};
$types = collect($types)
->filter()
->values()
->map(fn($t) => $t->getName());
return trim($types->join("|") . " $" . $param->getName());
})
->all();
$return = $method->getReturnType()?->getName();
return [$params, $return];
}
};
$models = new class($factory) {
protected $output;
public function __construct(protected $factory)
{
$this->output = new \Symfony\Component\Console\Output\BufferedOutput();
}
public function all()
{
collect(glob(base_path('**/Models/*.php')))->each(fn($file) => include_once($file));
return collect(get_declared_classes())
->filter(fn($class) => is_subclass_of($class, \Illuminate\Database\Eloquent\Model::class))
->filter(fn($class) => !in_array($class, [\Illuminate\Database\Eloquent\Relations\Pivot::class, \Illuminate\Foundation\Auth\User::class]))
->values()
->flatMap(fn(string $className) => $this->getInfo($className))
->filter();
}
protected function getCastReturnType($className)
{
if ($className === null) {
return null;
}
try {
$method = (new \ReflectionClass($className))->getMethod('get');
if ($method->hasReturnType()) {
return $method->getReturnType()->getName();
}
return $className;
} catch (\Exception | \Throwable $e) {
return $className;
}
}
protected function fromArtisan($className)
{
try {
\Illuminate\Support\Facades\Artisan::call(
"model:show",
[
"model" => $className,
"--json" => true,
],
$this->output
);
} catch (\Exception | \Throwable $e) {
return null;
}
return json_decode($this->output->fetch(), true);
}
protected function collectExistingProperties($reflection)
{
if ($this->factory === null) {
return collect();
}
if ($comment = $reflection->getDocComment()) {
$docblock = $this->factory->create($comment);
$existingProperties = collect($docblock->getTagsByName("property"))->map(fn($p) => $p->getVariableName());
$existingReadProperties = collect($docblock->getTagsByName("property-read"))->map(fn($p) => $p->getVariableName());
return $existingProperties->merge($existingReadProperties);
}
return collect();
}
protected function getParentClass(\ReflectionClass $reflection)
{
if (!$reflection->getParentClass()) {
return null;
}
$parent = $reflection->getParentClass()->getName();
if ($parent === \Illuminate\Database\Eloquent\Model::class) {
return null;
}
return \Illuminate\Support\Str::start($parent, '\\');
}
protected function getInfo($className)
{
if (($data = $this->fromArtisan($className)) === null) {
return null;
}
$reflection = new \ReflectionClass($className);
$data["extends"] = $this->getParentClass($reflection);
$existingProperties = $this->collectExistingProperties($reflection);
$data['attributes'] = collect($data['attributes'])
->map(fn($attrs) => array_merge($attrs, [
'title_case' => str($attrs['name'])->title()->replace('_', '')->toString(),
'documented' => $existingProperties->contains($attrs['name']),
'cast' => $this->getCastReturnType($attrs['cast'])
]))
->toArray();
$data['scopes'] = collect($reflection->getMethods())
->filter(fn($method) =>!$method->isStatic() && ($method->getAttributes(\Illuminate\Database\Eloquent\Attributes\Scope::class) || ($method->isPublic() && str_starts_with($method->name, 'scope'))))
->map(fn($method) => str($method->name)->replace('scope', '')->lcfirst()->toString())
->values()
->toArray();
$data['uri'] = $reflection->getFileName();
return [
$className => $data,
];
}
};
$builder = new class($docblocks) {
public function __construct(protected $docblocks) {}
public function methods()
{
$reflection = new \ReflectionClass(\Illuminate\Database\Query\Builder::class);
return collect($reflection->getMethods(\ReflectionMethod::IS_PUBLIC | \ReflectionMethod::IS_PROTECTED))
->filter(fn(ReflectionMethod $method) => !str_starts_with($method->getName(), "__") || (!$method->isPublic() && empty($method->getAttributes(\Illuminate\Database\Eloquent\Attributes\Scope::class))))
->map(fn(\ReflectionMethod $method) => $this->getMethodInfo($method))
->filter()
->values();
}
protected function getMethodInfo($method)
{
[$params, $return] = $this->docblocks->forMethod($method);
return [
"name" => $method->getName(),
"parameters" => $params,
"return" => $return,
];
}
};
echo json_encode([
'builderMethods' => $builder->methods(),
'models' => $models->all(),
]);
echo LaravelVsCode::outputMarker('END_OUTPUT');
exit(0);
<?php
error_reporting(E_ERROR | E_PARSE);
define('LARAVEL_START', microtime(true));
require_once __DIR__ . '/../autoload.php';
class LaravelVsCode
{
public static function relativePath($path)
{
if (!str_contains($path, base_path())) {
return (string) $path;
}
return ltrim(str_replace(base_path(), '', realpath($path) ?: $path), DIRECTORY_SEPARATOR);
}
public static function isVendor($path)
{
return str_contains($path, base_path("vendor"));
}
public static function outputMarker($key)
{
return '__VSCODE_LARAVEL_' . $key . '__';
}
public static function startupError(\Throwable $e)
{
throw new Error(self::outputMarker('STARTUP_ERROR') . ': ' . $e->getMessage());
}
}
try {
$app = require_once __DIR__ . '/../../bootstrap/app.php';
} catch (\Throwable $e) {
LaravelVsCode::startupError($e);
exit(1);
}
$app->register(new class($app) extends \Illuminate\Support\ServiceProvider
{
public function boot()
{
config([
'logging.channels.null' => [
'driver' => 'monolog',
'handler' => \Monolog\Handler\NullHandler::class,
],
'logging.default' => 'null',
]);
}
});
try {
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
$kernel->bootstrap();
} catch (\Throwable $e) {
LaravelVsCode::startupError($e);
exit(1);
}
echo LaravelVsCode::outputMarker('START_OUTPUT');
function vsCodeGetReflectionMethod(ReflectionClass $reflected): ReflectionMethod {
return match (true) {
$reflected->hasMethod('__invoke') => $reflected->getMethod('__invoke'),
default => $reflected->getMethod('handle'),
};
}
echo collect(app("Illuminate\Contracts\Http\Kernel")->getMiddlewareGroups())
->merge(app("Illuminate\Contracts\Http\Kernel")->getRouteMiddleware())
->map(function ($middleware, $key) {
$result = [
"class" => null,
"path" => null,
"line" => null,
"parameters" => null,
"groups" => [],
];
if (is_array($middleware)) {
$result["groups"] = collect($middleware)->map(function ($m) {
if (!class_exists($m)) {
return [
"class" => $m,
"path" => null,
"line" => null
];
}
$reflected = new ReflectionClass($m);
$reflectedMethod = vsCodeGetReflectionMethod($reflected);
return [
"class" => $m,
"path" => LaravelVsCode::relativePath($reflected->getFileName()),
"line" =>
$reflectedMethod->getFileName() === $reflected->getFileName()
? $reflectedMethod->getStartLine()
: null
];
})->all();
return $result;
}
$reflected = new ReflectionClass($middleware);
$reflectedMethod = vsCodeGetReflectionMethod($reflected);
$result = array_merge($result, [
"class" => $middleware,
"path" => LaravelVsCode::relativePath($reflected->getFileName()),
"line" => $reflectedMethod->getStartLine(),
]);
$parameters = collect($reflectedMethod->getParameters())
->filter(function ($rc) {
return $rc->getName() !== "request" && $rc->getName() !== "next";
})
->map(function ($rc) {
return $rc->getName() . ($rc->isVariadic() ? "..." : "");
});
if ($parameters->isEmpty()) {
return $result;
}
return array_merge($result, [
"parameters" => $parameters->implode(",")
]);
})
->toJson();
echo LaravelVsCode::outputMarker('END_OUTPUT');
exit(0);
<?php
error_reporting(E_ERROR | E_PARSE);
define('LARAVEL_START', microtime(true));
require_once __DIR__ . '/../autoload.php';
class LaravelVsCode
{
public static function relativePath($path)
{
if (!str_contains($path, base_path())) {
return (string) $path;
}
return ltrim(str_replace(base_path(), '', realpath($path) ?: $path), DIRECTORY_SEPARATOR);
}
public static function isVendor($path)
{
return str_contains($path, base_path("vendor"));
}
public static function outputMarker($key)
{
return '__VSCODE_LARAVEL_' . $key . '__';
}
public static function startupError(\Throwable $e)
{
throw new Error(self::outputMarker('STARTUP_ERROR') . ': ' . $e->getMessage());
}
}
try {
$app = require_once __DIR__ . '/../../bootstrap/app.php';
} catch (\Throwable $e) {
LaravelVsCode::startupError($e);
exit(1);
}
$app->register(new class($app) extends \Illuminate\Support\ServiceProvider
{
public function boot()
{
config([
'logging.channels.null' => [
'driver' => 'monolog',
'handler' => \Monolog\Handler\NullHandler::class,
],
'logging.default' => 'null',
]);
}
});
try {
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
$kernel->bootstrap();
} catch (\Throwable $e) {
LaravelVsCode::startupError($e);
exit(1);
}
echo LaravelVsCode::outputMarker('START_OUTPUT');
$translator = new class
{
public $paths = [];
public $values = [];
public $paramResults = [];
public $params = [];
public $emptyParams = [];
public $directoriesToWatch = [];
public $languages = [];
public function all()
{
$final = [];
foreach ($this->retrieve() as $value) {
if ($value instanceof \Illuminate\Support\LazyCollection) {
foreach ($value as $val) {
$dotKey = $val["k"];
$final[$dotKey] ??= [];
if (!in_array($val["la"], $this->languages)) {
$this->languages[] = $val["la"];
}
$final[$dotKey][$val["la"]] = $val["vs"];
}
} else {
foreach ($value["vs"] as $v) {
$dotKey = "{$value["k"]}.{$v['k']}";
$final[$dotKey] ??= [];
if (!in_array($value["la"], $this->languages)) {
$this->languages[] = $value["la"];
}
$final[$dotKey][$value["la"]] = $v['arr'];
}
}
}
return $final;
}
protected function retrieve()
{
$loader = app("translator")->getLoader();
$namespaces = $loader->namespaces();
$paths = $this->getPaths($loader);
$default = collect($paths)->flatMap(
fn($path) => $this->collectFromPath($path)
);
$namespaced = collect($namespaces)->flatMap(
fn($path, $namespace) => $this->collectFromPath($path, $namespace)
);
return $default->merge($namespaced);
}
protected function getPaths($loader)
{
$reflection = new ReflectionClass($loader);
$property = null;
if ($reflection->hasProperty("paths")) {
$property = $reflection->getProperty("paths");
} else if ($reflection->hasProperty("path")) {
$property = $reflection->getProperty("path");
}
if ($property !== null) {
$property->setAccessible(true);
return \Illuminate\Support\Arr::wrap($property->getValue($loader));
}
return [];
}
public function collectFromPath(string $path, ?string $namespace = null)
{
$realPath = realpath($path);
if (!is_dir($realPath)) {
return [];
}
if (!LaravelVsCode::isVendor($realPath)) {
$this->directoriesToWatch[] = LaravelVsCode::relativePath($realPath);
}
return array_map(
fn($file) => $this->fromFile($file, $path, $namespace),
\Illuminate\Support\Facades\File::allFiles($realPath),
);
}
protected function fromFile($file, $path, $namespace)
{
if (pathinfo($file, PATHINFO_EXTENSION) === 'json') {
return $this->fromJsonFile($file, $path, $namespace);
}
return $this->fromPhpFile($file, $path, $namespace);
}
protected function linesFromJsonFile($file)
{
$contents = file_get_contents($file);
try {
$json = json_decode($contents, true) ?? [];
} catch (\Throwable $e) {
return [[], []];
}
if (count($json) === 0) {
return [[], []];
}
$lines = explode(PHP_EOL, $contents);
$encoded = array_map(
fn($k) => [json_encode($k, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), $k],
array_keys($json),
);
$result = [];
$searchRange = 5;
foreach ($encoded as $index => $keys) {
// Pretty likely to be on the line that is the index, go happy path first
if (strpos($lines[$index + 1] ?? '', $keys[0]) !== false) {
$result[$keys[1]] = $index + 2;
continue;
}
// Search around the index, likely to be within $searchRange lines
$start = max(0, $index - $searchRange);
$end = min($index + $searchRange, count($lines) - 1);
$current = $start;
while ($current <= $end) {
if (strpos($lines[$current], $keys[0]) !== false) {
$result[$keys[1]] = $current + 1;
break;
}
$current++;
}
}
return [$json, $result];
}
protected function linesFromPhpFile($file)
{
$tokens = token_get_all(file_get_contents($file));
$found = [];
$inArrayKey = true;
$arrayDepth = -1;
$depthKeys = [];
foreach ($tokens as $token) {
if (!is_array($token)) {
if ($token === '[') {
$inArrayKey = true;
$arrayDepth++;
}
if ($token === ']') {
$inArrayKey = true;
$arrayDepth--;
array_pop($depthKeys);
}
continue;
}
if ($token[0] === T_DOUBLE_ARROW) {
$inArrayKey = false;
}
if ($inArrayKey && $token[0] === T_CONSTANT_ENCAPSED_STRING) {
$depthKeys[$arrayDepth] = trim($token[1], '"\'');
\Illuminate\Support\Arr::set($found, implode('.', $depthKeys), $token[2]);
}
if (!$inArrayKey && $token[0] === T_CONSTANT_ENCAPSED_STRING) {
$inArrayKey = true;
}
}
return \Illuminate\Support\Arr::dot($found);
}
protected function getDotted($key, $lang)
{
try {
return \Illuminate\Support\Arr::dot(
\Illuminate\Support\Arr::wrap(
__($key, [], $lang),
),
);
} catch (\Throwable $e) {
// Most likely, in this case, the lang file doesn't return an array
return [];
}
}
protected function getPathIndex($file)
{
$path = LaravelVsCode::relativePath($file);
$index = $this->paths[$path] ?? null;
if ($index !== null) {
return $index;
}
$this->paths[$path] = count($this->paths);
return $this->paths[$path];
}
protected function getValueIndex($value)
{
$index = $this->values[$value] ?? null;
if ($index !== null) {
return $index;
}
$this->values[$value] = count($this->values);
return $this->values[$value];
}
protected function getParamIndex($key)
{
$processed = $this->params[$key] ?? null;
if ($processed) {
return $processed[0];
}
if (in_array($key, $this->emptyParams)) {
return null;
}
$params = preg_match_all("/\:([A-Za-z0-9_]+)/", $key, $matches)
? $matches[1]
: [];
if (count($params) === 0) {
$this->emptyParams[] = $key;
return null;
}
$paramKey = json_encode($params);
$paramIndex = $this->paramResults[$paramKey] ?? null;
if ($paramIndex !== null) {
$this->params[$key] = [$paramIndex, $params];
return $paramIndex;
}
$paramIndex = count($this->paramResults);
$this->paramResults[$paramKey] = $paramIndex;
$this->params[$key] = [$paramIndex, $params];
return $paramIndex;
}
protected function fromJsonFile($file, $path, $namespace)
{
$lang = pathinfo($file, PATHINFO_FILENAME);
$relativePath = $this->getPathIndex($file);
$lines = \Illuminate\Support\Facades\File::lines($file);
return \Illuminate\Support\LazyCollection::make(function () use ($file, $lang, $relativePath, $lines) {
[$json, $lines] = $this->linesFromJsonFile($file);
foreach ($json as $key => $value) {
if (!array_key_exists($key, $lines) || is_array($value)) {
continue;
}
yield [
"k" => $key,
"la" => $lang,
"vs" => [
$this->getValueIndex($value),
$relativePath,
$lines[$key] ?? null,
$this->getParamIndex($key),
],
];
}
});
}
protected function fromPhpFile($file, $path, $namespace)
{
$key = pathinfo($file, PATHINFO_FILENAME);
if ($namespace) {
$key = "{$namespace}::{$key}";
}
$lang = collect(explode(DIRECTORY_SEPARATOR, str_replace($path, "", $file)))
->filter()
->slice(-2, 1)
->first();
$relativePath = $this->getPathIndex($file);
$lines = $this->linesFromPhpFile($file);
return [
"k" => $key,
"la" => $lang,
"vs" => \Illuminate\Support\LazyCollection::make(function () use ($key, $lang, $relativePath, $lines) {
foreach ($this->getDotted($key, [], $lang) as $key => $value) {
if (!array_key_exists($key, $lines) || is_array($value)) {
continue;
}
yield [
'k' => $key,
'arr' => [
$this->getValueIndex($value),
$relativePath,
$lines[$key],
$this->getParamIndex($value),
],
];
}
}),
];
}
};
echo json_encode([
'default' => \Illuminate\Support\Facades\App::currentLocale(),
'translations' => $translator->all(),
'languages' => $translator->languages,
'paths' => array_keys($translator->paths),
'values' => array_keys($translator->values),
'params' => array_map(fn($p) => json_decode($p, true), array_keys($translator->paramResults)),
'to_watch' => $translator->directoriesToWatch,
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
echo LaravelVsCode::outputMarker('END_OUTPUT');
exit(0);
<?php
error_reporting(E_ERROR | E_PARSE);
define('LARAVEL_START', microtime(true));
require_once __DIR__ . '/../autoload.php';
class LaravelVsCode
{
public static function relativePath($path)
{
if (!str_contains($path, base_path())) {
return (string) $path;
}
return ltrim(str_replace(base_path(), '', realpath($path) ?: $path), DIRECTORY_SEPARATOR);
}
public static function isVendor($path)
{
return str_contains($path, base_path("vendor"));
}
public static function outputMarker($key)
{
return '__VSCODE_LARAVEL_' . $key . '__';
}
public static function startupError(\Throwable $e)
{
throw new Error(self::outputMarker('STARTUP_ERROR') . ': ' . $e->getMessage());
}
}
try {
$app = require_once __DIR__ . '/../../bootstrap/app.php';
} catch (\Throwable $e) {
LaravelVsCode::startupError($e);
exit(1);
}
$app->register(new class($app) extends \Illuminate\Support\ServiceProvider
{
public function boot()
{
config([
'logging.channels.null' => [
'driver' => 'monolog',
'handler' => \Monolog\Handler\NullHandler::class,
],
'logging.default' => 'null',
]);
}
});
try {
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
$kernel->bootstrap();
} catch (\Throwable $e) {
LaravelVsCode::startupError($e);
exit(1);
}
echo LaravelVsCode::outputMarker('START_OUTPUT');
collect(glob(base_path('**/Models/*.php')))->each(fn($file) => include_once($file));
$modelPolicies = collect(get_declared_classes())
->filter(fn($class) => is_subclass_of($class, \Illuminate\Database\Eloquent\Model::class))
->filter(fn($class) => !in_array($class, [
\Illuminate\Database\Eloquent\Relations\Pivot::class,
\Illuminate\Foundation\Auth\User::class,
]))
->flatMap(fn($class) => [
$class => \Illuminate\Support\Facades\Gate::getPolicyFor($class),
])
->filter(fn($policy) => $policy !== null);
function vsCodeGetAuthenticatable() {
try {
$guard = auth()->guard();
$reflection = new \ReflectionClass($guard);
if (!$reflection->hasProperty("provider")) {
return null;
}
$property = $reflection->getProperty("provider");
$provider = $property->getValue($guard);
if ($provider instanceof \Illuminate\Auth\EloquentUserProvider) {
$providerReflection = new \ReflectionClass($provider);
$modelProperty = $providerReflection->getProperty("model");
return str($modelProperty->getValue($provider))->prepend("\\")->toString();
}
if ($provider instanceof \Illuminate\Auth\DatabaseUserProvider) {
return str(\Illuminate\Auth\GenericUser::class)->prepend("\\")->toString();
}
} catch (\Exception | \Throwable $e) {
return null;
}
return null;
}
function vsCodeGetPolicyInfo($policy, $model)
{
$methods = (new ReflectionClass($policy))->getMethods();
return collect($methods)->map(fn(ReflectionMethod $method) => [
'key' => $method->getName(),
'uri' => $method->getFileName(),
'policy' => is_string($policy) ? $policy : get_class($policy),
'model' => $model,
'line' => $method->getStartLine(),
])->filter(fn($ability) => !in_array($ability['key'], ['allow', 'deny']));
}
echo json_encode([
'authenticatable' => vsCodeGetAuthenticatable(),
'policies' => collect(\Illuminate\Support\Facades\Gate::abilities())
->map(function ($policy, $key) {
$reflection = new \ReflectionFunction($policy);
$policyClass = null;
$closureThis = $reflection->getClosureThis();
if ($closureThis !== null) {
if (get_class($closureThis) === \Illuminate\Auth\Access\Gate::class) {
$vars = $reflection->getClosureUsedVariables();
if (isset($vars['callback'])) {
[$policyClass, $method] = explode('@', $vars['callback']);
$reflection = new \ReflectionMethod($policyClass, $method);
}
}
}
return [
'key' => $key,
'uri' => $reflection->getFileName(),
'policy' => $policyClass,
'line' => $reflection->getStartLine(),
];
})
->merge(
collect(\Illuminate\Support\Facades\Gate::policies())->flatMap(fn($policy, $model) => vsCodeGetPolicyInfo($policy, $model)),
)
->merge(
$modelPolicies->flatMap(fn($policy, $model) => vsCodeGetPolicyInfo($policy, $model)),
)
->values()
->groupBy('key')
->map(fn($item) => $item->map(fn($i) => \Illuminate\Support\Arr::except($i, 'key'))),
]);
echo LaravelVsCode::outputMarker('END_OUTPUT');
exit(0);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment