Download the PHP package asika/muse without Composer
On this page you can find all versions of the php package asika/muse. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package muse
Short Description Muse - The PHP Code generator. She is Goddess, she is the Creator.
License GNU Lesser General Public License
Homepage https://github.com/asika32764/muse
Informations about the package muse
Muse - The PHP Code Generator
A powerful php scaffolding framework, help developers generate their code by custom templates.
Installation via Composer
Add this dependency in your composer.json
.
Or just create a project:
Getting Started
Muse is a command line based program, we will do everything though CLI. Please type:
You will get this help message:
Generate code by Acme Template
Acme template is a default template in Muse, generating code is very easy, please type:
Now you will see message like below:
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:
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
Using this command to init a new template.
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
Open FlowerTemplate
, you can set replaced string and copy path here:
Register replacing variables
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:
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 & Paths
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 & 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:
The CopyAllAction
class
These two class all very simple and follows single responsibility principle, we can organize our multiple actions in one controller like below:
The benefit of single action class is that we can re-use every classes in different task.
File Operation
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:
There will be more operator(eg: databaseOperator
, gitOperator
) in the future.
Filesystem
There are three filesystem classes: Path
, File
and Folder
, which extends from Windwalker Filesystem package,
please see: https://github.com/ventoviro/windwalker-filesystem
Simple usage:
So you can using Filesystem classes in Action class to help you operate files and directories.
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
Create a command class in src/Muse/Windwalker/Command/MyTask/MyTask.php
How to use Windwalker Console and Command? See: https://github.com/ventoviro/windwalker-console
(2) Register your command to application
Register this command in src/Muse/Windwalker/Application::registerCommands()
You will get new help like this:
(3) Create a new Task controller
Create a class in src/FlowerTemplate/Task/MyTask.php
Now you can do some actions here.
(4) Test your task
Typing this command and you can go into your task controller:
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:
Then use GeneratorController
in your project entry (For example: Symfony Console):
OK it's very easy, have a good time in your code recipe.
Todo
- DatabaseOperator
- GitOperator
- FtpOperator
- UnitTest
- Completed docblock
- Easy to add task controller and command
All versions of muse with dependencies
windwalker/structure Version ~3.0
windwalker/utilities Version ~3.0