PHPackages                             asika/muse - 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. [Framework](/categories/framework)
4. /
5. asika/muse

AbandonedArchivedFramework[Framework](/categories/framework)

asika/muse
==========

Muse - The PHP Code generator. She is Goddess, she is the Creator.

1.0.2(10y ago)1917.8k3[2 issues](https://github.com/asika32764/muse/issues)2GNU Lesser General Public LicensePHP

Since Jan 12Pushed 9y ago4 watchersCompare

[ Source](https://github.com/asika32764/muse)[ Packagist](https://packagist.org/packages/asika/muse)[ Docs](https://github.com/asika32764/muse)[ RSS](/packages/asika-muse/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (5)Versions (7)Used By (2)

Muse - The PHP Code Generator
=============================

[](#muse---the-php-code-generator)

[![Latest Stable Version](https://camo.githubusercontent.com/f2365ed18716d5e520872e674209d97364ed28f0e11b77a424af927dc46fb741/68747470733a2f2f706f7365722e707567782e6f72672f6173696b612f6d7573652f762f737461626c652e737667)](https://packagist.org/packages/asika/muse) [![Total Downloads](https://camo.githubusercontent.com/3d4b0d7c21ceeab43e28a542c95f6ce14d4bbec3c382b7a29cb54a60610ba930/68747470733a2f2f706f7365722e707567782e6f72672f6173696b612f6d7573652f646f776e6c6f6164732e737667)](https://packagist.org/packages/asika/muse) [![Latest Unstable Version](https://camo.githubusercontent.com/65223655419714e7e78cc9d6266832598fefd5b6593984434c9e27b423de6cd5/68747470733a2f2f706f7365722e707567782e6f72672f6173696b612f6d7573652f762f756e737461626c652e737667)](https://packagist.org/packages/asika/muse) [![License](https://camo.githubusercontent.com/af3b049cc4ee7051fd4e080149e1ab95bf744be9680f444f58de030d187c2d7c/68747470733a2f2f706f7365722e707567782e6f72672f6173696b612f6d7573652f6c6963656e73652e737667)](https://packagist.org/packages/asika/muse)

A powerful php scaffolding framework, help developers generate their code by custom templates.

Installation via Composer
-------------------------

[](#installation-via-composer)

Add this dependency in your `composer.json`.

```
{
    "require": {
        "asika/muse": "1.*",
        "windwalker/console": "~2.0"
    }
}
```

Or just create a project:

```
php composer.phar create-project asika/muse muse 1.*
```

Getting Started
---------------

[](#getting-started)

Muse is a command line based program, we will do everything though CLI. Please type:

```
php bin/muse
```

You will get this help message:

```
Muse - The Muse - version: 1
------------------------------------------------------------

[muse Help]

Muse console application.

Usage:
  muse  [option]

Options:

  -h | --help       Display this help message.
  -q | --quiet      Do not output any message.
  -v | --verbose    Increase the verbosity of messages.
  --ansi            Set 'off' to suppress ANSI colors on unsupported terminals.
  -p | --path       Dest path.
  -t | --tmpl       Sub template name.

Commands:

  gen             Genarate operation.
  tmpl-init       Init a new template.
  tmpl-convert    Convert a directory and files back to a template.

```

### Generate code by Acme Template

[](#generate-code-by-acme-template)

Acme template is a default template in Muse, generating code is very easy, please type:

```
php bin/muse gen acme test/MyApp
```

Now you will see message like below:

```
$ php bin/muse gen acme test/MyApp
File created: /var/www/muse/test/MyApp/admin/article/edit.twig
File created: /var/www/muse/test/MyApp/admin/article/index.twig
File created: /var/www/muse/test/MyApp/admin/category/edit.twig
File created: /var/www/muse/test/MyApp/admin/category/index.twig
File created: /var/www/muse/test/MyApp/article.twig
File created: /var/www/muse/test/MyApp/global/index.html
File created: /var/www/muse/test/MyApp/index.html
File created: /var/www/muse/test/MyApp/index.twig
```

### Put your SubTemplate to Acme Template

[](#put-your-subtemplate-to-acme-template)

Now you can put your code to `src/AcmeTemplate/Template/mytmpl`.

And using this command to generate your sub template:

```
php bin/muse gen acme test/MyApp2 -t mytmpl
```

Create your project template
----------------------------

[](#create-your-project-template)

Now everything is very easy, but how can we create our own template? We have to write some code to configure paths and variables.

### Init a sample template

[](#init-a-sample-template)

Using this command to init a new template.

```
php bin/muse tmpl-init flower
```

```
File created: /var/www/muse/src/FlowerTemplate/Action/ConvertAction.php
File created: /var/www/muse/src/FlowerTemplate/Action/CopyAllAction.php
File created: /var/www/muse/src/FlowerTemplate/Task/Convert.php
File created: /var/www/muse/src/FlowerTemplate/Task/Generate.php
File created: /var/www/muse/src/FlowerTemplate/Template/default/DefaultClass.php
File created: /var/www/muse/src/FlowerTemplate/FlowerTemplate.php

```

OK, we created a sample template named `flower`, this template will locate at `src/FlowerTemplate` with an entry class `FlowerTemplate`, actually you can create it manually, but this will be a little complex, so we are better using the sample first.

### Configure Variable and Paths

[](#configure-variable-and-paths)

Open `FlowerTemplate`, you can set replaced string and copy path here:

#### Register replacing variables

[](#register-replacing-variables)

```
protected $tagVariable = array('{@', '@}');

protected function registerReplaces($io, $replace = array())
{
    $item = $io->getOption('n', 'sakura');

    /*
     * Replace with your code name.
     */

    // Set item name, default is sakura
    $replace['item.lower'] = strtolower($item);
    $replace['item.upper'] = strtoupper($item);
    $replace['item.cap']   = ucfirst($item);

    // Set project name
    $replace['project.class'] = 'Muse';

    return $replace;
}
```

This example means we can type `-n {item}` to be a variable name. And in template code, the `{@item.lower@}` /`{@item.upper@}` /`{@item.cap@}` will be replace to the item name.

`sakura` is the default value if you don't give the `-n` param. This is an example that if `-n` not found, just exit and notice user type this param:

```
$item = $io->getOption('n') ? : exit('Please give me item using "-n {item_name}"');
```

You can add many string to `$replace` array, remember you will need each lower, upper and capital cases, and don't forget to return it.

#### Register Config &amp; Paths

[](#register-config--paths)

```
protected function registerConfig($io, $config)
{
    /*
     * Replace with your project path.
     */

    $subTemplate = $io->getOption('t', 'default');
    $dest        = $io->getArgument(1) ? : 'generated';

    $config['path.src']  = __DIR__ . '/Template/' . $subTemplate;
    $config['path.dest'] = GENERATOR_PATH . '/' . $dest;

    return $config;
}
```

You can set some useful config in this method, the most important is `path.src` and `path.dest`. These two config tell Muse where code from and where code copied to.

`GENERATOR_PATH` is root path of Muse, and the `$io->getArgument(1)` means get second argument of your command(First is 0).

### Task &amp; Action

[](#task--action)

We have two default task controller, `Generate` and `Convert`.

Generate task does the code generate action, and Convert task can help us convert code back to a template. In task controller we can using `doAction()` to execute some different action to do something we want to do.

The `Generate` controller class:

```
namespace FlowerTemplate\Task;

use FlowerTemplate\Action;
use Muse\Controller\AbstractTaskController;

class Generate extends AbstractTaskController
{
	public function execute()
	{
		$this->doAction(new Action\CopyAllAction);
	}
}
```

The `CopyAllAction` class

```
namespace FlowerTemplate\Action;

use Muse\Action\AbstractAction;
use Muse\FileOperator\CopyOperator;

class CopyAllAction extends AbstractAction
{
	protected function doExecute()
	{
		$copyOperator = new CopyOperator($this->io, (array) $this->config['tag.variable']);

		$copyOperator->copy($this->config['path.src'], $this->config['path.dest'], $this->config['replace']);
	}
}
```

These two class all very simple and follows single responsibility principle, we can organize our multiple actions in one controller like below:

```
class Generate extends AbstractTaskController
{
	public function execute()
	{
		$this->doAction(new Action\CopyAllAction);

		$this->doAction(new Action\ImportSqlAction);

		$this->doAction(new Action\Github\CloneSomeRepoAction);

		$this->doAction(new Action\User\CreateNewUserAction);
	}
}
```

The benefit of single action class is that we can re-use every classes in different task.

### File Operation

[](#file-operation)

#### Operator classes

[](#operator-classes)

We provides two operators now, `copyOperator` help us copy codes and replace tag to variables, `convertOperator` help us copy code too, but replace variable by tags.

Just new an instance and using copy method:

```
$copyOperator = new CopyOperator($this->io, array('{@', '@}'));

$copyOperator->copy($src, $dest, $replaceArray);
```

There will be more operator(eg: `databaseOperator`, `gitOperator`) in the future.

#### Filesystem

[](#filesystem)

There are three filesystem classes: `Path`, `File` and `Folder`, which extends from Windwalker Filesystem package, please see:

Simple usage:

```
namespace Muse\Filesystem;

Filesystem\Folder::copy($src, $dest);
Filesystem\Folder::move($src, $dest);
Filesystem\Folder::create($path);
Filesystem\Folder::delete($path);

Filesystem\File::copy($src, $dest);
Filesystem\File::move($src, $dest);
Filesystem\File::write($path, $buffer);
Filesystem\File::delete($path);

// Replace / and \ to DIRECTORY_SEPARATOR
$path = Filesystem\Path::clean($path);
```

So you can using Filesystem classes in Action class to help you operate files and directories.

### Create a new Task

[](#create-a-new-task)

If you want a new task controller, this will need some steps to create a task. The process not very easy, we will make the process easier in the future.

#### (1) Create a new Command

[](#1-create-a-new-command)

Create a command class in `src/Muse/Windwalker/Command/MyTask/MyTask.php`

```
namespace Muse\Windwalker\Command\MyTask;

use Muse\Controller\GeneratorController;
use Muse\Windwalker\IO;
use Windwalker\Console\Command\Command;

class MyTask extends Command
{
	protected $name = 'mytask';

	protected $description = 'Desc of my task.';

	protected $usage = 'mytask  [option]';

	public function configure()
	{
		parent::configure();
	}

	protected function doExecute()
	{
		$controller = new GeneratorController(new IO($this));

		$controller->setTask('mytask')->execute();
	}
}
```

How to use Windwalker Console and Command? See:

#### (2) Register your command to application

[](#2-register-your-command-to-application)

Register this command in `src/Muse/Windwalker/Application::registerCommands()`

```
protected function registerCommands()
{
    $this->addCommand(new Command\Generate\Generate);
    $this->addCommand(new Command\Init\Init);
    $this->addCommand(new Command\Convert\Convert);

    // Add here
    $this->addCommand(new Command\MyTask\Task);
}
```

You will get new help like this:

```
Available commands:

  gen             Genarate operation.
  tmpl-init       Init a new extension.
  tmpl-convert    Convert a code folder back to a template.
  mytask          Desc of my task.

```

#### (3) Create a new Task controller

[](#3-create-a-new-task-controller)

Create a class in `src/FlowerTemplate/Task/MyTask.php`

```
namespace FlowerTemplate\Task;

use FlowerTemplate\Action;
use Muse\Controller\TaskController;

class MyTask extends TaskController
{
	public function execute()
	{
		$this->doAction(new Action\CopyAllAction);
	}
}
```

Now you can do some actions here.

#### (4) Test your task

[](#4-test-your-task)

Typing this command and you can go into your task controller:

```
php bin/muse mytask
```

Integrate To Your Project or Framework
--------------------------------------

[](#integrate-to-your-project-or-framework)

Muse can integrate to any framework instead default Windwalker Console Application. Just create an `IO` class to help Muse input and output some information:

```
use Muse\IO\IOInterface;

class MyIOAdapter implements IOInterface
{
    // Implement this interface
}
```

Then use `GeneratorController` in your project entry (For example: Symfony Console):

```
$controller = new GeneratorController(new MyIOAdapter($input, $output));

$controller->setTask($input->getArgument('task'))->execute();
```

OK it's very easy, have a good time in your code recipe.

Todo
----

[](#todo)

- DatabaseOperator
- GitOperator
- FtpOperator
- UnitTest
- Completed docblock
- Easy to add task controller and command

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity67

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 ~134 days

Total

5

Last Release

3606d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1639206?v=4)[Simon Asika](/maintainers/asika32764)[@asika32764](https://github.com/asika32764)

---

Top Contributors

[![asika32764](https://avatars.githubusercontent.com/u/1639206?v=4)](https://github.com/asika32764 "asika32764 (55 commits)")

---

Tags

code-generatorcode-templatephpscaffoldscaffold-frameworkscaffoldingcodescaffoldinggeneratorscaffoldbuildermuse

### Embed Badge

![Health badge](/badges/asika-muse/health.svg)

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

###  Alternatives

[symfony/maker-bundle

Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget about writing boilerplate code.

3.4k111.1M568](/packages/symfony-maker-bundle)[amranidev/scaffold-interface

A Smart CRUD Generator For Laravel

92120.7k1](/packages/amranidev-scaffold-interface)[atk4/data

Agile Data - Database access abstraction framework

2811.7M37](/packages/atk4-data)[artem-schander/l5-modular

Modular pattern generator for Laravel

223235.5k](/packages/artem-schander-l5-modular)[winter/wn-builder-plugin

Builder plugin for Winter CMS

3938.3k](/packages/winter-wn-builder-plugin)[liinkiing/graphql-maker-bundle

Bundle to easily create GraphQL types for Overblog GraphQLBundle

103.9k](/packages/liinkiing-graphql-maker-bundle)

PHPackages © 2026

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