Skip to content

Debug/DebugClassLoader cannot Load PSR-4 Libs #10771

Closed
@wodka

Description

@wodka

Hi,

I'm having trouble (auto)loading Sylius.
Sylius/Sylius#1411
#10201

Basically the File Path Validation in the DebugClassLoader should work but since it compares the full path and not the subset it fails

Sylius\Component\Cart\SyliusCartEvents vs (...)/vendor/sylius/cart/SyliusCartEvents.php

while in the composer.json the following exists:

"autoload": {
        "psr-4": { "Sylius\\Component\\Resource\\": "" }
    },

I am using the 2.5 Version

To get it working I now added a small Code Snippet:

        if ($file) {
            if ('\\' == $class[0]) {
                $class = substr($class, 1);
            }

            $classPart = $class;

            /*
             * check if this is a PSR-4 based class
             */
            if (method_exists($this->classLoader[0], 'getPrefixesPsr4')){
                $psr4Prefixes = $this->classLoader[0]->getPrefixesPsr4();

                /*
                 * get the psr-4 prefix that was used
                 */
                $psr4PathFinder = function ($class) use ($psr4Prefixes){
                    foreach($psr4Prefixes as $prefix => $path){
                        if(strpos($class, $prefix) !== false){
                            return $prefix;
                        }
                    }

                    return false;
                };

                if(($tmp = $psr4PathFinder($class)) !== false){
                    $classPart = str_replace($tmp, '', $class);
                }
            }


            $i = 0;
            $tail = DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $classPart).'.php';
            $len = strlen($tail);

It is working without errors for the normal autoloader

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions