class ConfigRewrite

Configuration rewriter

https://github.com/daftspunk/laravel-config-writer

This class lets you rewrite array values inside a basic configuration file that returns a single array definition (a Laravel config file) whilst maintaining the integrity of the file, leaving comments and advanced settings intact.

The following value types are supported for writing:

  • strings
  • integers
  • booleans
  • nulls
  • single-dimension arrays

To do:

  • When an entry does not exist, provide a way to create it

Pro Regex tip: Use [\s\S] instead of . for multi-line support

Methods

toFile($filePath, $newValues, $useValidation = true)

No description

toContent($contents, $newValues, $useValidation = true)

No description

parseContent($contents, $newValues)

No description

parseContentValue($contents, $path, $value)

No description

writeValueToPhp($value)

No description

writeArrayToPhp($array)

No description

buildStringExpression($targetKey, $arrayItems = [], $quoteChar = "'")

No description

string
buildConstantExpression($targetKey, array $arrayItems = [])

Common constants only (true, false, null, integers)

string
buildArrayExpression($targetKey, array $arrayItems = [])

Single level arrays only

buildArrayOpeningExpression($arrayItems)

No description

Details

at line 30
toFile($filePath, $newValues, $useValidation = true)

No description

Parameters

$filePath
$newValues
$useValidation

at line 39
toContent($contents, $newValues, $useValidation = true)

No description

Parameters

$contents
$newValues
$useValidation

at line 65
protected parseContent($contents, $newValues)

No description

Parameters

$contents
$newValues

at line 75
protected parseContentValue($contents, $path, $value)

No description

Parameters

$contents
$path
$value

at line 99
protected writeValueToPhp($value)

No description

Parameters

$value

at line 125
protected writeArrayToPhp($array)

No description

Parameters

$array

at line 137
protected buildStringExpression($targetKey, $arrayItems = [], $quoteChar = "'")

No description

Parameters

$targetKey
$arrayItems
$quoteChar

at line 162
protected string buildConstantExpression($targetKey, array $arrayItems = [])

Common constants only (true, false, null, integers)

Parameters

$targetKey
array $arrayItems

Return Value

string

at line 184
protected string buildArrayExpression($targetKey, array $arrayItems = [])

Single level arrays only

Parameters

$targetKey
array $arrayItems

Return Value

string

at line 200
protected buildArrayOpeningExpression($arrayItems)

No description

Parameters

$arrayItems