PHPackages                             popphp/pop-kettle - 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. [CLI &amp; Console](/categories/cli)
4. /
5. popphp/pop-kettle

ActiveLibrary[CLI &amp; Console](/categories/cli)

popphp/pop-kettle
=================

A CLI helper application for the Pop PHP Framework.

2.3.4(6mo ago)44.3k13BSD-3-ClausePHPPHP &gt;=8.3.0CI passing

Since Mar 12Pushed 6mo ago1 watchersCompare

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

READMEChangelog (10)Dependencies (7)Versions (32)Used By (3)

pop-kettle
==========

[](#pop-kettle)

[![Build Status](https://github.com/popphp/pop-kettle/workflows/phpunit/badge.svg)](https://github.com/popphp/pop-kettle/actions)[![Coverage Status](https://camo.githubusercontent.com/51dc42fd726dffefc0b716c2182b1075fac9ea04cacb556681b36bf479b0248d/687474703a2f2f63632e706f707068702e6f72672f636f7665726167652e7068703f636f6d703d706f702d6b6574746c65)](http://cc.popphp.org/pop-kettle/)

[![Join the chat at https://discord.gg/TZjgT74U7E](https://camo.githubusercontent.com/acad7b0eeb78b78d08ffd2b85681ab243436388b5f86f8bcb956a69246e53739/68747470733a2f2f6d656469612e706f707068702e6f72672f696d672f646973636f72642e737667)](https://discord.gg/TZjgT74U7E)

- [Overview](#overview)
- [Install](#install)
- [Initializing an Application](#initializing-an-application)
    - [Application Status](#application-status)
- [Kettle Include](#kettle-include)
- [Managing the Database](#managing-the-database)
    - [Seeding the Database](#seeding-the-database)
    - [Database Migrations](#database-migrations)
    - [Migration State Storage](#migration-state-storage)
- [Creating Application Files](#creating-application-files)
    - [Data Model](#data-model)
- [Running the Web Server](#running-the-web-server)
- [Accessing the Application](#accessing-the-application)
- [Shell Completion](#shell-completion)
- [Using on Windows](#using-on-Windows)

Overview
--------

[](#overview)

`pop-kettle` is a CLI-helper application for the Pop PHP Framework that allows a user to quickly build the scaffolding for an application. It is included with the Pop PHP Framework as the command `kettle` within the main project directory.

[Top](#pop-kettle)

Install
-------

[](#install)

The `pop-kettle` component comes automatically installed when you install the full Pop PHP Framework. You should see the `kettle` script in the main project directory. However, if that is not the case, and you need to install it manually, you can place a copy of the `kettle`script from the `vendor/popphp/pop-kettle/kettle` location in the main project folder (adjacent to the `vendor` folder):

```
$ cp vendor/popphp/popphp-framework/kettle .
```

Once you've copied the script over, you have to change the reference to the script's config file from:

```
    $app = new Pop\Application(
        $autoloader, include __DIR__ . '/config/app.console.php'
    );
```

to

```
    $app = new Pop\Application(
        $autoloader, include __DIR__ . '/vendor/popphp/pop-kettle/config/app.console.php'
    );
```

and make sure the newly copied `kettle` script is set to execute (755)

```
$ chmod 755 kettle
```

[Top](#pop-kettle)

Initializing an Application
---------------------------

[](#initializing-an-application)

By running the following command, you can set up the basic files and folders required to run an application:

```
$ ./kettle app:init [--web] [--api] [--cli]
```

The `` parameter is the namespace of your application, for example `MyApp`. The optional parameters of `--web`, `--api`, and `--cli` will create the related files and folders to run the application as a normal web application, an API-driven web application, a CLI-driven console application or any combination thereof. The default route for the web application or the API application is `/`. However, if both are initialized, then the default route for the API application becomes `/api`. The web application will deliver a placeholder HTML page and the API application will deliver a placeholder JSON response.

The web/API application's front controller will be located in `public/index.php` and the main script for the CLI application will be located in `script/myapp` (named according to the provided &lt;namespace&gt; value.)

After the application files and folders are copied over, you will be asked if you would like to configure a database. Follow those steps to configure a database and create the database configuration file.

### Application Status

[](#application-status)

You can view and manage the status of the application with the following commands outlined below.

#### Check the current environment:

[](#check-the-current-environment)

The environment is set in the `.env` file under the `APP_ENV` variable. Options available are:

- `local`
- `dev`
- `testing`
- `staging`
- `production` (or `prod`)

```
$ ./kettle app:env
```

#### Check (or change) the current status:

[](#check-or-change-the-current-status)

The status of the application can either be "live" or in "maintenance mode". The value is set in the `.env` file under the `MAINTENANCE_MODE` variable (`true` or `false`).

```
$ ./kettle app:status
```

To put the application into maintenance mode, where it's not accessible, use the following command:

```
$ ./kettle app:down
```

You can generate a "secret" key to allow a select set of users to view the application while still in maintenance mode:

```
$ ./kettle app:down --secret
```

When the command finishes, it will output the auto-generated secret:

```
    The secret is SECRET_STRING

```

You can also provide your own secret:

```
$ ./kettle app:down --secret=MY_SECRET_STRING
```

Use that string one time in the browser as a URL query parameter to view the application while it is still in maintenance mode. It will store in the browser's cookies so subsequent requests will be valid:

```
http://localhost:8000/?secret=SECRET_STRING

```

To take the application out of maintenance mode and make it live again, use the following command:

```
$ ./kettle app:up
```

[Top](#pop-kettle)

Kettle Include
--------------

[](#kettle-include)

You should see a file `kettle.inc.php` next to the main `kettle` script. This serves as a configuration file for anything additional that needs to be wired up for your application to work with kettle. The file is included right after the creation of the `$autoloader` and `$app` objects, so you will have direct access to them. In this file you can add any additional runtime requirements, configurations or routes.

For example, there may be an instance were `kettle` needs to be aware of your application and its namespace. You can access the autoloader here and register your application with `kettle` in the `kettle.inc.php` file:

```
$autoloader->addPsr4('MyApp\\', __DIR__ . '/app/src');
```

**Note:** If the `kettle.inc.php` file isn't available, you can copy it from the `vendor/popphp/pop-kettle/kettle` location to the main project folder (adjacent to the `vendor` folder.)

[Top](#pop-kettle)

Managing the Database
---------------------

[](#managing-the-database)

Once the application is initialized, you can manage the database, or multiple databases, by using the `db` and `migrate` commands. If you don't pass anything in the optional `[]` parameter, it will default to the `default` database.

```
./kettle db:install []                    Install the database (Runs the config, test and seed commands)
./kettle db:config []                     Configure the database
./kettle db:test []                       Test the database connection
./kettle db:create-seed  []         Create database seed class
./kettle db:seed []                       Seed the database with data
./kettle db:export []                     Export the database to a file (MySQL only)
./kettle db:import  []              Import the database from a file (MySQL only)
./kettle db:reset []                      Reset the database with original seed data
./kettle db:clear []                      Clear the database of all data

./kettle migrate:create  []        Create new database migration class
./kettle migrate:run [] []         Perform forward database migration
./kettle migrate:rollback [] []    Perform backward database migration
./kettle migrate:point [] []          Point to specific migration, w/o running (.current file only)'
./kettle migrate:reset []                 Perform complete rollback of the database
```

### Seeding the Database

[](#seeding-the-database)

You can seed the database with data in one of two ways. You can either utilize a SQL file with the extension `.sql` in the `/database/seeds/` folder, or you can write a seeder class using PHP. To create a seeder class, you can run:

```
$ ./kettle db:create-seed  []
```

Where the `` is the base class name of the seeder class that will be created. The template seeder class will be copied to the `/database/seeds/` folder:

```
