PHPackages                             corneltek/genphp - 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/genphp

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

corneltek/genphp
================

1.4.0(9y ago)421.3k63PHPPHP &gt;=5.3.0

Since Mar 21Pushed 9y ago4 watchersCompare

[ Source](https://github.com/c9s/GenPHP)[ Packagist](https://packagist.org/packages/corneltek/genphp)[ RSS](/packages/corneltek-genphp/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (7)Versions (9)Used By (3)

GenPHP
======

[](#genphp)

GenPHP is a powerful, flexible PHP code/project generator, which helps you avoid repeating jobs.

GenPHP can generate anything you defined in the flavor, In the generator class, you can use the simple generator API to generate your code.

By using GenPHP, you can also seperate your global generator (`~/.genphp/flavors`), project-scope generator (`./flavors`).

GenPHP is using Twig template engine from Symfony.

[![Build Status](https://camo.githubusercontent.com/ced048d0e04c83df588450d84673643cbac46c5168b8b0cfb166aed7939d92ec/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f6339732f47656e5048502e706e67)](http://travis-ci.org/c9s/GenPHP)

[![](https://github.com/c9s/GenPHP/raw/master/screenshots/screenshot01.png)](https://github.com/c9s/GenPHP/raw/master/screenshots/screenshot01.png)

Requirements
------------

[](#requirements)

- PHP5.3

Installation
------------

[](#installation)

Copy this line to install genphp:

```
$ curl https://raw.github.com/c9s/GenPHP/master/scripts/install.sh | bash

```

Install built-in flavors
------------------------

[](#install-built-in-flavors)

```
$ git clone https://github.com/c9s/GenPHP-Flavors ~/.genphp/flavors

```

Usage
-----

[](#usage)

After installation, you can run `list` command to list your flavors, You can put your flavor (generator) in global flavor path (`~/.genphp/flavors`) or your current project flavor path (`./flavors` or `./.flavors`), for example:

```
~GenPHP $ genphp list

Available flavors:
    command     flavors
    flavor      flavors
    operation   flavors
    phpunit     flavors
    project     flavors
    flavor      /Users/c9s/.genphp/flavors
    phpunit     /Users/c9s/.genphp/flavors

```

### Creating New Flavors

[](#creating-new-flavors)

The concept of GenPHP is pretty simple, when you run `genphp new`, it first initialize a flavor loader, then use the flavor loader to look up matched flavor from several locations.

The loaded flavor instance initializes a generator (which can be GenericGenerator, or BaseGenerator) to generate the stuff from the flavor resource directory to the destination directory. your generator class works between the flavor resource directory and the destination directory.

#### Creating Flavor

[](#creating-flavor)

To create your flavor from your codebase in your project, type:

```
$ cd your_project
$ mkdir flavors
$ genphp new flavor foo ~/path/to/codebase

Loading flavor...
Inializing option specs...
Running generator...
    create        flavors/foo/Resource
    create        flavors/foo/Resource/file1
    create        flavors/foo/Resource/file2
    create        flavors/foo/Resource/file3
Done

```

You can see those created files files here, it's using GenericGenerator to copy `flavors/foo/Resource` to current directory.

Now you can put your own files (used by generator) into the `Resource` directory.

#### Customizing Your Flavor and Generator

[](#customizing-your-flavor-and-generator)

For more complex usage, to create your own generator, just run:

```
$ genphp new flavor foo

Loading flavor...
Inializing option specs...
Running generator...
    create        flavors/foo/Resource
    render        flavors/foo/Generator.php
Done

```

Create new flavor without codebase path, then open the `Generator.php` file, write your generator actions in the `generate` function.

```
class Generator {

    public function brief() { return 'your generator brief'; }

    public function generate($argument1,$argument2)
    {
        // do your operations here
        $this->copyDir('etc','etc');
    }
}
```

Put your favorite files into `flavors/foo/Resource`, then you can write operation code in PHP.

#### Testing Your Flavor

[](#testing-your-flavor)

Once you have done, You can run `new` command to generate your flavor:

```
$ genphp new foo argument1 argument2

```

And your code is generated.

If you want your flavor be global (system-wide), you can run install command:

```
$ genphp install flavors/foo

```

This installs flavor to your global flavor path.

### Using Operation

[](#using-operation)

GenPHP provides a lot of useful operations for you to write generation tasks very easily.

#### CopyOperation

[](#copyoperation)

To copy directory recursively from flavors/foo/Resource/from/path to to/path

```
$this->copyDir('from/path','to/path');
```

#### TouchOperation

[](#touchoperation)

To touch a file

```
$this->touch('path/to/touch');
```

#### CreateOperation

[](#createoperation)

To create a new file with content

```
$this->create('path/to/file', 'file content' );
```

#### CopyOperation

[](#copyoperation-1)

To copy a file, copy path/file1 from Resource dir to file2

```
$this->copy( 'path/file1' , 'file2' );
```

#### CreateDirOperation

[](#creatediroperation)

To create a directory:

```
$this->createDir( 'path/to/directory' );
```

#### RenderOperation

[](#renderoperation)

To load templateName.php.twig template from flavors/foo/Resource and render the code template with variables to a file:

```
$this->render('templateName.php.twig','path/to/file', array(
    'className' => $className
));
```

#### WriteJsonOperation

[](#writejsonoperation)

To write a json file

```
$this->writeJson('file.json', array( 'name' => 'John' ) );  // executes WriteJsonOperation
```

#### WriteYamlOperation

[](#writeyamloperation)

To write a yaml file

```
$this->writeYaml('file.yaml', array( 'name' => 'John' ) );  // executes WriteJsonOperation
```

#### GitCloneOperation

[](#gitcloneoperation)

To clone/pull a git repository:

```
$this->gitClone( 'git@github.com:.....git' , 'path/to/repo' );
```

#### HgCloneOperation

[](#hgcloneoperation)

To clone/pull a hg repository:

```
$this->hgClone( 'hg uri' , 'path/to/repo' );
```

Command Usage
-------------

[](#command-usage)

To generate a generic PHP project structure, GenPHP provides a built-in template for this:

```
$ genphp new project Foo

    create
    create      src
    create      src/Foo.php
    create      src/Foo
    dependency ant
    create      build.xml
    dependency phpunit
    create      phpunit.xml.dist
    create      tests
```

genphp looks for flavor in `./flavors`, `./.flavors`, `~/.genphp/flavors`, you can define your generator in those paths.

to generate a new flavor:

```
$ genphp new flavor flavorName
```

To generate a new flavor from current existing code base:

```
$ genphp new flavor ProjectA ~/path/to/OneProject
```

To list schemas

```
$ genphp list
```

please check `./flavors` directory of this repository for more details.

Flavor API
----------

[](#flavor-api)

```
$path = $flavor->path( 'license' );
```

Generator Runner
----------------

[](#generator-runner)

```
$loader = new \Flavor\FlavorLoader;
$flavor = $loader->load( $flavorName );
$generator = $flavor->getGenerator();
$generator->setLogger( $this->getLogger() );

$args = func_get_args();
array_shift($args);

$runner = new \GenPHP\GeneratorRunner;
$runner->logger = $logger;
$runner->run($generator,$args);
```

Generator API
-------------

[](#generator-api)

```
public fucntion generate($argument1,$argument2, ... )
{
    $file = $this->flavorLoader->load('license')->path('LICENSE.GPL2');
    $this->copy($file, 'LICENSE' );
    $this->copyDir( );
}
```

### Operations

[](#operations)

By using built-in operations, you can create your code generator very easily, for example, the built-in flavor code generator from GenPHP:

```
namespace flavor;
use GenPHP\Flavor\BaseGenerator;
use GenPHP\Path;

class Generator extends BaseGenerator
{
    public function brief() {
        return "Default Flavor";
    }

    public function generate($name)
    {
        $paths = Path::get_flavor_paths();
        foreach( $paths as $path ) {
            if( file_exists($path) ) {
                $base = $path . DIRECTORY_SEPARATOR . $name;
                $this->createDir( $base . DIRECTORY_SEPARATOR . "Resource");
                $this->render( 'Generator.php.twig',
                    $base . DIRECTORY_SEPARATOR . 'Generator.php',
                    array( 'name' => $name ) );
            }
        }

    }
}
```

Operation name magic:

```
// executes CopyDirOperation
$this->copyDir('from/path','to/path');

// executes TouchOperation
$this->touch('path/to/touch');

// executes TouchOperation
$this->create('path/to/file', 'file content' );

// executes RenderOperation
$this->render('templateName.php.twig','path/to/file', array(
    'className' => $className
));

// executes WriteJsonOperation
$this->writeJson('file.json', array( ... ) );  // executes WriteJsonOperation
```

GenPHP supports many operations:

- CopyDirOperation
- CopyOperation
- CreateDirOperation
- CreateOperation
- RenderOperation
- TouchOperation
- WriteJsonOperation
- WriteYamlOperation

Development
-----------

[](#development)

- Fork this probject on GitHub
- Git clone it:

    $ git clone :{{ your Id }}/GenPHP.git
- Install onion
- run `onion bundle` to install PEAR dependencies.
- run `scripts/genphp` to test your genphp script.
- run `phpunit` to run the test suites.
- run `scripts/compile.sh` to compile whole library into a executable phar file.

### Create New Opeartion

[](#create-new-opeartion)

There is a flavor for creating new opeartion already, just run:

```
$ ./scripts/genphp new operation DoSomething

```

### Create New Flavor

[](#create-new-flavor)

```
$ ./scripts/genphp new flavor flavor_name

```

### IRC

[](#irc)

Join us on irc channel: #genphp on irc.freenode.net

Reference
---------

[](#reference)

- newgem:
- Rails: [http://guides.rubyonrails.org/command\\\_line.html](http://guides.rubyonrails.org/command%5C_line.html)

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~217 days

Recently: every ~378 days

Total

8

Last Release

3332d ago

### 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 (320 commits)")

### Embed Badge

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

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

PHPackages © 2026

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