Documentation
¶
Overview ¶
Package php reads a PHP source file and returns a structured summary of the first class/interface/trait/enum declaration it finds: namespace, FQCN, modifiers, parent/implements, public methods, constructor dependencies, and the docblock summary.
The goal is to let downstream tools answer questions about a class without making the model cat the whole file.
Backend: github.com/VKCOM/php-parser (pure Go, no CGO). Adapter is the package-level Read/ReadString — swap backends here if VKCOM ever stops being viable.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Slice ¶
Slice returns the source text of the named top-level function or class method in src. symbol may be a bare name ("completeTask") or qualified ("CompleteTaskController::completeTask"). On no match, names lists the available function/method identifiers so callers can build a helpful error.
Types ¶
type Attr ¶
Attr is a PHP attribute together with its arguments, in source order. Name is the resolved FQCN (e.g. "Doctrine\ORM\Mapping\Column"), so consumers can match on a stable suffix regardless of the `use` alias.
type AttrArg ¶
AttrArg is one attribute argument. Name is the label for named args ("length", "type", ...) or "" for positional. Value is a best-effort stringification: strings unquoted, ints/floats verbatim, bools as "true"/"false", arrays as "[a,b]", class consts as "Foo::BAR".
type CtorDep ¶
CtorDep is one constructor argument. Promoted=true means it's also declared as a property (PHP 8 promoted-property syntax).
type EnumCase ¶
EnumCase is one case of a PHP enum. Value is the backing value for a backed enum (string/int); "" for a pure enum.
type Method ¶
type Method struct {
Name string
Params []Param
ReturnType string
Attributes []string
Attrs []Attr
}
Method is a public method signature. Attributes hold the bare names (#[Override] -> "Override"); Attrs additionally carries the resolved names with arguments (e.g. #[Route('/x', methods: ['GET'])]).
type Property ¶
type Property struct {
Name string
Type string // PHP type as written, resolved like params; "" if untyped
Visibility string // public | protected | private
Attributes []Attr
}
Property is a class property with its declared type and attributes.
type Symbol ¶
type Symbol struct {
File string
Namespace string
FQCN string
Kind Kind
Modifiers []string // final, readonly, abstract — in source order
Extends string // empty for interfaces/traits/enums; FQCN otherwise
Implements []string // for classes: implements list; for interfaces: extends list; for enums: implements list
Uses []string // FQCN of traits composed via `use` in the body (classes and traits)
DocSummary string // first non-tag line of the class-level docblock, or ""
Attributes []Attr // class-level attributes with arguments (e.g. #[ORM\Table(...)])
CtorDeps []CtorDep
Properties []Property // declared properties (any visibility) with type + attributes
Cases []EnumCase // enum cases (empty for non-enums)
Methods []Method // public only; __construct excluded (captured as CtorDeps)
Partial bool // recovered by the regex fallback, not the AST: names are unresolved and members are absent
}
Symbol is the structured summary of one PHP type declaration. All names are FQCN where applicable (parser resolves short names via `use`-imports).
func Read ¶
Read parses path and returns the first type declaration. Returns an error if no such declaration exists, or if the file cannot be parsed.
func ReadString ¶
ReadString parses src (which must begin with "<?php") and uses virtualPath as the Symbol.File field and as context in error messages. Useful for unit tests where the source lives in a string literal.