# 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.