Copies packaged or local resources into the consumer repository.
'copy-resource'
'Copies a file or directory resource into the current project.'
'This command copies a configured source file or every file in a source directory into the target path.'
Interfaces
Defines the logger contract consumed by reusable command result helpers.
Properties
Methods
Creates a new CopyResourceCommand instance.
Adds the standard JSON output options to the current command.
Configures source, target, and overwrite controls.
Copies the requested resource.
Determines whether JSON output was requested.
Determines whether pretty JSON output was requested.
Copies every file from a source directory into the target directory.
Copies a single file when the target does not exist or overwrite is enabled.
Logs a failed command result and returns the failure exit code.
Logs an informational command message at notice level.
Prompts whether a drifted resource should be replaced.
Logs a successful command result and returns the success exit code.
private
FileDiffer
$fileDiffer
private
FileLocatorInterface
$fileLocator
private
FilesystemInterface
$filesystem
private
FinderFactoryInterface
$finderFactory
private
LoggerInterface
$logger
Creates a new CopyResourceCommand instance.
public
__construct(FilesystemInterface
$filesystem, FileLocatorInterface
$fileLocator, FinderFactoryInterface
$finderFactory, FileDiffer
$fileDiffer, LoggerInterface
$logger) : mixed
Parameters
Description
the filesystem used for copy operations
$fileLocator
:
FileLocatorInterface
Description
the locator used to resolve source resources
Description
the factory used to create finders for directory resources
Description
the service used to summarize overwrite changes
$logger
:
LoggerInterface
Description
the output-aware logger
Adds the standard JSON output options to the current command.
protected
addJsonOption() : static
Return values
Configures source, target, and overwrite controls.
protected
configure() : void
Copies the requested resource.
protected
execute(InputInterface
$input, OutputInterface
$output) : int
Parameters
$input
:
InputInterface
Description
the input containing source and target paths
$output
:
OutputInterface
Description
the output used to report copy results
Return values
Description
the command status code
Determines whether JSON output was requested.
protected
isJsonOutput(InputInterface
$input) : bool
Description
The pretty-json flag SHALL imply JSON output.
Parameters
$input
:
InputInterface
Return values
Determines whether pretty JSON output was requested.
protected
isPrettyJsonOutput(InputInterface
$input) : bool
Parameters
$input
:
InputInterface
Return values
Copies every file from a source directory into the target directory.
private
copyDirectory(
string
$sourcePath,
string
$targetPath,
bool
$overwrite,
bool
$dryRun,
bool
$check,
bool
$interactive, InputInterface
$input, OutputInterface
$output) : int
Parameters
$sourcePath
:
string
Description
the resolved source directory
$targetPath
:
string
Description
the resolved target directory
$overwrite
:
bool
Description
whether existing files MAY be overwritten
$dryRun
:
bool
$check
:
bool
$interactive
:
bool
$input
:
InputInterface
$output
:
OutputInterface
Description
the output used to report copy results
Return values
Description
the command status code
Copies a single file when the target does not exist or overwrite is enabled.
private
copyFile(
string
$sourcePath,
string
$targetPath,
bool
$overwrite,
bool
$dryRun,
bool
$check,
bool
$interactive, InputInterface
$input, OutputInterface
$output) : int
Parameters
$sourcePath
:
string
Description
the resolved source file
$targetPath
:
string
Description
the resolved target file
$overwrite
:
bool
Description
whether an existing target file MAY be overwritten
$dryRun
:
bool
$check
:
bool
$interactive
:
bool
$input
:
InputInterface
$output
:
OutputInterface
Description
the output used to report copy results
Return values
Description
the command status code
Logs a failed command result and returns the failure exit code.
private
failure(
string
$message, InputInterface
$input[,
array<string, mixed>
$context = []][,
string|null
$file = null][,
int|null
$line = null]) : int
Parameters
$message
:
string
Description
the failure message
$input
:
InputInterface
Description
the originating command input
$context
:
array<string, mixed>
=
[]
Description
optional extra log context
$file
:
string|null
=
null
Description
the related file path when known
$line
:
int|null
=
null
Description
the related line when known
Return values
Logs an informational command message at notice level.
private
notice(
string
$message, InputInterface
$input[,
array<string, mixed>
$context = []]) : void
Parameters
$message
:
string
Description
the notice message
$input
:
InputInterface
Description
the originating command input
$context
:
array<string, mixed>
=
[]
Description
optional extra log context
Prompts whether a drifted resource should be replaced.
private
shouldReplaceResource(
string
$targetPath) : bool
Parameters
$targetPath
:
string
Description
the resource path that would be replaced
Return values
Description
true when the replacement SHOULD proceed
Logs a successful command result and returns the success exit code.
private
success(
string
$message, InputInterface
$input[,
array<string, mixed>
$context = []][,
string
$logLevel = LogLevel::INFO]) : int
Parameters
$message
:
string
Description
the success message
$input
:
InputInterface
Description
the originating command input
$context
:
array<string, mixed>
=
[]
Description
optional extra log context
$logLevel
:
string
=
LogLevel::INFO
Description
the PSR-3 log level used for the successful result