Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Php Generator Laravel Package

nette/php-generator

Generate PHP code via a fluent API: build classes, interfaces, functions, methods, properties, namespaces, and PHPDoc, then render to valid PHP. Handy for code generators, scaffolding tools, and runtime code output with strict formatting and escaping.

View on GitHub
Deep Wiki
Context7
v4.2.2

This release focuses on making namespaces and classes work together more naturally. Classes now know which namespace they belong to, constructors accept fully qualified names, and a new unified add() method on PhpFile ties it all together. Under the hood, the Factory got a thorough refactoring and the codebase passed its first mandatory static analysis check.

  • PhpNamespace::add() now automatically assigns itself as the namespace of any ClassLike passed to it. If your code relied on getNamespace() returning null after adding a class to a namespace, you'll need to update that assumption.

  • PhpFile::add() – a single entry point for adding classes, interfaces, traits, enums, functions, and namespaces to a file. It handles namespace creation and bracket syntax automatically, so you can build a complete file with just add() calls.

  • ClassLike::getFullName() – returns the fully qualified name when the class belongs to a namespace (e.g., App\Model\User), the short name otherwise, or null for anonymous classes.

  • ClassLike constructors now accept FQN – pass 'App\Model\User' and the namespace is extracted automatically. No need to create the namespace separately for simple cases.

  • PhpNamespace::add() accepts GlobalFunction – the unified add() method now handles functions alongside class-like types, making the namespace API more consistent.

  • The $namespace parameter in ClassLike constructors is deprecated. Use setNamespace() instead. The old signature still works for now, but will be removed in a future version.

v4.2.1

This release focuses on making namespaces and classes work together more naturally. Classes now know which namespace they belong to, constructors accept fully qualified names, and a new unified add() method on PhpFile ties it all together. Under the hood, the Factory got a thorough refactoring and the codebase passed its first mandatory static analysis check.

  • PhpNamespace::add() now automatically assigns itself as the namespace of any ClassLike passed to it. If your code relied on getNamespace() returning null after adding a class to a namespace, you'll need to update that assumption.

  • PhpFile::add() – a single entry point for adding classes, interfaces, traits, enums, functions, and namespaces to a file. It handles namespace creation and bracket syntax automatically, so you can build a complete file with just add() calls.

  • ClassLike::getFullName() – returns the fully qualified name when the class belongs to a namespace (e.g., App\Model\User), the short name otherwise, or null for anonymous classes.

  • ClassLike constructors now accept FQN – pass 'App\Model\User' and the namespace is extracted automatically. No need to create the namespace separately for simple cases.

  • PhpNamespace::add() accepts GlobalFunction – the unified add() method now handles functions alongside class-like types, making the namespace API more consistent.

  • The $namespace parameter in ClassLike constructors is deprecated. Use setNamespace() instead. The old signature still works for now, but will be removed in a future version.

v4.2.0
  • requires PHP 8.1
  • Visibility, PropertyHookType & PropertyAccessMode are enums (BC break)
  • removed deprecated stuff
  • addTrait() second argument is deprecated (BC break)
v4.1.9
  • support for PHP 8.5
  • final promoted property in PHP 8.5
  • optimized global function calls
