nette/php-generator
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
nette/utils | v4.0.4 | 61.98 kB | (BSD-3-Clause OR GPL-2.0-only OR GPL-3.0-only) | prod | 1 |
Nette PHP Generator is a convenient tool for developers, helping you generate neat and precise PHP code with ease. It supports the latest PHP features such as enums, attributes, and existing classes modification, among others. With the ability to structure the code for classes, functions, PHP files, and more according to the developer's guidelines, this PHP code generator is highly efficient and mature. The library outputs stable and PSR-12 compliant code, making it a widely used tool for developers.
To use Nette PHP Generator, you need to install it by using the following command:
composer require nette/php-generator
After the installation, you can utilize its functionalities in your PHP code. Here's a sample code usage:
$class = new Nette\PhpGenerator\ClassType('Demo');
$class->setFinal()
->setExtends(ParentClass::class)
->addImplement(Countable::class)
->addComment("Description of class.\nSecond line\n")
->addComment('@property-read Nette\Forms\Form $form');
echo $class;
This will generate the following PHP code:
/**
* Description of class.
* Second line
*
* @property-read Nette\Forms\Form $form
*/
final class Demo extends ParentClass implements Countable
{
}
Additional functionalities such as creating enums, setting up printers, defining types, adding attributes, and many more can be explored as well in reference to the documentation.
The documentation for nette/php-generator is available on the library's website at https://doc.nette.org/php-generator. The documentation covers all topics related to the PHP generator such as classes, interfaces, traits, enums, anonymous classes, global functions, closures, arrow functions, method and function signature, printers, and PSR compliance, types, literals, attributes, and many more. Through the documentation, developers can find all the information they need to utilize the PHP generator most efficiently.