# Command-Line

The PHP-Prefixer (opens new window) service has a command-line (CLI) that empowers you to use the service locally and process the project source code from your workstation.

The command calls the PHP-Prefixer service using the REST API (opens new window) to submit a project source code, apply the prefixes, wait and download the results.

The PHP-Prefixer CLI is available here: https://github.com/PHP-Prefixer/php-prefixer-cli (opens new window).

# How to install the CLI?

You can install the CLI using two ways:

The preferred installation method is with the PHP Prefixer CLI PHAR. You can download the latest PHAR from the most recent Github Releases (opens new window). After downloading it, copy the file into a directory on your local path and assign the execution permissions to run the following commands.

# 2. Install via Composer - Only For Development

Alternatively, you can install PHP-Prefixer CLI globally with Composer:

composer global require php-prefixer/php-prefixer-cli

The source code is available here: https://github.com/PHP-Prefixer/php-prefixer-cli (opens new window)

# Usage

To use the CLI, you must create an account on PHP-Prefixer (opens new window) and prepare your projects with the prefix definition in the composer.json schema.

Before using the command-line, we recommend checking the documentation and guides here: https://php-prefixer.com/docs/ (opens new window)

The CLI requires four parameters to function, and it can receive an additional parameter for GitHub integration:

Parameter Description
source-directory * The project source directory
target-directory * The target directory where the results are stored
personal-access-token* The personal access token, generated on PHP-Prefixer (opens new window) Settings
project-id * The identification of the configured project on PHP-Prefixer (opens new window) Projects
--github-access-token An optional GitHub token to access ´composer.json´ dependencies that are managed in private repositories
# Sample command-line
./php-prefixer-cli prefix \
    /sample/acme_project \
    /output/prefixed_project \
    "789|1234567890123456789012345678901234567890" \
    123456 \
    --github-access-token=1234567890123456789012345678901234567890

# Environment Variables

The CLI supports the definition of the parameters as environment variables in a project .env file.

# PHP Prefixer CLI - Sample .env

# Note: the .env file must be located in the php-prefixer-cli.phar directory

# Source Directory: The project source directory
SOURCE_DIRECTORY="/sample/acme_project"

# Target Directory: The target directory where the results are stored
TARGET_DIRECTORY="/output/prefixed_project"

# Personal Access Token: The personal access token, generated on PHP-Prefixer Settings
PERSONAL_ACCESS_TOKEN="789|1234567890123456789012345678901234567890"

# Project ID: The identification of the configured project on PHP-Prefixer Projects
PROJECT_ID="123456"

# GitHub Access Token:  An optional GitHub token to access composer.json dependencies that are managed in private repositories.
GITHUB_ACCESS_TOKEN="1234567890123456789012345678901234567890"

# Command-Line Development

If you want to customize the command-line or help us in the development, please, check the following steps:

Step 1: Clone the project:

  git clone https://github.com/php-prefixer/php-prefixer-cli

Step 2: Go to the project directory:

cd php-prefixer-cli

Step 3: Install dependencies:

composer update

Step 4: Build the PHAR:

./php-prefixer-cli app:build

Step 5: To run tests, execute the following command:

phpunit

# Contributing

The current CLI is a starting point to prefix PHP code. If you want to improve the current commmand-line, contributions are always welcome!

See CONTRIBUTING.md (opens new window) for ways to get started.

# Security

If you discover a security vulnerability within this package, please email to Tech Team at team@php-prefixer.com. We address all security vulnerabilities promptly.

# License

MIT (opens new window)

# Authors

Last Updated: 12/19/2023, 9:07:55 AM