argument('action'); if ($action === 'refresh') { $this->info($writer->refresh() ? 'Refreshed.' : 'The caches are emptied, but the file bootstrap/cache/manager-settings.php could not be written.'); return self::SUCCESS; } if ($action === 'list') { return $this->list($definitions, $store); } if (! in_array($action, ['get', 'set', 'reset'], true)) { $this->error('Use one of: list, get, set, reset, refresh.'); return self::FAILURE; } $key = (string) $this->argument('key'); $definition = $definitions->find($key); if ($definition === null) { $this->error("There is no setting {$key}. See: php artisan manager:settings list"); return self::FAILURE; } if ($action === 'get') { $this->line($definition['type'] === 'secret' ? (filled(config($key)) ? 'set' : 'not set') : $this->show(config($key))); return self::SUCCESS; } if ($action === 'reset') { $result = $writer->apply([$key => null]); $this->info("{$key} is back to what the config says.".($result['file_written'] ? '' : ' (The compiled file could not be written.)')); return self::SUCCESS; } return $this->set($definitions, $writer, $definition); } /** @param array $definition */ private function set(Definitions $definitions, Writer $writer, array $definition): int { $key = $definition['key']; if ($this->option('stdin')) { $raw = rtrim((string) stream_get_contents(STDIN), "\r\n"); } elseif ($definition['type'] === 'secret') { if ($this->argument('value') !== null) { $this->error('Do not type a secret as an argument: it stays in the history of the shell. Leave it out to be asked, or use --stdin.'); return self::FAILURE; } $raw = (string) $this->secret($definition['label']); } else { $raw = $this->argument('value'); if ($raw === null) { $this->error('Which value? php artisan manager:settings set '.$key.' '); return self::FAILURE; } } try { $value = $definitions->cast($definition, $raw); } catch (\InvalidArgumentException) { $this->error('This value is not valid for '.$key.' ('.$definition['type'].').'); return self::FAILURE; } $result = $writer->apply([$key => $value]); $this->info("{$key} is set.".($result['env_written'] ? ' Written into .env too.' : '').($result['file_written'] ? '' : ' (The compiled file could not be written: run `manager:settings refresh` when it can.)')); return self::SUCCESS; } private function list(Definitions $definitions, Store $store): int { $rows = []; foreach ($definitions->all() as $key => $definition) { $rows[] = [ 'key' => $key, 'type' => $definition['type'], 'value' => $definition['type'] === 'secret' ? (filled(config($key)) ? 'set' : 'not set') : $this->show(config($key)), 'saved' => $store->has($key), ]; } if ($this->option('json')) { $this->line(json_encode($rows, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); return self::SUCCESS; } $this->table(['Setting', 'Type', 'Value', 'Saved here'], array_map(fn ($row) => [$row['key'], $row['type'], $row['value'], $row['saved'] ? 'yes' : ''], $rows)); return self::SUCCESS; } private function show(mixed $value): string { return is_bool($value) ? ($value ? 'true' : 'false') : (string) ($value ?? ''); } }