Skip to content

Debug/DebugClassLoader cannot Load PSR-4 Libs #10771

@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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy