Create a new app or component

As of swoftcli v0.1.0 , it is possible to quickly create a new application skeleton with built-in commands or create a new component skeleton structure.

View command group

 php swoftcli.phar new
// or use alias
php swoftcli.phar create 

Command group description:

  • Command group new (group create ), which can be accessed by any one of them
  • Has two subcommands, application and component for creating new applications and new component structures respectively

Swoftcli-new

Create a new app

Creating a new app is by pulling on a template project repository that already exists on github, so you can easily customize the template to suit your needs.

By default, swoft provides five template repositories, which are convenient for users to pull different skeleton structures as needed. You can see which default skeletons are available in the command help below.

View command

 php swoftcli.phar create:app -h
// or use alias
php swoftcli.phar create:app 

Swoftcli-new-app

Command instructions

Command parameters:

  • name string sets the name new project and also the name of the directory as the new application. have to

Command options:

  • --repo string Customize the git address of the template repository, which can be UERANME/REPO or full url address
  • --type string Select one of the 5 template repositories provided by default as the source repository. The default is http

YOUR_APP_NAME refers to your new project name and is also the directory name for the new app.

Use create:app YOUR_APP_NAME directly, using the swoft-http-project template repository by default. If you need a template repository such as ws/tcp/rpc as the base template, you can specify the type option as follows.

 php swoftcli.phar create:app --type ws YOUR_APP_NAME
php swoftcli.phar create:app --type tcp YOUR_APP_NAME 

If you need to do some complete customization of the template, then you can create the required template repository on your github and use the following command:

 php swoftcli.phar create:app --repo UERANME/REPO YOUR_APP_NAME 

The full git repository address used; this is not limited to pulling from github, ie it can also be pulled from its own git service to initialize a new application.

 php swoftcli.phar create:app --repo https://github.com/UERANME/REPO.git YOUR_APP_NAME 

Create a new app with commands

Let's try the command to create a new app.

 php swoftcli.phar create:app --type http my-swoft-app 

We can see the following information:

Swoftcli-new-app

Create a new component

Swoft also provides simple and quick commands to create a new component skeleton.

The skeleton structure is very simple, including basic files such as composer.json README.md AutoLoader.php

View command

 php swoftcli.phar create:component --help
// or use alias
php swoftcli.phar create:c 

Swoftcli-new-cpt

Command instructions

Command parameters:

  • name string sets the name new component and also serves as the component directory name. have to

Command options:

  • -n, --namespace string Sets the namespace of the component. After setting, it will be automatically written to the PSR4 of composer.json .
  • --no-licence bool whether to add LICENSE file, it will be added by default
  • -o, --output string component creates an output path; if not set, it is created in the current directory
  • --pgk-name The package --pgk-name string component is automatically written to composer.json . If it is empty, it will be composed of the current user name plus the component name.

Create a new app with commands

Let's try to create a new component structure.

 php swoftcli.phar create:component my-swoft-component -n 'MySwoft\Component' -o vendor/somedir 

We can see the following information:

Swoftcli-new-app

/docs/2.x/en/tool/swoftcli/create-app-or-component.html
progress-bar