v4.1.8
  • Factory::fromClassReflection() extracts property hook bodies (#172)
  • Factory::fromClassReflection() rejects $withBodies for interfaces
  • improved tests
  • cs
v4.1.7
  • added support for PHP 8.4 features
    • properties hooks
    • asymmetric visibility
    • property can be abstract / final
    • interfaces can have properties
  • added Visibility
  • ClassManipulator::implement() can implement abstract classes
  • ClassManipulator::implementInterface() renamed to implement()
  • PsrPrinter is not final
  • Constant: type can be nullable
  • Factory: fixed visibility of promoted property
v4.0.10
  • Extractor::extractAll() fixed file comment parsing
  • Factory: $withBodies cannot be used for internal classes/functions
  • Printer: fixed falsy Attribute aren't printed (#142)
  • added Visibility
v4.1.6
  • added ClassManipulator
  • Parameter & Property: isNullable() returns true when default value is null (possible BC break)
  • added TraitsAware::hasTrait method (#163)
  • support for PHP 8.4
v4.1.5
  • added PhpNamespace::getClass() & getFunction()
  • added CommentAware::removeComment()
  • added PhpFile::removeNamespace()
  • Factory, Extractor: sets flag readonly for promoted properties #158 (reverts "Factory: properties in readonly classes are not readonly")
  • ClassType: cloning includes attributes and parameters
  • GlobalFunction, Method: from() accepts first-class callables
v4.1.4
  • PsrPrinter: opening bracket on the correct line #155
  • Make ClassLike::from return type assert the subclass type (BC break) (#154)
  • Dumper::dumpArray(), dumpArguments() optimization
  • Dumper: simplified list with negative keys
  • added parameter $overwrite to addMember(), addMethod(), addProperty(), addConstant(), addCase() #152
  • Factory: parameters 'int $foo = null' are parsed as '?int'
v4.1.3
  • Extractor: supports PHP-Parser 5.0 (#150)
  • Extractor: fix escaping quotes when converting to double quoted string #151
  • Extractor: NOWDOC/HEREDOC are not converted to single line strings
  • Dumper: added $customObjects
  • Dumper: refactoring, added dumpCustomObject()
  • Printer: option $omitEmptyNamespaces is applied by printFile() [Close #147]
v4.1.2
  • Support union type in Type::nullable (#141)
  • Extractor: fixed extracting of special arrays #143
v4.1.1
  • ClassType: added inheritMethod() & inheritProperty()
  • Printer: added option $omitEmptyNamespaces
  • added ConstantsAware::getConstant()
  • Extractor::extractAll() extracts only top-level classes and functions, fixed file comment parsing
  • Extractor: extracts native PHP values
  • ClassType: getType() is deprecated
  • Printer: fixed falsy Attribute aren't printed (#142)
v4.1.0
  • ClassType::class(), interface(), traits() & enum() are deprecated
  • removed Nette\SmartObject
  • removed deprecated stuff
v4.0.9
  • Parameters can have comments
  • added Literal::new() #130
  • fixed #135
v4.0.8
  • support for PHP 8.3
  • Factory: properties in readonly classes are not readonly
  • FunctionLike: added getParameter() & hasParameter()
  • ConstantsAware: added hasConstant() (#133)
v4.0.7
  • Printer: added $singleParameterOnOneLine (#132)
  • fixed class resolving in trait usages #128
  • Printer: multiline attributes are in own attribute block
  • Printer: attributes on parameters are placed on its own line
  • coding style
v4.0.6
  • added support for typed constants
  • Printer: print brace on next line when method/function has typehint
  • Printer: promoted parameters / parameter with attributes are always multiline
  • Printer: printAttributes & printReturnType are protected #123
  • used PhpStorm Language attribute
v4.0.5
  • added support for PHP 8.2 features: DNF types, constants in traits, readonly classes, Type::True
  • Type: constants are PascalCase
  • Extractor: keeps the first comment in the method #119
  • Printer: allow customizing comment formatting through protected printDocComment (#118)
  • Helpers::formatDocComment() added option $forceMultiLine
  • Factory: object class contains path from root namespace (#117)
  • Extractor: Fixed extracting enum method body #115 (#116)
  • PhpNamespace: better use-statements sorting behavior
v3.6.9
  • Extractor: keeps the first comment in the method #119
  • Factory: object class contains path from root namespace (#117)
  • Extractor: Fixed extracting enum method body #115 (#116)
  • Type: constants are PascalCase
v4.0.3
  • support for PHP 8.2
  • Dumper::dumpObject() refactoring
  • Printer: added $linesBetweenUseTypes (#114)
v3.6.8
  • support for PHP 8.2
  • Extractor: added support for Readonly promoted parameters (#111)
v4.0.2
  • Printer: added $bracesOnNextLine #112
  • Extractor: added support for Readonly promoted parameters (#111)
  • Printer: refactoring
  • Dumper: supports __serialize()
  • Dumper, Helpers::formatDocComment(), Printer::printFunction() & etc normalizes whitespace
  • Printer: always prints trailing comma #106
  • TraitType: traits cannot have constants
v4.0.1
  • ClassType divided into InterfaceType, TraitType & EnumType
  • Enum: value can be expression
  • Extractor: supports promoted parameters #103
  • Extractor: maintains exact visibility
  • PhpNamespace: added removeUse() #102
  • constants are PascalCase
  • strict fixes
  • ClassType::__clone() clones traits
v3.6.7
  • Extractor: supports promoted parameters #103
  • Extractor: maintains exact visibility
  • PhpNamespace: added removeUse() #102
  • constants are PascalCase
  • ClassType::__clone() clones traits
v4.0.0

This release takes advantage of all the new features of PHP 8 and cleans up some issues in the API.

  • uses PHP 8 typehints & property typehints
  • Dumper: prints comma after last argument

Stricter behaviour:

  • ClassType::add*() throws exception when method/property/etc already exists
  • PhpNamespace::add*() throws exception when class/function already exists

Changes:

  • ClassType::addTrait() returns new class TraitUse instead of $this
  • ClassType::getTraits() returns TraitUse[] instead of string[]
  • Method: body is always string, even for interfaces
  • ClassType::setConstants() and setTraits() accepts array of Constant resp TraitUse objects only

Deprecations:

  • deprecated magic properties (BC break)
  • ClassType::withBodiesFrom() replaced with from(..., withBodies: true)
  • GlobalFunction::withBodyFrom() replaced with from(..., withBody: true)
  • ClassType::from() & Factory::fromClassReflection(): removed parameter $materializeTraits
v3.6.6
  • Extractor: preserves the first comment in the file #100
  • PhpNamespace: added removeClass() & removeFunction()
  • coding style

This is the last 3.6.x release.

v3.6.5
  • PhpNamespace: added resolveName()
  • Extractor: fixed extracting attributes #98
  • PhpNamespace::addUse() ignores names in current namespace #96
  • Dumper: improved encoding of strings

BLOG POST: https://blog.nette.org/en/phpgenerator-3-6-news-from-php-8-1-and-more

v3.6.4
  • use-statements for functions & constants
  • ClassType: method names are case insensitive
  • PhpNamespace: class and function names are case-insensitive
  • PhpNamespace: addUse() & simplifyName() is case-insensitive
  • PhpNamespace::simplifyName() fixed collision when alias already exists
  • PhpNamespace: improved collision checking between class and alias
  • PhpNamespace::addUse() removed parameter $aliasOut (BC break)
  • PhpNamespace::addUse() simplified aliases generation
  • Factory: supports 'new' in parameters
  • accept numeric array keys when validating types #91
v3.6.2
  • Printer: added property $wrapLength #55 #56
  • getType(), getReturnType(): added option $asObject that returns Nette\Utils\Type
  • Factory: constant values are tagged for resolving
  • Resolving of names in body & literals #85
  • "use Trait" can have comments #90
  • added TraitUse, represents use-statement
  • PhpNamespace::simplifyType() supports generics like Foo<A, B>
  • PhpNamespace::unresolveName() renamed to simplifyName()
  • Helpers::unindent() fixed when level = 0
  • Dumper::format() placeholder ? must not be followed by \w
  • Dumper: added $indentation
  • Dumper: refactoring
  • Printer: refactoring, added property $dumper
  • Printer: refactoring, added property $namespace
  • Revert "Dumper: dumps Closure as PHP code" (BC break)
  • PhpNamespace::addUse() added validation
  • checks reserved class names
  • added validator for types
  • added Property and Parameter validation
  • improved validation error messages
  • Escapes */ in comments
v3.6.1
  • added ClassType::fromCode() & PhpFile::fromCode() #79
  • Factory::fromClassReflection() added option to materialize traits or not #89
  • PhpFile, PhpNamespace: can contain functions [Closes #80]
  • PhpFile: added getClasses()
  • Factory: generates trait resolutions
  • ClassType: constants are 'public' by default
  • Dumper: prints closures as func(...) in PHP 8.1
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport