php-cooper-symfony

ImportCommand extends Command
in package

FinalYes

`cooper:import <bundle> | --all [--reference] [--force]`: a bundle's YAML preset moved into CASC.

config/packages/<bundle>.yaml becomes config/packages/<bundle>.casc; each when@<env>: section, with config/packages/<env>/<bundle>.yaml merged over it, becomes config/<env>/<bundle>.casc -- the overlay import "${COOPER_ENV}/*.casc" reads. Values are converted by PresetValues (%env(int:PORT)% is !int(${PORT}), %param% stays), and what has no CASC form is listed. config/config.casc is made to import "packages/*.casc" once, before the environment's overlay; a missing one is created.

--all imports every preset in config/packages/. --reference follows each imported bundle's file with every option of its configuration tree and its default, commented out -- for a bundle with no preset, the reference alone.

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 YAML is never touched -- deleting it is the application's step, once the CASC says what it should.

Table of Contents

Constants

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'
PACKAGES_IMPORT  : mixed = 'import "packages/*.casc"'

Properties

$kernel  : KernelInterface|null
$projectDir  : string

Methods

__construct()  : mixed
configure()  : void
execute()  : int
configurationTree()  : NodeInterface|null
The configuration tree of the bundle whose extension alias is `$alias`, as `config:dump-reference` finds it.
ensureMainImport()  : void
Makes `config/config.casc` import `packages/*.casc` -- once, and before the environment's overlay, so an environment's settings still win. A missing document is created with both imports.
filesFor()  : array<string, string>
The CASC files one preset becomes, by path relative to the project.
kernelParameters()  : array<string, mixed>
mainDocument()  : string
say()  : void
Writes one line exactly as given: a path or a quoted value may hold `<...>`, which console markup would read as a style tag.
write()  : bool
Writes one file -- unless it would not change, or would and `$force` is off.

Constants

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'

PACKAGES_IMPORT

private mixed PACKAGES_IMPORT = 'import "packages/*.casc"'

Properties

$kernel read-only

private KernelInterface|null $kernel = null

Methods

__construct()

public __construct(string $projectDir[, KernelInterface|null $kernel = null ]) : mixed
Parameters
$projectDir : string

the application's root

$kernel : KernelInterface|null = null

the application's kernel, whose bundles --reference asks for their configuration trees

execute()

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

configurationTree()

The configuration tree of the bundle whose extension alias is `$alias`, as `config:dump-reference` finds it.

private configurationTree(string $alias, bool $named, PresetValues $values) : NodeInterface|null
Parameters
$alias : string
$named : bool
$values : PresetValues
Tags
throws
InvalidArgumentException

when $named and there is no such bundle

Return values
NodeInterface|null

ensureMainImport()

Makes `config/config.casc` import `packages/*.casc` -- once, and before the environment's overlay, so an environment's settings still win. A missing document is created with both imports.

private ensureMainImport(OutputInterface $output) : void
Parameters
$output : OutputInterface

filesFor()

The CASC files one preset becomes, by path relative to the project.

private filesFor(string $name, PresetValues $values, bool $reference, bool $named) : array<string, string>
Parameters
$name : string
$values : PresetValues
$reference : bool
$named : bool

whether the name was given, rather than found by --all -- then a missing reference is an error, not a note

Tags
throws
InvalidArgumentException

when there is nothing to import, or no bundle for --reference

Return values
array<string, string>

kernelParameters()

private kernelParameters() : array<string, mixed>
Return values
array<string, mixed>

mainDocument()

private static mainDocument() : string
Return values
string

say()

Writes one line exactly as given: a path or a quoted 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

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