Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Debug/DebugClassLoader cannot Load PSR-4 Libs #10771

Copy link
Copy link
Closed
@wodka

Description

@wodka
Issue body actions

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.