PhpFile
final class PhpFile
Definition of a PHP file.
Generates:
- opening tag (<?php)
- doc comments
- one or more namespaces
Methods
Adds a namespace, class-like type, or function to the file. If the item has a namespace, it will be added to that namespace (creating it if needed).
Adds a class to the file. If it already exists, throws an exception.
Adds an interface to the file. If it already exists, throws an exception.
Adds a trait to the file. If it already exists, throws an exception.
Adds a function to the file. If it already exists, throws an exception.
Adds a namespace to the file. If it already exists, it returns the existing one.
Removes the namespace from the file.
No description
No description
No description
Adds a use statement to the file, to the global namespace.
Adds declare(strict_types=1) to output.
No description
No description
Details
at line 33
static PhpFile
fromCode(string $code)
No description
at line 43
PhpFile
add(PhpNamespace $item)
Adds a namespace, class-like type, or function to the file. If the item has a namespace, it will be added to that namespace (creating it if needed).
at line 67
ClassType
addClass(string $name)
Adds a class to the file. If it already exists, throws an exception.
As a parameter, pass the full name with namespace.
at line 79
InterfaceType
addInterface(string $name)
Adds an interface to the file. If it already exists, throws an exception.
As a parameter, pass the full name with namespace.
at line 91
TraitType
addTrait(string $name)
Adds a trait to the file. If it already exists, throws an exception.
As a parameter, pass the full name with namespace.
at line 103
EnumType
addEnum(string $name)
Adds an enum to the file. If it already exists, throws an exception.
As a parameter, pass the full name with namespace.
at line 115
GlobalFunction
addFunction(string $name)
Adds a function to the file. If it already exists, throws an exception.
As a parameter, pass the full name with namespace.
at line 126
PhpNamespace
addNamespace(PhpNamespace $namespace)
Adds a namespace to the file. If it already exists, it returns the existing one.
at line 142
PhpFile
removeNamespace(PhpNamespace $namespace)
Removes the namespace from the file.
at line 157
array
getNamespaces()
No description
at line 164
array
getClasses()
No description
at line 179
array
getFunctions()
No description
at line 196
PhpFile
addUse(string $name, string|null $alias = null, string $of = PhpNamespace::NameNormal)
Adds a use statement to the file, to the global namespace.
at line 206
PhpFile
setStrictTypes(bool $state = true)
Adds declare(strict_types=1) to output.
at line 213
bool
hasStrictTypes()
No description
at line 219
string
__toString()
No description