Coder Social home page Coder Social logo

Comments (10)

veewee avatar veewee commented on June 19, 2024

The break was removed because both the autoloader from the project as the global autoloader should be loaded. When using normal classes, this isn't be a big problem. But because the assert library is registering functions, this is an issue. The only thing that can be done is adding function_exists() checks before defining the function. This needs to be done in the 3rd party package.

Maybe in your case it is better to install GrumPHP globally? Than it would use the autoloader of the current package + the global autoloader.

from grumphp.

veewee avatar veewee commented on June 19, 2024

@lykciv Does the answer solve your issue? I don't think there is anything we can do about this.

from grumphp.

lykciv avatar lykciv commented on June 19, 2024

Thank you for your feedback. I've installed grumphp globally, but unfortunately it doesn't solve my problem. The project autoloader is still used.

$autoloadLocations = array(
    getcwd() . '/vendor/autoload.php', // package autoloader
    getcwd() . '/../../autoload.php',  // project autoloader
    __DIR__ . '/../vendor/autoload.php', // does not exist
    __DIR__ . '/../../../autoload.php', // global autoloader
);

A possible solution would be to process the local and global autoloaders separately and do something like this:

$autoloadLocations = array(
    getcwd() . '/vendor/autoload.php',
    getcwd() . '/../../autoload.php',

);

$globalAutoloadLocations = array(
    __DIR__ . '/../vendor/autoload.php',
    __DIR__ . '/../../../autoload.php',
);

$loaded = false;
foreach ($autoloadLocations as $autoload) {
    if (is_file($autoload)) {
        require_once($autoload);
        $loaded = true;
        break;
    }
}

foreach ($globalAutoloadLocations as $autoload) {
    if (is_file($autoload)) {
        require_once($autoload);
        $loaded = true;
    }
}

from grumphp.

veewee avatar veewee commented on June 19, 2024

That won't resolve the actual issue:
When you install assert both on the project and global, you will still receive the error.
There isn't anything we can really do about this issue.

One other option could be to add an environment variable like GRUNT_USE_AUTOLOADER to make it possible to specify one or more autoloader files.

from grumphp.

jenssegers avatar jenssegers commented on June 19, 2024

Someone from our team had this issue as well, any news on this?

from grumphp.

veewee avatar veewee commented on June 19, 2024

Currently there is no progress on this issue.

from grumphp.

syslogic avatar syslogic commented on June 19, 2024

the check should be for ! class_exists(), wrapped around the require_once() ... which would prevent duplicate require instructions, which subsequently result in duplicate auto-loading.

from grumphp.

veewee avatar veewee commented on June 19, 2024

There is nothing wrong with duplicate autoloading. It is perfectly possible that you want to load both the globally installed packages + the framework specific packages. For classes this isn't a big issue since composer is smart enough to autoload them. Howerver, it is possible that 2 complete different versions of the same dependency are installed, which might cause errors.

The problem is with functions. Normally the package should check if the function already exists instead of just autoloading the functions. A good example on how to do this: https://github.com/symfony/polyfill-php71/blob/master/bootstrap.php

I would always recommend running grumphp in project mode and remove the globally installed version. It doesn't really add much value when it's installed globally in my opninion.

from grumphp.

syslogic avatar syslogic commented on June 19, 2024

it might depend on the case, if the 2 files are identical whether or not - because if both are the same version, one can already skip on file access. most granular might be an option to prefer global / local classes, if such a use case should exist.

from grumphp.

veewee avatar veewee commented on June 19, 2024

Since the path system got a rewrite in #644 which has better autolaoding support, I am closing this issue for now.
Feel free to test that PR out and validate if it still works on your environment.
A new release will follow soon-ish.
Feel free to open up a new issue if this PR doesn't solve this issue for you.

from grumphp.

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.