# Review the Prefixed PHP Project

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

# The New Composer.json of the Prefixed PrestaShop Module

The PHP-Prefixed process has produced a new composer.json schema and contains the original files, and file that are re-organized according to the applied PPP prefix.

{
    "name": "php-prefixer/hello-prestashop-products",
    "description": "Hello PrestaShop Products module. A module to showcase the PHP-Prefixer service. Install any library freely. PHP-Prefixer will manage your namespaces.",
    "type": "prestashop-module",
    "license": "MIT",
    "config": {
        "preferred-install": "dist"
    },
    "autoload": {
        "classmap": [
            "src/AlternativeDescription.php",
            "src/Hooks.php",
            "src/ProductsCollection.php",
            "vendor_prefixed/symfony/polyfill-php80/Resources/stubs/Stringable.php",
            "vendor_prefixed/symfony/var-dumper/Caster/AmqpCaster.php",
            "vendor_prefixed/symfony/var-dumper/Caster/ArgsStub.php",
            "vendor_prefixed/symfony/var-dumper/Caster/Caster.php",
            "vendor_prefixed/symfony/var-dumper/Caster/ClassStub.php",
            "vendor_prefixed/symfony/var-dumper/Caster/ConstStub.php",
...
            "vendor_prefixed/symfony/polyfill-mbstring/Mbstring.php",
            "vendor_prefixed/symfony/polyfill-php72/Php72.php",
            "vendor_prefixed/symfony/polyfill-php80/Php80.php",
            "vendor_prefixed/tightenco/collect/src/Collect/Contracts/Support/Arrayable.php",
            "vendor_prefixed/tightenco/collect/src/Collect/Contracts/Support/Htmlable.php",
            "vendor_prefixed/tightenco/collect/src/Collect/Contracts/Support/Jsonable.php",
            "vendor_prefixed/tightenco/collect/src/Collect/Support/Arr.php",
            "vendor_prefixed/tightenco/collect/src/Collect/Support/Collection.php",
            "vendor_prefixed/tightenco/collect/src/Collect/Support/HigherOrderCollectionProxy.php",
            "vendor_prefixed/tightenco/collect/src/Collect/Support/HtmlString.php",
            "vendor_prefixed/tightenco/collect/src/Collect/Support/Traits/Macroable.php",
            "vendor_prefixed/symfony/polyfill-php80/Resources/stubs/UnhandledMatchError.php",
            "vendor_prefixed/symfony/polyfill-php80/Resources/stubs/ValueError.php"
        ],
        "files": [
            "vendor_prefixed/symfony/polyfill-mbstring/bootstrap.php",
            "vendor_prefixed/symfony/polyfill-php72/bootstrap.php",
            "vendor_prefixed/symfony/polyfill-php80/bootstrap.php",
            "vendor_prefixed/symfony/var-dumper/Resources/functions/dump.php",
            "vendor_prefixed/tightenco/collect/src/Collect/Support/helpers.php",
            "vendor_prefixed/tightenco/collect/src/Collect/Support/alias.php"
        ]
    }
}

The files of the dependencies are stored in the vendor_prefixed folder. composer.json declares them in the classmap and files attributes to generate the autoloader.

No conflicts will be found if other modules were installed using the Symfony or Tightenco namespaces.

# The Prefixed Module

The project file src/ProductsCollection.php has been processed and the prefix PPP added to the Tightenco dependency call:

namespace PsProducts;

use PPP\Tightenco\Collect\Support\Collection;

/**
 * Manage a ProductsCollection instead of a collection of Products array.
 */
class ProductsCollection extends Collection
{
}

# The Prefixed Dependencies

The original libraries installed in the vendor folder have been prefixed and updated. These are a few examples:

# The Tightenco Collection

<?php
/* This file has been prefixed by <PHP-Prefixer> for "Hello PrestaShop Products" */

namespace PPP\Tightenco\Collect\Support;

use stdClass;
use Countable;
use Exception;
use ArrayAccess;
use Traversable;
use ArrayIterator;
use CachingIterator;
use JsonSerializable;
use IteratorAggregate;
use PPP\Tightenco\Collect\Support\Traits\Macroable;
use PPP\Tightenco\Collect\Contracts\Support\Jsonable;
use PPP\Symfony\Component\VarDumper\VarDumper;
use PPP\Tightenco\Collect\Contracts\Support\Arrayable;

...
class Collection implements ArrayAccess, Arrayable, Countable, IteratorAggregate, Jsonable, JsonSerializable
{
    use Macroable;

# The Prefixed Symfony VarDumper Component

...

namespace PPP\Symfony\Component\VarDumper;

use PPP\Symfony\Component\VarDumper\Caster\ReflectionCaster;
use PPP\Symfony\Component\VarDumper\Cloner\VarCloner;
use PPP\Symfony\Component\VarDumper\Dumper\CliDumper;
use PPP\Symfony\Component\VarDumper\Dumper\ContextProvider\SourceContextProvider;
use PPP\Symfony\Component\VarDumper\Dumper\ContextualizedDumper;
use PPP\Symfony\Component\VarDumper\Dumper\HtmlDumper;

...
class VarDumper
{
...

# The FIG Standards and Polyfills

The libraries defined by the FIG standards and polyfills are excluded from processing by the prefixer.

...

namespace Symfony\Polyfill\Php80;

...
final class Php80
{
    public static function fdiv(float $dividend, float $divisor): float
    {
        return @($dividend / $divisor);
    }
...

# Conclusion

In this guide, we presented a simple PrestaShop module Hello PrestaShop Products Module.

The module is based on the Friends of Presta/products (opens new window) module, and uses the tightenco/collect (opens new window) library to integrate the Illuminate Collections library.

In the guide, we introduced the original project, the prefixed project, and the different prefixing cases. These have been successfully processed to produce a complete function module, ready to be distributed and installed.

To keep the tutorial short and straightforward we didn't integrate the Laravel illuminate/support (opens new window) library.

In the following guide, we will use Laravel illuminate/support in PrestaShop using PHP-Prefixer.