Console Basics

Table of Contents

  1. Introduction
  2. Running Commands
  3. Getting Help
  4. Built-In Commands
    1. app:down
    2. app:env
    3. app:rename
    4. app:runlocally
    5. app:up
    6. composer:dump-autoload
    7. composer:update
    8. encryption:generatepassword
    9. framework:flushcache
    10. make:*
    11. uuid:generate
    12. views:flush

Introduction

Console applications are great for administrative tasks and code generation. Apex is Opulence's own robust console kernel. With it, you can easily create your own console commands, display question prompts, and use HTML-like syntax for output styling.

Running Commands

To run commands, type php apex COMMAND_NAME from the directory that Opulence is installed in.

Getting Help

To get help with any command, use the help command. There are a few different ways to call it:

php apex help COMMAND_NAME
php apex COMMAND_NAME -h
php apex COMMAND_NAME --help

Built-In Commands

A good place to start is to run php apex in the directory you installed Opulence. This will list the commands registered to the console. Out of the box, a few commands come bundled with Apex:

app:down

Creates a file that lets the Opulence\Framework\Http\Middleware\CheckMaintenanceMode middleware know to thrown a 503 HttpException, which renders a "Down for maintenance" response.

app:env

Displays the current application environment name, eg "Production" or "Development".

app:rename

When you install Opulence, the default namespace is "Project". Use this command to change this to something more fitting to your particular project. This will update namespaces, bootstrapper names, the directory under src, and the composer.json PSR-4 settings.

app:runlocally

Runs Opulence locally using the built-in PHP web server. You can change the domain and port using the --domain and --port options, respectively.

app:up

Deletes the file that forces the application into maintenance mode.

composer:dump-autoload

This provides a wrapper around Composer's dump-autoload command, and is useful when another command needs to dump the autoload after running.

composer:update

A common task is updating composer and dumping the autoload. Instead of having to run these commands manually, just run php apex composer:update.

encryption:generatepassword

The cryptography library uses a password, from which cryptographic keys are derived to encrypt and decrypt data. This command uses a CSPRNG to generate a password that can be used with the encryption library. Calling this will update the password that appears in config/environment/.env.app.php. Passing a --show option will instead only show a new password, not update the config.

framework:flushcache

Opulence has an internal cache for several of its components:

If you add/remove/modify any of these components in your application, you must run this command to flush the internal cache. Otherwise, your changes may not take effect.

make:*

To make creating new classes as simple as possible, Apex supports several make:* commands to generate class files:

  1. make:command
  2. make:controller
  3. make:datamapper
  4. make:entity
  5. make:httpmiddleware

They all accept a single argument: the name of the class to generate. If you input a fully-qualified class name, then that namespace and class name will be used. Otherwise, the default namespace will be used (eg controllers are under Project\Http\Controllers).

uuid:generate

This command creates a new UUID.

views:flush

If you also use Opulence's HTTP kernel and view template, you can use this command to clear the view cache. This is handy for when you've made updates to your views.