Using spl_autoload_register and composer autoloading together

I have a legacy app that uses spl_autload

to load classes (they have no namespace)

<?php

spl_autoload_extensions('.class.php,.php');

set_include_path(
    $listOfDir
);

spl_autoload_register();

// require composer autoloader
// can't place that line before the call spl_autoload_register without breaking everything.
require __DIR__ . "/../vendor/autoload.php";

      

Recently, we have presented the components of the composer and the Symfony container

, dependency-injection

and config

.

I'm trying to get the camelcase class to be loaded through composer (all new classes use camelcase cases to identify new and old code) without causing BC breaks.

Do you have a clue on how to do this? Should new classes have a namespace?

PS: The new classes will be distributed across "tons" of folders. Project size - 700,000 LOC.

+3


source to share


1 answer


So what I did was to put the new class in a folder src/

, add a namespace and add PSR-4

inside composer.json.

Since spl_autoload doesn't work with camelcase classes I'm fine. :-)



"autoload": {
    "psr-4": {
        "MyNamespace\\NotLegacy\\": "src/"
    }
}

      

+2


source







All Articles