ReplaceBlock
extends BaseTask
in package
Replace a block of content in given file.
<?php
// Insert content between the 'start' and 'end'.
$this->taskReplaceBlock('file.txt')
->start('#block-start')
->end('#block-end')
->content('This content will be between the start and the end')
->run();
// Insert content between the 'start' and 'end', and exclude 'start' and 'end'.
$this->taskReplaceBlock('file.txt')
->start('#block-start')
->end('#block-end')
->excludeStartEnd()
->content('This content will be between the start and the end')
->run();
?>
Table of Contents
Properties
- $content : string
- The content to write into the file.
- $end : string
- The end string to match.
- $filename : string
- The file to process.
- $start : string
- The start string to match.
- $excludeStartEnd : bool
- If true, the start and end matches will be removed.
Methods
- __construct() : mixed
- Class constructor.
- content() : $this
- Set the content.
- end() : $this
- Set the end block.
- excludeStartEnd() : $this
- Mark the start and end to be removed.
- filename() : $this
- Set the filename.
- run() : mixed
- Run the task.
- start() : $this
- Set the start block.
Properties
$content
The content to write into the file.
protected
string
$content
= ''
$end
The end string to match.
protected
string
$end
$filename
The file to process.
protected
string
$filename
$start
The start string to match.
protected
string
$start
$excludeStartEnd
If true, the start and end matches will be removed.
private
bool
$excludeStartEnd
= false
Methods
__construct()
Class constructor.
public
__construct([string $filename = '' ]) : mixed
Parameters
- $filename : string = ''
content()
Set the content.
public
content(string $content) : $this
Parameters
- $content : string
-
The content to insert.
Return values
$thisend()
Set the end block.
public
end(string $end) : $this
Parameters
- $end : string
-
The end block.
Return values
$thisexcludeStartEnd()
Mark the start and end to be removed.
public
excludeStartEnd([bool $exclude = true ]) : $this
Parameters
- $exclude : bool = true
-
Whether to exclude the 'start' and 'end'.
Return values
$thisfilename()
Set the filename.
public
filename(string $filename) : $this
Parameters
- $filename : string
-
The file to process.
Tags
Return values
$thisrun()
Run the task.
public
run() : mixed
start()
Set the start block.
public
start(string $start) : $this
Parameters
- $start : string
-
The start block.