PHPackages                             metehan/marsgen - 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. metehan/marsgen

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

metehan/marsgen
===============

A PHP code generation and scaffolding tool.

081PHP

Since Apr 25Pushed 9y agoCompare

[ Source](https://github.com/metehan/marsgen)[ Packagist](https://packagist.org/packages/metehan/marsgen)[ RSS](/packages/metehan-marsgen/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (1)Used By (0)

Marsgen PHP File Generator
==========================

[](#marsgen-php-file-generator)

Marsgen is a PHP generator. It generates predefined files and folders with given data. It can be used to generate scaffolding. It can create files and folders and put codes inside.

##### Steps

[](#steps)

- Prepare code generation template
- Create a seed file
- Run from command line

Usage
=====

[](#usage)

If you have PHP installed and if its callable from your terminal just download this repository and run this command: (for windows there is a bat file so you can just use "marsgen" instead of "php marsgen.php")

```
D:\marsgen>php marsgen.php generate /example/planets /example/planet_seed.php /output

```

This command will fetch every file under */example/planets* folder and it will load config from */example/planet\_seed.php* and generate all files and folders under */output* folder.

Seed file and output folder are optional. If no output folder defined it will generate files on the folder where command called from.

Templating and Syntax
=====================

[](#templating-and-syntax)

Template file names and folder names may have variables. Lets say you want to generate VenusModel.php and VenusView.php you can name the template files as -Planet-Model.php and -Planet-View.php and set what to replace in seed file. Inside `__FileSystem__` everything will be replaced by using *str\_replace()* function.

```
$seed['__FileSystem__'] = [
  '-Planet-' => 'Venus'
];
$seed['myVar'] = 'Hello World';
$seed['myArray'] = [['name'=>'item1'],['name'=>'item2']];
```

In template files you can place variables with `/*{myVar}*/` syntax with above seed file this will generate `Hello world` as output.

You can loop code blocks with "for" `/*{for:myArray}*/ Name value is /*{myArray>name}*/. /*{/for*/}` This "for" loop will output: `Name value is: item1. Name value is: item2.` You can use isset blocks inside for blocks. Probably you already noticed syntax for accessing array values is: `/*{myArray>name}*/`

Isset block is simple ` /*{isset:myVar}*/ myVar's value is /*{myVar}*/ /*{/isset}*/`

Sample
======

[](#sample)

**Template file: SourceFolder/Controllers/-Planet-Controller.php**

```
