为什么 Composer 无法在 Magento2 项目的克隆中设置 CodeSniffer?

发布于 2025-01-15 12:19:47 字数 4556 浏览 4 评论 0原文

我通过bitbucket克隆了一个repo,它是一个Magento2项目。

以下是一些细节:

  • 我在 Windows 环境中使用 ddevdocker
  • 我使用过 Ubuntu v18.04
  • php v7.4.1
  • composer v2

现在,我可以运行 ddev start 并返回三个URL来访问该网站。

但是,当我尝试访问其中每一个时,都会出现此错误:


Warning: require(/var/www/html/vendor/composer/../../app/etc/stores.php): failed to open stream: No such file or directory in /var/www/html/vendor/composer/autoload_real.php on line 82

Fatal error: require(): Failed opening required '/var/www/html/vendor/composer/../../app/etc/stores.php' (include_path='/var/www/html/vendor/magento/zendframework1/library:.:/usr/share/php:/var/www/html/vendor/deployer/recipes') in /var/www/html/vendor/composer/autoload_real.php on line 82

因此,我尝试从 shell (ddev ssh) 及其外部运行 composer install,但没有成功。

我尝试删除 vendor 文件夹并重新运行 composer install,但没有成功。

另外,每次我运行composer install时,它都无法设置CodeSniffer,如下所示:

Generating autoload files
137 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
Failed to set PHP CodeSniffer installed_paths Config

据我了解,问题出在这个autoload_real.php中> vendor/composer/ 文件夹内的文件:

<?php

// autoload_real.php @generated by Composer

class ComposerAutoloaderInit95a846f5f47c0550ba8f462ebc5cc61f
{
    private static $loader;

    public static function loadClassLoader($class)
    {
        if ('Composer\Autoload\ClassLoader' === $class) {
            require __DIR__ . '/ClassLoader.php';
        }
    }

    /**
     * @return \Composer\Autoload\ClassLoader
     */
    public static function getLoader()
    {
        if (null !== self::$loader) {
            return self::$loader;
        }

        require __DIR__ . '/platform_check.php';

        spl_autoload_register(array('ComposerAutoloaderInit95a846f5f47c0550ba8f462ebc5cc61f', 'loadClassLoader'), true, true);
        self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
        spl_autoload_unregister(array('ComposerAutoloaderInit95a846f5f47c0550ba8f462ebc5cc61f', 'loadClassLoader'));

        $includePaths = require __DIR__ . '/include_paths.php';
        $includePaths[] = get_include_path();
        set_include_path(implode(PATH_SEPARATOR, $includePaths));

        $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
        if ($useStaticLoader) {
            require __DIR__ . '/autoload_static.php';

            call_user_func(\Composer\Autoload\ComposerStaticInit95a846f5f47c0550ba8f462ebc5cc61f::getInitializer($loader));
        } else {
            $map = require __DIR__ . '/autoload_namespaces.php';
            foreach ($map as $namespace => $path) {
                $loader->set($namespace, $path);
            }

            $map = require __DIR__ . '/autoload_psr4.php';
            foreach ($map as $namespace => $path) {
                $loader->setPsr4($namespace, $path);
            }

            $classMap = require __DIR__ . '/autoload_classmap.php';
            if ($classMap) {
                $loader->addClassMap($classMap);
            }
        }

        $loader->register(true);

        if ($useStaticLoader) {
            $includeFiles = Composer\Autoload\ComposerStaticInit95a846f5f47c0550ba8f462ebc5cc61f::$files;
        } else {
            $includeFiles = require __DIR__ . '/autoload_files.php';
        }
        foreach ($includeFiles as $fileIdentifier => $file) {
            composerRequire95a846f5f47c0550ba8f462ebc5cc61f($fileIdentifier, $file);
        }

        return $loader;
    }
}

/**
 * @param string $fileIdentifier
 * @param string $file
 * @return void
 */
function composerRequire95a846f5f47c0550ba8f462ebc5cc61f($fileIdentifier, $file)
{
    if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
        $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

        require $file;
    }
}

我尝试的最后一个命令是 composer dump-autoload 但结果是相同的。

所以我需要消除网页中的错误,以便能够正确地看到它,并能够以某种方式设置 CodeSniffer。

为什么会出现这个错误,我该如何解决它?

如果有人能帮忙解决这个问题,那就太好了。谢谢你们。

另外,我已经尝试在全局安装CodeSniffer,但它没有解决问题。

I cloned a repo through bitbucket, it's a Magento2 project.

Here's some specifics:

  • I'm using ddev along with docker in a Windows environment.
  • I've used Ubuntu v18.04
  • php v7.4.1
  • composer v2

