Skip to main content

Unattended Setup Mode

The PostCreateScript supports unattended (non-interactive) setup via a JSON configuration file.

How It Works

  1. Place a setup.json file in one of the supported locations (see below)
  2. Run composer create-project
  3. The setup script will detect the file and run in unattended mode
  4. The setup.json file remains for reuse across multiple projects

Configuration File Locations

The script searches for setup.json in the following locations (in priority order):

1. Environment Variable (Highest Priority)

Use the SETUP_JSON environment variable to specify a custom location:

SETUP_JSON=/path/to/custom-setup.json composer -sdev create-project byjg/rest-reference-architecture my-project ^6.0

Use cases:

  • Custom configuration locations
  • CI/CD pipelines with specific configs
  • Temporary overrides for specific projects

2. Parent Directory

The script looks in the directory where you run the composer create-project command:

/home/user/projects/setup.json          # ← Config file here
/home/user/projects/my-project/ # ← New project created here

Use cases:

  • Project-specific configurations
  • Quick one-off setups
  • When you want config alongside projects

The script checks your home directory:

Linux/Mac:

~/.rest-reference-architecture/setup.json

Windows:

C:\Users\YourName\.rest-reference-architecture\setup.json

Use cases:

  • Personal default configurations
  • Settings you want to reuse for all projects
  • Keep your workspace clean

Setup Examples

Example 1: Personal Defaults in Home Directory

Create your personal defaults once:

# Linux/Mac
mkdir -p ~/.rest-reference-architecture
cat > ~/.rest-reference-architecture/setup.json << 'EOF'
{
"git_user_name": "John Doe",
"git_user_email": "[email protected]",
"install_examples": false
}
EOF

# Now create projects anywhere - they'll use your defaults
cd ~/projects
composer -sdev create-project byjg/rest-reference-architecture project1 ^6.0
composer -sdev create-project byjg/rest-reference-architecture project2 ^6.0

Example 2: Parent Directory (Quick Setup)

# Create config in your projects directory
cd ~/projects
cat > setup.json << 'EOF'
{
"namespace": "MyApp",
"composer_name": "mycompany/myapp",
"install_examples": false
}
EOF

# Create project in the same directory
composer -sdev create-project byjg/rest-reference-architecture my-project ^6.0

Example 3: Environment Variable (CI/CD)

# Store config anywhere
cat > /etc/ci-configs/rest-setup.json << 'EOF'
{
"git_user_name": "CI Bot",
"git_user_email": "[email protected]",
"namespace": "AutoDeployApp",
"install_examples": false
}
EOF

# Use it with environment variable
SETUP_JSON=/etc/ci-configs/rest-setup.json composer -sdev create-project byjg/rest-reference-architecture production-app ^6.0

Configuration Options

FieldTypeDefaultDescription
git_user_namestringGlobal git config or "Your Name"Git user name for the project
git_user_emailstringGlobal git config or "[email protected]"Git user email for the project
php_versionstringCurrent PHP versionPHP version (8.3, 8.4, 8.5)
namespacestring"MyRest"Project namespace (CamelCase)
composer_namestring"me/myrest"Composer package name (vendor/package)
db_schemastringmysqlOne of: mysql, postgres, sqlsrv, sqlite
db_hoststringmysql-containerDatabase host/container (ignored for SQLite)
db_userstringrootDatabase username
db_passwordstringmysqlp455w0rdDatabase password
db_name_devstringlocaldevDevelopment database/schema name
db_name_teststringlocaltestTest database/schema name
timezonestring"UTC"Server timezone
install_examplesbooleantrueInclude example code (Dummy, Sample classes)

Legacy compatibility: The older mysql_connection field is still accepted. When present, it will be parsed and used to populate the new database fields automatically, but it is recommended to migrate to the explicit settings above for clarity and to support other drivers.

All Fields Are Optional

If a field is not provided in setup.json, the default value will be used. You can provide only the fields you want to customize:

{
"namespace": "MyCustomApp",
"composer_name": "company/custom-app",
"install_examples": false
}

Priority Order

When multiple setup.json files exist, the script uses the first one found:

  1. SETUP_JSON environment variable → Highest priority
  2. ✅ Parent directory ../setup.json
  3. ✅ Home directory ~/.rest-reference-architecture/setup.json

Example: If you have both a home directory config and use SETUP_JSON, the environment variable wins.

Docker Warning in Unattended Mode

If Docker is not installed, the warning will be displayed, but the setup will continue automatically without waiting for user input.

Interactive Mode

If setup.json does not exist, the setup runs in interactive mode (default behavior) and prompts for all configuration values.

Security Note

The setup.json file is listed in .gitignore to prevent accidentally committing it to version control. If it contains sensitive information, consider adding it to your global gitignore as well.