zendframework/zend-code
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
zendframework/zend-eventmanager | 3.2.1 | 45.97 kB | BSD-3-Clause | prod | 1 |
Zendframework/zend-code is a powerful tool that extends the PHP Reflection API, providing the capabilities of static code scanning and code generation. This package offers an object-oriented interface to generate arbitrary code to either create new code pieces or to update the existing ones. While it's primarily used for generating PHP code, developers can extend the base class to generate codes for other tasks such as JavaScript, configuration files, apache vhosts, and more.
To use the zendframework/zend-code, you need first to install it via composer:
composer require zendframework/zend-code
Here's an example of how to generate a PHP Class using zend-code:
use Zend\Code\Generator\ClassGenerator;
use Zend\Code\Generator\MethodGenerator;
$generator = new ClassGenerator();
$generator->setName('MyClass')
->addMethodFromGenerator(MethodGenerator::fromArray([
'name' => 'sayHello',
'body' => 'return "Hello!";'
]));
echo $generator->generate();
This script will output:
class MyClass
{
public function sayHello()
{
return "Hello!";
}
}
The complete documentation for zendframework/zend-code can be found at Zend Code Documentation. If you're migrating from version 2 to version 3, there's a dedicated section for that in the documentation which can be accessed at Zend Code Migration Documentation. For any issues or queries, navigate to the GitHub issue page of zendframework/zend-code.