TmpFile
class TmpFile extends Write implements CompletionInterface (View source)
Create a temporary file that is automatically cleaned up once the task collection is is part of completes. When created, it is given a random filename.
This temporary file may be manipulated exacatly like taskWrite(). It is deleted as soon as the collection it is a part of completes or rolls back.
<?php
$collection = $this->collectionBuilder();
$tmpFilePath = $collection->taskTmpFile()
->line('-----')
->line(date('Y-m-d').' '.$title)
->line('----')
->getPath();
$collection->run();
?>
Traits
Task input/output methods. TaskIO is 'used' in BaseTask, so any task that extends this class has access to all of the methods here.
Task input/output methods. TaskIO is 'used' in BaseTask, so any task that extends this class has access to all of the methods here.
Properties
protected ConfigInterface | $config | from ConfigAwareTrait | |
protected OutputAdapterInterface | $outputAdapter | from VerbosityThresholdTrait | |
protected int | $verbosityThreshold | from VerbosityThresholdTrait | |
protected OutputInterface | $output | from OutputAwareTrait | |
protected TimeKeeper|null | $timer | from Timer | |
protected null|ProgressIndicator | $progressIndicator | from ProgressIndicatorAwareTrait | |
protected array | $stack | from Write | |
protected string | $filename | from Write | |
protected bool | $append | from Write | |
protected null|string | $originalContents | from Write |
Methods
Any class that uses ConfigAwareTrait SHOULD override this method , and define a prefix for its configuration items. This is usually done in a base class. When used, this method should return a string that ends with a "."; see BaseTask::configPrefix().
No description
No description
Required verbosity level before any TaskIO output will be produced.
Print a message if the selected verbosity level is over this task's verbosity threshold.
Print information about a task in progress.
Provide notification that some part of the task succeeded.
Provide notification that there is something wrong, but execution can continue.
Provide notification that some operation in the task failed, and the task cannot continue.
Provide debugging notification. These messages are only displayed if the log level is VERBOSITY_DEBUG.
Get the formatted task name for use in task output.
Ask the provided parent class to inject all of the dependencies that it has and we need.
Take all dependencies availble to this task and inject any that are needed into the provided task. The general pattern is that, for every FooAwareInterface that this class implements, it should test to see if the child also implements the same interface, and if so, should call $child->setFoo($this->foo).
No description
substitute a placeholder with value, placeholder must be enclosed by {}
.
replace any string with value using regular expression.
Append the provided text to the end of the buffer if the provided regex pattern matches any text already in the buffer.
Append the provided text to the end of the buffer unless the provided regex pattern matches any text already in the buffer.
No description
No description
No description
Delete this file when our collection completes.
Details
$this
setConfig(ConfigInterface $config)
Set the config management object.
ConfigInterface
getConfig()
Get the config management object.
static protected string
configPrefix()
Any class that uses ConfigAwareTrait SHOULD override this method , and define a prefix for its configuration items. This is usually done in a base class. When used, this method should return a string that ends with a "."; see BaseTask::configPrefix().
static protected
configClassIdentifier($classname)
No description
static protected
configPostfix()
No description
static
configure(string $key, mixed $value, ConfigInterface|null $config = null)
No description
protected mixed|null
getConfigValue(string $key, mixed|null $default = null)
No description
$this
setVerbosityThreshold(int $verbosityThreshold)
Required verbosity level before any TaskIO output will be produced.
e.g. OutputInterface::VERBOSITY_VERBOSE
int
verbosityThreshold()
No description
setOutputAdapter(OutputAdapterInterface $outputAdapter)
No description
OutputAdapterInterface
outputAdapter()
No description
bool
hasOutputAdapter()
No description
bool
verbosityMeetsThreshold()
No description
writeMessage(string $message)
Print a message if the selected verbosity level is over this task's verbosity threshold.
$this
setOutput(OutputInterface $output)
No description
protected OutputInterface
output()
No description
protected OutputInterface
stderr()
No description
protected OutputInterface
getOutput()
deprecated
deprecated
Backwards compatibility
in
TaskIO at line 49
null|LoggerInterface
logger()
deprecated
deprecated
No description
in
TaskIO at line 85
protected
printTaskInfo(string $text, null|array $context = null)
Print information about a task in progress.
With the Symfony Console logger, NOTICE is displayed at VERBOSITY_VERBOSE and INFO is displayed at VERBOSITY_VERY_VERBOSE.
Robo overrides the default such that NOTICE is displayed at VERBOSITY_NORMAL and INFO is displayed at VERBOSITY_VERBOSE.
n.b. We should probably have printTaskNotice for our ordinary output, and use printTaskInfo for less interesting messages.
protected
printTaskSuccess(string $text, null|array $context = null)
Provide notification that some part of the task succeeded.
With the Symfony Console logger, success messages are remapped to NOTICE, and displayed in VERBOSITY_VERBOSE. When used with the Robo logger, success messages are displayed at VERBOSITY_NORMAL.
protected
printTaskWarning(string $text, null|array $context = null)
Provide notification that there is something wrong, but execution can continue.
Warning messages are displayed at VERBOSITY_NORMAL.
protected
printTaskError(string $text, null|array $context = null)
Provide notification that some operation in the task failed, and the task cannot continue.
Error messages are displayed at VERBOSITY_NORMAL.
protected
printTaskDebug($text, null|array $context = null)
Provide debugging notification. These messages are only displayed if the log level is VERBOSITY_DEBUG.
protected
printTaskOutput(string $level, string $text, null|array $context)
deprecated
deprecated
No description
protected bool
hideTaskProgress()
No description
protected
showTaskProgress(bool $inProgress)
No description
protected string
formatBytes(int $size, int $precision = 2)
Format a quantity of bytes.
protected string
getPrintedTaskName(null|object $task = null)
Get the formatted task name for use in task output.
This is placed in the task context under 'name', and used as the log label by Robo\Common\RoboLogStyle, which is inserted at the head of log messages by Robo\Common\CustomLogStyle::formatMessage().
protected array
getTaskContext(null|array $context = null)
No description
in
Timer at line 12
protected
startTimer()
No description
in
Timer at line 20
protected
stopTimer()
No description
in
Timer at line 28
protected
resetTimer()
No description
in
Timer at line 36
protected float|null
getExecutionTime()
No description
int
progressIndicatorSteps()
No description
$this
setProgressIndicator(null|ProgressIndicator $progressIndicator)
No description
protected null|bool
hideProgressIndicator()
No description
protected
showProgressIndicator()
No description
protected
restoreProgressIndicator(bool $visible)
No description
protected int
getTotalExecutionTime()
No description
protected
startProgressIndicator()
No description
protected bool
inProgress()
No description
protected
stopProgressIndicator()
No description
protected
disableProgressIndicator()
No description
protected
detatchProgressIndicator()
No description
protected
advanceProgressIndicator(int $steps = 1)
No description
$this
inflect(InflectionInterface|mixed $parent)
Ask the provided parent class to inject all of the dependencies that it has and we need.
injectDependencies(mixed $child)
Take all dependencies availble to this task and inject any that are needed into the provided task. The general pattern is that, for every FooAwareInterface that this class implements, it should test to see if the child also implements the same interface, and if so, should call $child->setFoo($this->foo).
The benefits of this are pretty large. Any time an object that implements
InflectionInterface is created, just call $child->inflect($this)
, and
any available optional dependencies will be hooked up via setter injection.
The required dependencies of an object should be provided via constructor injection, not inflection.
__construct(string $filename = 'tmp', string $extension = '', string $baseDir = '', bool $includeRandomPart = true)
No description
in
Write at line 56
$this
filename(string $filename)
No description
in
Write at line 67
$this
append(bool $append = true)
No description
in
Write at line 81
$this
line(string $line)
add a line.
in
Write at line 95
$this
lines(array $lines)
add more lines.
in
Write at line 109
$this
text(string $text)
add a text.
in
Write at line 129
$this
textFromFile(string $filename)
add a text from a file.
Note that the file is read in the run() method of this task. To load text from the current state of a file (e.g. one that may be deleted or altered by other tasks prior the execution of this one), use: $task->text(file_get_contents($filename));
in
Write at line 144
$this
place(string $name, string $val)
substitute a placeholder with value, placeholder must be enclosed by {}
.
in
Write at line 160
$this
replace(string $string, string $replacement)
replace any string with value.
in
Write at line 175
$this
regexReplace(string $pattern, string $replacement)
replace any string with value using regular expression.
in
Write at line 190
$this
appendIfMatches(string $pattern, string $text)
Append the provided text to the end of the buffer if the provided regex pattern matches any text already in the buffer.
in
Write at line 205
$this
appendUnlessMatches(string $pattern, string $text)
Append the provided text to the end of the buffer unless the provided regex pattern matches any text already in the buffer.
in
Write at line 217
protected string
textFromFileCollect(string $contents, string $filename)
No description
in
Write at line 232
protected string|string[]
replaceCollect(string|string[] $contents, string|string[] $string, string|string[] $replacement)
No description
in
Write at line 244
protected string|string[]
regexReplaceCollect(string|string[] $contents, string|string[] $pattern, string|string[] $replacement)
No description
in
Write at line 255
protected string
textCollect(string $contents, string $text)
No description
in
Write at line 268
protected string
appendIfMatchesCollect(string $contents, string $pattern, string $text, bool $shouldMatch)
No description
in
Write at line 279
string
originalContents()
No description
in
Write at line 293
bool
wouldChange()
No description
in
Write at line 301
protected string
getContentsToWrite()
No description
in
Write at line 320
Result
run()
No description
in
Write at line 338
string
getPath()
No description
complete()
Delete this file when our collection completes.
If this temporary file is not part of a collection, then it will be deleted when the program terminates, presuming that it was created by taskTmpFile() or _tmpFile().