# Create the Build to be Prefixed

PHP-Prefixer is a Composer (opens new window) based dependency management tool. It allows you to declare the libraries your project depends on and manages (install/update) them for you. For more information about Composer, please, visit https://getcomposer.org/ (opens new window).

The “Getting Started" project is written based on the Composer original documentation, Basic usage / Autoloading (opens new window).

# Prefixing the "Getting Started" Project

In this guide, we’re going to prefix the project "Getting Started" and will prefix it with PPP.

The source code of the project can be found in this repository: https://github.com/PHP-Prefixer/Getting-Started (opens new window)

The results of the prefixing process of the project can be found in this repository: https://github.com/PHP-Prefixer/Getting-Started_prefixed (opens new window)

# The “Getting Started” Project

The project has a simple test to run the Monolog (opens new window) Logger and write a line with a warning message.

This is the composer.json:

{
    "name": "php-prefixer/getting-started",
    "autoload": {
        "psr-4": {"Acme\\": "src/"}
    },
    "require": {
        "monolog/monolog": "1.0.*"
    },
    "extra": {
        "php-prefixer": {
            "project-name": "PHP-Prefixer Getting Started",
            "namespaces-prefix":: "PPP",
            "global-scope-prefix": "PPP_"
        }
    }
}

This is the test a-simple-test.php:

<?php

# File: a-simple-test.php

use Acme\ASimpleLogWarning;

require __DIR__ . '/vendor/autoload.php';

$aSimpleLogWarning = new ASimpleLogWarning();
$aSimpleLogWarning->logWarn();

This is the class ASimpleLogWarning that uses the Monolog/Logger src/ASimpleLogWarning.php:

<?php

# File: src/ASimpleLogWarning.php

namespace Acme;

class ASimpleLogWarning
{
    public function logWarn()
    {
        $log = new \Monolog\Logger('name');
        $log->pushHandler(new \Monolog\Handler\StreamHandler('app.log', \Monolog\Logger::WARNING));
        $log->addWarning('Foo');
    }
}

When the test file is executed: php a-simple-test.php generates a log file app.log with the following sample output:

[2020-10-08 17:40:19] name.WARNING: Foo [] []

# The PHP-Prefixer Configuration

In the composer.json schema, in the extra configuration, the PHP-Prefixer configuration is the following:

    "extra": {
        "php-prefixer": {
            "project-name": "PHP-Prefixer Getting Started",
            "namespaces-prefix":: "PPP",
            "global-scope-prefix": "PPP_"
        },
    }

The configuration declares the project name and the prefix PPP is used for namespaces and global objects (functions, etc.).

# Verify Composer.json

To review the project, download the source code from the repository. Go to the project directory, run the following command to verify the schema, and lock the dependencies of the project that would be distributed:

~$ composer update --no-dev
...
Writing lock file
Generating autoload files
...

Then, compress the files in a new ZIP file. Alternatively, you can download the project's ZIP file from GitHub.

# Create a Build

Now, set up a new Build and prefix the project in the "Dashboard/ Projects” area in a matter of minutes. Follow the steps below to set up a Build and prefix the project ZIP file.

  1. In the “Project,” click on “Create Build,”
  2. Select the file to be prefixed,
  3. Upload and create the Build, and
  4. Click on “Create Build.”

Create a Build

# Validating the Build

Once the Build is created, the PHP-Prefixer service automatically validates the project and continues with the next steps.

Validating the Build

# Prefixing the Build

Once the Build is validated, the PHP-Prefixer service prefixes the files and notifies when the processing is completed.

Prefixing the Build

Congratulations, you’ve prefixed your first project!