Index

Field

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

class

Field

Field.php:19
class MMO\pdo\helpers\Field
Namespace
MMO\pdo\helpers

Index

AUTO_INCREMENT_FLAG
CUT_REGEXSplit a column definition on whitespace, keeping a quoted string or a parenthesised group as one token.
FULLTEXT_FLAG
INVISIBLE_FLAG
KEY_FLAG
NORM_TYPES
NOT_FLAG
NOT_NULL_FLAG
NULL_FLAG
PRIMARY_FLAG
TEXT_FLAGS
UNIQUE_FLAG
VISIBLE_FLAG
def
default
flags
foreign
name
add($text)
clear()
defaultToPHP($type)Translate the SQL DEFAULT token into a PHP literal valid for $type.
getDef()
getDefault()
getFlags()
getForeign()
getName()
getType()
isAutoIncrement()
isFulltext()
isInvisible()
isKey()
isNotNull()
isNull()
isPrimary()
isUnique()
isVisible()
parseValues($offset)Read the comma-separated value list of an ENUM(...)/SET(...), unquoted.
quoteValues($values)
toPHP()
typeToPHP($comments)Resolve this column into the PHP type its entity property should have, plus the schema annotations that describe it.
Unquote($text) staticStrip a SQL string literal's surrounding quotes, collapsing the doubled quote SQL escapes one with.
__construct($name, $text)

Constants13

AUTO_INCREMENT_FLAG

const AUTO_INCREMENT_FLAG = 32

CUT_REGEX

Split a column definition on whitespace, keeping a quoted string or a parenthesised group as one token.

const CUT_REGEX = '/"(?:\\\\.|""|[^\\\\"])*"|\\((?:\\\\.|\'(?:\\\\.|\'\'|[^\\\\\'])*\'|"(?:\\\\.|""|[^\\\\"])*"|[^\\\\)])*\\)|\'(?:\\\\.|\'\'|[^\\\\\'])*\'|[^(\'"\\s]+/'NOTE: two things the original pattern got wrong, both of which silently truncated a value rather than failing. The parenthesised alternative now allows quoted segments inside it -- without that it stopped at the first `)` whatever the context, so `ENUM('a)b','c')` was cut mid-value and the fragments were reassembled into the type definition with stray spaces. And a quoted token now accepts the doubled quote SQL escapes with (`''`), which otherwise ended the token early: `DEFAULT 'o''brien'` yielded just `o`.

FULLTEXT_FLAG

const FULLTEXT_FLAG = 256

INVISIBLE_FLAG

const INVISIBLE_FLAG = 128

KEY_FLAG

const KEY_FLAG = 1

NORM_TYPES

const NORM_TYPES = […18 items]

NOT_FLAG

const NOT_FLAG = 16

NOT_NULL_FLAG

const NOT_NULL_FLAG = 24

NULL_FLAG

const NULL_FLAG = 8

PRIMARY_FLAG

const PRIMARY_FLAG = 2

TEXT_FLAGS

const TEXT_FLAGS = […11 items]

UNIQUE_FLAG

const UNIQUE_FLAG = 4

VISIBLE_FLAG

const VISIBLE_FLAG = 64

Properties5

def

protected string $def = ''
Type
string

default

protected ?string $default = null
Type
null | string

flags

protected int $flags = 0
Type
int

foreign

protected ?string $foreign = null
Type
null | string

name

protected string $name
Type
string

Methods24

defaultToPHP($type)

Field.php:219

Translate the SQL DEFAULT token into a PHP literal valid for $type.

protected function defaultToPHP(string $type): ?string
See
$default holds the token exactly as written, quotes included ("'bob'"), because that is how the definition was tokenised -- so it has to be unquoted before it can be re-emitted as PHP, and it has to match the property's PHP type or the generated class will not even compile.
$typestringthe resolved PHP type, without the nullable ?
returnsnull | stringa PHP literal, or null for "no default" (an expression such as CURRENT_TIMESTAMP, or a value that cannot be represented in $type)

getDefault()

Field.php:107
function getDefault(): ?string
returnsnull | stringthe raw DEFAULT token as written in the definition (already quoted if it was quoted).

getFlags()

Field.php:102
function getFlags(): int
returnsinta bitmask of this class's *_FLAG constants.

getForeign()

Field.php:112
function getForeign(): ?string
returnsnull | stringthe raw FOREIGN KEY reference as written in the definition.

parseValues($offset)

Field.php:190

Read the comma-separated value list of an ENUM(...)/SET(...), unquoted.

protected function parseValues(int $offset): array
$offsetintwhere to start looking for the opening parenthesis in $def
returnsarray
throwsif the list is never closed

quoteValues($values)

Field.php:204
protected function quoteValues(array $values): string
$valuesarray
returnsstringthe values as a quoted @var type union, e.g. 'a'|'b'

toPHP()

Field.php:336
function toPHP(): string
returnsstringthis column as an #[ArrayProperty] PHP property declaration, for Table::toPHP.
throwsif the SQL type cannot be translated

typeToPHP($comments)

Field.php:269

Resolve this column into the PHP type its entity property should have, plus the schema annotations that describe it.

protected function typeToPHP(array &$comments): stringNOTE: ENUM/SET are matched FIRST, because their value list is arbitrary text that can contain any other type's keyword (`SET('a','date')`). And the date branch used to be `/\b(DATE)?(TIME(STAMP)?)?\b/i`, where every group is optional -- so it matched the empty string on ANY definition, making it an unconditional catch-all: it swallowed ENUM and SET (which are tested after it), and the final "unknown type" throw below was unreachable dead code. An unrecognised type therefore produced an untyped `protected $x;` instead of an error. Verified directly.
$commentsarray
returnsstringthe PHP type, without the nullable ?
throwsif the SQL type cannot be translated

Unquote($text)

staticField.php:177

Strip a SQL string literal's surrounding quotes, collapsing the doubled quote SQL escapes one with.

protected static function Unquote(string $text): string
$textstring
returnsstring$text unchanged if it is not a quoted literal