first commit
This commit is contained in:
+51
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Boost\Support;
|
||||
|
||||
class Composer
|
||||
{
|
||||
public static function packagesDirectories(): array
|
||||
{
|
||||
return collect(static::packages())
|
||||
->mapWithKeys(fn (string $key, string $package): array => [$package => implode(DIRECTORY_SEPARATOR, [
|
||||
base_path('vendor'),
|
||||
str_replace('/', DIRECTORY_SEPARATOR, $package),
|
||||
])])
|
||||
->filter(fn (string $path): bool => is_dir($path))
|
||||
->toArray();
|
||||
}
|
||||
|
||||
public static function packages(): array
|
||||
{
|
||||
$composerJsonPath = base_path('composer.json');
|
||||
|
||||
if (! file_exists($composerJsonPath)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$composerData = json_decode(file_get_contents($composerJsonPath), true);
|
||||
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return collect($composerData['require'] ?? [])
|
||||
->merge($composerData['require-dev'] ?? [])
|
||||
->mapWithKeys(fn (string $key, string $package): array => [$package => $key])
|
||||
->toArray();
|
||||
}
|
||||
|
||||
public static function packagesDirectoriesWithBoostGuidelines(): array
|
||||
{
|
||||
return collect(Composer::packagesDirectories())
|
||||
->map(fn (string $path): string => implode(DIRECTORY_SEPARATOR, [
|
||||
$path,
|
||||
'resources',
|
||||
'boost',
|
||||
'guidelines',
|
||||
]))->filter(fn (string $path): bool => is_dir($path))
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Boost\Support;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Config
|
||||
{
|
||||
protected const FILE = 'boost.json';
|
||||
|
||||
/**
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function getGuidelines(): array
|
||||
{
|
||||
return $this->get('guidelines', []);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, string> $guidelines
|
||||
*/
|
||||
public function setGuidelines(array $guidelines): void
|
||||
{
|
||||
$this->set('guidelines', $guidelines);
|
||||
}
|
||||
|
||||
public function setEditors(array $editors): void
|
||||
{
|
||||
$this->set('editors', $editors);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, string> $agents
|
||||
*/
|
||||
public function setAgents(array $agents): void
|
||||
{
|
||||
$this->set('agents', $agents);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function getAgents(): array
|
||||
{
|
||||
return $this->get('agents', []);
|
||||
}
|
||||
|
||||
public function getEditors(): array
|
||||
{
|
||||
return $this->get('editors', []);
|
||||
}
|
||||
|
||||
public function setHerdMcp(bool $installed): void
|
||||
{
|
||||
$this->set('herd_mcp', $installed);
|
||||
}
|
||||
|
||||
public function getHerdMcp(): bool
|
||||
{
|
||||
return $this->get('herd_mcp', false);
|
||||
}
|
||||
|
||||
public function setSail(bool $useSail): void
|
||||
{
|
||||
$this->set('sail', $useSail);
|
||||
}
|
||||
|
||||
public function getSail(): bool
|
||||
{
|
||||
return $this->get('sail', false);
|
||||
}
|
||||
|
||||
public function flush(): void
|
||||
{
|
||||
$path = base_path(self::FILE);
|
||||
|
||||
if (file_exists($path)) {
|
||||
unlink($path);
|
||||
}
|
||||
}
|
||||
|
||||
protected function get(string $key, mixed $default = null): mixed
|
||||
{
|
||||
$config = $this->all();
|
||||
|
||||
return data_get($config, $key, $default);
|
||||
}
|
||||
|
||||
protected function set(string $key, mixed $value): void
|
||||
{
|
||||
$config = array_filter($this->all());
|
||||
|
||||
data_set($config, $key, $value);
|
||||
|
||||
ksort($config);
|
||||
|
||||
$path = base_path(self::FILE);
|
||||
|
||||
file_put_contents($path, Str::of(json_encode($config, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES))->append(PHP_EOL));
|
||||
}
|
||||
|
||||
protected function all(): array
|
||||
{
|
||||
$path = base_path(self::FILE);
|
||||
|
||||
if (! file_exists($path)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$config = json_decode(file_get_contents($path), true);
|
||||
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $config ?? [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user