Now, I'm able to run ddev start and it returns me three URLs to visit the website.

But when I try to reach each one of them there's this error:


Warning: require(/var/www/html/vendor/composer/../../app/etc/stores.php): failed to open stream: No such file or directory in /var/www/html/vendor/composer/autoload_real.php on line 82

Fatal error: require(): Failed opening required '/var/www/html/vendor/composer/../../app/etc/stores.php' (include_path='/var/www/html/vendor/magento/zendframework1/library:.:/usr/share/php:/var/www/html/vendor/deployer/recipes') in /var/www/html/vendor/composer/autoload_real.php on line 82

So I tried to run composer install both from the shell (ddev ssh) and outside of it, to no success.

I tried to delete vendor folder and re-run composer install, to no success.

Also, everytime I run composer install it fails to set CodeSniffer as shown below:

Generating autoload files
137 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
Failed to set PHP CodeSniffer installed_paths Config

As I seem to understand, the problem is in this autoload_real.php file inside vendor/composer/ folder:

<?php

// autoload_real.php @generated by Composer

class ComposerAutoloaderInit95a846f5f47c0550ba8f462ebc5cc61f
{
    private static $loader;

    public static function loadClassLoader($class)
    {
        if ('Composer\Autoload\ClassLoader' === $class) {
            require __DIR__ . '/ClassLoader.php';
        }
    }

    /**
     * @return \Composer\Autoload\ClassLoader
     */
    public static function getLoader()
    {
        if (null !== self::$loader) {
            return self::$loader;
        }

        require __DIR__ . '/platform_check.php';

        spl_autoload_register(array('ComposerAutoloaderInit95a846f5f47c0550ba8f462ebc5cc61f', 'loadClassLoader'), true, true);
        self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
        spl_autoload_unregister(array('ComposerAutoloaderInit95a846f5f47c0550ba8f462ebc5cc61f', 'loadClassLoader'));

        $includePaths = require __DIR__ . '/include_paths.php';
        $includePaths[] = get_include_path();
        set_include_path(implode(PATH_SEPARATOR, $includePaths));

        $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
        if ($useStaticLoader) {
            require __DIR__ . '/autoload_static.php';

            call_user_func(\Composer\Autoload\ComposerStaticInit95a846f5f47c0550ba8f462ebc5cc61f::getInitializer($loader));
        } else {
            $map = require __DIR__ . '/autoload_namespaces.php';
            foreach ($map as $namespace => $path) {
                $loader->set($namespace, $path);
            }

            $map = require __DIR__ . '/autoload_psr4.php';
            foreach ($map as $namespace => $path) {
                $loader->setPsr4($namespace, $path);
            }

            $classMap = require __DIR__ . '/autoload_classmap.php';
            if ($classMap) {
                $loader->addClassMap($classMap);
            }
        }

        $loader->register(true);

        if ($useStaticLoader) {
            $includeFiles = Composer\Autoload\ComposerStaticInit95a846f5f47c0550ba8f462ebc5cc61f::$files;
        } else {
            $includeFiles = require __DIR__ . '/autoload_files.php';
        }
        foreach ($includeFiles as $fileIdentifier => $file) {
            composerRequire95a846f5f47c0550ba8f462ebc5cc61f($fileIdentifier, $file);
        }

        return $loader;
    }
}

/**
 * @param string $fileIdentifier
 * @param string $file
 * @return void
 */
function composerRequire95a846f5f47c0550ba8f462ebc5cc61f($fileIdentifier, $file)
{
    if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
        $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

        require $file;
    }
}

The last comand I've tried is composer dump-autoload but the result is the same.

So I need to get rid of that error in the webpage, to be able to see it correctly, and be able to set CodeSniffer in some way.

Why this error, and how could I resolve it?

If anyone can help on this, it would be awesome. Thanks guys.

Also, I've already tried to install CodeSniffer globally, but it didn't solve the problem.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怎会甘心 2025-01-22 12:19:47

html 目录运行 vendor/bin/phpcs --config-show
如果 installed_pa​​ths 未列出,或者不正确,请运行以下命令:

vendor/bin/phpcs --config-set installed_paths ../../magento/magento-coding-standard,../../phpcompatibility/php-compatibility

如果上述方法仍然不起作用,这里有一个在 magento 交换中发布的更深入的答案:https://magento.stackexchange.com/a/371402/113483

from the html directory run vendor/bin/phpcs --config-show
If installed_paths is not listed, or is incorrect run the following:

vendor/bin/phpcs --config-set installed_paths ../../magento/magento-coding-standard,../../phpcompatibility/php-compatibility

If the above still doesn't work, here is a more in-depth answer posted in the magento exchange: https://magento.stackexchange.com/a/371402/113483

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文