Oihana PHP Arango

MigrationGenerator

Generates a new migration file — the `migrate --create` boilerplate, with no database dependency (it only writes a file).

By default it produces a named, timestamped Migration subclass with empty // TODO up() / down() bodies, the intent written by a human afterwards. create() can also pre-fill those bodies with provided PHP code — the hook the arango:analyzers --fix action uses to emit a ready-to-review repair migration rather than an empty shell.

Tags
author

Marc Alcaraz (ekameleon)

since
1.2.0

Table of Contents

Properties

$namespace  : string
$path  : string

Methods

__construct()  : mixed
create()  : string
Writes a new `Version<timestamp>_<Label>.php` file and returns its path.
body()  : string
Indents a (possibly multi-line) code body to the method-body column of the generated file, leaving blank lines empty.
label()  : string
Turns a free description into a PascalCase class label.
skeleton()  : string
The body of a generated migration file.
timestamp()  : string
The current `YmdHis` version prefix (overridable in tests).
useBlock()  : string
Builds the `use …;` import block — the always-needed {@see Migration} plus the caller-supplied class names, deduplicated and sorted so the output is deterministic.

Properties

Methods

__construct()

public __construct(string $path[, string $namespace = '' ]) : mixed
Parameters
$path : string

The directory the version file is written to.

$namespace : string = ''

The PHP namespace the generated class is declared in.

create()

Writes a new `Version<timestamp>_<Label>.php` file and returns its path.

public create(string $description[, string|null $timestamp = null ][, string|null $up = null ][, string|null $down = null ][, array<int, string> $uses = [] ]) : string

By default the up() / down() bodies are left as a // TODO shell (the migrate --create case). When $up (and optionally $down) is given, that PHP code is injected verbatim into the method bodies — the hook the arango:analyzers --fix action uses to write a ready-to-review repair migration instead of an empty shell.

Parameters
$description : string

A human description (also turned into the class label).

$timestamp : string|null = null

The YmdHis version prefix — injected for determinism; defaults to now.

$up : string|null = null

PHP code for the up() body (without the method wrapper); null keeps the // TODO shell.

$down : string|null = null

PHP code for the down() body; null keeps the // TODO shell.

$uses : array<int, string> = []

Extra fully-qualified class names to use at the top of the file (so an injected body can reference them by their short name). Migration is always imported.

Tags
throws
RuntimeException

When the directory is missing or the file cannot be written.

Return values
string

The path of the created file.

body()

Indents a (possibly multi-line) code body to the method-body column of the generated file, leaving blank lines empty.

protected body(string $code) : string
Parameters
$code : string
Return values
string

label()

Turns a free description into a PascalCase class label.

protected label(string $description) : string
Parameters
$description : string
Return values
string

skeleton()

The body of a generated migration file.

protected skeleton(string $class, string $description[, string|null $up = null ][, string|null $down = null ][, array<int, string> $uses = [] ]) : string
Parameters
$class : string

The class name.

$description : string

The human description.

$up : string|null = null

PHP code for the up() body; null falls back to the // TODO shell.

$down : string|null = null

PHP code for the down() body; null falls back to the // TODO shell.

$uses : array<int, string> = []

Extra fully-qualified class names to import (deduplicated and sorted with Migration).

Return values
string

timestamp()

The current `YmdHis` version prefix (overridable in tests).

protected timestamp() : string
Return values
string

useBlock()

Builds the `use …;` import block — the always-needed {@see Migration} plus the caller-supplied class names, deduplicated and sorted so the output is deterministic.

protected useBlock(array<int, string> $uses) : string
Parameters
$uses : array<int, string>

Extra fully-qualified class names.

Return values
string
On this page

Search results