Toolkit

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

$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.
__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()  : Result
Run the task.
start()  : $this
Set the start block.

Properties

$content

The content to write into the file.

protected string $content = ''

$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 = ''
Return values
mixed

content()

Set the content.

public content(string $content) : $this
Parameters
$content : string

The content to insert.

Return values
$this

end()

Set the end block.

public end(string $end) : $this
Parameters
$end : string

The end block.

Return values
$this

excludeStartEnd()

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
$this

filename()

Set the filename.

public filename(string $filename) : $this
Parameters
$filename : string

The file to process.

Tags
throws
TaskException
Return values
$this

run()

Run the task.

public run() : Result
Return values
Result

start()

Set the start block.

public start(string $start) : $this
Parameters
$start : string

The start block.

Return values
$this

Search results