Neuron-PHP

FieldSet

An ordered collection of {@see Field} objects describing a resource.

A FieldSet can be built from a --fields definition string or from database introspection (see SchemaIntrospector). Generators consume it to produce models, DTOs, repositories, views and migrations.

Table of Contents

Properties

$fields  : array<string|int, mixed>

Methods

__construct()  : mixed
all()  : array<string|int, Field>
editable()  : array<string|int, Field>
Fields that should appear in forms and DTOs: excludes the primary key and the auto-managed timestamp columns.
except()  : self
Remove the named fields, but never drop the primary key.
fromDefinition()  : self
Build a FieldSet from a `--fields` definition string.
isEmpty()  : bool
listable()  : array<string|int, Field>
Fields suitable for an index listing (first few editable columns).
names()  : array<string|int, string>
Field names, in declaration order.
normalizeType()  : string
Normalize a user-supplied or DB type to a logical type.
only()  : self
Restrict the set to the named fields, preserving the primary key so the generated show view and key-based links stay coherent.
primary()  : Field|null
Get the primary key field, if one is defined.

Properties

$fields

private array<string|int, mixed> $fields = []

Methods

__construct()

public __construct([array<string|int, Field$fields = [] ]) : mixed
Parameters
$fields : array<string|int, Field> = []

all()

public all() : array<string|int, Field>
Return values
array<string|int, Field>

All fields.

editable()

Fields that should appear in forms and DTOs: excludes the primary key and the auto-managed timestamp columns.

public editable() : array<string|int, Field>
Return values
array<string|int, Field>

except()

Remove the named fields, but never drop the primary key.

public except(array<string|int, string> $names) : self
Parameters
$names : array<string|int, string>
Return values
self

fromDefinition()

Build a FieldSet from a `--fields` definition string.

public static fromDefinition(string $definition) : self

Format: "title:string,body:text,published:boolean,name:string:255". An optional third segment sets the length for string types.

Parameters
$definition : string
Return values
self

isEmpty()

public isEmpty() : bool
Return values
bool

Whether the set contains any fields.

listable()

Fields suitable for an index listing (first few editable columns).

public listable([int $max = 4 ]) : array<string|int, Field>
Parameters
$max : int = 4

Maximum number of columns to display

Return values
array<string|int, Field>

names()

Field names, in declaration order.

public names() : array<string|int, string>
Return values
array<string|int, string>

normalizeType()

Normalize a user-supplied or DB type to a logical type.

public static normalizeType(string $type) : string
Parameters
$type : string
Return values
string

only()

Restrict the set to the named fields, preserving the primary key so the generated show view and key-based links stay coherent.

public only(array<string|int, string> $names) : self
Parameters
$names : array<string|int, string>
Return values
self

primary()

Get the primary key field, if one is defined.

public primary() : Field|null
Return values
Field|null
On this page

Search results