Download the PHP package asika/php-code-generator without Composer

On this page you can find all versions of the php package asika/php-code-generator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-code-generator

PHP Code Generator

Latest Stable Version Total Downloads Latest Unstable Version License

Repository deprecated, please see: Muse

Installation via Composer

Add this dependency in your composer.json.

Or just create a project:

Getting Started

PHP Code Generator 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 PHP Code Generator, 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 PHP Code Generator where code from and where code copied to.

GENERATOR_PATH is root path of PHP Code Generator, 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/CodeGenerator/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/CodeGenerator/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

PHP Code Generator can integrate to any framework instead default Windwalker Console Application. Just create an IO class to help PHP Code Generator 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


All versions of php-code-generator with dependencies

PHP Build Version
Package Version
Requires windwalker/filesystem Version ~2.0@stable
windwalker/registry Version ~2.0@stable
windwalker/utilities Version ~2.0@stable
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package asika/php-code-generator contains the following files

Loading the files please wait ....