php-cooper-laravel

ImportCommand extends Command
in package

FinalYes

`cooper:import <package> | --all | --app [--required] [--force]`: PHP configuration moved into CASC.

  • <package> -- one package's configuration, by its name (sanctum for config('sanctum.*')), into config/packages/<name>.casc;
  • --all -- every package's configuration found (see ConfigSources);
  • --app -- the application's own config/*.php, a one-time migration, into config/app/<name>.casc.

The PHP is parsed, never run (see PhpConfigTranslator), and the CASC written with php-cooper-config's Writer. config/config.casc is made to import "packages/*.casc" and import "app/*.casc" -- once each, packages first, and both before the environment's overlay, so the application's settings win over the packages' and an environment's over both. A missing document is created.

env('X') without a default is written as ${X:nil} -- an empty string inside a concatenation, a cast's own zero value under a cast -- which reads an unset variable as env() did: the faithful translation. --required writes the strict ${X} instead, which fails the load while X is unset; since every artisan command loads the configuration, so does artisan.

The command ends with a summary: how many keys were written exactly, which went through !php, which were left out, and -- under --required -- which variables are now required.

A file already there is left alone when it would not change, and not overwritten without --force when it would: the difference is shown, and the command fails. The PHP files are never touched -- deleting the application's is its own step, once the CASC says what it should.

Table of Contents

Constants

DIRECTORIES  : mixed = ['package' => 'packages', 'app' => 'app']
Each kind of import's directory under `config/`, in the order the document imports them.
ENVIRONMENTS  : mixed = ['dev', 'test', 'prod']
The environments a created document gets an overlay directory for, as `cooper:init` does.
MAIN_DOCUMENT  : mixed = 'config/config.casc'

Properties

$app  : Application

Methods

__construct()  : mixed
configure()  : void
execute()  : int
ensureMainImports()  : void
Makes `config/config.casc` import each directory written to -- once, packages before the application, both before the environment's overlay. A missing document is created with them.
insertBeforeLaterImports()  : string
`$document` with `$import` on a line of its own before the first import it must precede -- the application's, for the packages', and the environment's for both -- else at the end.
mainDocument()  : string
nested()  : array<string, mixed>
`$tree` under the configuration name's segments: `services.mail` is `services { mail { ... } }`.
say()  : void
Writes one line exactly as given: a path or a value may hold `<...>`, which console markup would read as a style tag.
shown()  : string
`$file` relative to the application, where it is inside it.
summary()  : void
The closing account: how many keys were exact, and every one that was not, and every variable now required -- a list only `--required` fills, since the default translation requires none.
write()  : bool
Writes one file -- unless it would not change, or would and `$force` is off.

Constants

DIRECTORIES

Each kind of import's directory under `config/`, in the order the document imports them.

private mixed DIRECTORIES = ['package' => 'packages', 'app' => 'app']

ENVIRONMENTS

The environments a created document gets an overlay directory for, as `cooper:init` does.

private mixed ENVIRONMENTS = ['dev', 'test', 'prod']

MAIN_DOCUMENT

private mixed MAIN_DOCUMENT = 'config/config.casc'

Properties

Methods

__construct()

public __construct(Application $app) : mixed
Parameters
$app : Application

the application, whose providers name the packages' configuration and whose paths say where things go

execute()

protected execute(InputInterface $input, OutputInterface $output) : int
Parameters
$input : InputInterface
$output : OutputInterface
Return values
int

ensureMainImports()

Makes `config/config.casc` import each directory written to -- once, packages before the application, both before the environment's overlay. A missing document is created with them.

private ensureMainImports(array<int, string> $kinds, OutputInterface $output) : void
Parameters
$kinds : array<int, string>

the kinds imported (package, app)

$output : OutputInterface

insertBeforeLaterImports()

`$document` with `$import` on a line of its own before the first import it must precede -- the application's, for the packages', and the environment's for both -- else at the end.

private static insertBeforeLaterImports(string $document, string $import) : string
Parameters
$document : string
$import : string
Return values
string

mainDocument()

private static mainDocument(array<int, string> $imports) : string
Parameters
$imports : array<int, string>
Return values
string

nested()

`$tree` under the configuration name's segments: `services.mail` is `services { mail { ... } }`.

private static nested(array<int, string> $segments, array<string|int, mixed> $tree) : array<string, mixed>
Parameters
$segments : array<int, string>
$tree : array<string|int, mixed>
Return values
array<string, mixed>

say()

Writes one line exactly as given: a path or a value may hold `<...>`, which console markup would read as a style tag.

private static say(OutputInterface $output, string $line) : void
Parameters
$output : OutputInterface
$line : string

shown()

`$file` relative to the application, where it is inside it.

private shown(string $file) : string
Parameters
$file : string
Return values
string

summary()

The closing account: how many keys were exact, and every one that was not, and every variable now required -- a list only `--required` fills, since the default translation requires none.

private static summary(OutputInterface $output, int $exact, array<int, string> $viaPhp, array<int, string> $skipped, array<int, string> $required) : void
Parameters
$output : OutputInterface
$exact : int
$viaPhp : array<int, string>
$skipped : array<int, string>
$required : array<int, string>

write()

Writes one file -- unless it would not change, or would and `$force` is off.

private write(string $path, string $content, bool $force, OutputInterface $output) : bool
Parameters
$path : string
$content : string
$force : bool
$output : OutputInterface
Return values
bool —

false when a file was left alone because it would change

On this page

Search results