PHPackages                             corneltek/codegen - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. corneltek/codegen

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

corneltek/codegen
=================

PHP Code Generation Library

3.2.2(2y ago)38193.6k↓23.3%3[12 issues](https://github.com/c9s/CodeGen/issues)[1 PRs](https://github.com/c9s/CodeGen/pulls)10MITPHPPHP &gt;=5.3.0

Since Apr 25Pushed 2y ago5 watchersCompare

[ Source](https://github.com/c9s/CodeGen)[ Packagist](https://packagist.org/packages/corneltek/codegen)[ Docs](http://github.com/c9s/CodeGen)[ RSS](/packages/corneltek-codegen/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (34)Used By (10)

CodeGen
=======

[](#codegen)

[![Build Status](https://camo.githubusercontent.com/24cad2923fa1b8132655213fde96756f1915fa10e9b3829e730bd3bbaaebc7bf/68747470733a2f2f7472617669732d63692e6f72672f6339732f436f646547656e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/c9s/CodeGen)[![Latest Stable Version](https://camo.githubusercontent.com/a2657ff493d337b65ff86fc816fcfde22d1a3ebc00b58c6a2a91c6ba40dba9f0/68747470733a2f2f706f7365722e707567782e6f72672f636f726e656c74656b2f636f646567656e2f762f737461626c65)](https://packagist.org/packages/corneltek/codegen)[![Total Downloads](https://camo.githubusercontent.com/aae5b890e27533260a863329ec7fca836e0e1239c0206a2c1382d8a4f812cb3a/68747470733a2f2f706f7365722e707567782e6f72672f636f726e656c74656b2f636f646567656e2f646f776e6c6f616473)](https://packagist.org/packages/corneltek/codegen)[![Monthly Downloads](https://camo.githubusercontent.com/76ebca7b3d5647342ddfba3b13051a5fe80c28e8bce75338fa6359b7ca7b8db7/68747470733a2f2f706f7365722e707567782e6f72672f636f726e656c74656b2f636f646567656e2f642f6d6f6e74686c79)](https://packagist.org/packages/corneltek/codegen)[![Daily Downloads](https://camo.githubusercontent.com/69eb7a340748b7802b3054c5fe5fa37c216507296e4fd7e5685970fee92e8069/68747470733a2f2f706f7365722e707567782e6f72672f636f726e656c74656b2f636f646567656e2f642f6461696c79)](https://packagist.org/packages/corneltek/codegen)[![Latest Unstable Version](https://camo.githubusercontent.com/940cc9b6c1401e730de7185081127f95698469963c59601fee3e68b958450214/68747470733a2f2f706f7365722e707567782e6f72672f636f726e656c74656b2f636f646567656e2f762f756e737461626c65)](https://packagist.org/packages/corneltek/codegen)[![License](https://camo.githubusercontent.com/73e65c844e75172087a0dd4b7edce8993d2029de49690c836a71967238e37f21/68747470733a2f2f706f7365722e707567782e6f72672f636f726e656c74656b2f636f646567656e2f6c6963656e7365)](https://packagist.org/packages/corneltek/codegen)

Transform your dynamic calls to static calls!

Expressions
-----------

[](#expressions)

### ConcatExpr

[](#concatexpr)

```
$concat = new ConcatExpr('foo1', 'bar2');
$concat // 'foo1' . 'bar2'
```

### AssignExpr

[](#assignexpr)

```
$assign = new AssignExpr('$foo', 10);
echo $assign; // $foo = 10
```

### Wrapping Expr with Statement object

[](#wrapping-expr-with-statement-object)

```
$statement = new Statement($assign);
echo $statement; // $foo = 10;
```

UserClass
---------

[](#userclass)

### Creating UserClass

[](#creating-userclass)

```
use CodeGen\UserClass;
$cls = new UserClass('FooClass');
$code = $cls->render();
```

### Implementing an interface

[](#implementing-an-interface)

```
$cls = new UserClass('FooClass');
$class->implementInterface('ArrayAccess');
```

### Adding properties

[](#adding-properties)

```
$cls->addPublicProperty('foo');
$cls->addPublicProperty('foo', 1);
$cls->addPublicProperty('foo', ['foo','bar']);
```

```
$cls->addProtectedProperty('foo');
$cls->addProtectedProperty('foo', 1);
$cls->addProtectedProperty('foo', ['foo','bar']);
```

### Adding class methods

[](#adding-class-methods)

```
$cls->addMethod('public','getName',[],['return $this->name;']);
```

```
$cls->addMethod('public','setName',['$name'],['$this->name = $name;']);
```

### Generating class file by PSR-0 or PSR-4

[](#generating-class-file-by-psr-0-or-psr-4)

```
$cls->generatePsr0ClassUnder('src'); // This places 'Foo\Bar' at src/Foo/Bar.php
```

```
$cls->generatePsr4ClassUnder('src/Zoo'); // This places 'My\Foo\Bar' at src/Zoo/Bar.php
```

Generators
----------

[](#generators)

### ArrayAccessGenerator

[](#arrayaccessgenerator)

```
$generator = new ArrayAccessGenerator;
$userClass = new UserClass('MyZoo');
$userClass->addPublicProperty('animals', array(
    'tiger' => 'John',
    'cat'   => 'Lisa',
));
$generator->generate('animals', $userClass);
$userClass->requireAt('tests/generated/my_zoo.fixture');
$zoo = new MyZoo;
```

### AppClassGenerator

[](#appclassgenerator)

```
$foo = new FooClass(1,2);
$generator = new AppClassGenerator(array(
    'prefix' => 'OhMy',
));

$appClass = $generator->generate($foo);
// echo $appClass->render();

$this->assertCodeEqualsFile('tests/data/app_class_generator_ohmyfoo.fixture', $appClass);

$path = $appClass->generatePsr4ClassUnder('tests/generated');
$this->assertFileExists($path);
require_once($path);

$this->assertTrue(class_exists('OhMyFooClass'));

$ohMyFoo = new OhMyFooClass;
$this->assertEquals(1, $ohMyFoo->foo);
```

Statements
----------

[](#statements)

### Generating `require_once` statement

[](#generating-require_once-statement)

```
use CodeGen\Constant;
use CodeGen\Statement\RequireOnceStatement;
$varfile = new Constant('file.php');
$requireStmt = new RequireOnceStatement($varfile);
```

The code above generates:

```
require_once 'file.php';
```

### Generating `require` statement

[](#generating-require-statement)

```
use CodeGen\Constant;
use CodeGen\Statement\RequireStatement;
$varfile = new Constant('file.php');
$requireStmt = new RequireStatement($varfile);
```

The code above generates:

```
require 'file.php';
```

```
use CodeGen\Constant;
use CodeGen\Variable;
use CodeGen\Statement\RequireStatement;
$varfile = new Variable('$file');
$requireStmt = new RequireStatement($varfile);
```

The code above generates:

```
require $file;
```

### Generating if isset statement condition

[](#generating-if-isset-statement-condition)

```
$foo = new Variable('$foo');
$ifFoo = new IfIssetStatement($foo, ['key', 'key2', 0], function() use ($foo) {
    $block = new Block;
    $block[] = new Statement(new AssignExpr($foo, new Constant(30)));
    return $block;
});
```

The code above generates:

```
if (isset($foo['key']['key2'][0])) {
    $foo = 30;
}
```

Framework Generators
--------------------

[](#framework-generators)

### PHPUnit TestCase Generator

[](#phpunit-testcase-generator)

### Apache Config Generator

[](#apache-config-generator)

```
use CodeGen\Generator\AccessorClassGenerator;
use CodeGen\Frameworks\Apache2\VirtualHostDirectiveGroup;
$g = new AccessorClassGenerator([
    'prefix' => 'App',
]);
$appClass = $g->generate(new VirtualHostDirectiveGroup);
$appClass->generatePsr4ClassUnder('src/CodeGen/Frameworks/Apache2/');
```

```
use CodeGen\Generator\AccessorClassGenerator;
use CodeGen\Frameworks\Apache2\VirtualHostDirectiveGroup;
$g = new AccessorClassGenerator([
    'namespace' => 'CodeGen\Frameworks\Apache2',
    'class_name' => 'ApacheSiteConfig',
]);
$appClass = $g->generate(new VirtualHostDirectiveGroup);
$appClass->generatePsr4ClassUnder('src/CodeGen/Frameworks/Apache2/');
```

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance14

Infrequent updates — may be unmaintained

Popularity42

Moderate usage in the ecosystem

Community24

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 98.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~115 days

Recently: every ~645 days

Total

32

Last Release

828d ago

Major Versions

0.2.0 → 1.0.02014-04-25

1.4.5 → 2.0.02015-04-14

2.7.1 → 3.0.02016-06-10

PHP version history (2 changes)0.2.0PHP &gt;=5.3.0

2.0.0PHP &gt;=5.4.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/3cc34cde233b660869ff329ed8e20df611f75dfb61aab3e30889ac153d3e5e61?d=identicon)[c9s](/maintainers/c9s)

---

Top Contributors

[![c9s](https://avatars.githubusercontent.com/u/50894?v=4)](https://github.com/c9s "c9s (226 commits)")[![bitdeli-chef](https://avatars.githubusercontent.com/u/3092978?v=4)](https://github.com/bitdeli-chef "bitdeli-chef (1 commits)")[![detain](https://avatars.githubusercontent.com/u/1364504?v=4)](https://github.com/detain "detain (1 commits)")[![Ronmi](https://avatars.githubusercontent.com/u/59556?v=4)](https://github.com/Ronmi "Ronmi (1 commits)")

### Embed Badge

![Health badge](/badges/corneltek-codegen/health.svg)

```
[![Health](https://phpackages.com/badges/corneltek-codegen/health.svg)](https://phpackages.com/packages/corneltek-codegen)
```

###  Alternatives

[stfalcon/tinymce-bundle

This Bundle integrates TinyMCE WYSIWYG editor into a Symfony2 project.

2692.9M24](/packages/stfalcon-tinymce-bundle)[codefog/contao-haste

haste extension for Contao Open Source CMS

42650.8k139](/packages/codefog-contao-haste)[spomky-labs/pwa-bundle

Progressive Web App Manifest Generator Bundle for Symfony.

6144.4k1](/packages/spomky-labs-pwa-bundle)[leapt/core-bundle

Symfony LeaptCoreBundle

2529.1k4](/packages/leapt-core-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
