Index

PhpConfigEditor

MMO\admin\helpers · 1 symbol · generated 5 Oct 2026

class

PhpConfigEditor

PhpConfigEditor.php:26

Change values of one class's configuration in a PHP file -- the \MMO\config([...]) a project's scripts/bootstrap.php holds -- where they are written, leaving the rest of the file as a person wrote it.

class MMO\admin\helpers\PhpConfigEditor
Namespace
MMO\admin\helpers
The file is code someone reads: its comments say why each value is what it is. So nothing is regenerated. PHP's own tokenizer finds `Class::class => [ ... ]`, then `'key' => <expression>` directly inside it, and only that expression is replaced, by the new value written as PHP. A key the array does not have yet is added after its last one. It does not run the file, so it cannot tell what an expression evaluates to: the current values are the ones the running configuration holds. Lint what it returns (`php -l`) before writing it.
$php = new PhpConfigEditor(\MMO\core\files\get('scripts/bootstrap.php'), ProductionController::class); $php->set('postInstall', null); $php->set('buildCommands', ['php scripts/build-theme.php all --prod']); \MMO\core\files\set('scripts/bootstrap.php', $php->getCode());

Properties2

class

protected string $class
Type
string

code

protected string $code
Type
string

Methods12

entry($section, $key)

PhpConfigEditor.php:143
protected function entry(array $section, string $key): ?array
$sectionarraysection
$keystring
returnsnull | arrayint, 1: int, 2: string}|null where $key's expression starts and ends, and the indentation of its line.

export($value, $indent, $lines)

PhpConfigEditor.php:202
protected function export(mixed $value, string $indent, bool $lines = false): string
$valuemixed
$indentstringthe indentation of the line the value is on.
$lines = falseboolan array one item per line, even when it would fit on one.
returnsstring$value as PHP: short arrays, on one line when that stays short.

next($tokens, $i)

PhpConfigEditor.php:182
protected function next(array $tokens, int $i): ?int
$tokensarray
$iint
returnsnull | intthe index of the next token that is not whitespace or a comment.

section()

PhpConfigEditor.php:96
protected function section(): ?array
returnsnull | arrayint, 1: int, 2: string, 3: int|null}|null where the class's array opens and closes, the indentation of its entries, and where its last meaningful token ends (null for an empty array).

set($key, $value)

PhpConfigEditor.php:57

Write $value as $key's expression.

function set(string $key, mixed $value): static
$keystring
$valuemixednull, a scalar, or an array of those.
returnsstatic
throwswhen the file does not configure the class.

__construct($code, $class)

PhpConfigEditor.php:32
function __construct(string $code, string $class)
$codestringthe PHP file's content.
$classstringthe class whose configuration array is edited, as Foo::class names it -- written in the file fully qualified or not, it is matched on its last part.