doufei2662 2017-02-11 22:04
浏览 127
已采纳

Composer autoload_namespaces数组为空,但它正在下载我的包

I am using composer on windows, and it is successfully loading my 2 packages that I'm using from my composer.json file when I perform a composer install or composer update.

{
    "require": {
        "bcosca/fatfree": "dev-master",
        "respect/validation": "^1.1"
    }
}

The first line in my index.php is

require_once __DIR__ . '\vendor\autoload.php';

This didn't seem to be loading anything, a lot of errors related to classes not defined from these 2 packages, for example. I looked into it further and discovered that my autoload_namespaces.php is as follows:

<?php

// autoload_namespaces.php @generated by Composer

$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);

return array(
);

The array is completely empty, how does this happen? I expected to see these 2 packages' requirements in here...

Thanks for the help!

Adding composer.json from the packages themselves: F3:

{
    "name": "bcosca/fatfree",
    "description": "A powerful yet easy-to-use PHP micro-framework designed to help you build dynamic and robust Web applications - fast!",
    "homepage": "http://fatfreeframework.com/",
    "license": "GPL-3.0",
    "require": {
        "php": ">=5.3.6"
    },
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/bcosca/fatfree"
        }
    ],
    "autoload": {
        "files": ["lib/base.php"]
    }
}

Validator:

{
    "name": "respect/validation",
    "description": "The most awesome validation engine ever created for PHP",
    "keywords": ["respect", "validation", "validator"],
    "type": "library",
    "homepage": "http://respect.github.io/Validation/",
    "license": "BSD Style",
    "authors": [
        {
            "name": "Respect/Validation Contributors",
            "homepage": "https://github.com/Respect/Validation/graphs/contributors"
        }
    ],
    "require": {
        "php": ">=5.4",
        "symfony/polyfill-mbstring": "^1.2"
    },
    "require-dev": {
        "egulias/email-validator": "~1.2",
        "malkusch/bav": "~1.0",
        "mikey179/vfsStream": "^1.5",
        "phpunit/phpunit": "~4.0",
        "symfony/validator": "~2.6.9",
        "zendframework/zend-validator": "~2.3"
    },
    "suggest": {
        "ext-bcmath": "Arbitrary Precision Mathematics",
        "ext-mbstring": "Multibyte String Functions",
        "egulias/email-validator": "Strict (RFC compliant) email validation",
        "malkusch/bav": "German bank account validation",
        "symfony/validator": "Use Symfony validator through Respect\\Validation",
        "zendframework/zend-validator": "Use Zend Framework validator through Respect\\Validation",
        "fabpot/php-cs-fixer": "Fix PSR2 and other coding style issues"
    },
    "autoload": {
        "psr-4": {
            "Respect\\Validation\\": "library/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Respect\\Validation\\": "tests/library/"
        }
    },
    "extra": {
        "branch-alias": {
            "dev-master": "1.1-dev"
        }
    },
    "scripts": {
        "test": "./vendor/bin/phpunit"
    }
}

And after loading Validator, this Symfony component came with it:

{
    "name": "symfony/polyfill-mbstring",
    "type": "library",
    "description": "Symfony polyfill for the Mbstring extension",
    "keywords": ["polyfill", "shim", "compatibility", "portable", "mbstring"],
    "homepage": "https://symfony.com",
    "license": "MIT",
    "authors": [
        {
            "name": "Nicolas Grekas",
            "email": "p@tchwork.com"
        },
        {
            "name": "Symfony Community",
            "homepage": "https://symfony.com/contributors"
        }
    ],
    "require": {
        "php": ">=5.3.3"
    },
    "autoload": {
        "psr-4": { "Symfony\\Polyfill\\Mbstring\\": "" },
        "files": [ "bootstrap.php" ]
    },
    "suggest": {
        "ext-mbstring": "For best performance"
    },
    "minimum-stability": "dev",
    "extra": {
        "branch-alias": {
            "dev-master": "1.3-dev"
        }
    }
}
  • 写回答

2条回答 默认 最新

  • dongzhengzhong1282 2017-02-15 16:53
    关注

    The array is completely empty, how does this happen? I expected to see these 2 packages' requirements in here...

    • Composer supports multiple class loading methods. One important implements the PSR4 specification. Symfony and Respect are using PSR4. You can verify it by looking at their composer.json files or your generated vendor/composer/autoload_psr4.php file.

    • Fat-Free Framework lets Composer autoload its lib/base.php file. This is important to know because including base.php twice will throw a PHP Fatal error: Cannot declare class Cache, because the name is already in use. The solution is to let Composer do its job and fetch the $f3 = Base::instance() instead.

    Suggestions

    • Delete the vendor folder and make a clean install with Composer

    • Verify that the class namespaces aren't missing (or are imported) in your code, e.g. \Respect\Validation\Validator instead of Validator

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能