gpt4 book ai didi

php - Composer autoload_namespaces 数组是空的,但它正在下载我的包

转载 作者:可可西里 更新时间:2023-11-01 13:23:52 25 4
gpt4 key购买 nike

我在 Windows 上使用 composer,当我执行 composer installcomposer update .

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

我的 index.php 中的第一行是

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

这似乎没有加载任何东西,例如,很多与未从这 2 个包中定义的类相关的错误。我进一步查看它,发现我的 autoload_namespaces.php 如下:

<?php

// autoload_namespaces.php @generated by Composer

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

return array(
);

数组完全是空的,怎么会这样呢?我希望在这里看到这两个包的要求...

感谢您的帮助!

从包本身添加 composer.json: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"]
}
}

验证器:

{
"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"
}
}

在加载 Validator 之后,这个 Symfony 组件随之而来:

{
"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"
}
}
}

最佳答案

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

  • Composer 支持多种类加载方式。一个重要的实现 PSR4 规范。 SymfonyRespect 使用的是 PSR4。您可以通过查看他们的 composer.json 文件或您生成的 vendor/composer/autoload_psr4.php 文件来验证它。

  • Fat-Free Framework 让 Composer 自动加载它的 lib/base.php 文件。了解这一点很重要,因为包含 base.php 两次会抛出 PHP fatal error :无法声明类缓存,因为该名称已在使用中。解决方案是让 Composer 完成它的工作并取而代之获取 $f3 = Base::instance()

建议

  • 删除 vendor 文件夹并使用 Composer

    进行全新安装
  • 验证您的代码中是否缺少(或导入)类 namespace ,例如\Respect\Validation\Validator 而不是 Validator

关于php - Composer autoload_namespaces 数组是空的,但它正在下载我的包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42181760/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com