Code Monkey home page Code Monkey logo

Comments (17)

Hywan avatar Hywan commented on June 19, 2024

Hoa's autoloader runs if Composer's one failed. Can you confirm that?

from core.

jubianchi avatar jubianchi commented on June 19, 2024

@Hywan I think the fail here is that when Hoa fails to load a class, it forwards the autoloader call to composer but it does not forward it the same way it received it. Taking a look at the stack trace:

  • We got a call to spl_autoload_call('HTMLPurifier_Bootstrap')
  • This call gets handled by Hoa: Consistency::autoload('HTMLPurifier_Bootstrap')
  • Hoa tries to load HTMLPurifier.Bootstrap: Consistency->_import('HTMLPurifier.Bootstrap', true) (Hoa/Core/Consistency.php:335)
  • Hoa does not find the class and it forwards the SPL autoloader: spl_autoload_call('HTMLPurifier\Bootstrap') (Hoa/Core/Consistency.php:288)

The last forward shows that the original class name has been modified from HTMLPurifier_Bootstrap to HTMLPurifier\Bootstrap

from core.

UFOMelkor avatar UFOMelkor commented on June 19, 2024

When I remove the first entry of my autoload_files.php the class will be loaded correctly:

return array(
    $vendorDir . '/hoa/core/Hoa/Core/Core.php',
    $vendorDir . '/swiftmailer/swiftmailer/lib/swift_required.php',
    $vendorDir . '/symfony/symfony/src/Symfony/Component/Intl/Resources/stubs/functions.php',
    $vendorDir . '/kriswallsmith/assetic/src/functions.php',
    $vendorDir . '/ezyang/htmlpurifier/library/HTMLPurifier.composer.php',
    $vendorDir . '/beberlei/assert/lib/Assert/functions.php',
);

Otherwise the error appears. Unfortunately I can't provide a minimal example in a quick way, but I'll investigate time in the next days.

from core.

Hywan avatar Hywan commented on June 19, 2024

This PSR-0 vs. PSR-4. Hoa's autoloader is PSR-0 so it transforms _ into \ as the recommandation asks. In PSR-4, it has changed: _ has no longer any meaning.

from core.

Hywan avatar Hywan commented on June 19, 2024

No sorry, Hoa's autoloader is PSR-4 but for _, it works like PSR-0. So, what do we do? We propose a patch to be fully PSR-4 and remove everything from PSR-0?

from core.

Hywan avatar Hywan commented on June 19, 2024

Also, @UFOMelkor, why Composer does not handle your class?

from core.

jubianchi avatar jubianchi commented on June 19, 2024

@Hywan you can't blindly replace _ by \ because the class with \ does not exist. To handle this, composer will likely use a classmap strategy.

from core.

Hywan avatar Hywan commented on June 19, 2024

@jubianchi I replaced _ by \ because this is what PSR-0 required!

Each _ character in the CLASS NAME is converted to a DIRECTORY_SEPARATOR. The _ character has no special meaning in the namespace.

This is why we have added the 436f30f commit.

Also, Hoa's autoloader runs if and only if Composer has dropped. So, why Hoa's autoloader runs? Why Composer drops?

from core.

jubianchi avatar jubianchi commented on June 19, 2024

@Hywan PSR-0 never said that autoloader should replace _ with NS_SEPARATOR : if it did, it's a fail as this can not work.

The only thinkg I see is the following:

$fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';

Which is OK. DIRECTORY_SEPARATOR is different from \ which is NS_SEPARATOR and this is not Hoa's responsibility to do that: the only component allowed to do that is the one which knows how to resolve the path from the classname.

from core.

Hywan avatar Hywan commented on June 19, 2024

@jubianchi _ is converted into DIRECTORY_SEPARATOR, which is equivalent to say that: _ is converted into NAMESPACE_SEPARATOR and then (because this is PSR-0 or 4), NAMESPACE_SEPARATOR is converted into DIRECTORY_SEPARATOR. This is strictly identical, no?

from core.

jubianchi avatar jubianchi commented on June 19, 2024

@Hywan no it's not : when your replace character in class name, you create a bug : classes using _ notation won't always use PSR-0 directory structure.

I think that you should not do such assumption and just forward the autoloader call as you received it when you can't handle it.

from core.

Hywan avatar Hywan commented on June 19, 2024

The issue is still open. Why Composer does not handle that class?

from core.

UFOMelkor avatar UFOMelkor commented on June 19, 2024

I created a minimal example using symfony2. Perhaps anyone might have a look, I want have much time the next days.

What I did: I created a simple bundle and I added the Exercise/HTMLPurifierBundle and PhpMetrics to composer and activated the first one.

from core.

jubianchi avatar jubianchi commented on June 19, 2024

@Hywan autoloader files (which is how hoa/core works with composer) are called first, before the composer PSR autoloaders that's why this is not working: hoa is called first, does not find the requested class (HTMLPurifier_Bootstrap), changes its name (HTMLPurifier\Bootstrap), forwards the call to composer with the wrong classname.

from core.

Hywan avatar Hywan commented on June 19, 2024

@jubianchi So a solution is to remove this piece of code and everything will be ok. We assume that Hoa's autoloader is PSR-4 and voilà?

from core.

Hywan avatar Hywan commented on June 19, 2024

@UFOMelkor Could you test with #52 please?

from core.

UFOMelkor avatar UFOMelkor commented on June 19, 2024

Looks good 👍

from core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.