# 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-joomla-world_prefixed (opens new window)

# The New Composer.json of the Prefixed Joomla module

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

{
    "name": "php-prefixer/hello-prefixed-world-for-joomla",
    "description": "Hello Prefixed World module for Joomla. A module to showcase the PHP-Prefixer service. Install any library freely. PHP-Prefixer will manage your namespaces.",
    "autoload": {
        "classmap": [
            "vendor_prefixed/nesbot/carbon/src/Carbon/Carbon.php",
            "vendor_prefixed/nesbot/carbon/src/Carbon/CarbonConverterInterface.php",
            "vendor_prefixed/nesbot/carbon/src/Carbon/CarbonImmutable.php",
            "vendor_prefixed/nesbot/carbon/src/Carbon/CarbonInterface.php",
            "vendor_prefixed/nesbot/carbon/src/Carbon/CarbonInterval.php",
            "vendor_prefixed/nesbot/carbon/src/Carbon/CarbonPeriod.php",
            "vendor_prefixed/nesbot/carbon/src/Carbon/CarbonTimeZone.php",
            "vendor_prefixed/nesbot/carbon/src/Carbon/Cli/Invoker.php",
            "vendor_prefixed/nesbot/carbon/src/Carbon/Doctrine/CarbonDoctrineType.php",
            "vendor_prefixed/nesbot/carbon/src/Carbon/Doctrine/CarbonImmutableType.php",
            "vendor_prefixed/nesbot/carbon/src/Carbon/Doctrine/CarbonType.php",
...
            "vendor_prefixed/doctrine/inflector/lib/Doctrine/Inflector/CachedWordInflector.php",
            "vendor_prefixed/doctrine/inflector/lib/Doctrine/Inflector/GenericLanguageInflectorFactory.php",
            "vendor_prefixed/doctrine/inflector/lib/Doctrine/Inflector/Inflector.php",
            "vendor_prefixed/doctrine/inflector/lib/Doctrine/Inflector/InflectorFactory.php",
            "vendor_prefixed/doctrine/inflector/lib/Doctrine/Inflector/Language.php",
...
            "vendor_prefixed/illuminate/contracts/Auth/Access/Gate.php",
            "vendor_prefixed/illuminate/contracts/Auth/Authenticatable.php",
            "vendor_prefixed/illuminate/contracts/Auth/CanResetPassword.php",
            "vendor_prefixed/illuminate/contracts/Auth/Factory.php",
            "vendor_prefixed/illuminate/contracts/Auth/Guard.php",
...
            "src/Helper.php",
            "vendor_prefixed/psr/container/src/ContainerExceptionInterface.php",
            "vendor_prefixed/psr/container/src/ContainerInterface.php",
            "vendor_prefixed/psr/container/src/NotFoundExceptionInterface.php",
            "vendor_prefixed/psr/simple-cache/src/CacheException.php",
            "vendor_prefixed/psr/simple-cache/src/CacheInterface.php",
            "vendor_prefixed/psr/simple-cache/src/InvalidArgumentException.php",
            "vendor_prefixed/symfony/polyfill-php80/Resources/stubs/Stringable.php",
            "vendor_prefixed/symfony/translation/Catalogue/AbstractOperation.php",
            "vendor_prefixed/symfony/translation/Catalogue/MergeOperation.php",
            "vendor_prefixed/symfony/translation/Catalogue/OperationInterface.php",
            "vendor_prefixed/symfony/translation/Catalogue/TargetOperation.php",
            "vendor_prefixed/symfony/translation/Command/XliffLintCommand.php",
...
            "vendor_prefixed/symfony/polyfill-php80/Php80.php",
            "vendor_prefixed/symfony/polyfill-php80/Resources/stubs/UnhandledMatchError.php",
            "vendor_prefixed/symfony/polyfill-php80/Resources/stubs/ValueError.php",
            "vendor_prefixed/voku/portable-ascii/src/voku/helper/ASCII.php"
        ],
        "files": [
            "vendor_prefixed/symfony/polyfill-mbstring/bootstrap.php",
            "vendor_prefixed/symfony/polyfill-php80/bootstrap.php",
            "vendor_prefixed/illuminate/collections/helpers.php",
            "vendor_prefixed/illuminate/support/helpers.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 conflict will be found, if there were others modules installed using the Carbon, Doctrine, Illuminate or Symfony namespaces.

# The Prefixed Module

The project file src\Helper.php has been processed, and the prefix PPP added to the Carbon dependency call:

// The modified version of the Hello World module shows a formatted date before the message
use PPP\Carbon\Carbon;

class Helper
{
    /**
     * Retrieves the hello message
     *
     * @param   array  $params An object containing the module parameters
     *
     * @access public
     */
    public static function getHello($params)
    {
        $now = Carbon::now();
        $formattedDate = $now->toDateTimeString();

        return $formattedDate.' / Hello, World!';
    }
}

# The Prefixed Dependencies

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

# The Prefixed Doctrine Inflector

<?php /* This file has been prefixed by <PHP-Prefixer> for "Hello Prefixed World for Joomla" */

declare(strict_types=1);

namespace PPP\Doctrine\Inflector;

use RuntimeException;
use function chr;
use function function_exists;
use function lcfirst;
use function mb_strtolower;
use function ord;
use function preg_match;
use function preg_replace;
use function sprintf;
use function str_replace;
use function strlen;
use function strtolower;
use function strtr;
use function trim;
use function ucwords;

class Inflector
{

# The Prefixed Laravel Support Helpers

/* This file has been prefixed by <PHP-Prefixer> for "Hello Prefixed World for Joomla" */

use PPP\Illuminate\Contracts\Support\DeferringDisplayableValue;
use PPP\Illuminate\Contracts\Support\Htmlable;
use PPP\Illuminate\Support\Arr;
use PPP\Illuminate\Support\Env;
use PPP\Illuminate\Support\HigherOrderTapProxy;
use PPP\Illuminate\Support\Optional;

if (! function_exists('PPP_append_config')) {
    /**
     * Assign high numeric IDs to a config item to force appending.
     *
     * @param  array  $array
     * @return array
     */
    function PPP_append_config(array $array)
    {
        $start = 9999;

        foreach ($array as $key => $value) {
            if (is_numeric($key)) {
                $start++;

                $array[$start] = Arr::pull($array, $key);
            }
        }

        return $array;
    }
}
...
if (! function_exists('PPP_env')) {
    /**
     * Gets the value of an environment variable.
     *
     * @param  string  $key
     * @param  mixed  $default
     * @return mixed
     */
    function PPP_env($key, $default = null)
    {
        return Env::get($key, $default);
    }
}
...

# The Prefixed Carbon Library

<?php
/* This file has been prefixed by <PHP-Prefixer> for "Hello Prefixed World for Joomla" */

/**
 * This file is part of the Carbon package.
 *
...
 */
namespace PPP\Carbon;

use PPP\Carbon\Traits\Date;
use DateTime;
use DateTimeInterface;
use DateTimeZone;

/**
 * A simple API extension for DateTime.
 *
...
 */
class Carbon extends DateTime implements CarbonInterface
{
    use Date;

    /**
     * Returns true if the current class/instance is mutable.
     *
     * @return bool
     */
    public static function isMutable()
    {
        return true;
    }
}

# The Polyfills

The Polyfills libraries are excluded from processing by the prefixer.

// vendor_prefixed/symfony/polyfill-php80/Resources/stubs/Stringable.php
interface Stringable
{
    /**
     * @return string
     */
    public function __toString();
}

# The Prefixed Portable ASCII

<?php /* This file has been prefixed by <PHP-Prefixer> for "Hello Prefixed World for Joomla" */

declare(strict_types=1);

namespace PPP\voku\helper;

/**
 * @psalm-immutable
 */
final class ASCII
{

# Conclusion

In this guide, we presented a simple Joomla module Hello Prefixed World module for Joomla.

The module is based on the Hello World (opens new window) module. To integrate a Composer dependency, we install the Laravel illuminate/support (opens new window) library and use it to show a formatted date before the Hello World message.

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 functional module, ready to be distributed and installed.

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